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

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.