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