xref: /aosp_15_r20/external/autotest/docs/faft-how-to-run-doc.md (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1# How to run FAFT (Fully Automated Firmware Test) {#faft-how-to-run}
2
3_Self-link: [go/faft-running](https://goto.google.com/faft-running)_
4
5[TOC]
6
7## FAFT Overview {#faft-overview}
8
9[FAFT] (Fully Automated Firmware Tests) is a collection of tests and related
10infrastructure that exercise and verify capabilities of ChromeOS.
11The features tested by FAFT are implemented through low-level software
12(firmware/BIOS) and hardware. FAFT evolved from SAFT
13(Semi-Automated Firmware Tests) and you can locate tests in the [FAFT suite]
14in the Autotest tree as directories with the prefix `firmware_`.
15
16The founding principles of FAFT are:
17
18- Fully automated, no human intervention required
19- Real test of physical hardware, like USB plug-in, Ctrl-D key press
20- High test coverage of complicated verified boot flows
21- Easy to integrate with existing test infrastructure (e.g. test lab, continuous testing, etc).
22
23To access some of these low-level capabilities, the tests require a
24[servod] instance running and executing controls with the help of physical
25[servo] board ([servo v2], [servo v4] with [servo micro] or [servo v4 Type-C])
26
27The servo board is connected directly to the DUT (Device Under Test) to enable
28access to low-level hardware interfaces, as well as staging areas for backup
29software (on a USB drive).
30
31The [FAFT framework] runs the tests with a tool called [test that] and it is
32based on a client-server architecture, where the client runs on the DUT and
33the server runs on the host machine.
34
35The tests may corrupt various states in the EC, firmware, and kernel to verify
36recovery processes. In these cases you can almost always use FAFT to restore
37the system to its original state.
38The FAFT suite of tests can be invoked locally or remotely.
39This document describes how to set up the local configuration only.
40
41The ChromeOS firmware controls, among other things, the initial setup of the
42system hardware during the boot process. They are necessarily complicated,
43providing reliability against various corruption scenarios and security to
44ensure trusted software is controlling the system. Currently, the purpose of
45FAFT is to exercise EC firmware and BIOS firmware functionality and performance.
46
47## Hardware Setup {#hardware-setup}
48
49### General requirements
50
51The firmware running on the system needs to be able to deal with the
52signatures on the disks, so when testing your own local ChromeOS build
53signed with dev keys, install dev signed firmware as well.
54
55The setup requires a USB drive: Pick the fastest option that you can
56reasonably employ but even more than that, ensure that it's reliable!
57If the drive is quirky in manual use, FAFT will definitely be confused
58because it won't be able to deal with extraordinary circumstances.
59
60The OS image installed on the USB drive MUST NOT be a recovery image. FAFT
61switches pretty often between normal and dev mode, and the transition into
62dev mode is done by going through the recovery screen. With a recovery
63image present, it will do a recovery instead of going through the dev
64mode transition flow.
65
66The OS on the USB drive and on the disk must be a test image. If not, it
67will lack important tooling for running the tests: If you see messages
68that `rsync` can't be found you're not using a test image and while
69this step will work (albeit slowly because the fallback is to scp files
70individually), running the DUT's side of the tests will fail because
71non-test ChromeOS lacks a suitable python interpreter.
72
73### ServoV4 Type-A with Micro {#servov4-typea-micro}
74
75The hardware configuration for running FAFT on a servo v4 Type-A
76with servo micro includes:
77
78- A test controller (your host workstation with a working chroot environment)
79- The test device (a device / DUT that can boot ChromeOS)
80- A servo board
81- Related cables and components
82    - servo-micro cable
83    - USB type-A to USB micro cable for DUT connection (~ 2' in length)
84    - USB type-A to USB micro cable for test controller connection (~ 4' - 6' in length)
85    - Ethernet cable
86    - USB drive (flashed with the appropriate OS image)
87
88Figure 1 shows a diagram of how to connect the latest debug boards,
89servoV4 Type-A and servo micro, to the test controller, DUT, and network.
90It is important to ensure the DUT is powered off
91before plugging in cables and components to the servo.
92
93![Figure1](assets/faft_rc_typeA.png)
94
95**Figure 1.Diagram of hardware configuration for a ServoV4 Type-A with servo micro.**
96
97Details of servoV4 Type-A with micro connections:
98
991. Connect one end (micro USB) of the servo micro to servoV4 using a micro USB to USB cable.
1002. Connect the servo micro to the debug header on the chrome device.
1013. Connect the USB type A cable of the servoV4 to the DUT.
1024. Prepare a USB flash drive with valid ChromeOS image and plug into the USB port of the servo as shown in the diagram.
1035. Connect the micro USB port of the servo to the host machine (typically your workstation).
1046. Connect an Ethernet cable to the Ethernet jack of the servo that goes to the a network reachable from the network that your host machine is on.
105
106### ServoV4 Type-C {#servov4-typec}
107
108The hardware configuration for running FAFT with a servo v4 type-C includes:
109
110- A test controller (your host workstation with a working chroot environment)
111- The test device (a device / DUT that can boot ChromeOS)
112- A servo board
113- Related cables and components
114    - USB type-A to USB micro cable for test controller connection (~ 4' - 6' in length)
115    - Ethernet cable
116    - USB drive (flashed with the appropriate OS image)
117
118Figure 2 shows a diagram of how to connect a servoV4 Type-C, to the test
119controller, DUT, and network. It is important to ensure the DUT is powered off
120before plugging in cables and components to the servo and DUT.
121
122![Figure2](assets/faft_rc_typec.png)
123
124**Figure 2.Diagram of hardware configuration for a ServoV4 Type-C.**
125
126Details of servoV4 Type-C connections in Figure 2:
127
1281. Connect the USB Type-C cable of the servoV4 to the DUT.
1292. Prepare a USB flash drive with valid ChromeOS image and plug into the USB port of the servo as shown in the diagram.
1303. Connect the micro USB port of the servo to the host machine (typically your workstation).
1314. Connect an Ethernet cable to the Ethernet jack of the servo that goes to the a network reachable from the network that your host machine is on.
132
133### ServoV4 Type-C with servo micro {#servov4-typec-micro}
134
135Make sure to use the following servo type and configuration
136for running the faft_pd suite or the faft_cr50 suite (note: the cr50 suite
137requires special images so is not runnable outside of Google).  This setup
138requires servod to be in "DUAL_V4" mode.  You should generally only use this
139setup for faft_pd and faft_cr50, faft_ec and faft_bios do not expect servod to
140be in DUAL_V4 mode.
141
142![Figure3](assets/faft_rc_pd_typeC.png)
143
144**Figure 3.Diagram of hardware configuration for a ServoV4 Type-C with servo micro.**
145
146Details about FAFT PD's ServoV4 Type-C + servo micro setup (Figure 3):
147
148- The suite should only be run on devices released in 2019 and forward.
149- The charger connected to the servo must have support for 5V, 12V, and 20V.
150- The servo v4 and servo micro cable must be updated to their latest FW:
151    - Servo_v4: servo_v4_v2.3.30-b35860984
152    - servo micro: servo_micro_v2.3.30-b35960984
153
154To check or upgrade the FW on the servo v4 and servo micro, respectively, before kicking off the FAFT PD suite:
155
156- Have the servo v4 connected to your workstation/labstation along with the servo micro connected to the servo.
157- Run the following commands on chroot one after the other:
158    - sudo servo_updater -b servo_v4
159    - sudo servo_updater -b servo_micro
160
161### (Deprecated) ServoV2 {#servov2-deprecated}
162
163(Deprecated) The following photo shows the details how to connect the older,
164deprecated servo v2 board to the test controller, test device, and network.
165
166![Figure4](assets/faft_rc_servov2_deprecated.jpg)
167
168**Figure 4.Diagram of hardware configuration for a ServoV2 board.**
169
170Details of servo v2 connections:
171
1721. Connect one end(ribbon cable) of the flex cable to servoV2 and the other end to the debug header on the chrome device.
1732. Connect DUT_HUB_IN(micro USB port) of the servo to the DUT.
1743. Prepare a USB flash drive with valid ChromeOS image and plug into the USB port of the servo as shown in the photo.
1754. Connect the micro USB port of the servo to the host machine(workstation or a labstation).
1765. Connect an Ethernet cable to the Ethernet jack of the servo.
177
178### Installing Test Image onto USB Stick {#image-onto-usb}
179
180After the hardware components are correctly connected,
181prepare and install a test Chromium OS image:
182
1831. Build the binary (chromiumos_test_image.bin) with build_image test, or fetch the file from a buildbot.
1842. Load the test image onto a USB drive (use cros flash).
1853. Insert the USB drive into the servo board, as shown in the photo.
1864. Install the test image onto the internal disk by booting from the USB drive and running chromeos-install.
187
188## Running Tests {#faft-running-tests}
189
190FAFT tests are written in two different frameworks: Autotest and Tast.
191
192Autotest tests are run using the `test_that` command, described below. Tast tests are run using the `tast run` command, which is documented at [go/tast-running](http://chromium.googlesource.com/chromiumos/platform/tast/+/HEAD/docs/running_tests.md).
193
194### Setup Confirmation {#setup-confirmation}
195
196To run Autotest tests, use the `test_that` tool, which does not automatically
197start a `servod` process for communicating with the servo board. Running FAFT
198is easiest with `servod` and `test_that` running in separate terminals inside
199the SDK, using either multiple SDK instances (`cros_sdk --enter --no-ns-pid`)
200or a tool such as `screen` inside an SDK instance. Before running any tests, go
201into the chroot:
202
2031.  Make sure your tools are up to date.
204    1.  Run `repo sync -j8`
205    2.  Run `./update_chroot`
2062.  (chroot 1) Run `$ sudo servod --board=$BOARD` where `$BOARD` is the code name of the board you are testing. For example: `$ sudo servod --board=eve`
2073.  Go into a second chroot
2084.  (chroot 2) Run the `firmware_FAFTSetup` test to verify basic functionality and ensure that your setup is correct.
2095.  If test_that is in `/usr/bin`, the syntax is `$ /usr/bin/test_that --autotest_dir ~/trunk/src/third_party/autotest/files/ --board=$BOARD $DUT_IP firmware_FAFTSetup`
2106.  Run the `firmware.Pre.normal` test to verify tast tests are working also. `tast run --var=servo=localhost:9999 $DUT_IP firmware.Pre.normal`
211
212You can omit the --autotest_dir if you have built packages for the board and want to use the build version of the tests, i.e.:
213
214(chroot) `$ ./build_packages --board=$BOARD` where `$BOARD` is the code name of the board under test
215(chroot) `$ /usr/bin/test_that --board=$BOARD $DUT_IP firmware_FAFTSetup`
216
217### Sample Commands {#sample-commands}
218
219A few sample invocations of launching Autotest tests against a DUT:
220
221Running FAFT test with test case name
222
223- `$ /usr/bin/test_that --autotest_dir ~/trunk/src/third_party/autotest/files/ --board=$BOARD $DUT_IP f:.*DevMode/control`
224
225Some tests can be run in either normal mode or dev mode, specify the control file
226
227- `$ /usr/bin/test_that --autotest_dir ~/trunk/src/third_party/autotest/files/ --board=$BOARD $DUT_IP f:.*TryFwB/control.dev`
228
229FAFT can install ChromeOS image from the USB when image filename is specified
230
231- `$ /usr/bin/test_that --autotest_dir ~/trunk/src/third_party/autotest/files/ --board=$BOARD $DUT_IP --args "image=$IMAGE_FILE" f:.*RecoveryButton/control.normal`
232
233To update the firmware using the shellball in the image, specify the argument firmware_update=1
234
235- `$ /usr/bin/test_that --autotest_dir ~/trunk/src/third_party/autotest/files/ --board=$BOARD $DUT_IP --args "image=$IMAGE_FILE firmware_update=1" f:.*RecoveryButton/control.normal`
236
237Run the entire faft_bios suite
238
239- `$ /usr/bin/test_that --autotest_dir ~/trunk/src/third_party/autotest/files/ --board=$BOARD $DUT_IP suite:faft_bios`
240
241Run the entire faft_ec suite
242
243- `$ /usr/bin/test_that --autotest_dir ~/trunk/src/third_party/autotest/files/ --board=$BOARD $DUT_IP suite:faft_ec`
244
245Run the entire faft_pd suite
246
247- `$ /usr/bin/test_that --autotest_dir ~/trunk/src/third_party/autotest/files/ --board=$BOARD $DUT_IP suite:faft_pd`
248
249To run servod in a different host, specify the servo_host and servo_port arguments.
250
251- `$ /usr/bin/test_that --autotest_dir ~/trunk/src/third_party/autotest/files/ --board=$BOARD $DUT_IP --args "servo_host=$SERVO_HOST servo_port=$SERVO_PORT" suite:faft_ec`
252
253To run multiple servo boards on the same servo host (labstation), use serial and port number.
254
255- `$ sudo servod --board=$BOARD --port $port_number --serial $servo_serial_number`
256- `$ /usr/bin/test_that --autotest_dir ~/trunk/src/third_party/autotest/files/ --board=$BOARD $DUT_IP --args "servo_host=localhost servo_port=$port_number faft_iterations=5000" f:.*firmware_ConsecutiveBoot/control`
257
258### Running Against DUTs With Tunnelled SSH
259
260If you have ssh tunnels setup for your DUT and servo host (for example, via
261[SSH watcher](https://chromium.googlesource.com/chromiumos/platform/dev-util/+/HEAD/contrib/sshwatcher),
262the syntax (with the assumption that your DUT's network interface and your servo
263host's network interface is tunnelled to 2203 and servod is listening on port
2649901 on your servo host) for running tests is:
265
266- `$ test_that localhost:2222 --args="servo_host=localhost servo_host_ssh_port=2223 servo_port=9901 use_icmp=false" $TESTS`
267- `$ tast run -build=false -var=servo=127.0.0.1:9901:ssh:2223 127.0.0.1:2222  $TESTS`
268
269Note that for tast, you will likely need to manually start servod.  Note that
270the tast invocation is a bit unintuitive, as the servo port in the first port
271reference is the real servo port on the servo host, not the redirected one,
272because TAST ssh's to the servohost and tunnels it's own port.  If you don't
273need to run commands on the servo host you can also use
274servo=localhost:${LOCAL_SERVO_PORT}:nossh
275
276## Running FAFT on a new kernel {#faft-kernel-next}
277
278The lab hosts shown in go/cros-testing-kernelnext provide a static environment
279for FAFT to be executed continuously and the recommendation is to pursue the
280sustainable approach of using these DUTs for kernel-next FAFT execution.
281
282Local execution via go/faft-running may be required to debug layers of
283accumulated problems in boards where end-to-end integration tests lack an
284effective continuous execution. Install a kernelnext image onto the test USB
285stick and ensure that a kernelnext image is also installed in the DUT prior
286to running FAFT. The test_that commands to execute tests on a DUT with a
287kernelnext OS are the same.
288
289The key point is to ensure that the USB and DUT contain a kernelnext image.
290
291## Frequently Asked Questions (FAQ) {#faq}
292
293Q: All of my FAFT tests are failing. What should I do?
294
295- A1: Run `firmware_FAFTSetup` as a single test. Once it fails, check the log and determine which step failed and why.
296- A2: Check that the servo has all the wired connections and a USB drive with the valid OS plugged in.  A missing USB drive is guaranteed to make `firmware_FAFTSetup` fail.
297
298Q: A few of my FAFT tests failed, but most tests are passing. What should I do?
299
300- A1: Re-run the failed tests and try to isolate between flaky infrastructure, an actual firmware bug, or non-firmware bugs.
301- A2: See if you were running FAFT without the AC charger connected.  The DUT's battery may have completely drained during the middle of the FAFT suite.
302
303Q: I still need help. Who can help me?
304
305- A: Try joining the [FAFT-users chromium.org mailing list](https://groups.google.com/a/chromium.org/forum/#!forum/faft-users) and asking for help. Be sure to include logs and test details in your request for help.
306
307Q: I got an error while running FAFT: `AutoservRunError: command execution error:  sudo -n which flash_ec` . What's wrong?
308
309- A: Run `sudo emerge chromeos-ec` inside your chroot.
310
311Q: All tests are failing to run, saying that python was not found.
312   What's wrong?
313
314- A: This happens when the stateful partition that holds Python is wiped by a
315  powerwash.
316
317  It is usually caused by the stateful filesystem becoming corrupted, since
318  ChromeOS performs a powerwash instead of running `fsck` like a standard
319  Linux distribution would.
320
321Q: What causes filesystem corruption?
322
323- A1: Most cases of corruption are triggered by a test performing an EC reset,
324  because the current sync logic in Autotest doesn't fully guarantee that all
325  writes have been completed, especially on USB storage devices.
326
327- A2: If the outer stateful partition (`/mnt/stateful_partition`) becomes full,
328  the inner loop-mounted DM device (`/mnt/stateful_partition/encrypted`)
329  will encounter write errors, likely corrupting the filesystem.
330
331  Note: Running out of space only tends to happens when running FAFT tests that
332  leave the DUT running from the USB disk, and only if the image's
333  [stateful partition is too small].
334
335Q: Can I compare the results obtained with a Type-C servo to those obtained with a Type-A servo + micro?
336
337- A: When running tests with a Type-C servo, it is recommended to to rerun a failure using the Type-A setup to do a fast check prior to digging deeper, i.e. before connecting a USB analyzer or probing the signals.
338
339Q: How can I obtain a device for a local FAFT execution?
340
341- A: The lab is a good source of devices for FAFT per go/cros-testing-kernelnext. If DUTs are not available or cannot be repaired by the lab team, request a DUT for development via go/hwrequest.
342
343\[FAFT suite\]: https://chromium.googlesource.com/chromiumos/third_party/autotest/+/main/server/site_tests/ <br>
344\[servo\]: https://chromium.googlesource.com/chromiumos/third_party/hdctools/+/refs/heads/main/README.md#Power-Measurement <br>
345\[servo v2\]: https://chromium.googlesource.com/chromiumos/third_party/hdctools/+/refs/heads/main/docs/servo_v2.md <br>
346\[servo v4\]: https://chromium.googlesource.com/chromiumos/third_party/hdctools/+/refs/heads/main/docs/servo_v4.md <br>
347\[servo micro\]: https://chromium.googlesource.com/chromiumos/third_party/hdctools/+/refs/heads/main/docs/servo_micro.md <br>
348\[servo v4 Type-C\]: https://chromium.googlesource.com/chromiumos/third_party/hdctools/+/refs/heads/main/docs/servo_v4.md#Type_C-Version <br>
349\[stateful partition is too small\]: https://crrev.com/c/1935408 <br>
350\[FAFT\]: https://chromium.googlesource.com/chromiumos/third_party/autotest/+/refs/heads/main/docs/faft-design-doc.md <br>
351\[FAFT framework\]: https://chromium.googlesource.com/chromiumos/third_party/autotest/+/refs/heads/main/docs/faft-code.md <br>
352\[servod\]: https://chromium.googlesource.com/chromiumos/third_party/hdctools/+/refs/heads/main/docs/servod.md <br>
353\[test that\]: https://chromium.googlesource.com/chromiumos/third_party/autotest/+/refs/heads/main/docs/test-that.md <br>
354