Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 1 | # Copyright 2019 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 Artifacts operations.""" |
| 6 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 7 | import os |
Mike Frysinger | 166fea0 | 2021-02-12 05:30:33 -0500 | [diff] [blame] | 8 | from unittest import mock |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 9 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 10 | from chromite.api import api_config |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 11 | from chromite.api.controller import artifacts |
| 12 | from chromite.api.gen.chromite.api import artifacts_pb2 |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 13 | from chromite.api.gen.chromite.api import toolchain_pb2 |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 14 | from chromite.cbuildbot import commands |
Michael Mortensen | 7da39cc | 2021-03-09 10:28:45 -0700 | [diff] [blame] | 15 | from chromite.lib import build_target_lib |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 16 | from chromite.lib import chroot_lib |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 17 | from chromite.lib import constants |
| 18 | from chromite.lib import cros_build_lib |
| 19 | from chromite.lib import cros_test_lib |
| 20 | from chromite.lib import osutils |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 21 | from chromite.lib import sysroot_lib |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 22 | from chromite.service import artifacts as artifacts_svc |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 23 | |
| 24 | |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 25 | class BundleRequestMixin(object): |
| 26 | """Mixin to provide bundle request methods.""" |
| 27 | |
| 28 | def EmptyRequest(self): |
| 29 | return artifacts_pb2.BundleRequest() |
| 30 | |
| 31 | def BuildTargetRequest(self, build_target=None, output_dir=None, chroot=None): |
| 32 | """Get a build target format request instance.""" |
| 33 | request = self.EmptyRequest() |
| 34 | if build_target: |
| 35 | request.build_target.name = build_target |
| 36 | if output_dir: |
| 37 | request.output_dir = output_dir |
| 38 | if chroot: |
| 39 | request.chroot.path = chroot |
| 40 | |
| 41 | return request |
| 42 | |
| 43 | def SysrootRequest(self, |
| 44 | sysroot=None, |
| 45 | build_target=None, |
| 46 | output_dir=None, |
| 47 | chroot=None): |
| 48 | """Get a sysroot format request instance.""" |
| 49 | request = self.EmptyRequest() |
| 50 | if sysroot: |
| 51 | request.sysroot.path = sysroot |
| 52 | if build_target: |
| 53 | request.sysroot.build_target.name = build_target |
| 54 | if output_dir: |
| 55 | request.output_dir = output_dir |
| 56 | if chroot: |
| 57 | request.chroot.path = chroot |
| 58 | |
| 59 | return request |
| 60 | |
| 61 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 62 | class BundleTestCase(cros_test_lib.MockTempDirTestCase, |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 63 | api_config.ApiConfigMixin, BundleRequestMixin): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 64 | """Basic setup for all artifacts unittests.""" |
| 65 | |
| 66 | def setUp(self): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 67 | self.output_dir = os.path.join(self.tempdir, 'artifacts') |
| 68 | osutils.SafeMakedirs(self.output_dir) |
| 69 | self.sysroot_path = '/build/target' |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 70 | self.sysroot = sysroot_lib.Sysroot(self.sysroot_path) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 71 | self.chroot_path = os.path.join(self.tempdir, 'chroot') |
| 72 | full_sysroot_path = os.path.join(self.chroot_path, |
| 73 | self.sysroot_path.lstrip(os.sep)) |
| 74 | osutils.SafeMakedirs(full_sysroot_path) |
| 75 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 76 | # All requests use same response type. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 77 | self.response = artifacts_pb2.BundleResponse() |
| 78 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 79 | # Build target request. |
| 80 | self.target_request = self.BuildTargetRequest( |
| 81 | build_target='target', |
| 82 | output_dir=self.output_dir, |
| 83 | chroot=self.chroot_path) |
| 84 | |
| 85 | # Sysroot request. |
| 86 | self.sysroot_request = self.SysrootRequest( |
| 87 | sysroot=self.sysroot_path, |
| 88 | build_target='target', |
| 89 | output_dir=self.output_dir, |
| 90 | chroot=self.chroot_path) |
| 91 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 92 | self.source_root = self.tempdir |
| 93 | self.PatchObject(constants, 'SOURCE_ROOT', new=self.tempdir) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 94 | |
| 95 | |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 96 | class BundleImageArchivesTest(BundleTestCase): |
| 97 | """BundleImageArchives tests.""" |
| 98 | |
| 99 | def testValidateOnly(self): |
| 100 | """Sanity check that a validate only call does not execute any logic.""" |
| 101 | patch = self.PatchObject(artifacts_svc, 'ArchiveImages') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 102 | artifacts.BundleImageArchives(self.target_request, self.response, |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 103 | self.validate_only_config) |
| 104 | patch.assert_not_called() |
| 105 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 106 | def testMockCall(self): |
| 107 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 108 | patch = self.PatchObject(artifacts_svc, 'ArchiveImages') |
| 109 | artifacts.BundleImageArchives(self.target_request, self.response, |
| 110 | self.mock_call_config) |
| 111 | patch.assert_not_called() |
| 112 | self.assertEqual(len(self.response.artifacts), 2) |
| 113 | self.assertEqual(self.response.artifacts[0].path, |
| 114 | os.path.join(self.output_dir, 'path0.tar.xz')) |
| 115 | self.assertEqual(self.response.artifacts[1].path, |
| 116 | os.path.join(self.output_dir, 'path1.tar.xz')) |
| 117 | |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 118 | def testNoBuildTarget(self): |
| 119 | """Test that no build target fails.""" |
| 120 | request = self.BuildTargetRequest(output_dir=self.tempdir) |
| 121 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 122 | artifacts.BundleImageArchives(request, self.response, self.api_config) |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 123 | |
| 124 | def testNoOutputDir(self): |
| 125 | """Test no output dir fails.""" |
| 126 | request = self.BuildTargetRequest(build_target='board') |
| 127 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 128 | artifacts.BundleImageArchives(request, self.response, self.api_config) |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 129 | |
| 130 | def testInvalidOutputDir(self): |
| 131 | """Test invalid output dir fails.""" |
| 132 | request = self.BuildTargetRequest( |
| 133 | build_target='board', output_dir=os.path.join(self.tempdir, 'DNE')) |
| 134 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 135 | artifacts.BundleImageArchives(request, self.response, self.api_config) |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 136 | |
| 137 | def testOutputHandling(self): |
| 138 | """Test the artifact output handling.""" |
| 139 | expected = [os.path.join(self.output_dir, f) for f in ('a', 'b', 'c')] |
| 140 | self.PatchObject(artifacts_svc, 'ArchiveImages', return_value=expected) |
| 141 | self.PatchObject(os.path, 'exists', return_value=True) |
| 142 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 143 | artifacts.BundleImageArchives(self.target_request, self.response, |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 144 | self.api_config) |
| 145 | |
Mike Frysinger | 678735c | 2019-09-28 18:23:28 -0400 | [diff] [blame] | 146 | self.assertCountEqual(expected, [a.path for a in self.response.artifacts]) |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 147 | |
| 148 | |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 149 | class BundleImageZipTest(BundleTestCase): |
| 150 | """Unittests for BundleImageZip.""" |
| 151 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 152 | def testValidateOnly(self): |
| 153 | """Sanity check that a validate only call does not execute any logic.""" |
| 154 | patch = self.PatchObject(commands, 'BuildImageZip') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 155 | artifacts.BundleImageZip(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 156 | self.validate_only_config) |
| 157 | patch.assert_not_called() |
| 158 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 159 | def testMockCall(self): |
| 160 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 161 | patch = self.PatchObject(commands, 'BuildImageZip') |
| 162 | artifacts.BundleImageZip(self.target_request, self.response, |
| 163 | self.mock_call_config) |
| 164 | patch.assert_not_called() |
| 165 | self.assertEqual(len(self.response.artifacts), 1) |
| 166 | self.assertEqual(self.response.artifacts[0].path, |
| 167 | os.path.join(self.output_dir, 'image.zip')) |
| 168 | |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 169 | def testBundleImageZip(self): |
| 170 | """BundleImageZip calls cbuildbot/commands with correct args.""" |
Michael Mortensen | 0191092 | 2019-07-24 14:48:10 -0600 | [diff] [blame] | 171 | bundle_image_zip = self.PatchObject( |
| 172 | artifacts_svc, 'BundleImageZip', return_value='image.zip') |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 173 | self.PatchObject(os.path, 'exists', return_value=True) |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 174 | artifacts.BundleImageZip(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 175 | self.api_config) |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 176 | self.assertEqual( |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 177 | [artifact.path for artifact in self.response.artifacts], |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 178 | [os.path.join(self.output_dir, 'image.zip')]) |
| 179 | |
| 180 | latest = os.path.join(self.source_root, 'src/build/images/target/latest') |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 181 | self.assertEqual( |
Michael Mortensen | 0191092 | 2019-07-24 14:48:10 -0600 | [diff] [blame] | 182 | bundle_image_zip.call_args_list, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 183 | [mock.call(self.output_dir, latest)]) |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 184 | |
| 185 | def testBundleImageZipNoImageDir(self): |
| 186 | """BundleImageZip dies when image dir does not exist.""" |
| 187 | self.PatchObject(os.path, 'exists', return_value=False) |
| 188 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 189 | artifacts.BundleImageZip(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 190 | self.api_config) |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 191 | |
| 192 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 193 | class BundleAutotestFilesTest(BundleTestCase): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 194 | """Unittests for BundleAutotestFiles.""" |
| 195 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 196 | def testValidateOnly(self): |
| 197 | """Sanity check that a validate only call does not execute any logic.""" |
| 198 | patch = self.PatchObject(artifacts_svc, 'BundleAutotestFiles') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 199 | artifacts.BundleAutotestFiles(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 200 | self.validate_only_config) |
| 201 | patch.assert_not_called() |
| 202 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 203 | def testMockCall(self): |
| 204 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 205 | patch = self.PatchObject(artifacts_svc, 'BundleAutotestFiles') |
| 206 | artifacts.BundleAutotestFiles(self.target_request, self.response, |
| 207 | self.mock_call_config) |
| 208 | patch.assert_not_called() |
| 209 | self.assertEqual(len(self.response.artifacts), 1) |
| 210 | self.assertEqual(self.response.artifacts[0].path, |
| 211 | os.path.join(self.output_dir, 'autotest-a.tar.gz')) |
| 212 | |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 213 | def testBundleAutotestFilesLegacy(self): |
| 214 | """BundleAutotestFiles calls service correctly with legacy args.""" |
| 215 | files = { |
| 216 | artifacts_svc.ARCHIVE_CONTROL_FILES: '/tmp/artifacts/autotest-a.tar.gz', |
| 217 | artifacts_svc.ARCHIVE_PACKAGES: '/tmp/artifacts/autotest-b.tar.gz', |
| 218 | } |
| 219 | patch = self.PatchObject(artifacts_svc, 'BundleAutotestFiles', |
| 220 | return_value=files) |
| 221 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 222 | artifacts.BundleAutotestFiles(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 223 | self.api_config) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 224 | |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 225 | # Verify the arguments are being passed through. |
Alex Klein | e21a095 | 2019-08-23 16:08:16 -0600 | [diff] [blame] | 226 | patch.assert_called_with(mock.ANY, self.sysroot, self.output_dir) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 227 | |
| 228 | # Verify the output proto is being populated correctly. |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 229 | self.assertTrue(self.response.artifacts) |
| 230 | paths = [artifact.path for artifact in self.response.artifacts] |
Mike Frysinger | 1f4478c | 2019-10-20 18:33:17 -0400 | [diff] [blame] | 231 | self.assertCountEqual(list(files.values()), paths) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 232 | |
| 233 | def testBundleAutotestFiles(self): |
| 234 | """BundleAutotestFiles calls service correctly.""" |
| 235 | files = { |
| 236 | artifacts_svc.ARCHIVE_CONTROL_FILES: '/tmp/artifacts/autotest-a.tar.gz', |
| 237 | artifacts_svc.ARCHIVE_PACKAGES: '/tmp/artifacts/autotest-b.tar.gz', |
| 238 | } |
| 239 | patch = self.PatchObject(artifacts_svc, 'BundleAutotestFiles', |
| 240 | return_value=files) |
| 241 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 242 | artifacts.BundleAutotestFiles(self.sysroot_request, self.response, |
| 243 | self.api_config) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 244 | |
| 245 | # Verify the arguments are being passed through. |
Alex Klein | e21a095 | 2019-08-23 16:08:16 -0600 | [diff] [blame] | 246 | patch.assert_called_with(mock.ANY, self.sysroot, self.output_dir) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 247 | |
| 248 | # Verify the output proto is being populated correctly. |
| 249 | self.assertTrue(self.response.artifacts) |
| 250 | paths = [artifact.path for artifact in self.response.artifacts] |
Mike Frysinger | 1f4478c | 2019-10-20 18:33:17 -0400 | [diff] [blame] | 251 | self.assertCountEqual(list(files.values()), paths) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 252 | |
| 253 | def testInvalidOutputDir(self): |
| 254 | """Test invalid output directory argument.""" |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 255 | request = self.SysrootRequest(chroot=self.chroot_path, |
| 256 | sysroot=self.sysroot_path) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 257 | |
| 258 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 259 | artifacts.BundleAutotestFiles(request, self.response, self.api_config) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 260 | |
| 261 | def testInvalidSysroot(self): |
| 262 | """Test no sysroot directory.""" |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 263 | request = self.SysrootRequest(chroot=self.chroot_path, |
| 264 | output_dir=self.output_dir) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 265 | |
| 266 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 267 | artifacts.BundleAutotestFiles(request, self.response, self.api_config) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 268 | |
| 269 | def testSysrootDoesNotExist(self): |
| 270 | """Test dies when no sysroot does not exist.""" |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 271 | request = self.SysrootRequest(chroot=self.chroot_path, |
| 272 | sysroot='/does/not/exist', |
| 273 | output_dir=self.output_dir) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 274 | |
| 275 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 276 | artifacts.BundleAutotestFiles(request, self.response, self.api_config) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 277 | |
| 278 | |
| 279 | class BundleTastFilesTest(BundleTestCase): |
| 280 | """Unittests for BundleTastFiles.""" |
| 281 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 282 | def testValidateOnly(self): |
| 283 | """Sanity check that a validate only call does not execute any logic.""" |
| 284 | patch = self.PatchObject(artifacts_svc, 'BundleTastFiles') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 285 | artifacts.BundleTastFiles(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 286 | self.validate_only_config) |
| 287 | patch.assert_not_called() |
| 288 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 289 | def testMockCall(self): |
| 290 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 291 | patch = self.PatchObject(artifacts_svc, 'BundleTastFiles') |
| 292 | artifacts.BundleTastFiles(self.target_request, self.response, |
| 293 | self.mock_call_config) |
| 294 | patch.assert_not_called() |
| 295 | self.assertEqual(len(self.response.artifacts), 1) |
| 296 | self.assertEqual(self.response.artifacts[0].path, |
| 297 | os.path.join(self.output_dir, 'tast_bundles.tar.gz')) |
| 298 | |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 299 | def testBundleTastFilesNoLogs(self): |
LaMont Jones | b9793cd | 2020-06-11 08:14:46 -0600 | [diff] [blame] | 300 | """BundleTasteFiles succeeds when no tast files found.""" |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 301 | self.PatchObject(commands, 'BuildTastBundleTarball', |
| 302 | return_value=None) |
LaMont Jones | b9793cd | 2020-06-11 08:14:46 -0600 | [diff] [blame] | 303 | artifacts.BundleTastFiles(self.target_request, self.response, |
| 304 | self.api_config) |
| 305 | self.assertEqual(list(self.response.artifacts), []) |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 306 | |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 307 | def testBundleTastFilesLegacy(self): |
| 308 | """BundleTastFiles handles legacy args correctly.""" |
| 309 | buildroot = self.tempdir |
| 310 | chroot_dir = os.path.join(buildroot, 'chroot') |
| 311 | sysroot_path = os.path.join(chroot_dir, 'build', 'board') |
| 312 | output_dir = os.path.join(self.tempdir, 'results') |
| 313 | osutils.SafeMakedirs(sysroot_path) |
| 314 | osutils.SafeMakedirs(output_dir) |
| 315 | |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 316 | chroot = chroot_lib.Chroot(chroot_dir) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 317 | sysroot = sysroot_lib.Sysroot('/build/board') |
| 318 | |
| 319 | expected_archive = os.path.join(output_dir, artifacts_svc.TAST_BUNDLE_NAME) |
| 320 | # Patch the service being called. |
| 321 | bundle_patch = self.PatchObject(artifacts_svc, 'BundleTastFiles', |
| 322 | return_value=expected_archive) |
| 323 | self.PatchObject(constants, 'SOURCE_ROOT', new=buildroot) |
| 324 | |
| 325 | request = artifacts_pb2.BundleRequest(build_target={'name': 'board'}, |
| 326 | output_dir=output_dir) |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 327 | artifacts.BundleTastFiles(request, self.response, self.api_config) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 328 | self.assertEqual( |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 329 | [artifact.path for artifact in self.response.artifacts], |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 330 | [expected_archive]) |
| 331 | bundle_patch.assert_called_once_with(chroot, sysroot, output_dir) |
| 332 | |
| 333 | def testBundleTastFiles(self): |
| 334 | """BundleTastFiles calls service correctly.""" |
Alex Klein | b49be8a | 2019-12-20 10:23:03 -0700 | [diff] [blame] | 335 | chroot = chroot_lib.Chroot(self.chroot_path) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 336 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 337 | expected_archive = os.path.join(self.output_dir, |
| 338 | artifacts_svc.TAST_BUNDLE_NAME) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 339 | # Patch the service being called. |
| 340 | bundle_patch = self.PatchObject(artifacts_svc, 'BundleTastFiles', |
| 341 | return_value=expected_archive) |
| 342 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 343 | artifacts.BundleTastFiles(self.sysroot_request, self.response, |
| 344 | self.api_config) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 345 | |
| 346 | # Make sure the artifact got recorded successfully. |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 347 | self.assertTrue(self.response.artifacts) |
| 348 | self.assertEqual(expected_archive, self.response.artifacts[0].path) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 349 | # Make sure the service got called correctly. |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 350 | bundle_patch.assert_called_once_with(chroot, self.sysroot, self.output_dir) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 351 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 352 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 353 | class BundleFirmwareTest(BundleTestCase): |
| 354 | """Unittests for BundleFirmware.""" |
| 355 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 356 | def testValidateOnly(self): |
| 357 | """Sanity check that a validate only call does not execute any logic.""" |
| 358 | patch = self.PatchObject(artifacts_svc, 'BundleTastFiles') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 359 | artifacts.BundleFirmware(self.sysroot_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 360 | self.validate_only_config) |
| 361 | patch.assert_not_called() |
Michael Mortensen | 3867519 | 2019-06-28 16:52:55 +0000 | [diff] [blame] | 362 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 363 | def testMockCall(self): |
| 364 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 365 | patch = self.PatchObject(artifacts_svc, 'BundleTastFiles') |
| 366 | artifacts.BundleFirmware(self.sysroot_request, self.response, |
| 367 | self.mock_call_config) |
| 368 | patch.assert_not_called() |
| 369 | self.assertEqual(len(self.response.artifacts), 1) |
| 370 | self.assertEqual(self.response.artifacts[0].path, |
| 371 | os.path.join(self.output_dir, 'firmware.tar.gz')) |
| 372 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 373 | def testBundleFirmware(self): |
| 374 | """BundleFirmware calls cbuildbot/commands with correct args.""" |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 375 | self.PatchObject( |
| 376 | artifacts_svc, |
| 377 | 'BuildFirmwareArchive', |
| 378 | return_value=os.path.join(self.output_dir, 'firmware.tar.gz')) |
| 379 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 380 | artifacts.BundleFirmware(self.sysroot_request, self.response, |
| 381 | self.api_config) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 382 | self.assertEqual( |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 383 | [artifact.path for artifact in self.response.artifacts], |
| 384 | [os.path.join(self.output_dir, 'firmware.tar.gz')]) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 385 | |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 386 | def testBundleFirmwareNoLogs(self): |
| 387 | """BundleFirmware dies when no firmware found.""" |
| 388 | self.PatchObject(commands, 'BuildFirmwareArchive', return_value=None) |
| 389 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 390 | artifacts.BundleFirmware(self.sysroot_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 391 | self.api_config) |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 392 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 393 | |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 394 | class BundleFpmcuUnittestsTest(BundleTestCase): |
| 395 | """Unittests for BundleFpmcuUnittests.""" |
| 396 | |
| 397 | def testValidateOnly(self): |
| 398 | """Sanity check that a validate only call does not execute any logic.""" |
| 399 | patch = self.PatchObject(artifacts_svc, 'BundleFpmcuUnittests') |
| 400 | artifacts.BundleFpmcuUnittests(self.sysroot_request, self.response, |
| 401 | self.validate_only_config) |
| 402 | patch.assert_not_called() |
| 403 | |
| 404 | def testMockCall(self): |
| 405 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 406 | patch = self.PatchObject(artifacts_svc, 'BundleFpmcuUnittests') |
| 407 | artifacts.BundleFpmcuUnittests(self.sysroot_request, self.response, |
| 408 | self.mock_call_config) |
| 409 | patch.assert_not_called() |
| 410 | self.assertEqual(len(self.response.artifacts), 1) |
| 411 | self.assertEqual(self.response.artifacts[0].path, |
| 412 | os.path.join(self.output_dir, |
| 413 | 'fpmcu_unittests.tar.gz')) |
| 414 | |
| 415 | def testBundleFpmcuUnittests(self): |
| 416 | """BundleFpmcuUnittests calls cbuildbot/commands with correct args.""" |
| 417 | self.PatchObject( |
| 418 | artifacts_svc, |
| 419 | 'BundleFpmcuUnittests', |
| 420 | return_value=os.path.join(self.output_dir, 'fpmcu_unittests.tar.gz')) |
| 421 | artifacts.BundleFpmcuUnittests(self.sysroot_request, self.response, |
| 422 | self.api_config) |
| 423 | self.assertEqual( |
| 424 | [artifact.path for artifact in self.response.artifacts], |
| 425 | [os.path.join(self.output_dir, 'fpmcu_unittests.tar.gz')]) |
| 426 | |
| 427 | def testBundleFpmcuUnittestsNoLogs(self): |
| 428 | """BundleFpmcuUnittests does not die when no fpmcu unittests found.""" |
| 429 | self.PatchObject(artifacts_svc, 'BundleFpmcuUnittests', |
| 430 | return_value=None) |
| 431 | artifacts.BundleFpmcuUnittests(self.sysroot_request, self.response, |
| 432 | self.api_config) |
| 433 | self.assertFalse(self.response.artifacts) |
| 434 | |
| 435 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 436 | class BundleEbuildLogsTest(BundleTestCase): |
| 437 | """Unittests for BundleEbuildLogs.""" |
| 438 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 439 | def testValidateOnly(self): |
| 440 | """Sanity check that a validate only call does not execute any logic.""" |
| 441 | patch = self.PatchObject(commands, 'BuildEbuildLogsTarball') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 442 | artifacts.BundleEbuildLogs(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 443 | self.validate_only_config) |
| 444 | patch.assert_not_called() |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 445 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 446 | def testMockCall(self): |
| 447 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 448 | patch = self.PatchObject(commands, 'BuildEbuildLogsTarball') |
| 449 | artifacts.BundleEbuildLogs(self.target_request, self.response, |
| 450 | self.mock_call_config) |
| 451 | patch.assert_not_called() |
| 452 | self.assertEqual(len(self.response.artifacts), 1) |
| 453 | self.assertEqual(self.response.artifacts[0].path, |
| 454 | os.path.join(self.output_dir, 'ebuild-logs.tar.gz')) |
| 455 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 456 | def testBundleEbuildLogs(self): |
| 457 | """BundleEbuildLogs calls cbuildbot/commands with correct args.""" |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 458 | bundle_ebuild_logs_tarball = self.PatchObject( |
| 459 | artifacts_svc, 'BundleEBuildLogsTarball', |
| 460 | return_value='ebuild-logs.tar.gz') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 461 | artifacts.BundleEbuildLogs(self.sysroot_request, self.response, |
| 462 | self.api_config) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 463 | self.assertEqual( |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 464 | [artifact.path for artifact in self.response.artifacts], |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 465 | [os.path.join(self.output_dir, 'ebuild-logs.tar.gz')]) |
Evan Hernandez | a478d80 | 2019-04-08 15:08:24 -0600 | [diff] [blame] | 466 | self.assertEqual( |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 467 | bundle_ebuild_logs_tarball.call_args_list, |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 468 | [mock.call(mock.ANY, self.sysroot, self.output_dir)]) |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 469 | |
| 470 | def testBundleEBuildLogsOldProto(self): |
| 471 | bundle_ebuild_logs_tarball = self.PatchObject( |
| 472 | artifacts_svc, 'BundleEBuildLogsTarball', |
| 473 | return_value='ebuild-logs.tar.gz') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 474 | |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 475 | artifacts.BundleEbuildLogs(self.target_request, self.response, |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 476 | self.api_config) |
| 477 | |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 478 | self.assertEqual( |
| 479 | bundle_ebuild_logs_tarball.call_args_list, |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 480 | [mock.call(mock.ANY, self.sysroot, self.output_dir)]) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 481 | |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 482 | def testBundleEbuildLogsNoLogs(self): |
| 483 | """BundleEbuildLogs dies when no logs found.""" |
| 484 | self.PatchObject(commands, 'BuildEbuildLogsTarball', return_value=None) |
| 485 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 486 | artifacts.BundleEbuildLogs(self.sysroot_request, self.response, |
| 487 | self.api_config) |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 488 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 489 | |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 490 | class BundleChromeOSConfigTest(BundleTestCase): |
| 491 | """Unittests for BundleChromeOSConfig""" |
| 492 | |
| 493 | def testValidateOnly(self): |
| 494 | """Sanity check that a validate only call does not execute any logic.""" |
| 495 | patch = self.PatchObject(artifacts_svc, 'BundleChromeOSConfig') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 496 | artifacts.BundleChromeOSConfig(self.target_request, self.response, |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 497 | self.validate_only_config) |
| 498 | patch.assert_not_called() |
| 499 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 500 | def testMockCall(self): |
| 501 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 502 | patch = self.PatchObject(artifacts_svc, 'BundleChromeOSConfig') |
| 503 | artifacts.BundleChromeOSConfig(self.target_request, self.response, |
| 504 | self.mock_call_config) |
| 505 | patch.assert_not_called() |
| 506 | self.assertEqual(len(self.response.artifacts), 1) |
| 507 | self.assertEqual(self.response.artifacts[0].path, |
| 508 | os.path.join(self.output_dir, 'config.yaml')) |
| 509 | |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 510 | def testBundleChromeOSConfigCallWithSysroot(self): |
| 511 | """Call with a request that sets sysroot.""" |
| 512 | bundle_chromeos_config = self.PatchObject( |
| 513 | artifacts_svc, 'BundleChromeOSConfig', return_value='config.yaml') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 514 | artifacts.BundleChromeOSConfig(self.sysroot_request, self.response, |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 515 | self.api_config) |
| 516 | self.assertEqual( |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 517 | [artifact.path for artifact in self.response.artifacts], |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 518 | [os.path.join(self.output_dir, 'config.yaml')]) |
| 519 | |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 520 | self.assertEqual(bundle_chromeos_config.call_args_list, |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 521 | [mock.call(mock.ANY, self.sysroot, self.output_dir)]) |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 522 | |
| 523 | def testBundleChromeOSConfigCallWithBuildTarget(self): |
| 524 | """Call with a request that sets build_target.""" |
| 525 | bundle_chromeos_config = self.PatchObject( |
| 526 | artifacts_svc, 'BundleChromeOSConfig', return_value='config.yaml') |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 527 | artifacts.BundleChromeOSConfig(self.target_request, self.response, |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 528 | self.api_config) |
| 529 | |
| 530 | self.assertEqual( |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 531 | [artifact.path for artifact in self.response.artifacts], |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 532 | [os.path.join(self.output_dir, 'config.yaml')]) |
| 533 | |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 534 | self.assertEqual(bundle_chromeos_config.call_args_list, |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 535 | [mock.call(mock.ANY, self.sysroot, self.output_dir)]) |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 536 | |
| 537 | def testBundleChromeOSConfigNoConfigFound(self): |
| 538 | """An error is raised if the config payload isn't found.""" |
| 539 | self.PatchObject(artifacts_svc, 'BundleChromeOSConfig', return_value=None) |
| 540 | |
| 541 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 68c8fdf | 2019-09-25 15:09:11 -0600 | [diff] [blame] | 542 | artifacts.BundleChromeOSConfig(self.sysroot_request, self.response, |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 543 | self.api_config) |
| 544 | |
| 545 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 546 | class BundleTestUpdatePayloadsTest(cros_test_lib.MockTempDirTestCase, |
| 547 | api_config.ApiConfigMixin): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 548 | """Unittests for BundleTestUpdatePayloads.""" |
| 549 | |
| 550 | def setUp(self): |
| 551 | self.source_root = os.path.join(self.tempdir, 'cros') |
| 552 | osutils.SafeMakedirs(self.source_root) |
| 553 | |
| 554 | self.archive_root = os.path.join(self.tempdir, 'output') |
| 555 | osutils.SafeMakedirs(self.archive_root) |
| 556 | |
| 557 | self.target = 'target' |
Evan Hernandez | 59690b7 | 2019-04-08 16:24:45 -0600 | [diff] [blame] | 558 | self.image_root = os.path.join(self.source_root, |
| 559 | 'src/build/images/target/latest') |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 560 | |
| 561 | self.input_proto = artifacts_pb2.BundleRequest() |
| 562 | self.input_proto.build_target.name = self.target |
| 563 | self.input_proto.output_dir = self.archive_root |
| 564 | self.output_proto = artifacts_pb2.BundleResponse() |
| 565 | |
| 566 | self.PatchObject(constants, 'SOURCE_ROOT', new=self.source_root) |
| 567 | |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 568 | def MockPayloads(image_path, archive_dir): |
| 569 | osutils.WriteFile(os.path.join(archive_dir, 'payload1.bin'), image_path) |
| 570 | osutils.WriteFile(os.path.join(archive_dir, 'payload2.bin'), image_path) |
| 571 | return [os.path.join(archive_dir, 'payload1.bin'), |
| 572 | os.path.join(archive_dir, 'payload2.bin')] |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 573 | |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 574 | self.bundle_patch = self.PatchObject( |
| 575 | artifacts_svc, 'BundleTestUpdatePayloads', side_effect=MockPayloads) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 576 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 577 | def testValidateOnly(self): |
| 578 | """Sanity check that a validate only call does not execute any logic.""" |
| 579 | patch = self.PatchObject(artifacts_svc, 'BundleTestUpdatePayloads') |
| 580 | artifacts.BundleTestUpdatePayloads(self.input_proto, self.output_proto, |
| 581 | self.validate_only_config) |
| 582 | patch.assert_not_called() |
| 583 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 584 | def testMockCall(self): |
| 585 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 586 | patch = self.PatchObject(artifacts_svc, 'BundleTestUpdatePayloads') |
| 587 | artifacts.BundleTestUpdatePayloads(self.input_proto, self.output_proto, |
| 588 | self.mock_call_config) |
| 589 | patch.assert_not_called() |
| 590 | self.assertEqual(len(self.output_proto.artifacts), 1) |
| 591 | self.assertEqual(self.output_proto.artifacts[0].path, |
| 592 | os.path.join(self.archive_root, 'payload1.bin')) |
| 593 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 594 | def testBundleTestUpdatePayloads(self): |
| 595 | """BundleTestUpdatePayloads calls cbuildbot/commands with correct args.""" |
| 596 | image_path = os.path.join(self.image_root, constants.BASE_IMAGE_BIN) |
| 597 | osutils.WriteFile(image_path, 'image!', makedirs=True) |
| 598 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 599 | artifacts.BundleTestUpdatePayloads(self.input_proto, self.output_proto, |
| 600 | self.api_config) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 601 | |
| 602 | actual = [ |
| 603 | os.path.relpath(artifact.path, self.archive_root) |
| 604 | for artifact in self.output_proto.artifacts |
| 605 | ] |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 606 | expected = ['payload1.bin', 'payload2.bin'] |
Mike Frysinger | 678735c | 2019-09-28 18:23:28 -0400 | [diff] [blame] | 607 | self.assertCountEqual(actual, expected) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 608 | |
| 609 | actual = [ |
| 610 | os.path.relpath(path, self.archive_root) |
| 611 | for path in osutils.DirectoryIterator(self.archive_root) |
| 612 | ] |
Mike Frysinger | 678735c | 2019-09-28 18:23:28 -0400 | [diff] [blame] | 613 | self.assertCountEqual(actual, expected) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 614 | |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 615 | def testBundleTestUpdatePayloadsNoImageDir(self): |
| 616 | """BundleTestUpdatePayloads dies if no image dir is found.""" |
| 617 | # Intentionally do not write image directory. |
Alex Klein | d2bf146 | 2019-10-24 16:37:04 -0600 | [diff] [blame] | 618 | artifacts.BundleTestUpdatePayloads(self.input_proto, self.output_proto, |
| 619 | self.api_config) |
| 620 | self.assertFalse(self.output_proto.artifacts) |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 621 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 622 | def testBundleTestUpdatePayloadsNoImage(self): |
| 623 | """BundleTestUpdatePayloads dies if no usable image is found for target.""" |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 624 | # Intentionally do not write image, but create the directory. |
| 625 | osutils.SafeMakedirs(self.image_root) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 626 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 627 | artifacts.BundleTestUpdatePayloads(self.input_proto, self.output_proto, |
| 628 | self.api_config) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 629 | |
| 630 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 631 | class BundleSimpleChromeArtifactsTest(cros_test_lib.MockTempDirTestCase, |
| 632 | api_config.ApiConfigMixin): |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 633 | """BundleSimpleChromeArtifacts tests.""" |
| 634 | |
| 635 | def setUp(self): |
| 636 | self.chroot_dir = os.path.join(self.tempdir, 'chroot_dir') |
| 637 | self.sysroot_path = '/sysroot' |
| 638 | self.sysroot_dir = os.path.join(self.chroot_dir, 'sysroot') |
| 639 | osutils.SafeMakedirs(self.sysroot_dir) |
| 640 | self.output_dir = os.path.join(self.tempdir, 'output_dir') |
| 641 | osutils.SafeMakedirs(self.output_dir) |
| 642 | |
| 643 | self.does_not_exist = os.path.join(self.tempdir, 'does_not_exist') |
| 644 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 645 | self.response = artifacts_pb2.BundleResponse() |
| 646 | |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 647 | def _GetRequest(self, chroot=None, sysroot=None, build_target=None, |
| 648 | output_dir=None): |
| 649 | """Helper to create a request message instance. |
| 650 | |
| 651 | Args: |
| 652 | chroot (str): The chroot path. |
| 653 | sysroot (str): The sysroot path. |
| 654 | build_target (str): The build target name. |
| 655 | output_dir (str): The output directory. |
| 656 | """ |
| 657 | return artifacts_pb2.BundleRequest( |
| 658 | sysroot={'path': sysroot, 'build_target': {'name': build_target}}, |
| 659 | chroot={'path': chroot}, output_dir=output_dir) |
| 660 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 661 | def testValidateOnly(self): |
| 662 | """Sanity check that a validate only call does not execute any logic.""" |
| 663 | patch = self.PatchObject(artifacts_svc, 'BundleSimpleChromeArtifacts') |
| 664 | request = self._GetRequest(chroot=self.chroot_dir, |
| 665 | sysroot=self.sysroot_path, |
| 666 | build_target='board', output_dir=self.output_dir) |
| 667 | artifacts.BundleSimpleChromeArtifacts(request, self.response, |
| 668 | self.validate_only_config) |
| 669 | patch.assert_not_called() |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 670 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 671 | def testMockCall(self): |
| 672 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 673 | patch = self.PatchObject(artifacts_svc, 'BundleSimpleChromeArtifacts') |
| 674 | request = self._GetRequest(chroot=self.chroot_dir, |
| 675 | sysroot=self.sysroot_path, |
| 676 | build_target='board', output_dir=self.output_dir) |
| 677 | artifacts.BundleSimpleChromeArtifacts(request, self.response, |
| 678 | self.mock_call_config) |
| 679 | patch.assert_not_called() |
| 680 | self.assertEqual(len(self.response.artifacts), 1) |
| 681 | self.assertEqual(self.response.artifacts[0].path, |
| 682 | os.path.join(self.output_dir, 'simple_chrome.txt')) |
| 683 | |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 684 | def testNoBuildTarget(self): |
| 685 | """Test no build target fails.""" |
| 686 | request = self._GetRequest(chroot=self.chroot_dir, |
| 687 | sysroot=self.sysroot_path, |
| 688 | output_dir=self.output_dir) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 689 | response = self.response |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 690 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 691 | artifacts.BundleSimpleChromeArtifacts(request, response, self.api_config) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 692 | |
| 693 | def testNoSysroot(self): |
| 694 | """Test no sysroot fails.""" |
| 695 | request = self._GetRequest(build_target='board', output_dir=self.output_dir) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 696 | response = self.response |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 697 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 698 | artifacts.BundleSimpleChromeArtifacts(request, response, self.api_config) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 699 | |
| 700 | def testSysrootDoesNotExist(self): |
| 701 | """Test no sysroot fails.""" |
| 702 | request = self._GetRequest(build_target='board', output_dir=self.output_dir, |
| 703 | sysroot=self.does_not_exist) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 704 | response = self.response |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 705 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 706 | artifacts.BundleSimpleChromeArtifacts(request, response, self.api_config) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 707 | |
| 708 | def testNoOutputDir(self): |
| 709 | """Test no output dir fails.""" |
| 710 | request = self._GetRequest(chroot=self.chroot_dir, |
| 711 | sysroot=self.sysroot_path, |
| 712 | build_target='board') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 713 | response = self.response |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 714 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 715 | artifacts.BundleSimpleChromeArtifacts(request, response, self.api_config) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 716 | |
| 717 | def testOutputDirDoesNotExist(self): |
| 718 | """Test no output dir fails.""" |
| 719 | request = self._GetRequest(chroot=self.chroot_dir, |
| 720 | sysroot=self.sysroot_path, |
| 721 | build_target='board', |
| 722 | output_dir=self.does_not_exist) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 723 | response = self.response |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 724 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 725 | artifacts.BundleSimpleChromeArtifacts(request, response, self.api_config) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 726 | |
| 727 | def testOutputHandling(self): |
| 728 | """Test response output.""" |
| 729 | files = ['file1', 'file2', 'file3'] |
| 730 | expected_files = [os.path.join(self.output_dir, f) for f in files] |
| 731 | self.PatchObject(artifacts_svc, 'BundleSimpleChromeArtifacts', |
| 732 | return_value=expected_files) |
| 733 | request = self._GetRequest(chroot=self.chroot_dir, |
| 734 | sysroot=self.sysroot_path, |
| 735 | build_target='board', output_dir=self.output_dir) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 736 | response = self.response |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 737 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 738 | artifacts.BundleSimpleChromeArtifacts(request, response, self.api_config) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 739 | |
| 740 | self.assertTrue(response.artifacts) |
Mike Frysinger | 678735c | 2019-09-28 18:23:28 -0400 | [diff] [blame] | 741 | self.assertCountEqual(expected_files, [a.path for a in response.artifacts]) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 742 | |
| 743 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 744 | class BundleVmFilesTest(cros_test_lib.MockTempDirTestCase, |
| 745 | api_config.ApiConfigMixin): |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 746 | """BuildVmFiles tests.""" |
| 747 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 748 | def setUp(self): |
| 749 | self.output_dir = os.path.join(self.tempdir, 'output') |
| 750 | osutils.SafeMakedirs(self.output_dir) |
| 751 | |
| 752 | self.response = artifacts_pb2.BundleResponse() |
| 753 | |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 754 | def _GetInput(self, chroot=None, sysroot=None, test_results_dir=None, |
| 755 | output_dir=None): |
| 756 | """Helper to build out an input message instance. |
| 757 | |
| 758 | Args: |
| 759 | chroot (str|None): The chroot path. |
| 760 | sysroot (str|None): The sysroot path relative to the chroot. |
| 761 | test_results_dir (str|None): The test results directory relative to the |
| 762 | sysroot. |
| 763 | output_dir (str|None): The directory where the results tarball should be |
| 764 | saved. |
| 765 | """ |
| 766 | return artifacts_pb2.BundleVmFilesRequest( |
| 767 | chroot={'path': chroot}, sysroot={'path': sysroot}, |
| 768 | test_results_dir=test_results_dir, output_dir=output_dir, |
| 769 | ) |
| 770 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 771 | def testValidateOnly(self): |
| 772 | """Sanity check that a validate only call does not execute any logic.""" |
| 773 | patch = self.PatchObject(artifacts_svc, 'BundleVmFiles') |
| 774 | in_proto = self._GetInput(chroot='/chroot/dir', sysroot='/build/board', |
| 775 | test_results_dir='/test/results', |
| 776 | output_dir=self.output_dir) |
| 777 | artifacts.BundleVmFiles(in_proto, self.response, self.validate_only_config) |
| 778 | patch.assert_not_called() |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 779 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 780 | def testMockCall(self): |
| 781 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 782 | patch = self.PatchObject(artifacts_svc, 'BundleVmFiles') |
| 783 | in_proto = self._GetInput(chroot='/chroot/dir', sysroot='/build/board', |
| 784 | test_results_dir='/test/results', |
| 785 | output_dir=self.output_dir) |
| 786 | artifacts.BundleVmFiles(in_proto, self.response, self.mock_call_config) |
| 787 | patch.assert_not_called() |
| 788 | self.assertEqual(len(self.response.artifacts), 1) |
| 789 | self.assertEqual(self.response.artifacts[0].path, |
| 790 | os.path.join(self.output_dir, 'f1.tar')) |
| 791 | |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 792 | def testChrootMissing(self): |
| 793 | """Test error handling for missing chroot.""" |
| 794 | in_proto = self._GetInput(sysroot='/build/board', |
| 795 | test_results_dir='/test/results', |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 796 | output_dir=self.output_dir) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 797 | |
| 798 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 799 | artifacts.BundleVmFiles(in_proto, self.response, self.api_config) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 800 | |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 801 | def testTestResultsDirMissing(self): |
| 802 | """Test error handling for missing test results directory.""" |
| 803 | in_proto = self._GetInput(chroot='/chroot/dir', sysroot='/build/board', |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 804 | output_dir=self.output_dir) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 805 | |
| 806 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 807 | artifacts.BundleVmFiles(in_proto, self.response, self.api_config) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 808 | |
| 809 | def testOutputDirMissing(self): |
| 810 | """Test error handling for missing output directory.""" |
| 811 | in_proto = self._GetInput(chroot='/chroot/dir', sysroot='/build/board', |
| 812 | test_results_dir='/test/results') |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 813 | |
| 814 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 815 | artifacts.BundleVmFiles(in_proto, self.response, self.api_config) |
| 816 | |
| 817 | def testOutputDirDoesNotExist(self): |
| 818 | """Test error handling for output directory that does not exist.""" |
| 819 | in_proto = self._GetInput(chroot='/chroot/dir', sysroot='/build/board', |
| 820 | output_dir=os.path.join(self.tempdir, 'dne'), |
| 821 | test_results_dir='/test/results') |
| 822 | |
| 823 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 824 | artifacts.BundleVmFiles(in_proto, self.response, self.api_config) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 825 | |
| 826 | def testValidCall(self): |
| 827 | """Test image dir building.""" |
| 828 | in_proto = self._GetInput(chroot='/chroot/dir', sysroot='/build/board', |
| 829 | test_results_dir='/test/results', |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 830 | output_dir=self.output_dir) |
| 831 | |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 832 | expected_files = ['/tmp/output/f1.tar', '/tmp/output/f2.tar'] |
Michael Mortensen | 51f0672 | 2019-07-18 09:55:50 -0600 | [diff] [blame] | 833 | patch = self.PatchObject(artifacts_svc, 'BundleVmFiles', |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 834 | return_value=expected_files) |
| 835 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 836 | artifacts.BundleVmFiles(in_proto, self.response, self.api_config) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 837 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 838 | patch.assert_called_with(mock.ANY, '/test/results', self.output_dir) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 839 | |
| 840 | # Make sure we have artifacts, and that every artifact is an expected file. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 841 | self.assertTrue(self.response.artifacts) |
| 842 | for artifact in self.response.artifacts: |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 843 | self.assertIn(artifact.path, expected_files) |
| 844 | expected_files.remove(artifact.path) |
| 845 | |
| 846 | # Make sure we've seen all of the expected files. |
| 847 | self.assertFalse(expected_files) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 848 | |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 849 | |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 850 | |
| 851 | class BundleAFDOGenerationArtifactsTestCase( |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 852 | cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin): |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 853 | """Unittests for BundleAFDOGenerationArtifacts.""" |
| 854 | |
| 855 | @staticmethod |
| 856 | def mock_die(message, *args): |
| 857 | raise cros_build_lib.DieSystemExit(message % args) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 858 | |
| 859 | def setUp(self): |
| 860 | self.chroot_dir = os.path.join(self.tempdir, 'chroot_dir') |
| 861 | osutils.SafeMakedirs(self.chroot_dir) |
| 862 | temp_dir = os.path.join(self.chroot_dir, 'tmp') |
| 863 | osutils.SafeMakedirs(temp_dir) |
| 864 | self.output_dir = os.path.join(self.tempdir, 'output_dir') |
| 865 | osutils.SafeMakedirs(self.output_dir) |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 866 | self.chrome_root = os.path.join(self.tempdir, 'chrome_root') |
| 867 | osutils.SafeMakedirs(self.chrome_root) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 868 | self.build_target = 'board' |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 869 | self.valid_artifact_type = toolchain_pb2.ORDERFILE |
| 870 | self.invalid_artifact_type = toolchain_pb2.NONE_TYPE |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 871 | self.does_not_exist = os.path.join(self.tempdir, 'does_not_exist') |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 872 | self.PatchObject(cros_build_lib, 'Die', new=self.mock_die) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 873 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 874 | self.response = artifacts_pb2.BundleResponse() |
| 875 | |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 876 | def _GetRequest(self, chroot=None, build_target=None, chrome_root=None, |
| 877 | output_dir=None, artifact_type=None): |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 878 | """Helper to create a request message instance. |
| 879 | |
| 880 | Args: |
| 881 | chroot (str): The chroot path. |
| 882 | build_target (str): The build target name. |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 883 | chrome_root (str): The path to Chrome root. |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 884 | output_dir (str): The output directory. |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 885 | artifact_type (artifacts_pb2.AFDOArtifactType): |
| 886 | The type of the artifact. |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 887 | """ |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 888 | return artifacts_pb2.BundleChromeAFDORequest( |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 889 | chroot={'path': chroot, 'chrome_dir': chrome_root}, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 890 | build_target={'name': build_target}, |
| 891 | output_dir=output_dir, |
| 892 | artifact_type=artifact_type, |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 893 | ) |
| 894 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 895 | def testValidateOnly(self): |
| 896 | """Sanity check that a validate only call does not execute any logic.""" |
| 897 | patch = self.PatchObject(artifacts_svc, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 898 | 'BundleAFDOGenerationArtifacts') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 899 | request = self._GetRequest(chroot=self.chroot_dir, |
| 900 | build_target=self.build_target, |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 901 | chrome_root=self.chrome_root, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 902 | output_dir=self.output_dir, |
| 903 | artifact_type=self.valid_artifact_type) |
| 904 | artifacts.BundleAFDOGenerationArtifacts(request, self.response, |
| 905 | self.validate_only_config) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 906 | patch.assert_not_called() |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 907 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 908 | def testMockCall(self): |
| 909 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 910 | patch = self.PatchObject(artifacts_svc, |
| 911 | 'BundleAFDOGenerationArtifacts') |
| 912 | request = self._GetRequest(chroot=self.chroot_dir, |
| 913 | build_target=self.build_target, |
| 914 | chrome_root=self.chrome_root, |
| 915 | output_dir=self.output_dir, |
| 916 | artifact_type=self.valid_artifact_type) |
| 917 | artifacts.BundleAFDOGenerationArtifacts(request, self.response, |
| 918 | self.mock_call_config) |
| 919 | patch.assert_not_called() |
| 920 | self.assertEqual(len(self.response.artifacts), 1) |
| 921 | self.assertEqual(self.response.artifacts[0].path, |
| 922 | os.path.join(self.output_dir, 'artifact1')) |
| 923 | |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 924 | def testNoBuildTarget(self): |
| 925 | """Test no build target fails.""" |
| 926 | request = self._GetRequest(chroot=self.chroot_dir, |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 927 | chrome_root=self.chrome_root, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 928 | output_dir=self.output_dir, |
| 929 | artifact_type=self.valid_artifact_type) |
| 930 | with self.assertRaises(cros_build_lib.DieSystemExit) as context: |
| 931 | artifacts.BundleAFDOGenerationArtifacts(request, self.response, |
| 932 | self.api_config) |
| 933 | self.assertEqual('build_target.name is required.', |
| 934 | str(context.exception)) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 935 | |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 936 | def testNoChromeRoot(self): |
| 937 | """Test no chrome root fails.""" |
| 938 | request = self._GetRequest(chroot=self.chroot_dir, |
| 939 | build_target=self.build_target, |
| 940 | output_dir=self.output_dir, |
| 941 | artifact_type=self.valid_artifact_type) |
| 942 | with self.assertRaises(cros_build_lib.DieSystemExit) as context: |
| 943 | artifacts.BundleAFDOGenerationArtifacts(request, self.response, |
| 944 | self.api_config) |
| 945 | self.assertEqual('chroot.chrome_dir path does not exist: ', |
| 946 | str(context.exception)) |
| 947 | |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 948 | def testNoOutputDir(self): |
| 949 | """Test no output dir fails.""" |
| 950 | request = self._GetRequest(chroot=self.chroot_dir, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 951 | build_target=self.build_target, |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 952 | chrome_root=self.chrome_root, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 953 | artifact_type=self.valid_artifact_type) |
| 954 | with self.assertRaises(cros_build_lib.DieSystemExit) as context: |
| 955 | artifacts.BundleAFDOGenerationArtifacts(request, self.response, |
| 956 | self.api_config) |
| 957 | self.assertEqual('output_dir is required.', |
| 958 | str(context.exception)) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 959 | |
| 960 | def testOutputDirDoesNotExist(self): |
| 961 | """Test output directory not existing fails.""" |
| 962 | request = self._GetRequest(chroot=self.chroot_dir, |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 963 | build_target=self.build_target, |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 964 | chrome_root=self.chrome_root, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 965 | output_dir=self.does_not_exist, |
| 966 | artifact_type=self.valid_artifact_type) |
| 967 | with self.assertRaises(cros_build_lib.DieSystemExit) as context: |
| 968 | artifacts.BundleAFDOGenerationArtifacts(request, self.response, |
| 969 | self.api_config) |
| 970 | self.assertEqual( |
| 971 | 'output_dir path does not exist: %s' % self.does_not_exist, |
| 972 | str(context.exception)) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 973 | |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 974 | def testNoArtifactType(self): |
| 975 | """Test no artifact type.""" |
| 976 | request = self._GetRequest(chroot=self.chroot_dir, |
| 977 | build_target=self.build_target, |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 978 | chrome_root=self.chrome_root, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 979 | output_dir=self.output_dir) |
| 980 | with self.assertRaises(cros_build_lib.DieSystemExit) as context: |
| 981 | artifacts.BundleAFDOGenerationArtifacts(request, self.response, |
| 982 | self.api_config) |
| 983 | self.assertIn('artifact_type (0) must be in', |
| 984 | str(context.exception)) |
| 985 | |
| 986 | def testWrongArtifactType(self): |
| 987 | """Test passing wrong artifact type.""" |
| 988 | request = self._GetRequest(chroot=self.chroot_dir, |
| 989 | build_target=self.build_target, |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 990 | chrome_root=self.chrome_root, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 991 | output_dir=self.output_dir, |
| 992 | artifact_type=self.invalid_artifact_type) |
| 993 | with self.assertRaises(cros_build_lib.DieSystemExit) as context: |
| 994 | artifacts.BundleAFDOGenerationArtifacts(request, self.response, |
| 995 | self.api_config) |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 996 | self.assertIn('artifact_type (%d) must be in' % self.invalid_artifact_type, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 997 | str(context.exception)) |
| 998 | |
| 999 | def testOutputHandlingOnOrderfile(self, |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 1000 | artifact_type=toolchain_pb2.ORDERFILE): |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 1001 | """Test response output for orderfile.""" |
| 1002 | files = ['artifact1', 'artifact2', 'artifact3'] |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 1003 | expected_files = [os.path.join(self.output_dir, f) for f in files] |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 1004 | self.PatchObject(artifacts_svc, 'BundleAFDOGenerationArtifacts', |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 1005 | return_value=expected_files) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 1006 | |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 1007 | request = self._GetRequest(chroot=self.chroot_dir, |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 1008 | build_target=self.build_target, |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 1009 | chrome_root=self.chrome_root, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 1010 | output_dir=self.output_dir, |
| 1011 | artifact_type=artifact_type) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 1012 | |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 1013 | artifacts.BundleAFDOGenerationArtifacts(request, self.response, |
| 1014 | self.api_config) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 1015 | |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 1016 | self.assertTrue(self.response.artifacts) |
Mike Frysinger | 678735c | 2019-09-28 18:23:28 -0400 | [diff] [blame] | 1017 | self.assertCountEqual(expected_files, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 1018 | [a.path for a in self.response.artifacts]) |
| 1019 | |
| 1020 | def testOutputHandlingOnAFDO(self): |
| 1021 | """Test response output for AFDO.""" |
| 1022 | self.testOutputHandlingOnOrderfile( |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 1023 | artifact_type=toolchain_pb2.BENCHMARK_AFDO) |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 1024 | |
| 1025 | |
| 1026 | class ExportCpeReportTest(cros_test_lib.MockTempDirTestCase, |
| 1027 | api_config.ApiConfigMixin): |
| 1028 | """ExportCpeReport tests.""" |
| 1029 | |
| 1030 | def setUp(self): |
| 1031 | self.response = artifacts_pb2.BundleResponse() |
| 1032 | |
| 1033 | def testValidateOnly(self): |
| 1034 | """Sanity check validate only calls don't execute.""" |
| 1035 | patch = self.PatchObject(artifacts_svc, 'GenerateCpeReport') |
| 1036 | |
| 1037 | request = artifacts_pb2.BundleRequest() |
| 1038 | request.build_target.name = 'board' |
| 1039 | request.output_dir = self.tempdir |
| 1040 | |
| 1041 | artifacts.ExportCpeReport(request, self.response, self.validate_only_config) |
| 1042 | |
| 1043 | patch.assert_not_called() |
| 1044 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 1045 | def testMockCall(self): |
| 1046 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 1047 | patch = self.PatchObject(artifacts_svc, 'GenerateCpeReport') |
| 1048 | |
| 1049 | request = artifacts_pb2.BundleRequest() |
| 1050 | request.build_target.name = 'board' |
| 1051 | request.output_dir = self.tempdir |
| 1052 | |
| 1053 | artifacts.ExportCpeReport(request, self.response, self.mock_call_config) |
| 1054 | |
| 1055 | patch.assert_not_called() |
| 1056 | self.assertEqual(len(self.response.artifacts), 2) |
| 1057 | self.assertEqual(self.response.artifacts[0].path, |
| 1058 | os.path.join(self.tempdir, 'cpe_report.txt')) |
| 1059 | self.assertEqual(self.response.artifacts[1].path, |
| 1060 | os.path.join(self.tempdir, 'cpe_warnings.txt')) |
| 1061 | |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 1062 | def testNoBuildTarget(self): |
| 1063 | request = artifacts_pb2.BundleRequest() |
| 1064 | request.output_dir = self.tempdir |
| 1065 | |
| 1066 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 1067 | artifacts.ExportCpeReport(request, self.response, self.api_config) |
| 1068 | |
| 1069 | def testSuccess(self): |
| 1070 | """Test success case.""" |
| 1071 | expected = artifacts_svc.CpeResult( |
| 1072 | report='/output/report.json', warnings='/output/warnings.json') |
| 1073 | self.PatchObject(artifacts_svc, 'GenerateCpeReport', return_value=expected) |
| 1074 | |
| 1075 | request = artifacts_pb2.BundleRequest() |
| 1076 | request.build_target.name = 'board' |
| 1077 | request.output_dir = self.tempdir |
| 1078 | |
| 1079 | artifacts.ExportCpeReport(request, self.response, self.api_config) |
| 1080 | |
| 1081 | for artifact in self.response.artifacts: |
| 1082 | self.assertIn(artifact.path, [expected.report, expected.warnings]) |
Shao-Chuan Lee | a44dddc | 2020-10-30 17:16:55 +0900 | [diff] [blame] | 1083 | |
| 1084 | |
| 1085 | class BundleGceTarballTest(BundleTestCase): |
| 1086 | """Unittests for BundleGceTarball.""" |
| 1087 | |
| 1088 | def testValidateOnly(self): |
| 1089 | """Check that a validate only call does not execute any logic.""" |
| 1090 | patch = self.PatchObject(artifacts_svc, 'BundleGceTarball') |
| 1091 | artifacts.BundleGceTarball(self.target_request, self.response, |
| 1092 | self.validate_only_config) |
| 1093 | patch.assert_not_called() |
| 1094 | |
| 1095 | def testMockCall(self): |
| 1096 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 1097 | patch = self.PatchObject(artifacts_svc, 'BundleGceTarball') |
| 1098 | artifacts.BundleGceTarball(self.target_request, self.response, |
| 1099 | self.mock_call_config) |
| 1100 | patch.assert_not_called() |
| 1101 | self.assertEqual(len(self.response.artifacts), 1) |
| 1102 | self.assertEqual(self.response.artifacts[0].path, |
| 1103 | os.path.join(self.output_dir, |
| 1104 | constants.TEST_IMAGE_GCE_TAR)) |
| 1105 | |
| 1106 | def testBundleGceTarball(self): |
| 1107 | """BundleGceTarball calls cbuildbot/commands with correct args.""" |
| 1108 | bundle_gce_tarball = self.PatchObject( |
| 1109 | artifacts_svc, 'BundleGceTarball', |
| 1110 | return_value=os.path.join(self.output_dir, |
| 1111 | constants.TEST_IMAGE_GCE_TAR)) |
| 1112 | self.PatchObject(os.path, 'exists', return_value=True) |
| 1113 | artifacts.BundleGceTarball(self.target_request, self.response, |
| 1114 | self.api_config) |
| 1115 | self.assertEqual( |
| 1116 | [artifact.path for artifact in self.response.artifacts], |
| 1117 | [os.path.join(self.output_dir, constants.TEST_IMAGE_GCE_TAR)]) |
| 1118 | |
| 1119 | latest = os.path.join(self.source_root, 'src/build/images/target/latest') |
| 1120 | self.assertEqual( |
| 1121 | bundle_gce_tarball.call_args_list, |
| 1122 | [mock.call(self.output_dir, latest)]) |
| 1123 | |
| 1124 | def testBundleGceTarballNoImageDir(self): |
| 1125 | """BundleGceTarball dies when image dir does not exist.""" |
| 1126 | self.PatchObject(os.path, 'exists', return_value=False) |
| 1127 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 1128 | artifacts.BundleGceTarball(self.target_request, self.response, |
| 1129 | self.api_config) |
Michael Mortensen | 6667b54 | 2020-12-12 11:09:55 -0700 | [diff] [blame] | 1130 | |
| 1131 | |
| 1132 | class BundleDebugSymbolsTest(BundleTestCase): |
| 1133 | """Unittests for BundleDebugSymbols.""" |
| 1134 | |
| 1135 | def setUp(self): |
| 1136 | # Create a chroot_path that also includes a chroot tmp dir. |
| 1137 | self.chroot_path = os.path.join(self.tempdir, 'chroot_dir') |
| 1138 | osutils.SafeMakedirs(self.chroot_path) |
| 1139 | osutils.SafeMakedirs(os.path.join(self.chroot_path, 'tmp')) |
| 1140 | # Create output dir. |
| 1141 | output_dir = os.path.join(self.tempdir, 'output_dir') |
| 1142 | osutils.SafeMakedirs(output_dir) |
| 1143 | # Build target request. |
| 1144 | self.target_request = self.BuildTargetRequest( |
| 1145 | build_target='target', |
| 1146 | output_dir=self.output_dir, |
| 1147 | chroot=self.chroot_path) |
| 1148 | |
| 1149 | def testValidateOnly(self): |
| 1150 | """Check that a validate only call does not execute any logic.""" |
| 1151 | patch = self.PatchObject(artifacts_svc, 'GenerateBreakpadSymbols') |
| 1152 | artifacts.BundleDebugSymbols(self.target_request, self.response, |
| 1153 | self.validate_only_config) |
| 1154 | patch.assert_not_called() |
| 1155 | |
| 1156 | def testMockCall(self): |
| 1157 | """Test that a mock call does not execute logic, returns mocked value.""" |
| 1158 | patch = self.PatchObject(artifacts_svc, 'GenerateBreakpadSymbols') |
| 1159 | artifacts.BundleDebugSymbols(self.target_request, self.response, |
| 1160 | self.mock_call_config) |
| 1161 | patch.assert_not_called() |
| 1162 | self.assertEqual(len(self.response.artifacts), 1) |
| 1163 | self.assertEqual(self.response.artifacts[0].path, |
| 1164 | os.path.join(self.output_dir, |
| 1165 | constants.DEBUG_SYMBOLS_TAR)) |
| 1166 | |
| 1167 | def testBundleDebugSymbols(self): |
| 1168 | """BundleDebugSymbols calls cbuildbot/commands with correct args.""" |
| 1169 | # Patch service layer functions. |
| 1170 | generate_breakpad_symbols_patch = self.PatchObject( |
| 1171 | artifacts_svc, 'GenerateBreakpadSymbols', |
| 1172 | return_value=cros_build_lib.CommandResult(returncode=0, output='')) |
| 1173 | gather_symbol_files_patch = self.PatchObject( |
| 1174 | artifacts_svc, 'GatherSymbolFiles', |
| 1175 | return_value=[artifacts_svc.SymbolFileTuple( |
| 1176 | source_file_name='path/to/source/file1.sym', |
| 1177 | relative_path='file1.sym')]) |
| 1178 | |
| 1179 | artifacts.BundleDebugSymbols(self.target_request, self.response, |
| 1180 | self.api_config) |
| 1181 | # Verify mock objects were called. |
Michael Mortensen | 7da39cc | 2021-03-09 10:28:45 -0700 | [diff] [blame] | 1182 | build_target = build_target_lib.BuildTarget('target') |
| 1183 | generate_breakpad_symbols_patch.assert_called_with( |
| 1184 | mock.ANY, build_target, debug=True) |
Michael Mortensen | 6667b54 | 2020-12-12 11:09:55 -0700 | [diff] [blame] | 1185 | gather_symbol_files_patch.assert_called() |
| 1186 | |
| 1187 | # Verify response proto contents and output directory contents. |
| 1188 | self.assertEqual( |
| 1189 | [artifact.path for artifact in self.response.artifacts], |
| 1190 | [os.path.join(self.output_dir, constants.DEBUG_SYMBOLS_TAR)]) |
| 1191 | files = os.listdir(self.output_dir) |
| 1192 | self.assertEqual(files, [constants.DEBUG_SYMBOLS_TAR]) |
| 1193 | |
| 1194 | def testBundleGceTarballNoImageDir(self): |
| 1195 | """BundleDebugSymbols dies when image dir does not exist.""" |
| 1196 | self.PatchObject(os.path, 'exists', return_value=False) |
| 1197 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 1198 | artifacts.BundleDebugSymbols(self.target_request, self.response, |
| 1199 | self.api_config) |