tree: 6932996749ebf85736b94df1cdb06a6b04cdce60 [path history] [tgz]
  1. README.md
  2. __init__.py
  3. ac_power.py
  4. accelerometers.py
  5. accelerometers_calibration.py
  6. accelerometers_lid_angle.py
  7. audio.py
  8. audio_basic.py
  9. audio_diagnostic.py
  10. audio_diagnostic_static/
  11. audio_loop.py
  12. audio_loop_static/
  13. audio_quality.py
  14. audio_quality_static/
  15. backlight.py
  16. bad_blocks.py
  17. bad_blocks_static/
  18. battery.py
  19. battery_basic.py
  20. battery_current.py
  21. battery_cycle.py
  22. battery_cycle_static/
  23. battery_sysfs.py
  24. bft_fixture.py
  25. blocking_charge.py
  26. blocking_charge_static/
  27. bluetooth.py
  28. bluetooth_host.py
  29. brightness/
  30. button.py
  31. buzzer.py
  32. camera.py
  33. camera_static/
  34. cellular_switch_firmware.py
  35. chameleon.py
  36. chameleon_static/
  37. charger.py
  38. check_cr50_board_id.py
  39. check_image_version.py
  40. check_serial_number.py
  41. compass.py
  42. compass_static/
  43. countdown.py
  44. countdown_static/
  45. display.py
  46. display_images.py
  47. display_images_static/
  48. display_point.py
  49. display_point_static/
  50. display_static/
  51. dsm_calibration.py
  52. ethernet.py
  53. exec_python.py
  54. exec_shell.py
  55. exec_shell_static/
  56. external_display.py
  57. external_display_static/
  58. factory_state.py
  59. factory_state_unittest.py
  60. fan_speed.py
  61. fan_speed_static/
  62. fastboot_flash.py
  63. finalize.py
  64. fingerprint_mcu.py
  65. flash_netboot.py
  66. gps.py
  67. gyroscope.py
  68. gyroscope_calibration.py
  69. hwid.py
  70. interrupt.py
  71. keyboard.py
  72. keyboard_backlight.py
  73. keyboard_smt.py
  74. keyboard_smt_static/
  75. keyboard_static/
  76. led.py
  77. led_static/
  78. lid_switch.py
  79. light_sensor.py
  80. light_sensor_calibration.json
  81. light_sensor_calibration.py
  82. light_sensor_calibration.schema.json
  83. light_sensor_calibration_static/
  84. light_sensor_static/
  85. lightbar.py
  86. line_check_item.py
  87. lte_verify_config.py
  88. memory_size.py
  89. message.py
  90. model_sku.json
  91. model_sku.py
  92. model_sku.schema.json
  93. model_sku_static/
  94. modem_security.py
  95. mrc_cache.py
  96. network_setup/
  97. nop.py
  98. offline_test/
  99. partition_table.py
  100. pd_fw_min_version.py
  101. ping_test.py
  102. plankton_cc2_pull_test.py
  103. plankton_cc_flip_check.py
  104. plankton_charge.py
  105. plankton_display.py
  106. plankton_display_static/
  107. power_under_stress.py
  108. probe/
  109. probe_cellular_info.py
  110. probe_cellular_info_unittest.py
  111. probe_sim.py
  112. probe_sim_card_tray.py
  113. read_device_data_from_vpd.py
  114. removable_storage.py
  115. removable_storage_static/
  116. retrieve_config.py
  117. retrieve_parameter.py
  118. retrieve_parameter_static/
  119. rf_graphyte/
  120. robot_movement.py
  121. robot_movement_unittest.py
  122. sample_customized_test.py
  123. sar_proximity_sensor.py
  124. scan.py
  125. select_for_sampling.py
  126. serial_echo.py
  127. serial_echo_unittest.py
  128. shopfloor_service.py
  129. shutdown.py
  130. spatial_sensor_calibration.py
  131. start.py
  132. station_entry.py
  133. station_entry_unittest.py
  134. station_setup.py
  135. station_setup_static/
  136. storage_simple_stress.py
  137. stressapptest.py
  138. stylus.py
  139. stylus_static/
  140. summary.py
  141. summary_static/
  142. suspend_resume.py
  143. sync_factory_server.py
  144. sync_factory_server_static/
  145. sync_time.py
  146. tablet_mode.py
  147. tablet_mode_static/
  148. tablet_rotation.py
  149. tablet_rotation_static/
  150. thermal_load.py
  151. thermal_sensors.py
  152. thermal_slope.py
  153. touch_device_fw_update.py
  154. touch_uniformity.py
  155. touchpad.py
  156. touchpad_hover.py
  157. touchpad_static/
  158. touchscreen.py
  159. touchscreen_calibration/
  160. touchscreen_static/
  161. tpm_clear_owner.py
  162. tpm_diagnosis.py
  163. tpm_verify_ek.py
  164. update_cr50_firmware.py
  165. update_device_data.py
  166. update_device_data_static/
  167. update_firmware.py
  168. update_fpmcu_firmware.py
  169. update_kernel.py
  170. update_sku.py
  171. urandom.py
  172. usb.py
  173. verify_component.py
  174. verify_component_static/
  175. verify_root_partition.py
  176. video_playback.py
  177. video_playback_static/
  178. vswr/
  179. vsync.py
  180. wait_external_test.py
  181. wait_fixture_ready.py
  182. webgl_aquarium.py
  183. webgl_aquarium_static/
  184. whale_check_voltage.py
  185. whale_cover.py
  186. wifi_check_calibration.py
  187. wifi_throughput.py
  188. wireless_antenna.py
  189. write_device_data_to_vpd.py
  190. write_protect_switch.py
py/test/pytests/README.md

Chrome OS Reference Python Factory Tests

This folder contains all reference factory tests for Chrome OS Factory Software.

For more details of individual test, please look at the SDK document or read the source of individual tests.

Pytest Overview

Take start.py as an example, a pytest should contain 4 sections.

  • Copyright header
  • Test documentation
  • Imports
  • Implementation

Copyright header

Always add copyright header to the beginning of the file.

# Copyright 2018 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

2018 is year of file created date.

Test Documentation

To help both developers and non-developers understand better how these tests works, how to use it and what's needed to make it run, we have defined a template for documentation. The tests will be processed by Sphinx Documentation, so you just need to write the module doc string in reStructedText format with following sections:

"""Test summary here.

Description
-----------
A section for who wants to know what this test is, and how to use it.

You probably want to write the first section as a general description, and
remaining sections to explain more details, and how to assign the arguments
if the test arguments are pretty complicated (or try using a JSON configuration
via `config_utils` instead).

Test Procedure
--------------
Write "This is an automated test without user interaction." as first line if
the test does not need user interaction.

This is a section as "reference to write SOP for operators". Use simpler words
and abstraction of what will happen.

Dependency
----------
This is a section about "what people will need when they want to port the test
for a new platform, for example Android or even Windows.

Try to list everything needed outside Chrome OS factory repo, especially
kernel and driver dependency.

If you are using Device API (`cros.factory.device.*`), try to list the explicit
API you are using, with few typical dependency that it needs.

Examples
--------
Examples of how to use this test (in test list). Usually we want a "minimal" one
explaining what default behavior it will do, with few more examples to
demonstrate how to use the arguments.
"""

To preview your changes to doc, run make doc in chroot and browse build/doc/pytests/index.html.

For more examples on how to write these docs and how they looks on SDK site, try to look at following tests:

Imports

Import lines are organized in 3 categories:

  • Standard python libraries, e.g. import os
  • Third-party modules, e.g. import jsonlibrpc
  • ChromeOS Factory modules

import factory_common # pylint: disable=unused-import injects cros.factory namespace, so the following from cros.factory.... lines could work.

Implementation

All pytests are a python class inherits test_case.TestCase, which is a subclass of unittest.TestCase from Python unittest module. When a pytest is executed, the following functions will be called (in exact order):

  1. setUp()
  2. runTest()
  3. tearDown()

Writing a new test

All the tests must have implementation file named in lowercase_with_underline style and the Python class named in CamelCase style, following PEP-8 and Chrome OS Factory Coding Style. You can write test as a single Python file like start.py, or implement it as Python package in its own folder like probe/.

To use your test (say mytest.py), define an entry in test list:

  {
    "pytest_name": "mytest"
  }

Using arguments

To read arguments specified from test list, use cros.factory.utils.arg_utils.Arg by adding declarations as class variable. For example:

  ARGS = [Arg('wait_secs', int, 'Wait for N seconds.', default=0)]

Then you can use this by reading self.args.wait_secs.

Since JSON serialization doesn‘t support tuple type, new pytests shouldn’t use tuple in argument type, and should use list instead.

Schema validation

If the argument is complicated, you may want to define a schema rule to validate the structure of the schema. For example:

  Arg(..., schema=schema_object)

The schema object should be one of the schema classes defined in schema.py. Then the argument value would automatically be validated with the schema rule.

You can check tablet_rotation.py as an example usage.

Using user interface

The Chrome OS Factory Software provides a web based user interface. The test UI object will be injected to test instance as self.ui. Read Test UI API for more details.