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.
Take start.py
as an example, a pytest should contain 4 sections.
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.
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:
Import lines are organized in 3 categories:
import os
import jsonlibrpc
import factory_common # pylint: disable=unused-import
injects cros.factory
namespace, so the following from cros.factory....
lines could work.
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):
setUp()
runTest()
tearDown()
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" }
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.
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.