security_test_image: port to chromite
BUG=chromium:875003
TEST=new tests, run_tests
TEST=build_packages --board=reef && build_image --board=reef && \
mod_image_for_recovery.sh --board=reef && security_test_image --board=reef
CQ-DEPEND=CL:1302273
Change-Id: I78f64a66cce28ec11b4e732ed87a61db1568c5ba
Reviewed-on: https://chromium-review.googlesource.com/1302253
Commit-Ready: Alex Klein <saklein@chromium.org>
Tested-by: Alex Klein <saklein@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/scripts/security_test_image_unittest.py b/scripts/security_test_image_unittest.py
new file mode 100644
index 0000000..9b650c8
--- /dev/null
+++ b/scripts/security_test_image_unittest.py
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+# 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.
+
+"""Unittests for the security_test_image script."""
+
+from __future__ import print_function
+
+import os
+
+from chromite.lib import cros_build_lib
+from chromite.lib import cros_test_lib
+from chromite.lib import image_lib
+from chromite.scripts import security_test_image
+
+
+class SecurityTestImageTest(cros_test_lib.MockTempDirTestCase):
+ """Security test image script tests."""
+
+ def setUp(self):
+ D = cros_test_lib.Directory
+ filesystem = (
+ D('board', ('recovery_image.bin',)),
+ 'other_image.bin',
+ )
+ cros_test_lib.CreateOnDiskHierarchy(self.tempdir, filesystem)
+
+ def testParseArgs(self):
+ """Argument parsing tests."""
+ # pylint: disable=protected-access
+ # Test no arguments.
+ self.PatchObject(cros_build_lib, 'GetDefaultBoard', return_value=None)
+ with self.assertRaises(SystemExit):
+ security_test_image._ParseArgs([])
+
+ # Test board is set but not used when we have the full image path.
+ self.PatchObject(cros_build_lib, 'GetDefaultBoard', return_value='board')
+ opts = security_test_image._ParseArgs(
+ ['--image', os.path.join(self.tempdir, 'other_image.bin')])
+ self.assertEqual('board', opts.board)
+ self.assertEqual(opts.image,
+ os.path.join(self.tempdir, 'other_image.bin'))
+
+ # Test the board is fetched and used when using the default image basename.
+ self.PatchObject(image_lib, 'GetLatestImageLink',
+ return_value=os.path.join(self.tempdir, 'board'))
+ opts = security_test_image._ParseArgs([])
+ self.assertEqual('board', opts.board)
+ self.assertEqual(opts.image,
+ os.path.join(self.tempdir,
+ 'board/recovery_image.bin'))