tree: 70c5098797949dbdbd19a4775bdb0048645f33bf [path history] [tgz]
  1. accelerometers_lid_angle_static/
  2. audio_diagnostic_static/
  3. audio_loop_static/
  4. audio_quality_static/
  5. bad_blocks_static/
  6. battery_cycle_static/
  7. blocking_charge_static/
  8. brightness/
  9. camera_static/
  10. chameleon_static/
  11. compass_static/
  12. countdown_static/
  13. display_images_static/
  14. display_interactive/
  15. display_point_static/
  16. display_static/
  17. download_from_factory_drive_static/
  18. exec_shell_static/
  19. external_display_static/
  20. fan_speed_static/
  21. fingerprint_mcu_static/
  22. gyroscope_angle_static/
  23. gyroscope_static/
  24. keyboard_smt_static/
  25. keyboard_static/
  26. led_static/
  27. light_sensor_calibration_static/
  28. light_sensor_static/
  29. model_sku_static/
  30. mouse_static/
  31. network_setup/
  32. plankton_display_static/
  33. probe/
  34. proximity_sensor_static/
  35. removable_storage_static/
  36. rf_graphyte/
  37. station_setup_static/
  38. stylus_static/
  39. summary_static/
  40. sync_factory_server_static/
  41. tablet_mode_static/
  42. tablet_rotation_static/
  43. touchpad_static/
  44. touchscreen_calibration/
  45. touchscreen_static/
  46. update_device_data_static/
  47. verify_component_static/
  48. video_playback_static/
  49. vswr/
  50. webgl_aquarium_static/
  51. __init__.py
  52. ac_power.py
  53. accelerometers.py
  54. accelerometers_calibration.py
  55. accelerometers_lid_angle.py
  56. audio.py
  57. audio_basic.py
  58. audio_diagnostic.py
  59. audio_loop.py
  60. audio_loop_unittest.py
  61. audio_quality.py
  62. backlight.py
  63. bad_blocks.py
  64. battery.py
  65. battery_basic.py
  66. battery_current.py
  67. battery_cycle.py
  68. battery_sysfs.py
  69. bcic.py
  70. bft_fixture.py
  71. blocking_charge.py
  72. bluetooth.py
  73. bluetooth_host.py
  74. branded_chassis.py
  75. branded_chassis_unittest.py
  76. button.py
  77. buzzer.py
  78. camera.py
  79. camera_unittest.py
  80. cec.py
  81. cellular_switch_firmware.py
  82. charger.py
  83. check_cr50_board_id.py
  84. check_image_version.py
  85. check_release_lvm_stateful.py
  86. check_retimer_firmware.py
  87. check_secdata_version.py
  88. check_serial_number.py
  89. check_test_list.py
  90. clear_inactive_gsc_slot.py
  91. compass.py
  92. copy_minios.py
  93. countdown.py
  94. cr50_ap_ro_hash.py
  95. cr50_ap_ro_verification.py
  96. display.py
  97. display_images.py
  98. display_point.py
  99. download_from_factory_drive.py
  100. dsm_calibration.py
  101. edp_panel_timing.py
  102. ethernet.py
  103. exec_python.py
  104. exec_shell.py
  105. external_display.py
  106. factory_state.py
  107. factory_state_unittest.py
  108. fan_speed.py
  109. feature_compliance_version.py
  110. finalize.py
  111. finalize_unittest.py
  112. fingerprint_mcu.py
  113. flash_netboot.py
  114. get_intel_desc_status.py
  115. gyroscope.py
  116. gyroscope_angle.py
  117. gyroscope_calibration.py
  118. hps.py
  119. hwid.py
  120. keyboard.py
  121. keyboard_backlight.py
  122. keyboard_smt.py
  123. keyboard_unittest.py
  124. led.py
  125. lid_switch.py
  126. light_sensor.py
  127. light_sensor_calibration.json
  128. light_sensor_calibration.py
  129. light_sensor_calibration.schema.json
  130. lightbar.py
  131. line_check_item.py
  132. lte_verify_config.py
  133. memory_size.py
  134. message.py
  135. model_sku.json
  136. model_sku.py
  137. model_sku.schema.json
  138. modem_security.py
  139. mouse.py
  140. mrc_cache.py
  141. nop.py
  142. partition_table.py
  143. pd_fw_min_version.py
  144. ping_test.py
  145. plankton_cc2_pull_test.py
  146. plankton_cc_flip_check.py
  147. plankton_charge.py
  148. plankton_display.py
  149. privacy_screen.py
  150. probe_cellular_info.py
  151. probe_cellular_info_unittest.py
  152. probe_device_info.py
  153. probe_sim.py
  154. probe_sim_card_tray.py
  155. provision_drm_key.py
  156. provision_drm_key_unittest.py
  157. proximity_sensor.py
  158. read_device_data_from_cros_config.py
  159. read_device_data_from_cros_config_unittest.py
  160. read_device_data_from_vpd.py
  161. README.md
  162. record_csv_entry_example.py
  163. removable_storage.py
  164. retrieve_config.py
  165. robot_movement.py
  166. robot_movement_unittest.py
  167. sample_customized_test.py
  168. scan.py
  169. select_for_sampling.py
  170. serial_echo.py
  171. serial_echo_unittest.py
  172. setup_psr_feature.py
  173. shopfloor_service.py
  174. shopfloor_service_unittest.py
  175. shutdown.py
  176. spatial_sensor_calibration.py
  177. start.py
  178. station_entry.py
  179. station_entry_unittest.py
  180. station_setup.py
  181. storage_simple_stress.py
  182. stressapptest.py
  183. stressapptest_unittest.py
  184. stylus.py
  185. stylus_garage.py
  186. summary.py
  187. summary_unittest.py
  188. suspend_resume.py
  189. suspend_stress.py
  190. switch_test_list.py
  191. sync_factory_server.py
  192. sync_time.py
  193. tablet_mode.py
  194. tablet_rotation.py
  195. thermal_load.py
  196. thermal_sensors.py
  197. thermal_slope.py
  198. thunderbolt_loopback.py
  199. ti50_ap_ro_verification.py
  200. touch_device_fw_update.py
  201. touch_uniformity.py
  202. touchpad.py
  203. touchpad_hover.py
  204. touchscreen.py
  205. tpm_clear_owner.py
  206. tpm_diagnosis.py
  207. tpm_state.py
  208. tpm_state_unittest.py
  209. tpm_verify_ek.py
  210. update_cbi.py
  211. update_cr50_firmware.py
  212. update_detachable_base.py
  213. update_device_data.py
  214. update_device_data_unittest.py
  215. update_firmware.py
  216. update_fpmcu_firmware.py
  217. update_kernel.py
  218. update_plugin_firmware.py
  219. update_psr_oem_data.py
  220. urandom.py
  221. verify_component.py
  222. verify_keybox.py
  223. verify_root_partition.py
  224. video_playback.py
  225. vsync.py
  226. wait_external_test.py
  227. wait_fixture_ready.py
  228. webgl_aquarium.py
  229. whale_check_voltage.py
  230. whale_cover.py
  231. wifi_throughput.py
  232. wireless_antenna.py
  233. wireless_charge.py
  234. wireless_charge_unittest.py
  235. wireless_connect.py
  236. write_device_data_to_vpd.py
  237. write_device_data_to_vpd_unittest.py
  238. 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 2022 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

2022 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

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"
  }

Writting a test with reboot process

There are two ways to write a test that contains reboot process.

  1. We recommended to use shutdown.py if feasible.
    You can add RebootStep as an independent test item in the test group, it will trigger a reboot and continue executing the remain test items after reboot.

    For example:

    {
      "label": "Test Group Label",
      "subtests": [
        "PytestWithReboot",
        "RebootStep",
        "PytestWithReboot"
      ]
    }
    
  2. Sometimes the reboot is triggered by 3rd-party commands/operations, which is not supported by shutdown.py.
    In this situation, you can set allow_reboot: true for the test item in test_list, and then use AddTask(task, *args, reboot=True, **kwargs) to add tasks in your pytest.

    For example:

    def Task(arg):
      # task
      ...
    
    def RebootTask(arg):
      # task with reboot process
      ...
    
    AddTask(Task, arg)
    AddTask(RebootTask, arg, reboot=True)
    AddTask(Task, arg)
    

See JSON_TEST_LIST.md and test_case.py for more details.

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.