Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 1 | # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Unittests for 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 | |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 27 | class UpdateEbuildWithAFDOArtifactsTest(cros_test_lib.MockTestCase, |
| 28 | api_config.ApiConfigMixin): |
| 29 | """Unittests for UpdateEbuildWithAFDOArtifacts.""" |
| 30 | |
| 31 | @staticmethod |
| 32 | def mock_die(message, *args): |
| 33 | raise cros_build_lib.DieSystemExit(message % args) |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 34 | |
| 35 | def setUp(self): |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 36 | self.board = 'board' |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 37 | self.response = toolchain_pb2.VerifyAFDOArtifactsResponse() |
| 38 | self.invalid_artifact_type = toolchain_pb2.BENCHMARK_AFDO |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 39 | self.PatchObject(cros_build_lib, 'Die', new=self.mock_die) |
| 40 | |
| 41 | def _GetRequest(self, build_target=None, artifact_type=None): |
| 42 | return toolchain_pb2.VerifyAFDOArtifactsRequest( |
| 43 | build_target={'name': build_target}, |
| 44 | artifact_type=artifact_type, |
| 45 | ) |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 46 | |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 47 | |
LaMont Jones | 4579e8c | 2019-12-06 14:20:37 -0700 | [diff] [blame] | 48 | class PrepareForBuildTest(cros_test_lib.MockTempDirTestCase, |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 49 | api_config.ApiConfigMixin): |
| 50 | """Unittests for PrepareForBuild.""" |
| 51 | |
| 52 | def setUp(self): |
| 53 | self.response = toolchain_pb2.PrepareForToolchainBuildResponse() |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 54 | self.prep = self.PatchObject( |
Tiancong Wang | ba2a1c2 | 2021-01-19 10:45:06 -0800 | [diff] [blame] | 55 | toolchain_util, |
| 56 | 'PrepareForBuild', |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 57 | return_value=toolchain_util.PrepareForBuildReturn.NEEDED) |
| 58 | self.bundle = self.PatchObject( |
| 59 | toolchain_util, 'BundleArtifacts', return_value=[]) |
Tiancong Wang | ba2a1c2 | 2021-01-19 10:45:06 -0800 | [diff] [blame] | 60 | self.PatchObject( |
| 61 | toolchain, '_TOOLCHAIN_ARTIFACT_HANDLERS', { |
| 62 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE: |
| 63 | toolchain._Handlers('UnverifiedChromeLlvmOrderfile', self.prep, |
| 64 | self.bundle), |
| 65 | }) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 66 | |
Tiancong Wang | ba2a1c2 | 2021-01-19 10:45:06 -0800 | [diff] [blame] | 67 | def _GetRequest(self, |
| 68 | artifact_types=None, |
| 69 | input_artifacts=None, |
| 70 | additional_args=None): |
Mike Frysinger | 3bb61cb | 2022-04-14 16:07:44 -0400 | [diff] [blame] | 71 | chroot = common_pb2.Chroot(path=str(self.tempdir)) |
LaMont Jones | 4579e8c | 2019-12-06 14:20:37 -0700 | [diff] [blame] | 72 | sysroot = sysroot_pb2.Sysroot( |
| 73 | path='/build/board', build_target=common_pb2.BuildTarget(name='board')) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 74 | return toolchain_pb2.PrepareForToolchainBuildRequest( |
Tiancong Wang | ba2a1c2 | 2021-01-19 10:45:06 -0800 | [diff] [blame] | 75 | artifact_types=artifact_types, |
| 76 | chroot=chroot, |
| 77 | sysroot=sysroot, |
| 78 | input_artifacts=input_artifacts, |
| 79 | additional_args=additional_args) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 80 | |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 81 | def testRaisesForUnknown(self): |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 82 | request = self._GetRequest([BuilderConfig.Artifacts.IMAGE_ARCHIVES]) |
Tiancong Wang | ba2a1c2 | 2021-01-19 10:45:06 -0800 | [diff] [blame] | 83 | self.assertRaises(KeyError, toolchain.PrepareForBuild, request, |
| 84 | self.response, self.api_config) |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 85 | |
| 86 | def testAcceptsNone(self): |
| 87 | request = toolchain_pb2.PrepareForToolchainBuildRequest( |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 88 | artifact_types=[ |
Tiancong Wang | ba2a1c2 | 2021-01-19 10:45:06 -0800 | [diff] [blame] | 89 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE |
| 90 | ], |
| 91 | chroot=None, |
| 92 | sysroot=None) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 93 | toolchain.PrepareForBuild(request, self.response, self.api_config) |
Tiancong Wang | ba2a1c2 | 2021-01-19 10:45:06 -0800 | [diff] [blame] | 94 | self.prep.assert_called_once_with('UnverifiedChromeLlvmOrderfile', None, '', |
| 95 | '', {}, {}) |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 96 | |
| 97 | def testHandlesUnknownInputArtifacts(self): |
| 98 | request = toolchain_pb2.PrepareForToolchainBuildRequest( |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 99 | artifact_types=[ |
Tiancong Wang | ba2a1c2 | 2021-01-19 10:45:06 -0800 | [diff] [blame] | 100 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE |
| 101 | ], |
| 102 | chroot=None, |
| 103 | sysroot=None, |
| 104 | input_artifacts=[ |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 105 | BuilderConfig.Artifacts.InputArtifactInfo( |
| 106 | input_artifact_type=BuilderConfig.Artifacts.IMAGE_ZIP, |
| 107 | input_artifact_gs_locations=['path1']), |
| 108 | ]) |
| 109 | toolchain.PrepareForBuild(request, self.response, self.api_config) |
Tiancong Wang | ba2a1c2 | 2021-01-19 10:45:06 -0800 | [diff] [blame] | 110 | self.prep.assert_called_once_with('UnverifiedChromeLlvmOrderfile', None, '', |
| 111 | '', {}, {}) |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 112 | |
LaMont Jones | e782167 | 2020-04-09 08:56:26 -0600 | [diff] [blame] | 113 | def testPassesProfileInfo(self): |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 114 | request = toolchain_pb2.PrepareForToolchainBuildRequest( |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 115 | artifact_types=[ |
| 116 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE], |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 117 | chroot=None, sysroot=None, input_artifacts=[ |
| 118 | BuilderConfig.Artifacts.InputArtifactInfo( |
Mike Frysinger | fcca49e | 2021-03-17 01:09:20 -0400 | [diff] [blame] | 119 | input_artifact_type= |
Alex Klein | cd03a5e | 2021-10-18 13:23:47 -0600 | [diff] [blame] | 120 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE, |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 121 | input_artifact_gs_locations=['path1', 'path2']), |
| 122 | BuilderConfig.Artifacts.InputArtifactInfo( |
Mike Frysinger | fcca49e | 2021-03-17 01:09:20 -0400 | [diff] [blame] | 123 | input_artifact_type= |
Alex Klein | cd03a5e | 2021-10-18 13:23:47 -0600 | [diff] [blame] | 124 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE, |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 125 | input_artifact_gs_locations=['path3']), |
| 126 | ], |
LaMont Jones | e782167 | 2020-04-09 08:56:26 -0600 | [diff] [blame] | 127 | profile_info=common_pb2.ArtifactProfileInfo( |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 128 | chrome_cwp_profile='CWPVERSION'), |
| 129 | ) |
| 130 | toolchain.PrepareForBuild(request, self.response, self.api_config) |
| 131 | self.prep.assert_called_once_with( |
LaMont Jones | d394458 | 2020-03-04 10:37:05 -0700 | [diff] [blame] | 132 | 'UnverifiedChromeLlvmOrderfile', None, '', '', { |
Tiancong Wang | ba2a1c2 | 2021-01-19 10:45:06 -0800 | [diff] [blame] | 133 | 'UnverifiedChromeLlvmOrderfile': |
| 134 | ['gs://path1', 'gs://path2', 'gs://path3'], |
| 135 | }, {'chrome_cwp_profile': 'CWPVERSION'}) |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 136 | |
LaMont Jones | e782167 | 2020-04-09 08:56:26 -0600 | [diff] [blame] | 137 | def testPassesProfileInfoAfdoRelease(self): |
| 138 | request = toolchain_pb2.PrepareForToolchainBuildRequest( |
| 139 | artifact_types=[ |
| 140 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE], |
| 141 | chroot=None, sysroot=None, input_artifacts=[ |
| 142 | BuilderConfig.Artifacts.InputArtifactInfo( |
Mike Frysinger | fcca49e | 2021-03-17 01:09:20 -0400 | [diff] [blame] | 143 | input_artifact_type= |
Alex Klein | cd03a5e | 2021-10-18 13:23:47 -0600 | [diff] [blame] | 144 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE, |
LaMont Jones | e782167 | 2020-04-09 08:56:26 -0600 | [diff] [blame] | 145 | input_artifact_gs_locations=['path1', 'path2']), |
| 146 | BuilderConfig.Artifacts.InputArtifactInfo( |
Mike Frysinger | fcca49e | 2021-03-17 01:09:20 -0400 | [diff] [blame] | 147 | input_artifact_type= |
Alex Klein | cd03a5e | 2021-10-18 13:23:47 -0600 | [diff] [blame] | 148 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE, |
LaMont Jones | e782167 | 2020-04-09 08:56:26 -0600 | [diff] [blame] | 149 | input_artifact_gs_locations=['path3']), |
| 150 | ], |
| 151 | profile_info=common_pb2.ArtifactProfileInfo( |
| 152 | afdo_release=common_pb2.AfdoRelease( |
| 153 | chrome_cwp_profile='CWPVERSION', |
| 154 | image_build_id=1234)), |
| 155 | ) |
| 156 | toolchain.PrepareForBuild(request, self.response, self.api_config) |
| 157 | self.prep.assert_called_once_with( |
| 158 | 'UnverifiedChromeLlvmOrderfile', None, '', '', { |
Tiancong Wang | ba2a1c2 | 2021-01-19 10:45:06 -0800 | [diff] [blame] | 159 | 'UnverifiedChromeLlvmOrderfile': |
| 160 | ['gs://path1', 'gs://path2', 'gs://path3'], |
| 161 | }, { |
| 162 | 'chrome_cwp_profile': 'CWPVERSION', |
| 163 | 'image_build_id': 1234 |
| 164 | }) |
LaMont Jones | e782167 | 2020-04-09 08:56:26 -0600 | [diff] [blame] | 165 | |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 166 | def testHandlesDuplicateInputArtifacts(self): |
| 167 | request = toolchain_pb2.PrepareForToolchainBuildRequest( |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 168 | artifact_types=[ |
| 169 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE], |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 170 | chroot=None, sysroot=None, input_artifacts=[ |
| 171 | BuilderConfig.Artifacts.InputArtifactInfo( |
Mike Frysinger | fcca49e | 2021-03-17 01:09:20 -0400 | [diff] [blame] | 172 | input_artifact_type= |
Alex Klein | cd03a5e | 2021-10-18 13:23:47 -0600 | [diff] [blame] | 173 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE, |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 174 | input_artifact_gs_locations=['path1', 'path2']), |
| 175 | BuilderConfig.Artifacts.InputArtifactInfo( |
Mike Frysinger | fcca49e | 2021-03-17 01:09:20 -0400 | [diff] [blame] | 176 | input_artifact_type= |
Alex Klein | cd03a5e | 2021-10-18 13:23:47 -0600 | [diff] [blame] | 177 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE, |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 178 | input_artifact_gs_locations=['path3']), |
| 179 | ]) |
| 180 | toolchain.PrepareForBuild(request, self.response, self.api_config) |
| 181 | self.prep.assert_called_once_with( |
LaMont Jones | d394458 | 2020-03-04 10:37:05 -0700 | [diff] [blame] | 182 | 'UnverifiedChromeLlvmOrderfile', None, '', '', { |
Tiancong Wang | ba2a1c2 | 2021-01-19 10:45:06 -0800 | [diff] [blame] | 183 | 'UnverifiedChromeLlvmOrderfile': |
| 184 | ['gs://path1', 'gs://path2', 'gs://path3'], |
LaMont Jones | d394458 | 2020-03-04 10:37:05 -0700 | [diff] [blame] | 185 | }, {}) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 186 | |
| 187 | |
| 188 | class BundleToolchainTest(cros_test_lib.MockTempDirTestCase, |
| 189 | api_config.ApiConfigMixin): |
| 190 | """Unittests for BundleToolchain.""" |
| 191 | |
| 192 | def setUp(self): |
| 193 | self.response = toolchain_pb2.BundleToolchainResponse() |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 194 | self.prep = self.PatchObject( |
Tiancong Wang | ba2a1c2 | 2021-01-19 10:45:06 -0800 | [diff] [blame] | 195 | toolchain_util, |
| 196 | 'PrepareForBuild', |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 197 | return_value=toolchain_util.PrepareForBuildReturn.NEEDED) |
| 198 | self.bundle = self.PatchObject( |
| 199 | toolchain_util, 'BundleArtifacts', return_value=[]) |
Tiancong Wang | ba2a1c2 | 2021-01-19 10:45:06 -0800 | [diff] [blame] | 200 | self.PatchObject( |
| 201 | toolchain, '_TOOLCHAIN_ARTIFACT_HANDLERS', { |
| 202 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE: |
| 203 | toolchain._Handlers('UnverifiedChromeLlvmOrderfile', self.prep, |
| 204 | self.bundle), |
| 205 | }) |
Alex Klein | cd03a5e | 2021-10-18 13:23:47 -0600 | [diff] [blame] | 206 | osutils.WriteFile(os.path.join(self.tempdir, 'artifact.txt'), 'test') |
| 207 | osutils.Touch(os.path.join(self.tempdir, 'empty')) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 208 | |
| 209 | def _GetRequest(self, artifact_types=None): |
Mike Frysinger | 3bb61cb | 2022-04-14 16:07:44 -0400 | [diff] [blame] | 210 | chroot = common_pb2.Chroot(path=str(self.tempdir)) |
LaMont Jones | 4579e8c | 2019-12-06 14:20:37 -0700 | [diff] [blame] | 211 | sysroot = sysroot_pb2.Sysroot( |
| 212 | path='/build/board', build_target=common_pb2.BuildTarget(name='board')) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 213 | return toolchain_pb2.BundleToolchainRequest( |
Tiancong Wang | ba2a1c2 | 2021-01-19 10:45:06 -0800 | [diff] [blame] | 214 | chroot=chroot, |
| 215 | sysroot=sysroot, |
Mike Frysinger | 3bb61cb | 2022-04-14 16:07:44 -0400 | [diff] [blame] | 216 | output_dir=str(self.tempdir), |
LaMont Jones | 4579e8c | 2019-12-06 14:20:37 -0700 | [diff] [blame] | 217 | artifact_types=artifact_types, |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 218 | ) |
| 219 | |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 220 | def testRaisesForUnknown(self): |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 221 | request = self._GetRequest([BuilderConfig.Artifacts.IMAGE_ARCHIVES]) |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 222 | self.assertEqual( |
| 223 | controller.RETURN_CODE_UNRECOVERABLE, |
| 224 | toolchain.BundleArtifacts(request, self.response, self.api_config)) |
Michael Mortensen | 3232ab3 | 2020-01-05 19:14:36 -0700 | [diff] [blame] | 225 | |
| 226 | def testValidateOnly(self): |
| 227 | """Sanity check that a validate only call does not execute any logic.""" |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 228 | request = self._GetRequest( |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 229 | [BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE]) |
Tiancong Wang | ba2a1c2 | 2021-01-19 10:45:06 -0800 | [diff] [blame] | 230 | toolchain.BundleArtifacts(request, self.response, self.validate_only_config) |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 231 | self.bundle.assert_not_called() |
| 232 | |
| 233 | def testSetsArtifactsInfo(self): |
| 234 | request = self._GetRequest( |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 235 | [BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE]) |
Alex Klein | cd03a5e | 2021-10-18 13:23:47 -0600 | [diff] [blame] | 236 | self.bundle.return_value = ['artifact.txt', 'empty', 'does_not_exist'] |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 237 | toolchain.BundleArtifacts(request, self.response, self.api_config) |
| 238 | self.assertEqual(1, len(self.response.artifacts_info)) |
| 239 | self.assertEqual( |
| 240 | self.response.artifacts_info[0], |
| 241 | toolchain_pb2.ArtifactInfo( |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 242 | artifact_type=( |
| 243 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE), |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 244 | artifacts=[ |
Tiancong Wang | ba2a1c2 | 2021-01-19 10:45:06 -0800 | [diff] [blame] | 245 | artifacts_pb2.Artifact(path=self.bundle.return_value[0]) |
| 246 | ])) |
Tiancong Wang | d521413 | 2021-01-12 10:43:57 -0800 | [diff] [blame] | 247 | |
| 248 | |
| 249 | class GetUpdatedFilesTest(cros_test_lib.MockTempDirTestCase, |
| 250 | api_config.ApiConfigMixin): |
| 251 | """Unittests for GetUpdatedFiles.""" |
| 252 | |
| 253 | def setUp(self): |
| 254 | self.response = toolchain_pb2.GetUpdatedFilesResponse() |
| 255 | self.artifact_path = '/any/path/to/metadata' |
| 256 | self.profile_info = common_pb2.ArtifactProfileInfo(kernel_version='4.4') |
| 257 | self.update = self.PatchObject( |
| 258 | toolchain_util, 'GetUpdatedFiles', return_value=([], '')) |
| 259 | |
| 260 | def _GetRequest(self, uploaded_artifacts): |
| 261 | uploaded = [] |
| 262 | for artifact_type, artifact_path, profile_info in uploaded_artifacts: |
| 263 | uploaded.append( |
| 264 | toolchain_pb2.GetUpdatedFilesRequest.UploadedArtifacts( |
| 265 | artifact_info=toolchain_pb2.ArtifactInfo( |
| 266 | artifact_type=artifact_type, |
| 267 | artifacts=[artifacts_pb2.Artifact(path=artifact_path)]), |
| 268 | profile_info=profile_info)) |
| 269 | return toolchain_pb2.GetUpdatedFilesRequest(uploaded_artifacts=uploaded) |
| 270 | |
| 271 | def testRaisesForUnknown(self): |
| 272 | request = self._GetRequest([ |
| 273 | (BuilderConfig.Artifacts.UNVERIFIED_KERNEL_CWP_AFDO_FILE, |
| 274 | self.artifact_path, self.profile_info) |
| 275 | ]) |
| 276 | self.assertEqual( |
| 277 | controller.RETURN_CODE_UNRECOVERABLE, |
| 278 | toolchain.GetUpdatedFiles(request, self.response, self.api_config)) |
| 279 | |
| 280 | def testValidateOnly(self): |
| 281 | """Sanity check that a validate only call does not execute any logic.""" |
| 282 | request = self._GetRequest([ |
| 283 | (BuilderConfig.Artifacts.VERIFIED_KERNEL_CWP_AFDO_FILE, |
| 284 | self.artifact_path, self.profile_info) |
| 285 | ]) |
| 286 | toolchain.GetUpdatedFiles(request, self.response, self.validate_only_config) |
| 287 | |
| 288 | def testUpdateSuccess(self): |
| 289 | updated_file = '/path/to/updated_file' |
| 290 | self.update.return_value = ([updated_file], 'Commit Message') |
| 291 | request = self._GetRequest([ |
| 292 | (BuilderConfig.Artifacts.VERIFIED_KERNEL_CWP_AFDO_FILE, |
| 293 | self.artifact_path, self.profile_info) |
| 294 | ]) |
| 295 | toolchain.GetUpdatedFiles(request, self.response, self.api_config) |
| 296 | print(self.response.updated_files) |
| 297 | self.assertEqual(len(self.response.updated_files), 1) |
| 298 | self.assertEqual( |
| 299 | self.response.updated_files[0], |
| 300 | toolchain_pb2.GetUpdatedFilesResponse.UpdatedFile(path=updated_file), |
| 301 | ) |
| 302 | self.assertIn('Commit Message', self.response.commit_message) |
| 303 | self.assertEqual(len(self.response.commit_footer), 0) |
Jack Neus | 4ee7b1d | 2022-06-27 19:54:18 +0000 | [diff] [blame] | 304 | |
| 305 | |
| 306 | class GetToolchainsForBoardTest(cros_test_lib.MockTempDirTestCase, |
| 307 | api_config.ApiConfigMixin): |
| 308 | """Unittests for GetToolchainsForBoard.""" |
| 309 | |
| 310 | def setUp(self): |
| 311 | self.response = toolchain_pb2.ToolchainsResponse() |
| 312 | |
| 313 | def _GetRequest(self, board='betty-pi-arc'): |
| 314 | return toolchain_pb2.ToolchainsRequest(board=board) |
| 315 | |
| 316 | def testValidateOnly(self): |
| 317 | """Confidence check that a validate only call does not execute any logic.""" |
| 318 | request = self._GetRequest() |
| 319 | toolchain.GetToolchainsForBoard(request, self.response, |
| 320 | self.validate_only_config) |
| 321 | |
| 322 | def testUpdateSuccess(self): |
| 323 | toolchain_info = { |
| 324 | 'default-a': {'default': True}, |
| 325 | 'default-b': {'default': True}, |
| 326 | 'nondefault-a': {'default': False}, |
| 327 | 'nondefault-b': {'default': False}, |
| 328 | } |
| 329 | self.PatchObject(toolchain_lib, 'GetToolchainsForBoard', |
| 330 | return_value=toolchain_info) |
| 331 | |
| 332 | request = self._GetRequest() |
| 333 | toolchain.GetToolchainsForBoard(request, self.response, self.api_config) |
| 334 | |
| 335 | self.assertEqual(self.response.default_toolchains, |
| 336 | ['default-a', 'default-b']) |
| 337 | self.assertEqual(self.response.nondefault_toolchains, |
| 338 | ['nondefault-a', 'nondefault-b']) |