Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Unittests for Toolchain-related operations.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
Mike Frysinger | ef94e4c | 2020-02-10 23:59:54 -0500 | [diff] [blame] | 10 | import sys |
| 11 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 12 | from chromite.api import api_config |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 13 | from chromite.api import controller |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 14 | from chromite.api.controller import toolchain |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 15 | from chromite.api.gen.chromite.api import artifacts_pb2 |
LaMont Jones | 4579e8c | 2019-12-06 14:20:37 -0700 | [diff] [blame] | 16 | from chromite.api.gen.chromite.api import sysroot_pb2 |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 17 | from chromite.api.gen.chromite.api import toolchain_pb2 |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 18 | from chromite.api.gen.chromiumos.builder_config_pb2 import BuilderConfig |
LaMont Jones | 4579e8c | 2019-12-06 14:20:37 -0700 | [diff] [blame] | 19 | from chromite.api.gen.chromiumos import common_pb2 |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 20 | |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 21 | from chromite.lib import cros_build_lib |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 22 | from chromite.lib import cros_test_lib |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 23 | from chromite.lib import toolchain_util |
| 24 | |
Mike Frysinger | ef94e4c | 2020-02-10 23:59:54 -0500 | [diff] [blame] | 25 | |
| 26 | assert sys.version_info >= (3, 6), 'This module requires Python 3.6+' |
| 27 | |
| 28 | |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 29 | # pylint: disable=protected-access |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 30 | |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 31 | class UpdateEbuildWithAFDOArtifactsTest(cros_test_lib.MockTestCase, |
| 32 | api_config.ApiConfigMixin): |
| 33 | """Unittests for UpdateEbuildWithAFDOArtifacts.""" |
| 34 | |
| 35 | @staticmethod |
| 36 | def mock_die(message, *args): |
| 37 | raise cros_build_lib.DieSystemExit(message % args) |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 38 | |
| 39 | def setUp(self): |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 40 | self.board = 'board' |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 41 | self.response = toolchain_pb2.VerifyAFDOArtifactsResponse() |
| 42 | self.invalid_artifact_type = toolchain_pb2.BENCHMARK_AFDO |
| 43 | self.orderfile_command = self.PatchObject( |
| 44 | toolchain_util, 'OrderfileUpdateChromeEbuild', return_value=True) |
| 45 | self.kernel_command = self.PatchObject( |
| 46 | toolchain_util, 'AFDOUpdateKernelEbuild', return_value=True) |
Tiancong Wang | f9c736c | 2019-08-26 13:54:38 -0700 | [diff] [blame] | 47 | self.chrome_command = self.PatchObject( |
| 48 | toolchain_util, 'AFDOUpdateChromeEbuild', return_value=True) |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 49 | self.PatchObject(cros_build_lib, 'Die', new=self.mock_die) |
| 50 | |
| 51 | def _GetRequest(self, build_target=None, artifact_type=None): |
| 52 | return toolchain_pb2.VerifyAFDOArtifactsRequest( |
| 53 | build_target={'name': build_target}, |
| 54 | artifact_type=artifact_type, |
| 55 | ) |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 56 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 57 | def testValidateOnly(self): |
| 58 | """Sanity check that a validate only call does not execute any logic.""" |
| 59 | patch = self.PatchObject(toolchain_util, 'OrderfileUpdateChromeEbuild') |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 60 | request = self._GetRequest( |
| 61 | build_target=self.board, artifact_type=toolchain_pb2.ORDERFILE) |
| 62 | toolchain.UpdateEbuildWithAFDOArtifacts(request, self.response, |
| 63 | self.validate_only_config) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 64 | patch.assert_not_called() |
| 65 | |
Michael Mortensen | 54bd70a | 2019-11-21 14:45:38 -0700 | [diff] [blame] | 66 | def testMockCall(self): |
| 67 | """Test that a mock call does not execute logic, returns mock value.""" |
| 68 | patch = self.PatchObject(toolchain_util, 'OrderfileUpdateChromeEbuild') |
| 69 | request = self._GetRequest( |
| 70 | build_target=self.board, artifact_type=toolchain_pb2.ORDERFILE) |
| 71 | toolchain.UpdateEbuildWithAFDOArtifacts(request, self.response, |
| 72 | self.mock_call_config) |
| 73 | patch.assert_not_called() |
| 74 | self.assertEqual(self.response.status, True) |
| 75 | |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 76 | def testWrongArtifactType(self): |
| 77 | """Test passing wrong artifact type.""" |
| 78 | request = self._GetRequest( |
| 79 | build_target=self.board, artifact_type=self.invalid_artifact_type) |
| 80 | with self.assertRaises(cros_build_lib.DieSystemExit) as context: |
| 81 | toolchain.UpdateEbuildWithAFDOArtifacts(request, self.response, |
| 82 | self.api_config) |
| 83 | self.assertIn('artifact_type (%d) must be in' % self.invalid_artifact_type, |
| 84 | str(context.exception)) |
| 85 | |
| 86 | def testOrderfileSuccess(self): |
| 87 | """Test the command is called correctly with orderfile.""" |
| 88 | request = self._GetRequest( |
| 89 | build_target=self.board, artifact_type=toolchain_pb2.ORDERFILE) |
| 90 | toolchain.UpdateEbuildWithAFDOArtifacts(request, self.response, |
| 91 | self.api_config) |
| 92 | self.orderfile_command.assert_called_once_with(self.board) |
| 93 | self.kernel_command.assert_not_called() |
Tiancong Wang | f9c736c | 2019-08-26 13:54:38 -0700 | [diff] [blame] | 94 | self.chrome_command.assert_not_called() |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 95 | |
| 96 | def testKernelAFDOSuccess(self): |
| 97 | """Test the command is called correctly with kernel afdo.""" |
| 98 | request = self._GetRequest( |
| 99 | build_target=self.board, artifact_type=toolchain_pb2.KERNEL_AFDO) |
| 100 | toolchain.UpdateEbuildWithAFDOArtifacts(request, self.response, |
| 101 | self.api_config) |
| 102 | self.kernel_command.assert_called_once_with(self.board) |
| 103 | self.orderfile_command.assert_not_called() |
Tiancong Wang | f9c736c | 2019-08-26 13:54:38 -0700 | [diff] [blame] | 104 | self.chrome_command.assert_not_called() |
| 105 | |
| 106 | def testChromeAFDOSuccess(self): |
| 107 | """Test the command is called correctly with Chrome afdo.""" |
| 108 | request = self._GetRequest( |
| 109 | build_target=self.board, artifact_type=toolchain_pb2.CHROME_AFDO) |
| 110 | toolchain.UpdateEbuildWithAFDOArtifacts(request, self.response, |
| 111 | self.api_config) |
| 112 | self.chrome_command.assert_called_once_with(self.board) |
| 113 | self.orderfile_command.assert_not_called() |
| 114 | self.kernel_command.assert_not_called() |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 115 | |
| 116 | |
Tiancong Wang | f9c736c | 2019-08-26 13:54:38 -0700 | [diff] [blame] | 117 | class UploadVettedFDOArtifactsTest(UpdateEbuildWithAFDOArtifactsTest): |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 118 | """Unittests for UploadVettedAFDOArtifacts.""" |
| 119 | |
| 120 | @staticmethod |
| 121 | def mock_die(message, *args): |
| 122 | raise cros_build_lib.DieSystemExit(message % args) |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 123 | |
| 124 | def setUp(self): |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 125 | self.board = 'board' |
| 126 | self.response = toolchain_pb2.VerifyAFDOArtifactsResponse() |
| 127 | self.invalid_artifact_type = toolchain_pb2.BENCHMARK_AFDO |
| 128 | self.command = self.PatchObject( |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 129 | toolchain_util, |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 130 | 'UploadAndPublishVettedAFDOArtifacts', |
| 131 | return_value=True) |
| 132 | self.PatchObject(cros_build_lib, 'Die', new=self.mock_die) |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 133 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 134 | def testValidateOnly(self): |
| 135 | """Sanity check that a validate only call does not execute any logic.""" |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 136 | request = self._GetRequest( |
| 137 | build_target=self.board, artifact_type=toolchain_pb2.ORDERFILE) |
Michael Mortensen | 54bd70a | 2019-11-21 14:45:38 -0700 | [diff] [blame] | 138 | toolchain.UploadVettedAFDOArtifacts(request, self.response, |
| 139 | self.validate_only_config) |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 140 | self.command.assert_not_called() |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 141 | |
Michael Mortensen | 54bd70a | 2019-11-21 14:45:38 -0700 | [diff] [blame] | 142 | def testMockCall(self): |
| 143 | """Test that a mock call does not execute logic, returns mock value.""" |
| 144 | request = self._GetRequest( |
| 145 | build_target=self.board, artifact_type=toolchain_pb2.ORDERFILE) |
| 146 | toolchain.UploadVettedAFDOArtifacts(request, self.response, |
| 147 | self.mock_call_config) |
| 148 | self.command.assert_not_called() |
| 149 | self.assertEqual(self.response.status, True) |
| 150 | |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 151 | def testWrongArtifactType(self): |
| 152 | """Test passing wrong artifact type.""" |
| 153 | request = self._GetRequest( |
| 154 | build_target=self.board, artifact_type=self.invalid_artifact_type) |
| 155 | with self.assertRaises(cros_build_lib.DieSystemExit) as context: |
Michael Mortensen | 54bd70a | 2019-11-21 14:45:38 -0700 | [diff] [blame] | 156 | toolchain.UploadVettedAFDOArtifacts(request, self.response, |
| 157 | self.api_config) |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 158 | self.assertIn('artifact_type (%d) must be in' % self.invalid_artifact_type, |
| 159 | str(context.exception)) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 160 | |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 161 | def testOrderfileSuccess(self): |
| 162 | """Test the command is called correctly with orderfile.""" |
| 163 | request = self._GetRequest( |
| 164 | build_target=self.board, artifact_type=toolchain_pb2.ORDERFILE) |
| 165 | toolchain.UploadVettedAFDOArtifacts(request, self.response, self.api_config) |
| 166 | self.command.assert_called_once_with('orderfile', self.board) |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 167 | |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 168 | def testKernelAFDOSuccess(self): |
| 169 | """Test the command is called correctly with kernel afdo.""" |
| 170 | request = self._GetRequest( |
| 171 | build_target=self.board, artifact_type=toolchain_pb2.KERNEL_AFDO) |
| 172 | toolchain.UploadVettedAFDOArtifacts(request, self.response, self.api_config) |
| 173 | self.command.assert_called_once_with('kernel_afdo', self.board) |
Tiancong Wang | f9c736c | 2019-08-26 13:54:38 -0700 | [diff] [blame] | 174 | |
| 175 | def testChromeAFDOSuccess(self): |
| 176 | """Test the command is called correctly with Chrome afdo.""" |
| 177 | request = self._GetRequest( |
| 178 | build_target=self.board, artifact_type=toolchain_pb2.CHROME_AFDO) |
| 179 | toolchain.UploadVettedAFDOArtifacts(request, self.response, self.api_config) |
| 180 | self.command.assert_called_once_with('chrome_afdo', self.board) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 181 | |
| 182 | |
LaMont Jones | 4579e8c | 2019-12-06 14:20:37 -0700 | [diff] [blame] | 183 | class PrepareForBuildTest(cros_test_lib.MockTempDirTestCase, |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 184 | api_config.ApiConfigMixin): |
| 185 | """Unittests for PrepareForBuild.""" |
| 186 | |
| 187 | def setUp(self): |
| 188 | self.response = toolchain_pb2.PrepareForToolchainBuildResponse() |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 189 | self.prep = self.PatchObject( |
| 190 | toolchain_util, 'PrepareForBuild', |
| 191 | return_value=toolchain_util.PrepareForBuildReturn.NEEDED) |
| 192 | self.bundle = self.PatchObject( |
| 193 | toolchain_util, 'BundleArtifacts', return_value=[]) |
| 194 | self.PatchObject(toolchain, '_TOOLCHAIN_ARTIFACT_HANDLERS', { |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 195 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE: |
LaMont Jones | d394458 | 2020-03-04 10:37:05 -0700 | [diff] [blame] | 196 | toolchain._Handlers('UnverifiedChromeLlvmOrderfile', |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 197 | self.prep, self.bundle), |
| 198 | }) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 199 | |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 200 | def _GetRequest( |
| 201 | self, artifact_types=None, input_artifacts=None, additional_args=None): |
LaMont Jones | 4579e8c | 2019-12-06 14:20:37 -0700 | [diff] [blame] | 202 | chroot = common_pb2.Chroot(path=self.tempdir) |
| 203 | sysroot = sysroot_pb2.Sysroot( |
| 204 | path='/build/board', build_target=common_pb2.BuildTarget(name='board')) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 205 | return toolchain_pb2.PrepareForToolchainBuildRequest( |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 206 | artifact_types=artifact_types, chroot=chroot, sysroot=sysroot, |
| 207 | input_artifacts=input_artifacts, additional_args=additional_args) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 208 | |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 209 | def testRaisesForUnknown(self): |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 210 | request = self._GetRequest([BuilderConfig.Artifacts.IMAGE_ARCHIVES]) |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 211 | self.assertRaises( |
| 212 | KeyError, |
| 213 | toolchain.PrepareForBuild, request, self.response, self.api_config) |
| 214 | |
| 215 | def testAcceptsNone(self): |
| 216 | request = toolchain_pb2.PrepareForToolchainBuildRequest( |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 217 | artifact_types=[ |
| 218 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE], |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 219 | chroot=None, sysroot=None) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 220 | toolchain.PrepareForBuild(request, self.response, self.api_config) |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 221 | self.prep.assert_called_once_with( |
LaMont Jones | d394458 | 2020-03-04 10:37:05 -0700 | [diff] [blame] | 222 | 'UnverifiedChromeLlvmOrderfile', None, '', '', {}, {}) |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 223 | |
| 224 | def testHandlesUnknownInputArtifacts(self): |
| 225 | request = toolchain_pb2.PrepareForToolchainBuildRequest( |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 226 | artifact_types=[ |
| 227 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE], |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 228 | chroot=None, sysroot=None, input_artifacts=[ |
| 229 | BuilderConfig.Artifacts.InputArtifactInfo( |
| 230 | input_artifact_type=BuilderConfig.Artifacts.IMAGE_ZIP, |
| 231 | input_artifact_gs_locations=['path1']), |
| 232 | ]) |
| 233 | toolchain.PrepareForBuild(request, self.response, self.api_config) |
| 234 | self.prep.assert_called_once_with( |
LaMont Jones | d394458 | 2020-03-04 10:37:05 -0700 | [diff] [blame] | 235 | 'UnverifiedChromeLlvmOrderfile', None, '', '', {}, {}) |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 236 | |
LaMont Jones | e782167 | 2020-04-09 08:56:26 -0600 | [diff] [blame^] | 237 | def testPassesProfileInfo(self): |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 238 | request = toolchain_pb2.PrepareForToolchainBuildRequest( |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 239 | artifact_types=[ |
| 240 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE], |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 241 | chroot=None, sysroot=None, input_artifacts=[ |
| 242 | BuilderConfig.Artifacts.InputArtifactInfo( |
| 243 | input_artifact_type=\ |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 244 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE, |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 245 | input_artifact_gs_locations=['path1', 'path2']), |
| 246 | BuilderConfig.Artifacts.InputArtifactInfo( |
| 247 | input_artifact_type=\ |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 248 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE, |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 249 | input_artifact_gs_locations=['path3']), |
| 250 | ], |
LaMont Jones | e782167 | 2020-04-09 08:56:26 -0600 | [diff] [blame^] | 251 | profile_info=common_pb2.ArtifactProfileInfo( |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 252 | chrome_cwp_profile='CWPVERSION'), |
| 253 | ) |
| 254 | toolchain.PrepareForBuild(request, self.response, self.api_config) |
| 255 | self.prep.assert_called_once_with( |
LaMont Jones | d394458 | 2020-03-04 10:37:05 -0700 | [diff] [blame] | 256 | 'UnverifiedChromeLlvmOrderfile', None, '', '', { |
| 257 | 'UnverifiedChromeLlvmOrderfile': [ |
| 258 | 'gs://path1', 'gs://path2', 'gs://path3'], |
| 259 | }, |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 260 | {'chrome_cwp_profile': 'CWPVERSION'}) |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 261 | |
LaMont Jones | e782167 | 2020-04-09 08:56:26 -0600 | [diff] [blame^] | 262 | def testPassesProfileInfoAfdoRelease(self): |
| 263 | request = toolchain_pb2.PrepareForToolchainBuildRequest( |
| 264 | artifact_types=[ |
| 265 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE], |
| 266 | chroot=None, sysroot=None, input_artifacts=[ |
| 267 | BuilderConfig.Artifacts.InputArtifactInfo( |
| 268 | input_artifact_type=\ |
| 269 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE, |
| 270 | input_artifact_gs_locations=['path1', 'path2']), |
| 271 | BuilderConfig.Artifacts.InputArtifactInfo( |
| 272 | input_artifact_type=\ |
| 273 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE, |
| 274 | input_artifact_gs_locations=['path3']), |
| 275 | ], |
| 276 | profile_info=common_pb2.ArtifactProfileInfo( |
| 277 | afdo_release=common_pb2.AfdoRelease( |
| 278 | chrome_cwp_profile='CWPVERSION', |
| 279 | image_build_id=1234)), |
| 280 | ) |
| 281 | toolchain.PrepareForBuild(request, self.response, self.api_config) |
| 282 | self.prep.assert_called_once_with( |
| 283 | 'UnverifiedChromeLlvmOrderfile', None, '', '', { |
| 284 | 'UnverifiedChromeLlvmOrderfile': [ |
| 285 | 'gs://path1', 'gs://path2', 'gs://path3'], |
| 286 | }, |
| 287 | {'chrome_cwp_profile': 'CWPVERSION', 'image_build_id': 1234}) |
| 288 | |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 289 | def testHandlesDuplicateInputArtifacts(self): |
| 290 | request = toolchain_pb2.PrepareForToolchainBuildRequest( |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 291 | artifact_types=[ |
| 292 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE], |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 293 | chroot=None, sysroot=None, input_artifacts=[ |
| 294 | BuilderConfig.Artifacts.InputArtifactInfo( |
| 295 | input_artifact_type=\ |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 296 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE, |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 297 | input_artifact_gs_locations=['path1', 'path2']), |
| 298 | BuilderConfig.Artifacts.InputArtifactInfo( |
| 299 | input_artifact_type=\ |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 300 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE, |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 301 | input_artifact_gs_locations=['path3']), |
| 302 | ]) |
| 303 | toolchain.PrepareForBuild(request, self.response, self.api_config) |
| 304 | self.prep.assert_called_once_with( |
LaMont Jones | d394458 | 2020-03-04 10:37:05 -0700 | [diff] [blame] | 305 | 'UnverifiedChromeLlvmOrderfile', None, '', '', { |
| 306 | 'UnverifiedChromeLlvmOrderfile': [ |
| 307 | 'gs://path1', 'gs://path2', 'gs://path3'], |
| 308 | }, {}) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 309 | |
| 310 | |
| 311 | class BundleToolchainTest(cros_test_lib.MockTempDirTestCase, |
| 312 | api_config.ApiConfigMixin): |
| 313 | """Unittests for BundleToolchain.""" |
| 314 | |
| 315 | def setUp(self): |
| 316 | self.response = toolchain_pb2.BundleToolchainResponse() |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 317 | self.prep = self.PatchObject( |
| 318 | toolchain_util, 'PrepareForBuild', |
| 319 | return_value=toolchain_util.PrepareForBuildReturn.NEEDED) |
| 320 | self.bundle = self.PatchObject( |
| 321 | toolchain_util, 'BundleArtifacts', return_value=[]) |
| 322 | self.PatchObject(toolchain, '_TOOLCHAIN_ARTIFACT_HANDLERS', { |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 323 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE: |
LaMont Jones | d394458 | 2020-03-04 10:37:05 -0700 | [diff] [blame] | 324 | toolchain._Handlers('UnverifiedChromeLlvmOrderfile', |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 325 | self.prep, self.bundle), |
| 326 | }) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 327 | |
| 328 | def _GetRequest(self, artifact_types=None): |
LaMont Jones | 4579e8c | 2019-12-06 14:20:37 -0700 | [diff] [blame] | 329 | chroot = common_pb2.Chroot(path=self.tempdir) |
| 330 | sysroot = sysroot_pb2.Sysroot( |
| 331 | path='/build/board', build_target=common_pb2.BuildTarget(name='board')) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 332 | return toolchain_pb2.BundleToolchainRequest( |
LaMont Jones | 4579e8c | 2019-12-06 14:20:37 -0700 | [diff] [blame] | 333 | chroot=chroot, sysroot=sysroot, |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 334 | output_dir=self.tempdir, |
LaMont Jones | 4579e8c | 2019-12-06 14:20:37 -0700 | [diff] [blame] | 335 | artifact_types=artifact_types, |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 336 | ) |
| 337 | |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 338 | def testRaisesForUnknown(self): |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 339 | request = self._GetRequest([BuilderConfig.Artifacts.IMAGE_ARCHIVES]) |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 340 | self.assertEqual( |
| 341 | controller.RETURN_CODE_UNRECOVERABLE, |
| 342 | toolchain.BundleArtifacts(request, self.response, self.api_config)) |
Michael Mortensen | 3232ab3 | 2020-01-05 19:14:36 -0700 | [diff] [blame] | 343 | |
| 344 | def testValidateOnly(self): |
| 345 | """Sanity check that a validate only call does not execute any logic.""" |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 346 | request = self._GetRequest( |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 347 | [BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE]) |
Michael Mortensen | 3232ab3 | 2020-01-05 19:14:36 -0700 | [diff] [blame] | 348 | toolchain.BundleArtifacts(request, self.response, |
| 349 | self.validate_only_config) |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 350 | self.bundle.assert_not_called() |
| 351 | |
| 352 | def testSetsArtifactsInfo(self): |
| 353 | request = self._GetRequest( |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 354 | [BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE]) |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 355 | self.bundle.return_value = ['artifact.xz'] |
| 356 | toolchain.BundleArtifacts(request, self.response, self.api_config) |
| 357 | self.assertEqual(1, len(self.response.artifacts_info)) |
| 358 | self.assertEqual( |
| 359 | self.response.artifacts_info[0], |
| 360 | toolchain_pb2.ArtifactInfo( |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 361 | artifact_type=( |
| 362 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE), |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 363 | artifacts=[ |
| 364 | artifacts_pb2.Artifact(path=self.bundle.return_value[0])])) |