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