blob: 9f08101ff2bd7ced65e2b4c6949bd819cb72a132 [file] [log] [blame]
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -07001# Copyright 2021 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Unittests for build_minios.py"""
6
7import os
8import tempfile
9from unittest import mock
10
11from chromite.lib import constants
12from chromite.lib import cros_test_lib
13from chromite.lib import minios
14from chromite.scripts import build_minios
15
16
17class BuildMiniosTest(cros_test_lib.RunCommandTempDirTestCase):
18 """Unit tests for build_minios."""
19
20 def setUp(self):
21 self.create_minios_mock_return = '/some/kernel/path'
22 self.create_minios_mock = self.PatchObject(
23 minios, 'CreateMiniOsKernelImage',
24 return_value=self.create_minios_mock_return)
25
26 self.insert_minios_mock = self.PatchObject(
27 minios, 'InsertMiniOsKernelImage')
28
29 # Patch to assert against the tempdir that's created under the anchored
30 # tempdir created by cros_test_lib.
31 self._tempdir = os.path.join(self.tempdir, 'test-dir')
32 self.PatchObject(tempfile, 'mkdtemp', return_value=self._tempdir)
33
34 def testDefaultArguments(self):
35 """Test that default arguments of build_minios are formatted correct."""
36 test_board = 'test-board'
Vyshu92153902021-06-16 13:31:53 -040037 test_version = '0.0.0.0'
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070038 test_image = '/some/image/path'
39 build_minios.main([
40 # --board is a required argument.
41 '--board', test_board,
Vyshu92153902021-06-16 13:31:53 -040042 # --version is a required argument.
43 '--version', test_version,
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070044 # --image is a required argument.
45 '--image', test_image,
46 ])
47
48 self.assertEqual(self.create_minios_mock.mock_calls, [mock.call(
49 test_board,
Vyshu92153902021-06-16 13:31:53 -040050 test_version,
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070051 self._tempdir,
52 constants.VBOOT_DEVKEYS_DIR,
53 constants.RECOVERY_PUBLIC_KEY,
Jae Hoon Kim4e35db82021-06-16 13:05:44 -070054 constants.MINIOS_DATA_PRIVATE_KEY,
55 constants.MINIOS_KEYBLOCK,
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070056 None,
Henry Barnore0dfd562022-02-16 10:01:54 -080057 True,
58 False,
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070059 )])
60
61 self.assertEqual(self.insert_minios_mock.mock_calls, [mock.call(
62 test_image, self.create_minios_mock_return,
63 )])
64
65 def testOverridenArguments(self):
66 """Test that overridden arguments of build_minios are formatted correct."""
67 test_board = 'test-board'
Vyshu92153902021-06-16 13:31:53 -040068 test_version = '1.0.0.0'
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070069 test_image = '/some/image/path'
70 test_keys_dir = '/some/path/test-keys-dir'
71 test_public_key = 'test-public-key'
72 test_private_key = 'test-private-key'
73 test_keyblock = 'test-keyblock'
74 test_serial = 'test-serial'
75 build_minios.main([
76 # --board is a required argument.
77 '--board', test_board,
Vyshu92153902021-06-16 13:31:53 -040078 # --version is a required argument.
79 '--version', test_version,
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070080 # --image is a required argument.
81 '--image', test_image,
82 '--keys-dir', test_keys_dir,
83 '--public-key', test_public_key,
84 '--private-key', test_private_key,
85 '--keyblock', test_keyblock,
86 '--serial', test_serial,
Henry Barnore0dfd562022-02-16 10:01:54 -080087 '--force-build',
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070088 ])
89
90 self.assertEqual(self.create_minios_mock.mock_calls, [mock.call(
91 test_board,
Vyshu92153902021-06-16 13:31:53 -040092 test_version,
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070093 self._tempdir,
94 test_keys_dir,
95 test_public_key,
96 test_private_key,
97 test_keyblock,
98 test_serial,
Henry Barnore0dfd562022-02-16 10:01:54 -080099 True,
100 False,
101 )])
102
103 self.assertEqual(self.insert_minios_mock.mock_calls, [mock.call(
104 test_image, self.create_minios_mock_return,
105 )])
106
107 def testModForDev(self):
108 """Test that default arguments of build_minios are formatted correct."""
109 test_board = 'test-board'
110 test_version = '0.0.0.0'
111 test_image = '/some/image/path'
112 build_minios.main([
113 # --board is a required argument.
114 '--board', test_board,
115 # --version is a required argument.
116 '--version', test_version,
117 # --image is a required argument.
118 '--image', test_image,
119 '--mod-for-dev',
120 ])
121
122 self.assertEqual(self.create_minios_mock.mock_calls, [mock.call(
123 test_board,
124 test_version,
125 self._tempdir,
126 constants.VBOOT_DEVKEYS_DIR,
127 constants.RECOVERY_PUBLIC_KEY,
128 constants.MINIOS_DATA_PRIVATE_KEY,
129 constants.MINIOS_KEYBLOCK,
130 None,
131 False,
132 True,
133 )])
134
135 self.assertEqual(self.insert_minios_mock.mock_calls, [mock.call(
136 test_image, self.create_minios_mock_return,
137 )])
138
139 def testModForDevWithForceBuild(self):
140 """Test that default arguments of build_minios are formatted correct."""
141 test_board = 'test-board'
142 test_version = '0.0.0.0'
143 test_image = '/some/image/path'
144 build_minios.main([
145 # --board is a required argument.
146 '--board', test_board,
147 # --version is a required argument.
148 '--version', test_version,
149 # --image is a required argument.
150 '--image', test_image,
151 '--mod-for-dev',
152 '--force-build',
153 ])
154
155 self.assertEqual(self.create_minios_mock.mock_calls, [mock.call(
156 test_board,
157 test_version,
158 self._tempdir,
159 constants.VBOOT_DEVKEYS_DIR,
160 constants.RECOVERY_PUBLIC_KEY,
161 constants.MINIOS_DATA_PRIVATE_KEY,
162 constants.MINIOS_KEYBLOCK,
163 None,
164 True,
165 True,
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -0700166 )])
167
168 self.assertEqual(self.insert_minios_mock.mock_calls, [mock.call(
169 test_image, self.create_minios_mock_return,
170 )])