Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2019 The ChromiumOS Authors |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [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 Toolchain-related operations.""" |
| 6 | |
Alex Klein | cd03a5e | 2021-10-18 13:23:47 -0600 | [diff] [blame] | 7 | import os |
| 8 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 9 | from chromite.api import api_config |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 10 | from chromite.api import controller |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 11 | from chromite.api.controller import toolchain |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 12 | from chromite.api.gen.chromite.api import artifacts_pb2 |
LaMont Jones | 4579e8c | 2019-12-06 14:20:37 -0700 | [diff] [blame] | 13 | from chromite.api.gen.chromite.api import sysroot_pb2 |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 14 | from chromite.api.gen.chromite.api import toolchain_pb2 |
LaMont Jones | 4579e8c | 2019-12-06 14:20:37 -0700 | [diff] [blame] | 15 | from chromite.api.gen.chromiumos import common_pb2 |
Mike Frysinger | 1cc8f1f | 2022-04-28 22:40:40 -0400 | [diff] [blame] | 16 | from chromite.api.gen.chromiumos.builder_config_pb2 import BuilderConfig |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 17 | from chromite.lib import cros_build_lib |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 18 | from chromite.lib import cros_test_lib |
Alex Klein | cd03a5e | 2021-10-18 13:23:47 -0600 | [diff] [blame] | 19 | from chromite.lib import osutils |
Jack Neus | 4ee7b1d | 2022-06-27 19:54:18 +0000 | [diff] [blame] | 20 | from chromite.lib import toolchain as toolchain_lib |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 21 | from chromite.lib import toolchain_util |
| 22 | |
Mike Frysinger | 1cc8f1f | 2022-04-28 22:40:40 -0400 | [diff] [blame] | 23 | |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 24 | # pylint: disable=protected-access |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 25 | |
Tiancong Wang | ba2a1c2 | 2021-01-19 10:45:06 -0800 | [diff] [blame] | 26 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 27 | class UpdateEbuildWithAFDOArtifactsTest( |
| 28 | cros_test_lib.MockTestCase, api_config.ApiConfigMixin |
| 29 | ): |
| 30 | """Unittests for UpdateEbuildWithAFDOArtifacts.""" |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 31 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 32 | @staticmethod |
| 33 | def mock_die(message, *args): |
| 34 | raise cros_build_lib.DieSystemExit(message % args) |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 35 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 36 | def setUp(self): |
| 37 | self.board = "board" |
| 38 | self.response = toolchain_pb2.VerifyAFDOArtifactsResponse() |
| 39 | self.invalid_artifact_type = toolchain_pb2.BENCHMARK_AFDO |
| 40 | self.PatchObject(cros_build_lib, "Die", new=self.mock_die) |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 41 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 42 | def _GetRequest(self, build_target=None, artifact_type=None): |
| 43 | return toolchain_pb2.VerifyAFDOArtifactsRequest( |
| 44 | build_target={"name": build_target}, |
| 45 | artifact_type=artifact_type, |
| 46 | ) |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 47 | |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 48 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 49 | class PrepareForBuildTest( |
| 50 | cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin |
| 51 | ): |
| 52 | """Unittests for PrepareForBuild.""" |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 53 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 54 | def setUp(self): |
| 55 | self.response = toolchain_pb2.PrepareForToolchainBuildResponse() |
| 56 | self.prep = self.PatchObject( |
| 57 | toolchain_util, |
| 58 | "PrepareForBuild", |
| 59 | return_value=toolchain_util.PrepareForBuildReturn.NEEDED, |
| 60 | ) |
| 61 | self.bundle = self.PatchObject( |
| 62 | toolchain_util, "BundleArtifacts", return_value=[] |
| 63 | ) |
| 64 | self.PatchObject( |
| 65 | toolchain, |
| 66 | "_TOOLCHAIN_ARTIFACT_HANDLERS", |
| 67 | { |
| 68 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE: toolchain._Handlers( |
| 69 | "UnverifiedChromeLlvmOrderfile", self.prep, self.bundle |
| 70 | ), |
| 71 | }, |
| 72 | ) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 73 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 74 | def _GetRequest( |
| 75 | self, artifact_types=None, input_artifacts=None, additional_args=None |
| 76 | ): |
| 77 | chroot = common_pb2.Chroot(path=str(self.tempdir)) |
| 78 | sysroot = sysroot_pb2.Sysroot( |
| 79 | path="/build/board", |
| 80 | build_target=common_pb2.BuildTarget(name="board"), |
| 81 | ) |
| 82 | return toolchain_pb2.PrepareForToolchainBuildRequest( |
| 83 | artifact_types=artifact_types, |
| 84 | chroot=chroot, |
| 85 | sysroot=sysroot, |
| 86 | input_artifacts=input_artifacts, |
| 87 | additional_args=additional_args, |
| 88 | ) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 89 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 90 | def testRaisesForUnknown(self): |
| 91 | request = self._GetRequest([BuilderConfig.Artifacts.IMAGE_ARCHIVES]) |
| 92 | self.assertRaises( |
| 93 | KeyError, |
| 94 | toolchain.PrepareForBuild, |
| 95 | request, |
| 96 | self.response, |
| 97 | self.api_config, |
| 98 | ) |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 99 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 100 | def testAcceptsNone(self): |
| 101 | request = toolchain_pb2.PrepareForToolchainBuildRequest( |
| 102 | artifact_types=[ |
| 103 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE |
| 104 | ], |
| 105 | chroot=None, |
| 106 | sysroot=None, |
| 107 | ) |
| 108 | toolchain.PrepareForBuild(request, self.response, self.api_config) |
| 109 | self.prep.assert_called_once_with( |
| 110 | "UnverifiedChromeLlvmOrderfile", None, "", "", {}, {} |
| 111 | ) |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 112 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 113 | def testHandlesUnknownInputArtifacts(self): |
| 114 | request = toolchain_pb2.PrepareForToolchainBuildRequest( |
| 115 | artifact_types=[ |
| 116 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE |
| 117 | ], |
| 118 | chroot=None, |
| 119 | sysroot=None, |
| 120 | input_artifacts=[ |
| 121 | BuilderConfig.Artifacts.InputArtifactInfo( |
| 122 | input_artifact_type=BuilderConfig.Artifacts.IMAGE_ZIP, |
| 123 | input_artifact_gs_locations=["path1"], |
| 124 | ), |
| 125 | ], |
| 126 | ) |
| 127 | toolchain.PrepareForBuild(request, self.response, self.api_config) |
| 128 | self.prep.assert_called_once_with( |
| 129 | "UnverifiedChromeLlvmOrderfile", None, "", "", {}, {} |
| 130 | ) |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 131 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 132 | def testPassesProfileInfo(self): |
| 133 | request = toolchain_pb2.PrepareForToolchainBuildRequest( |
| 134 | artifact_types=[ |
| 135 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE |
| 136 | ], |
| 137 | chroot=None, |
| 138 | sysroot=None, |
| 139 | input_artifacts=[ |
| 140 | BuilderConfig.Artifacts.InputArtifactInfo( |
| 141 | input_artifact_type=BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE, |
| 142 | input_artifact_gs_locations=["path1", "path2"], |
| 143 | ), |
| 144 | BuilderConfig.Artifacts.InputArtifactInfo( |
| 145 | input_artifact_type=BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE, |
| 146 | input_artifact_gs_locations=["path3"], |
| 147 | ), |
| 148 | ], |
| 149 | profile_info=common_pb2.ArtifactProfileInfo( |
| 150 | chrome_cwp_profile="CWPVERSION" |
| 151 | ), |
| 152 | ) |
| 153 | toolchain.PrepareForBuild(request, self.response, self.api_config) |
| 154 | self.prep.assert_called_once_with( |
| 155 | "UnverifiedChromeLlvmOrderfile", |
| 156 | None, |
| 157 | "", |
| 158 | "", |
| 159 | { |
| 160 | "UnverifiedChromeLlvmOrderfile": [ |
| 161 | "gs://path1", |
| 162 | "gs://path2", |
| 163 | "gs://path3", |
| 164 | ], |
| 165 | }, |
| 166 | {"chrome_cwp_profile": "CWPVERSION"}, |
| 167 | ) |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 168 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 169 | def testPassesProfileInfoAfdoRelease(self): |
| 170 | request = toolchain_pb2.PrepareForToolchainBuildRequest( |
| 171 | artifact_types=[ |
| 172 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE |
| 173 | ], |
| 174 | chroot=None, |
| 175 | sysroot=None, |
| 176 | input_artifacts=[ |
| 177 | BuilderConfig.Artifacts.InputArtifactInfo( |
| 178 | input_artifact_type=BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE, |
| 179 | input_artifact_gs_locations=["path1", "path2"], |
| 180 | ), |
| 181 | BuilderConfig.Artifacts.InputArtifactInfo( |
| 182 | input_artifact_type=BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE, |
| 183 | input_artifact_gs_locations=["path3"], |
| 184 | ), |
| 185 | ], |
| 186 | profile_info=common_pb2.ArtifactProfileInfo( |
| 187 | afdo_release=common_pb2.AfdoRelease( |
| 188 | chrome_cwp_profile="CWPVERSION", image_build_id=1234 |
| 189 | ) |
| 190 | ), |
| 191 | ) |
| 192 | toolchain.PrepareForBuild(request, self.response, self.api_config) |
| 193 | self.prep.assert_called_once_with( |
| 194 | "UnverifiedChromeLlvmOrderfile", |
| 195 | None, |
| 196 | "", |
| 197 | "", |
| 198 | { |
| 199 | "UnverifiedChromeLlvmOrderfile": [ |
| 200 | "gs://path1", |
| 201 | "gs://path2", |
| 202 | "gs://path3", |
| 203 | ], |
| 204 | }, |
| 205 | {"chrome_cwp_profile": "CWPVERSION", "image_build_id": 1234}, |
| 206 | ) |
LaMont Jones | e782167 | 2020-04-09 08:56:26 -0600 | [diff] [blame] | 207 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 208 | def testHandlesDuplicateInputArtifacts(self): |
| 209 | request = toolchain_pb2.PrepareForToolchainBuildRequest( |
| 210 | artifact_types=[ |
| 211 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE |
| 212 | ], |
| 213 | chroot=None, |
| 214 | sysroot=None, |
| 215 | input_artifacts=[ |
| 216 | BuilderConfig.Artifacts.InputArtifactInfo( |
| 217 | input_artifact_type=BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE, |
| 218 | input_artifact_gs_locations=["path1", "path2"], |
| 219 | ), |
| 220 | BuilderConfig.Artifacts.InputArtifactInfo( |
| 221 | input_artifact_type=BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE, |
| 222 | input_artifact_gs_locations=["path3"], |
| 223 | ), |
| 224 | ], |
| 225 | ) |
| 226 | toolchain.PrepareForBuild(request, self.response, self.api_config) |
| 227 | self.prep.assert_called_once_with( |
| 228 | "UnverifiedChromeLlvmOrderfile", |
| 229 | None, |
| 230 | "", |
| 231 | "", |
| 232 | { |
| 233 | "UnverifiedChromeLlvmOrderfile": [ |
| 234 | "gs://path1", |
| 235 | "gs://path2", |
| 236 | "gs://path3", |
| 237 | ], |
| 238 | }, |
| 239 | {}, |
| 240 | ) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 241 | |
| 242 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 243 | class BundleToolchainTest( |
| 244 | cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin |
| 245 | ): |
| 246 | """Unittests for BundleToolchain.""" |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 247 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 248 | def setUp(self): |
| 249 | self.response = toolchain_pb2.BundleToolchainResponse() |
| 250 | self.prep = self.PatchObject( |
| 251 | toolchain_util, |
| 252 | "PrepareForBuild", |
| 253 | return_value=toolchain_util.PrepareForBuildReturn.NEEDED, |
| 254 | ) |
| 255 | self.bundle = self.PatchObject( |
| 256 | toolchain_util, "BundleArtifacts", return_value=[] |
| 257 | ) |
| 258 | self.PatchObject( |
| 259 | toolchain, |
| 260 | "_TOOLCHAIN_ARTIFACT_HANDLERS", |
| 261 | { |
| 262 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE: toolchain._Handlers( |
| 263 | "UnverifiedChromeLlvmOrderfile", self.prep, self.bundle |
| 264 | ), |
| 265 | }, |
| 266 | ) |
| 267 | osutils.WriteFile(os.path.join(self.tempdir, "artifact.txt"), "test") |
| 268 | osutils.Touch(os.path.join(self.tempdir, "empty")) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 269 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 270 | def _GetRequest(self, artifact_types=None): |
| 271 | chroot = common_pb2.Chroot(path=str(self.tempdir)) |
| 272 | sysroot = sysroot_pb2.Sysroot( |
| 273 | path="/build/board", |
| 274 | build_target=common_pb2.BuildTarget(name="board"), |
| 275 | ) |
| 276 | return toolchain_pb2.BundleToolchainRequest( |
| 277 | chroot=chroot, |
| 278 | sysroot=sysroot, |
| 279 | output_dir=str(self.tempdir), |
| 280 | artifact_types=artifact_types, |
| 281 | ) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 282 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 283 | def testRaisesForUnknown(self): |
| 284 | request = self._GetRequest([BuilderConfig.Artifacts.IMAGE_ARCHIVES]) |
| 285 | self.assertEqual( |
| 286 | controller.RETURN_CODE_UNRECOVERABLE, |
| 287 | toolchain.BundleArtifacts(request, self.response, self.api_config), |
| 288 | ) |
Michael Mortensen | 3232ab3 | 2020-01-05 19:14:36 -0700 | [diff] [blame] | 289 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 290 | def testValidateOnly(self): |
| 291 | """Sanity check that a validate only call does not execute any logic.""" |
| 292 | request = self._GetRequest( |
| 293 | [BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE] |
| 294 | ) |
| 295 | toolchain.BundleArtifacts( |
| 296 | request, self.response, self.validate_only_config |
| 297 | ) |
| 298 | self.bundle.assert_not_called() |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 299 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 300 | def testSetsArtifactsInfo(self): |
| 301 | request = self._GetRequest( |
| 302 | [BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE] |
| 303 | ) |
| 304 | self.bundle.return_value = ["artifact.txt", "empty", "does_not_exist"] |
| 305 | toolchain.BundleArtifacts(request, self.response, self.api_config) |
| 306 | self.assertEqual(1, len(self.response.artifacts_info)) |
| 307 | self.assertEqual( |
| 308 | self.response.artifacts_info[0], |
| 309 | toolchain_pb2.ArtifactInfo( |
| 310 | artifact_type=( |
| 311 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE |
| 312 | ), |
| 313 | artifacts=[ |
| 314 | artifacts_pb2.Artifact(path=self.bundle.return_value[0]) |
| 315 | ], |
| 316 | ), |
| 317 | ) |
Tiancong Wang | d521413 | 2021-01-12 10:43:57 -0800 | [diff] [blame] | 318 | |
| 319 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 320 | class GetUpdatedFilesTest( |
| 321 | cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin |
| 322 | ): |
| 323 | """Unittests for GetUpdatedFiles.""" |
Tiancong Wang | d521413 | 2021-01-12 10:43:57 -0800 | [diff] [blame] | 324 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 325 | def setUp(self): |
| 326 | self.response = toolchain_pb2.GetUpdatedFilesResponse() |
| 327 | self.artifact_path = "/any/path/to/metadata" |
| 328 | self.profile_info = common_pb2.ArtifactProfileInfo(kernel_version="4.4") |
| 329 | self.update = self.PatchObject( |
| 330 | toolchain_util, "GetUpdatedFiles", return_value=([], "") |
| 331 | ) |
Tiancong Wang | d521413 | 2021-01-12 10:43:57 -0800 | [diff] [blame] | 332 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 333 | def _GetRequest(self, uploaded_artifacts): |
| 334 | uploaded = [] |
| 335 | for artifact_type, artifact_path, profile_info in uploaded_artifacts: |
| 336 | uploaded.append( |
| 337 | toolchain_pb2.GetUpdatedFilesRequest.UploadedArtifacts( |
| 338 | artifact_info=toolchain_pb2.ArtifactInfo( |
| 339 | artifact_type=artifact_type, |
| 340 | artifacts=[artifacts_pb2.Artifact(path=artifact_path)], |
| 341 | ), |
| 342 | profile_info=profile_info, |
| 343 | ) |
| 344 | ) |
| 345 | return toolchain_pb2.GetUpdatedFilesRequest(uploaded_artifacts=uploaded) |
Tiancong Wang | d521413 | 2021-01-12 10:43:57 -0800 | [diff] [blame] | 346 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 347 | def testRaisesForUnknown(self): |
| 348 | request = self._GetRequest( |
| 349 | [ |
| 350 | ( |
| 351 | BuilderConfig.Artifacts.UNVERIFIED_KERNEL_CWP_AFDO_FILE, |
| 352 | self.artifact_path, |
| 353 | self.profile_info, |
| 354 | ) |
| 355 | ] |
| 356 | ) |
| 357 | self.assertEqual( |
| 358 | controller.RETURN_CODE_UNRECOVERABLE, |
| 359 | toolchain.GetUpdatedFiles(request, self.response, self.api_config), |
| 360 | ) |
Tiancong Wang | d521413 | 2021-01-12 10:43:57 -0800 | [diff] [blame] | 361 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 362 | def testValidateOnly(self): |
| 363 | """Sanity check that a validate only call does not execute any logic.""" |
| 364 | request = self._GetRequest( |
| 365 | [ |
| 366 | ( |
| 367 | BuilderConfig.Artifacts.VERIFIED_KERNEL_CWP_AFDO_FILE, |
| 368 | self.artifact_path, |
| 369 | self.profile_info, |
| 370 | ) |
| 371 | ] |
| 372 | ) |
| 373 | toolchain.GetUpdatedFiles( |
| 374 | request, self.response, self.validate_only_config |
| 375 | ) |
Tiancong Wang | d521413 | 2021-01-12 10:43:57 -0800 | [diff] [blame] | 376 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 377 | def testUpdateSuccess(self): |
| 378 | updated_file = "/path/to/updated_file" |
| 379 | self.update.return_value = ([updated_file], "Commit Message") |
| 380 | request = self._GetRequest( |
| 381 | [ |
| 382 | ( |
| 383 | BuilderConfig.Artifacts.VERIFIED_KERNEL_CWP_AFDO_FILE, |
| 384 | self.artifact_path, |
| 385 | self.profile_info, |
| 386 | ) |
| 387 | ] |
| 388 | ) |
| 389 | toolchain.GetUpdatedFiles(request, self.response, self.api_config) |
| 390 | print(self.response.updated_files) |
| 391 | self.assertEqual(len(self.response.updated_files), 1) |
| 392 | self.assertEqual( |
| 393 | self.response.updated_files[0], |
| 394 | toolchain_pb2.GetUpdatedFilesResponse.UpdatedFile( |
| 395 | path=updated_file |
| 396 | ), |
| 397 | ) |
| 398 | self.assertIn("Commit Message", self.response.commit_message) |
| 399 | self.assertEqual(len(self.response.commit_footer), 0) |
Jack Neus | 4ee7b1d | 2022-06-27 19:54:18 +0000 | [diff] [blame] | 400 | |
| 401 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 402 | class GetToolchainsForBoardTest( |
| 403 | cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin |
| 404 | ): |
| 405 | """Unittests for GetToolchainsForBoard.""" |
Jack Neus | 4ee7b1d | 2022-06-27 19:54:18 +0000 | [diff] [blame] | 406 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 407 | def setUp(self): |
| 408 | self.response = toolchain_pb2.ToolchainsResponse() |
Jack Neus | 4ee7b1d | 2022-06-27 19:54:18 +0000 | [diff] [blame] | 409 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 410 | def _GetRequest(self, board="betty-pi-arc"): |
| 411 | return toolchain_pb2.ToolchainsRequest(board=board) |
Jack Neus | 4ee7b1d | 2022-06-27 19:54:18 +0000 | [diff] [blame] | 412 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 413 | def testValidateOnly(self): |
| 414 | """Confidence check that a validate only call does not execute any logic.""" |
| 415 | request = self._GetRequest() |
| 416 | toolchain.GetToolchainsForBoard( |
| 417 | request, self.response, self.validate_only_config |
| 418 | ) |
Jack Neus | 4ee7b1d | 2022-06-27 19:54:18 +0000 | [diff] [blame] | 419 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 420 | def testUpdateSuccess(self): |
| 421 | toolchain_info = { |
| 422 | "default-a": {"default": True}, |
| 423 | "default-b": {"default": True}, |
| 424 | "nondefault-a": {"default": False}, |
| 425 | "nondefault-b": {"default": False}, |
| 426 | } |
| 427 | self.PatchObject( |
| 428 | toolchain_lib, "GetToolchainsForBoard", return_value=toolchain_info |
| 429 | ) |
Jack Neus | 4ee7b1d | 2022-06-27 19:54:18 +0000 | [diff] [blame] | 430 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 431 | request = self._GetRequest() |
| 432 | toolchain.GetToolchainsForBoard(request, self.response, self.api_config) |
Jack Neus | 4ee7b1d | 2022-06-27 19:54:18 +0000 | [diff] [blame] | 433 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 434 | self.assertEqual( |
| 435 | self.response.default_toolchains, ["default-a", "default-b"] |
| 436 | ) |
| 437 | self.assertEqual( |
| 438 | self.response.nondefault_toolchains, |
| 439 | ["nondefault-a", "nondefault-b"], |
| 440 | ) |