1*9c5db199SXin Li# FAFT Code Overview 2*9c5db199SXin Li 3*9c5db199SXin Li_Self-link: [go/faft-code](https://goto.google.com/faft-code)_ 4*9c5db199SXin Li 5*9c5db199SXin Li_Last updated: 2020/03/13_ 6*9c5db199SXin Li 7*9c5db199SXin Li## Introduction 8*9c5db199SXin LiThe FAFT framework provides a set of python modules that simplifies writing of firmware tests. The [design doc](faft-design-doc.md) was written in 2011 and the code itself has since evolved to support hundreds of firmware tests. This document provides a high level overview of the current code base. 9*9c5db199SXin Li 10*9c5db199SXin Li## Code Architecture 11*9c5db199SXin LiThe framework itself is split up into a [server side](/server/cros/faft) and a [client side](/client/cros/faft). The server side runs on the host machine, while the client side runs on the DUT. 12*9c5db199SXin Li 13*9c5db199SXin Li- ### [Client](#client-code-details) 14*9c5db199SXin Li The client consists of an [XML rpc server](/client/cros/faft/rpc_server.py) that listens for requests from the server side, and a set of [utility classes](/client/cros/faft/utils) that are able to execute shell commands on the DUT to fulfill the requests. 15*9c5db199SXin Li 16*9c5db199SXin Li- ### [Server](#server-code-details) 17*9c5db199SXin Li The server consists of base skeleton autotest test classes that perform DUT initialization and contain references to a set of utility methods and classes that can perform useful actions. Some actions require interaction with the DUT that is not possible via the client RPC server, so these ultimately use servod to carry out the interaction. Others send XML RPC calls to the client on the DUT to perform the needed work. 18*9c5db199SXin Li 19*9c5db199SXin Li- ### [Tests](#test-code-details) 20*9c5db199SXin Li These are autotest style tests consisting of control file(s) and a test class. The control file documents the test and invokes a job to run the test class. The test class will subclass one of the base test classes, thereby gaining functionality exposed by the framework. 21*9c5db199SXin Li 22*9c5db199SXin Li## Client Code Details 23*9c5db199SXin Li- [rpc_server](/client/cros/faft/rpc_server.py): Listens for RPC requests from the server and routes them to rpc_functions module. 24*9c5db199SXin Li- [rpc_functions](/client/cros/faft/rpc_functions.py): Delegates requested actions to servicers in utils. 25*9c5db199SXin Li- Servicers in [utils](/client/cros/faft/utils) 26*9c5db199SXin Li - [cgpt_handler](/client/cros/faft/utils/cgpt_handler.py): GUID Partition Table manipulation. 27*9c5db199SXin Li - [firmware_check_keys](/client/cros/faft/utils/firmware_check_keys.py): Check firmware keys. 28*9c5db199SXin Li - [firmware_updater](/client/cros/faft/utils/firmware_updater.py): Manipulate firmware images. 29*9c5db199SXin Li - [flashrom_handler](/client/cros/faft/utils/flashrom_handler.py): Read/write/parse flashrom chip images. 30*9c5db199SXin Li - [kernel_handler](/client/cros/faft/utils/kernel_handler.py): Manipulate chromeos kernel. 31*9c5db199SXin Li - [os_interface](/client/cros/faft/utils/os_interface.py): Wraps misc useful shell commands such as crossystem. 32*9c5db199SXin Li - [rootfs_handler](/client/cros/faft/utils/rootfs_handler.py): Verifies integrity of root fs. 33*9c5db199SXin Li - [saft_flashrom_util](/client/cros/faft/utils/saft_flashrom_util.py): Interact with flashrom, used by flashrom_handler. 34*9c5db199SXin Li - [shell_wrapper](/client/cros/faft/utils/shell_wrapper.py): Runs shell commands, used by others servicers. 35*9c5db199SXin Li - [tpm_handler](/client/cros/faft/utils/tpm_handler.py): Controls TPM device’s NVRAM. 36*9c5db199SXin Li 37*9c5db199SXin Li## Server Code Details 38*9c5db199SXin Li 39*9c5db199SXin Li- ### [Base test classes](/server/cros/faft) 40*9c5db199SXin Li - [FirmwareTest](/server/cros/faft/firmware_test.py): The main base test class. It contains a test skeleton, methods, and references to utility classes to perform useful tasks. 41*9c5db199SXin Li - [Cr50Test](/server/cros/faft/cr50_test.py): Base test class for firmware_Cr50 tests. It has initialization and utility methods tailored to Cr50 tests. 42*9c5db199SXin Li - [FingerprintTest](/server/cros/faft/fingerprint_test.py): Base test class firmware_Fingerprint tests. It has initialization and utility methods tailored to fingerprint tests. 43*9c5db199SXin Li- ### [Utility modules](/server/cros/faft/utils) 44*9c5db199SXin Li - [config](/server/cros/faft/utils/config.py): Table of board specific properties (makes use of [config json](/server/cros/faft/configs) files) 45*9c5db199SXin Li - [faft_checkers](/server/cros/faft/utils/faft_checkers.py): Various assertions about DUT state. 46*9c5db199SXin Li - [mode_switcher](/server/cros/faft/utils/mode_switcher.py): Boots the DUT into a specified mode (as in normal, developer, recovery). 47*9c5db199SXin Li 48*9c5db199SXin Li## Test Code Details 49*9c5db199SXin LiThe tests are those prefixed with “[firmware_](https://source.chromium.org/search?q=f:site_tests%2Ffirmware_&sq=&ss=chromiumos)” in [site_tests](/server/site_tests). See [firmware_FAFTSetup](/server/site_tests/firmware_FAFTSetup) for a simple example. 50*9c5db199SXin Li 51*9c5db199SXin Li- ### Test Directory 52*9c5db199SXin Li This is where the control files and test classes (along with any supporting files) reside under site_tests. It must have the same name as the test class. 53*9c5db199SXin Li 54*9c5db199SXin Li- ### Control File 55*9c5db199SXin Li The control file specifies metadata and invocation details about the test. If multiple control files use the same test class, the naming convention is control.<variation>. 56*9c5db199SXin Li 57*9c5db199SXin Li- ### Test Class 58*9c5db199SXin Li The test class contains logic to execute the test. It must be in a module with the same name as the test directory, and the class name must also be the same as the test directory. Its run_once method is allowed to take additional parameters, and these will be populated according to the job invocation in the control files. This facilitates code reuse by allowing multiple control files to share a common test class. 59*9c5db199SXin Li 60*9c5db199SXin Li## Note to Contributors 61*9c5db199SXin LiIf you’re fixing a bug or adding a new feature to the framework in order to support an immediate need, please write unit and/or integration tests for the code you’ve touched. Adding some additional documentation here or in the code itself may also be helpful. 62