faft: Make sure the USB stick in servo matches the board under test
It's surprisingly easy to accidentally run FAFT with a wrong USB stick
plugged in. As long as it's any kind of test image, the pre-test checks
will pass... and when running tests that boot from USB, the fact that
the dev keys are a single keyset shared across all boards (unlike
(pre-)MP keys) means that ARM boards will happily try to boot x86
kernels and other nonsense like that, with results that look very much
like real test failures.
This patch adds a simple check to assert_test_image_in_usb_disk() to
make sure that the image on the USB stick is for the same board as the
image currently booted on the DUT (from local storage), which should
catch at least the most simple of mix-ups.
BUG=chrome-os-partner:37128
TEST=Ran firmware_RecoveryButton on a Jerry. Succeeded with a Jerry
image and failed with a Falco image plugged in.
Change-Id: Ifa5576afdec1bdd29ee872dcc8e987717138b97d
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/254432
Reviewed-by: Yusuf Mohsinally <mohsinally@chromium.org>
diff --git a/server/cros/faft/firmware_test.py b/server/cros/faft/firmware_test.py
index 662b9bf..166a81e 100644
--- a/server/cros/faft/firmware_test.py
+++ b/server/cros/faft/firmware_test.py
@@ -377,22 +377,30 @@
tmpd = self.servo.system_output('mktemp -d -t usbcheck.XXXX')
self.servo.system('mount -o ro %s %s' % (rootfs, tmpd))
- if install_shim:
- dir_list = self.servo.system_output('ls -a %s' %
- os.path.join(tmpd, 'root'))
- check_passed = '.factory_installer' in dir_list
- else:
- check_passed = self.servo.system_output(
- 'grep -i "CHROMEOS_RELEASE_DESCRIPTION=.*test" %s' %
- os.path.join(tmpd, 'etc/lsb-release'),
- ignore_status=True)
- for cmd in ('umount %s' % rootfs, 'sync', 'rm -rf %s' % tmpd):
- self.servo.system(cmd)
-
- if not check_passed:
- raise error.TestError(
- 'No Chrome OS %s found on the USB flash plugged into servo' %
- ('install shim' if install_shim else 'test'))
+ try:
+ if install_shim:
+ dir_list = self.servo.system_output('ls -a %s' %
+ os.path.join(tmpd, 'root'))
+ if '.factory_installer' not in dir_list:
+ raise error.TestError(
+ 'USB stick in servo is not a factory install shim')
+ else:
+ usb_lsb = self.servo.system_output('cat %s' %
+ os.path.join(tmpd, 'etc/lsb-release'))
+ logging.debug('Dumping lsb-release on USB stick:\n%s', usb_lsb)
+ dut_lsb = '\n'.join(self.faft_client.system.
+ run_shell_command_get_output('cat /etc/lsb-release'))
+ logging.debug('Dumping lsb-release on DUT:\n%s', dut_lsb)
+ if not re.search(r'RELEASE_DESCRIPTION=.*test', usb_lsb):
+ raise error.TestError('USB stick in servo is no test image')
+ usb_board = re.search(r'BOARD=(.*)', usb_lsb).group(1)
+ dut_board = re.search(r'BOARD=(.*)', dut_lsb).group(1)
+ if usb_board != dut_board:
+ raise error.TestError('USB stick in servo contains a %s '
+ 'image, but DUT is a %s' % (usb_board, dut_board))
+ finally:
+ for cmd in ('umount %s' % rootfs, 'sync', 'rm -rf %s' % tmpd):
+ self.servo.system(cmd)
self.mark_setup_done('usb_check')