blob: 37174c1f195115480ea8ab2dfeb47e380b550f83 [file] [log] [blame]
Alex Kleina2e42c42019-04-17 16:13:19 -06001# 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"""The test controller tests."""
6
Alex Klein9f915782020-02-14 23:15:09 +00007import contextlib
Lizzy Presland4feb2372022-01-20 05:16:30 +00008import datetime
Mike Frysingeref94e4c2020-02-10 23:59:54 -05009import os
Mike Frysinger3bb61cb2022-04-14 16:07:44 -040010from pathlib import Path
Mike Frysinger40443592022-05-05 13:03:40 -040011from typing import Union
Mike Frysinger166fea02021-02-12 05:30:33 -050012from unittest import mock
Mike Frysingeref94e4c2020-02-10 23:59:54 -050013
Mike Frysinger1cc8f1f2022-04-28 22:40:40 -040014from chromite.third_party.google.protobuf import json_format
15
Alex Klein231d2da2019-07-22 16:44:45 -060016from chromite.api import api_config
Alex Klein8cb365a2019-05-15 16:24:53 -060017from chromite.api import controller
Lizzy Presland4feb2372022-01-20 05:16:30 +000018from chromite.api.controller import controller_util
Alex Kleina2e42c42019-04-17 16:13:19 -060019from chromite.api.controller import test as test_controller
20from chromite.api.gen.chromite.api import test_pb2
Mike Frysinger1cc8f1f2022-04-28 22:40:40 -040021from chromite.api.gen.chromiumos import common_pb2
Sean McAllister3834fef2021-10-08 15:45:18 -060022from chromite.api.gen.chromiumos.build.api import container_metadata_pb2
Jack Neusc9707c32021-07-23 21:48:54 +000023from chromite.lib import build_target_lib
Evan Hernandeze1e05d32019-07-19 12:32:18 -060024from chromite.lib import chroot_lib
Alex Kleina2e42c42019-04-17 16:13:19 -060025from chromite.lib import cros_build_lib
26from chromite.lib import cros_test_lib
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -060027from chromite.lib import image_lib
Alex Kleina2e42c42019-04-17 16:13:19 -060028from chromite.lib import osutils
David Wellingc1433c22021-06-25 16:29:48 +000029from chromite.lib import sysroot_lib
Alex Klein18a60af2020-06-11 12:08:47 -060030from chromite.lib.parser import package_info
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -060031from chromite.scripts import cros_set_lsb_release
32from chromite.service import test as test_service
Mike Frysingere652ba12019-09-08 00:57:43 -040033from chromite.utils import key_value_store
Alex Kleina2e42c42019-04-17 16:13:19 -060034
35
Michael Mortensen8ca4d3b2019-11-27 09:35:22 -070036class DebugInfoTestTest(cros_test_lib.MockTempDirTestCase,
37 api_config.ApiConfigMixin):
38 """Tests for the DebugInfoTest function."""
39
40 def setUp(self):
41 self.board = 'board'
42 self.chroot_path = os.path.join(self.tempdir, 'chroot')
43 self.sysroot_path = '/build/board'
44 self.full_sysroot_path = os.path.join(self.chroot_path,
45 self.sysroot_path.lstrip(os.sep))
46 osutils.SafeMakedirs(self.full_sysroot_path)
47
48 def _GetInput(self, sysroot_path=None, build_target=None):
49 """Helper to build an input message instance."""
50 proto = test_pb2.DebugInfoTestRequest()
51 if sysroot_path:
52 proto.sysroot.path = sysroot_path
53 if build_target:
54 proto.sysroot.build_target.name = build_target
55 return proto
56
57 def _GetOutput(self):
58 """Helper to get an empty output message instance."""
59 return test_pb2.DebugInfoTestResponse()
60
61 def testValidateOnly(self):
62 """Sanity check that a validate only call does not execute any logic."""
63 patch = self.PatchObject(test_service, 'DebugInfoTest')
64 input_msg = self._GetInput(sysroot_path=self.full_sysroot_path)
65 test_controller.DebugInfoTest(input_msg, self._GetOutput(),
66 self.validate_only_config)
67 patch.assert_not_called()
68
Michael Mortensen85d38402019-12-12 09:50:29 -070069 def testMockError(self):
70 """Test mock error call does not execute any logic, returns error."""
71 patch = self.PatchObject(test_service, 'DebugInfoTest')
72
73 input_msg = self._GetInput(sysroot_path=self.full_sysroot_path)
74 rc = test_controller.DebugInfoTest(input_msg, self._GetOutput(),
75 self.mock_error_config)
76 patch.assert_not_called()
77 self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc)
78
79 def testMockCall(self):
80 """Test mock call does not execute any logic, returns success."""
81 patch = self.PatchObject(test_service, 'DebugInfoTest')
82
83 input_msg = self._GetInput(sysroot_path=self.full_sysroot_path)
84 rc = test_controller.DebugInfoTest(input_msg, self._GetOutput(),
85 self.mock_call_config)
86 patch.assert_not_called()
87 self.assertEqual(controller.RETURN_CODE_SUCCESS, rc)
88
Michael Mortensen8ca4d3b2019-11-27 09:35:22 -070089 def testNoBuildTargetNoSysrootFails(self):
90 """Test missing build target name and sysroot path fails."""
91 input_msg = self._GetInput()
92 output_msg = self._GetOutput()
93 with self.assertRaises(cros_build_lib.DieSystemExit):
94 test_controller.DebugInfoTest(input_msg, output_msg, self.api_config)
95
96 def testDebugInfoTest(self):
97 """Call DebugInfoTest with valid sysroot_path."""
98 request = self._GetInput(sysroot_path=self.full_sysroot_path)
99
100 test_controller.DebugInfoTest(request, self._GetOutput(), self.api_config)
101
102
Alex Klein231d2da2019-07-22 16:44:45 -0600103class BuildTargetUnitTestTest(cros_test_lib.MockTempDirTestCase,
104 api_config.ApiConfigMixin):
Alex Kleina2e42c42019-04-17 16:13:19 -0600105 """Tests for the UnitTest function."""
106
Lizzy Presland4feb2372022-01-20 05:16:30 +0000107 def setUp(self):
108 # Set up portage log directory.
109 self.sysroot = os.path.join(self.tempdir, 'build', 'board')
110 osutils.SafeMakedirs(self.sysroot)
111 self.target_sysroot = sysroot_lib.Sysroot(self.sysroot)
112 self.portage_dir = os.path.join(self.tempdir, 'portage_logdir')
113 self.PatchObject(
114 sysroot_lib.Sysroot, 'portage_logdir', new=self.portage_dir)
115 osutils.SafeMakedirs(self.portage_dir)
116
Navil Perezc0b29a82020-07-07 14:17:48 +0000117 def _GetInput(self,
118 board=None,
119 result_path=None,
120 chroot_path=None,
121 cache_dir=None,
122 empty_sysroot=None,
123 packages=None,
Alex Kleinb64e5f82020-09-23 10:55:31 -0600124 blocklist=None):
Alex Kleina2e42c42019-04-17 16:13:19 -0600125 """Helper to build an input message instance."""
Navil Perezc0b29a82020-07-07 14:17:48 +0000126 formatted_packages = []
127 for pkg in packages or []:
128 formatted_packages.append({
129 'category': pkg.category,
130 'package_name': pkg.package
131 })
Alex Kleinb64e5f82020-09-23 10:55:31 -0600132 formatted_blocklist = []
133 for pkg in blocklist or []:
134 formatted_blocklist.append({'category': pkg.category,
Alex Kleinf2674462019-05-16 16:47:24 -0600135 'package_name': pkg.package})
136
Mike Frysinger3bb61cb2022-04-14 16:07:44 -0400137 # Protobufs can't handle Path objects.
138 if isinstance(result_path, Path):
139 result_path = str(result_path)
140
Alex Kleina2e42c42019-04-17 16:13:19 -0600141 return test_pb2.BuildTargetUnitTestRequest(
142 build_target={'name': board}, result_path=result_path,
Alex Kleinfa6ebdc2019-05-10 10:57:31 -0600143 chroot={'path': chroot_path, 'cache_dir': cache_dir},
Alex Kleinf2674462019-05-16 16:47:24 -0600144 flags={'empty_sysroot': empty_sysroot},
Alex Klein64ac34c2020-09-23 10:21:33 -0600145 packages=formatted_packages,
Alex Klein157caf42021-07-01 14:36:43 -0600146 package_blocklist=formatted_blocklist,
Alex Kleina2e42c42019-04-17 16:13:19 -0600147 )
148
149 def _GetOutput(self):
150 """Helper to get an empty output message instance."""
151 return test_pb2.BuildTargetUnitTestResponse()
152
Mike Frysinger40443592022-05-05 13:03:40 -0400153 def _CreatePortageLogFile(self,
154 log_path: Union[str, os.PathLike],
155 pkg_info: package_info.PackageInfo,
156 timestamp: datetime.datetime) -> str:
Lizzy Presland4feb2372022-01-20 05:16:30 +0000157 """Creates a log file for testing for individual packages built by Portage.
158
159 Args:
Mike Frysinger40443592022-05-05 13:03:40 -0400160 log_path: The PORTAGE_LOGDIR path.
161 pkg_info: name components for log file.
162 timestamp: Timestamp used to name the file.
Lizzy Presland4feb2372022-01-20 05:16:30 +0000163 """
164 path = os.path.join(log_path,
165 f'{pkg_info.category}:{pkg_info.pvr}:' \
166 f'{timestamp.strftime("%Y%m%d-%H%M%S")}.log')
167 osutils.WriteFile(path,
168 f'Test log file for package {pkg_info.category}/'
169 f'{pkg_info.package} written to {path}')
170 return path
171
Alex Klein231d2da2019-07-22 16:44:45 -0600172 def testValidateOnly(self):
173 """Sanity check that a validate only call does not execute any logic."""
174 patch = self.PatchObject(test_service, 'BuildTargetUnitTest')
175
176 input_msg = self._GetInput(board='board', result_path=self.tempdir)
177 test_controller.BuildTargetUnitTest(input_msg, self._GetOutput(),
178 self.validate_only_config)
179 patch.assert_not_called()
180
Michael Mortensen82cd62d2019-12-01 14:58:54 -0700181 def testMockCall(self):
182 """Test that a mock call does not execute logic, returns mocked value."""
183 patch = self.PatchObject(test_service, 'BuildTargetUnitTest')
184
185 input_msg = self._GetInput(board='board', result_path=self.tempdir)
186 response = self._GetOutput()
187 test_controller.BuildTargetUnitTest(input_msg, response,
188 self.mock_call_config)
189 patch.assert_not_called()
190 self.assertEqual(response.tarball_path,
191 os.path.join(input_msg.result_path, 'unit_tests.tar'))
192
193 def testMockError(self):
Michael Mortensen85d38402019-12-12 09:50:29 -0700194 """Test that a mock error does not execute logic, returns error."""
Michael Mortensen82cd62d2019-12-01 14:58:54 -0700195 patch = self.PatchObject(test_service, 'BuildTargetUnitTest')
196
197 input_msg = self._GetInput(board='board', result_path=self.tempdir)
198 response = self._GetOutput()
199 rc = test_controller.BuildTargetUnitTest(input_msg, response,
200 self.mock_error_config)
201 patch.assert_not_called()
202 self.assertEqual(controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE, rc)
Lizzy Presland239459a2022-05-05 22:03:19 +0000203 self.assertTrue(response.failed_package_data)
204 self.assertEqual(response.failed_package_data[0].name.category, 'foo')
205 self.assertEqual(response.failed_package_data[0].name.package_name, 'bar')
206 self.assertEqual(response.failed_package_data[1].name.category, 'cat')
207 self.assertEqual(response.failed_package_data[1].name.package_name, 'pkg')
Michael Mortensen82cd62d2019-12-01 14:58:54 -0700208
Alex Klein64ac34c2020-09-23 10:21:33 -0600209 def testInvalidPackageFails(self):
210 """Test missing result path fails."""
211 # Missing result_path.
212 pkg = package_info.PackageInfo(package='bar')
213 input_msg = self._GetInput(board='board', result_path=self.tempdir,
214 packages=[pkg])
215 output_msg = self._GetOutput()
216 with self.assertRaises(cros_build_lib.DieSystemExit):
217 test_controller.BuildTargetUnitTest(input_msg, output_msg,
218 self.api_config)
219
Alex Kleina2e42c42019-04-17 16:13:19 -0600220 def testPackageBuildFailure(self):
221 """Test handling of raised BuildPackageFailure."""
222 tempdir = osutils.TempDir(base_dir=self.tempdir)
223 self.PatchObject(osutils, 'TempDir', return_value=tempdir)
224
Lizzy Presland4feb2372022-01-20 05:16:30 +0000225 pkgs = ['cat/pkg-1.0-r1', 'foo/bar-2.0-r1']
226 cpvrs = [package_info.parse(pkg) for pkg in pkgs]
Alex Kleina2e42c42019-04-17 16:13:19 -0600227 expected = [('cat', 'pkg'), ('foo', 'bar')]
Lizzy Presland4feb2372022-01-20 05:16:30 +0000228 new_logs = {}
229 for i, pkg in enumerate(pkgs):
230 self._CreatePortageLogFile(self.portage_dir, cpvrs[i],
231 datetime.datetime(2021, 6, 9, 13, 37, 0))
232 new_logs[pkg] = self._CreatePortageLogFile(self.portage_dir, cpvrs[i],
233 datetime.datetime(2021, 6, 9,
234 16, 20, 0))
Alex Kleina2e42c42019-04-17 16:13:19 -0600235
Alex Klein38c7d9e2019-05-08 09:31:19 -0600236 result = test_service.BuildTargetUnitTestResult(1, None)
Alex Kleinea0c89e2021-09-09 15:17:35 -0600237 result.failed_pkgs = [package_info.parse(p) for p in pkgs]
Alex Klein38c7d9e2019-05-08 09:31:19 -0600238 self.PatchObject(test_service, 'BuildTargetUnitTest', return_value=result)
Alex Kleina2e42c42019-04-17 16:13:19 -0600239
240 input_msg = self._GetInput(board='board', result_path=self.tempdir)
241 output_msg = self._GetOutput()
242
Alex Klein231d2da2019-07-22 16:44:45 -0600243 rc = test_controller.BuildTargetUnitTest(input_msg, output_msg,
244 self.api_config)
Alex Kleina2e42c42019-04-17 16:13:19 -0600245
Alex Klein8cb365a2019-05-15 16:24:53 -0600246 self.assertEqual(controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE, rc)
Lizzy Presland4feb2372022-01-20 05:16:30 +0000247 self.assertTrue(output_msg.failed_package_data)
Alex Kleina2e42c42019-04-17 16:13:19 -0600248
Lizzy Presland4feb2372022-01-20 05:16:30 +0000249 failed_with_logs = []
250 for data in output_msg.failed_package_data:
251 failed_with_logs.append((data.name.category, data.name.package_name))
252 package = controller_util.deserialize_package_info(data.name)
253 self.assertEqual(data.log_path.path, new_logs[package.cpvr])
254 self.assertCountEqual(expected, failed_with_logs)
255
256
Alex Kleina2e42c42019-04-17 16:13:19 -0600257 def testOtherBuildScriptFailure(self):
258 """Test build script failure due to non-package emerge error."""
259 tempdir = osutils.TempDir(base_dir=self.tempdir)
260 self.PatchObject(osutils, 'TempDir', return_value=tempdir)
261
Alex Klein38c7d9e2019-05-08 09:31:19 -0600262 result = test_service.BuildTargetUnitTestResult(1, None)
263 self.PatchObject(test_service, 'BuildTargetUnitTest', return_value=result)
Alex Kleina2e42c42019-04-17 16:13:19 -0600264
Alex Kleinf2674462019-05-16 16:47:24 -0600265 pkgs = ['foo/bar', 'cat/pkg']
Alex Kleinb64e5f82020-09-23 10:55:31 -0600266 blocklist = [package_info.SplitCPV(p, strict=False) for p in pkgs]
Alex Klein2e91e522022-01-14 09:22:03 -0700267 input_msg = self._GetInput(board='board', empty_sysroot=True,
268 blocklist=blocklist)
Alex Kleina2e42c42019-04-17 16:13:19 -0600269 output_msg = self._GetOutput()
270
Alex Klein231d2da2019-07-22 16:44:45 -0600271 rc = test_controller.BuildTargetUnitTest(input_msg, output_msg,
272 self.api_config)
Alex Kleina2e42c42019-04-17 16:13:19 -0600273
Alex Klein8cb365a2019-05-15 16:24:53 -0600274 self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc)
Lizzy Presland239459a2022-05-05 22:03:19 +0000275 self.assertFalse(output_msg.failed_package_data)
Evan Hernandez4e388a52019-05-01 12:16:33 -0600276
Michael Mortensen82cd62d2019-12-01 14:58:54 -0700277 def testBuildTargetUnitTest(self):
278 """Test BuildTargetUnitTest successful call."""
Navil Perezc0b29a82020-07-07 14:17:48 +0000279 pkgs = ['foo/bar', 'cat/pkg']
Alex Klein18a60af2020-06-11 12:08:47 -0600280 packages = [package_info.SplitCPV(p, strict=False) for p in pkgs]
Alex Klein2e91e522022-01-14 09:22:03 -0700281 input_msg = self._GetInput(board='board', packages=packages)
Michael Mortensen82cd62d2019-12-01 14:58:54 -0700282
283 result = test_service.BuildTargetUnitTestResult(0, None)
284 self.PatchObject(test_service, 'BuildTargetUnitTest', return_value=result)
285
Michael Mortensen82cd62d2019-12-01 14:58:54 -0700286 response = self._GetOutput()
287 test_controller.BuildTargetUnitTest(input_msg, response,
288 self.api_config)
Lizzy Presland239459a2022-05-05 22:03:19 +0000289 self.assertFalse(response.failed_package_data)
Michael Mortensen82cd62d2019-12-01 14:58:54 -0700290
Evan Hernandez4e388a52019-05-01 12:16:33 -0600291
Sean McAllister17eed8d2021-09-21 10:41:16 -0600292class DockerConstraintsTest(cros_test_lib.MockTestCase):
293 """Tests for Docker argument constraints."""
294
295 def assertValid(self, output):
296 return output is None
297
298 def assertInvalid(self, output):
299 return not self.assertValid(output)
300
301 def testValidDockerTag(self):
302 """Check logic for validating docker tag format."""
303 # pylint: disable=protected-access
304
305 invalid_tags = [
306 '.invalid-tag',
307 '-invalid-tag',
308 'invalid-tag;',
309 'invalid'*100,
310 ]
311
312 for tag in invalid_tags:
313 self.assertInvalid(test_controller._ValidDockerTag(tag))
314
315 valid_tags = [
316 'valid-tag',
317 'valid-tag-',
318 'valid.tag.',
319 ]
320
321 for tag in valid_tags:
322 self.assertValid(test_controller._ValidDockerTag(tag))
323
324
325 def testValidDockerLabelKey(self):
326 """Check logic for validating docker label key format."""
327 # pylint: disable=protected-access
328
329 invalid_keys = [
330 'Invalid-keY',
331 'Invalid-key',
332 'invalid-keY',
333 'iNVALID-KEy',
334 'invalid_key',
335 'invalid-key;',
336 ]
337
338 for key in invalid_keys:
339 self.assertInvalid(test_controller._ValidDockerLabelKey(key))
340
341 valid_keys = [
342 'chromeos.valid-key',
343 'chromeos.valid-key-2',
344 ]
345
346 for key in valid_keys:
347 self.assertValid(test_controller._ValidDockerLabelKey(key))
348
349
Sean McAllister3834fef2021-10-08 15:45:18 -0600350class BuildTestServiceContainers(cros_test_lib.RunCommandTempDirTestCase,
David Wellingc1433c22021-06-25 16:29:48 +0000351 api_config.ApiConfigMixin):
C Shapiro91af1ce2021-06-17 12:42:09 -0500352 """Tests for the BuildTestServiceContainers function."""
353
354 def setUp(self):
355 self.request = test_pb2.BuildTestServiceContainersRequest(
356 chroot={'path': '/path/to/chroot'},
357 build_target={'name': 'build_target'},
David Wellingc1433c22021-06-25 16:29:48 +0000358 version='R93-14033.0.0',
C Shapiro91af1ce2021-06-17 12:42:09 -0500359 )
360
C Shapiro91af1ce2021-06-17 12:42:09 -0500361 def testSuccess(self):
362 """Check passing case with mocked cros_build_lib.run."""
Sean McAllister3834fef2021-10-08 15:45:18 -0600363
364 def ContainerMetadata():
365 """Return mocked ContainerImageInfo proto"""
366 metadata = container_metadata_pb2.ContainerImageInfo()
367 metadata.repository.hostname = 'gcr.io'
368 metadata.repository.project = 'chromeos-bot'
369 metadata.name = 'random-container-name'
370 metadata.digest = (
371 '09b730f8b6a862f9c2705cb3acf3554563325f5fca5c784bf5c98beb2e56f6db')
372 metadata.tags[:] = [
373 'staging-cq-amd64-generic.R96-1.2.3',
374 '8834106026340379089',
375 ]
376 return metadata
377
378 def WriteContainerMetadata(path):
379 """Write json formatted metadata to the given file."""
380 osutils.WriteFile(
381 path,
382 json_format.MessageToJson(ContainerMetadata()),
383 )
384
385 # Write out mocked container metadata to a temporary file.
386 output_path = os.path.join(self.tempdir, 'metadata.jsonpb')
387 self.rc.SetDefaultCmdResult(
388 returncode=0,
389 side_effect=lambda *_, **__: WriteContainerMetadata(output_path)
390 )
391
392 # Patch TempDir so that we always use this test's directory.
393 self.PatchObject(osutils.TempDir, '__enter__', return_value=self.tempdir)
C Shapiro91af1ce2021-06-17 12:42:09 -0500394
395 response = test_pb2.BuildTestServiceContainersResponse()
396 test_controller.BuildTestServiceContainers(
397 self.request,
398 response,
399 self.api_config)
Sean McAllister3834fef2021-10-08 15:45:18 -0600400
401 self.assertTrue(self.rc.called)
C Shapiro91af1ce2021-06-17 12:42:09 -0500402 for result in response.results:
403 self.assertEqual(result.WhichOneof('result'), 'success')
Sean McAllister3834fef2021-10-08 15:45:18 -0600404 self.assertEqual(result.success.image_info, ContainerMetadata())
C Shapiro91af1ce2021-06-17 12:42:09 -0500405
C Shapiro91af1ce2021-06-17 12:42:09 -0500406 def testFailure(self):
407 """Check failure case with mocked cros_build_lib.run."""
408 patch = self.PatchObject(
409 cros_build_lib, 'run',
410 return_value=cros_build_lib.CommandResult(returncode=1))
411
412 response = test_pb2.BuildTestServiceContainersResponse()
413 test_controller.BuildTestServiceContainers(
414 self.request,
415 response,
416 self.api_config)
417 patch.assert_called()
418 for result in response.results:
Derek Beckettcbe64c82022-05-05 15:00:18 -0700419 if 'beta' in result.name:
Derek Beckett2b89c6f2022-05-02 15:21:16 -0700420 self.assertEqual(result.WhichOneof('result'), 'success')
421 else:
422 self.assertEqual(result.WhichOneof('result'), 'failure')
C Shapiro91af1ce2021-06-17 12:42:09 -0500423
Michael Mortensen8ca4d3b2019-11-27 09:35:22 -0700424class ChromiteUnitTestTest(cros_test_lib.MockTestCase,
425 api_config.ApiConfigMixin):
426 """Tests for the ChromiteInfoTest function."""
427
428 def setUp(self):
429 self.board = 'board'
430 self.chroot_path = '/path/to/chroot'
431
432 def _GetInput(self, chroot_path=None):
433 """Helper to build an input message instance."""
434 proto = test_pb2.ChromiteUnitTestRequest(
435 chroot={'path': chroot_path},
436 )
437 return proto
438
439 def _GetOutput(self):
440 """Helper to get an empty output message instance."""
441 return test_pb2.ChromiteUnitTestResponse()
442
443 def testValidateOnly(self):
444 """Sanity check that a validate only call does not execute any logic."""
445 patch = self.PatchObject(cros_build_lib, 'run')
446
447 input_msg = self._GetInput(chroot_path=self.chroot_path)
448 test_controller.ChromiteUnitTest(input_msg, self._GetOutput(),
449 self.validate_only_config)
450 patch.assert_not_called()
451
Michael Mortensen7a860eb2019-12-03 20:25:15 -0700452 def testMockError(self):
453 """Test mock error call does not execute any logic, returns error."""
454 patch = self.PatchObject(cros_build_lib, 'run')
455
456 input_msg = self._GetInput(chroot_path=self.chroot_path)
457 rc = test_controller.ChromiteUnitTest(input_msg, self._GetOutput(),
458 self.mock_error_config)
459 patch.assert_not_called()
460 self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc)
461
462 def testMockCall(self):
463 """Test mock call does not execute any logic, returns success."""
464 patch = self.PatchObject(cros_build_lib, 'run')
465
466 input_msg = self._GetInput(chroot_path=self.chroot_path)
467 rc = test_controller.ChromiteUnitTest(input_msg, self._GetOutput(),
468 self.mock_call_config)
469 patch.assert_not_called()
470 self.assertEqual(controller.RETURN_CODE_SUCCESS, rc)
471
Michael Mortensen8ca4d3b2019-11-27 09:35:22 -0700472 def testChromiteUnitTest(self):
473 """Call ChromiteUnitTest with mocked cros_build_lib.run."""
474 request = self._GetInput(chroot_path=self.chroot_path)
475 patch = self.PatchObject(
476 cros_build_lib, 'run',
477 return_value=cros_build_lib.CommandResult(returncode=0))
478
479 test_controller.ChromiteUnitTest(request, self._GetOutput(),
480 self.api_config)
481 patch.assert_called_once()
482
483
Alex Klein4bc8f4f2019-08-16 14:53:30 -0600484class CrosSigningTestTest(cros_test_lib.RunCommandTestCase,
485 api_config.ApiConfigMixin):
486 """CrosSigningTest tests."""
487
Michael Mortensen82cd62d2019-12-01 14:58:54 -0700488 def setUp(self):
489 self.chroot_path = '/path/to/chroot'
490
491 def _GetInput(self, chroot_path=None):
492 """Helper to build an input message instance."""
493 proto = test_pb2.CrosSigningTestRequest(
494 chroot={'path': chroot_path},
495 )
496 return proto
497
498 def _GetOutput(self):
499 """Helper to get an empty output message instance."""
500 return test_pb2.CrosSigningTestResponse()
501
Alex Klein4bc8f4f2019-08-16 14:53:30 -0600502 def testValidateOnly(self):
503 """Sanity check that a validate only call does not execute any logic."""
504 test_controller.CrosSigningTest(None, None, self.validate_only_config)
505 self.assertFalse(self.rc.call_count)
506
Michael Mortensen7a7646d2019-12-12 15:36:14 -0700507 def testMockCall(self):
508 """Test mock call does not execute any logic, returns success."""
509 rc = test_controller.CrosSigningTest(None, None, self.mock_call_config)
510 self.assertFalse(self.rc.call_count)
511 self.assertEqual(controller.RETURN_CODE_SUCCESS, rc)
512
Michael Mortensen82cd62d2019-12-01 14:58:54 -0700513 def testCrosSigningTest(self):
514 """Call CrosSigningTest with mocked cros_build_lib.run."""
515 request = self._GetInput(chroot_path=self.chroot_path)
516 patch = self.PatchObject(
517 cros_build_lib, 'run',
518 return_value=cros_build_lib.CommandResult(returncode=0))
519
520 test_controller.CrosSigningTest(request, self._GetOutput(),
521 self.api_config)
522 patch.assert_called_once()
523
Alex Klein4bc8f4f2019-08-16 14:53:30 -0600524
Michael Mortensenc28d6f12019-10-03 13:34:51 -0600525class SimpleChromeWorkflowTestTest(cros_test_lib.MockTestCase,
526 api_config.ApiConfigMixin):
527 """Test the SimpleChromeWorkflowTest endpoint."""
528
529 @staticmethod
530 def _Output():
531 return test_pb2.SimpleChromeWorkflowTestResponse()
532
David Wellingc1433c22021-06-25 16:29:48 +0000533 def _Input(self,
534 sysroot_path=None,
535 build_target=None,
536 chrome_root=None,
Michael Mortensenc28d6f12019-10-03 13:34:51 -0600537 goma_config=None):
538 proto = test_pb2.SimpleChromeWorkflowTestRequest()
539 if sysroot_path:
540 proto.sysroot.path = sysroot_path
541 if build_target:
542 proto.sysroot.build_target.name = build_target
543 if chrome_root:
544 proto.chrome_root = chrome_root
545 if goma_config:
546 proto.goma_config = goma_config
547 return proto
548
549 def setUp(self):
550 self.chrome_path = 'path/to/chrome'
551 self.sysroot_dir = 'build/board'
552 self.build_target = 'amd64'
553 self.mock_simple_chrome_workflow_test = self.PatchObject(
554 test_service, 'SimpleChromeWorkflowTest')
555
556 def testMissingBuildTarget(self):
Michael Mortensen82cd62d2019-12-01 14:58:54 -0700557 """Test SimpleChromeWorkflowTest dies when build_target not set."""
Michael Mortensenc28d6f12019-10-03 13:34:51 -0600558 input_proto = self._Input(build_target=None, sysroot_path='/sysroot/dir',
559 chrome_root='/chrome/path')
560 with self.assertRaises(cros_build_lib.DieSystemExit):
561 test_controller.SimpleChromeWorkflowTest(input_proto, None,
562 self.api_config)
563
564 def testMissingSysrootPath(self):
Michael Mortensen82cd62d2019-12-01 14:58:54 -0700565 """Test SimpleChromeWorkflowTest dies when build_target not set."""
Michael Mortensenc28d6f12019-10-03 13:34:51 -0600566 input_proto = self._Input(build_target='board', sysroot_path=None,
567 chrome_root='/chrome/path')
568 with self.assertRaises(cros_build_lib.DieSystemExit):
569 test_controller.SimpleChromeWorkflowTest(input_proto, None,
570 self.api_config)
571
572 def testMissingChromeRoot(self):
Michael Mortensen82cd62d2019-12-01 14:58:54 -0700573 """Test SimpleChromeWorkflowTest dies when build_target not set."""
Michael Mortensenc28d6f12019-10-03 13:34:51 -0600574 input_proto = self._Input(build_target='board', sysroot_path='/sysroot/dir',
575 chrome_root=None)
576 with self.assertRaises(cros_build_lib.DieSystemExit):
577 test_controller.SimpleChromeWorkflowTest(input_proto, None,
578 self.api_config)
579
580 def testSimpleChromeWorkflowTest(self):
581 """Call SimpleChromeWorkflowTest with valid args and temp dir."""
582 request = self._Input(sysroot_path='sysroot_path', build_target='board',
583 chrome_root='/path/to/chrome')
584 response = self._Output()
585
586 test_controller.SimpleChromeWorkflowTest(request, response, self.api_config)
587 self.mock_simple_chrome_workflow_test.assert_called()
588
589 def testValidateOnly(self):
590 request = self._Input(sysroot_path='sysroot_path', build_target='board',
591 chrome_root='/path/to/chrome')
592 test_controller.SimpleChromeWorkflowTest(request, self._Output(),
593 self.validate_only_config)
594 self.mock_simple_chrome_workflow_test.assert_not_called()
595
Michael Mortensen7a7646d2019-12-12 15:36:14 -0700596 def testMockCall(self):
597 """Test mock call does not execute any logic, returns success."""
598 patch = self.mock_simple_chrome_workflow_test = self.PatchObject(
599 test_service, 'SimpleChromeWorkflowTest')
600
601 request = self._Input(sysroot_path='sysroot_path', build_target='board',
602 chrome_root='/path/to/chrome')
603 rc = test_controller.SimpleChromeWorkflowTest(request, self._Output(),
604 self.mock_call_config)
605 patch.assert_not_called()
606 self.assertEqual(controller.RETURN_CODE_SUCCESS, rc)
607
Michael Mortensenc28d6f12019-10-03 13:34:51 -0600608
Alex Klein231d2da2019-07-22 16:44:45 -0600609class VmTestTest(cros_test_lib.RunCommandTestCase, api_config.ApiConfigMixin):
Evan Hernandez4e388a52019-05-01 12:16:33 -0600610 """Test the VmTest endpoint."""
611
612 def _GetInput(self, **kwargs):
613 values = dict(
614 build_target=common_pb2.BuildTarget(name='target'),
Alex Klein311b8022019-06-05 16:00:07 -0600615 vm_path=common_pb2.Path(path='/path/to/image.bin',
616 location=common_pb2.Path.INSIDE),
Evan Hernandez4e388a52019-05-01 12:16:33 -0600617 test_harness=test_pb2.VmTestRequest.TAST,
618 vm_tests=[test_pb2.VmTestRequest.VmTest(pattern='suite')],
619 ssh_options=test_pb2.VmTestRequest.SshOptions(
Alex Klein231d2da2019-07-22 16:44:45 -0600620 port=1234, private_key_path={'path': '/path/to/id_rsa',
Alex Kleinaa705412019-06-04 15:00:30 -0600621 'location': common_pb2.Path.INSIDE}),
Evan Hernandez4e388a52019-05-01 12:16:33 -0600622 )
623 values.update(kwargs)
624 return test_pb2.VmTestRequest(**values)
625
Michael Mortensen82cd62d2019-12-01 14:58:54 -0700626 def _Output(self):
627 return test_pb2.VmTestResponse()
628
Alex Klein231d2da2019-07-22 16:44:45 -0600629 def testValidateOnly(self):
630 """Sanity check that a validate only call does not execute any logic."""
631 test_controller.VmTest(self._GetInput(), None, self.validate_only_config)
632 self.assertEqual(0, self.rc.call_count)
Evan Hernandez4e388a52019-05-01 12:16:33 -0600633
Michael Mortensen7a7646d2019-12-12 15:36:14 -0700634 def testMockCall(self):
635 """Test mock call does not execute any logic."""
636 patch = self.PatchObject(cros_build_lib, 'run')
637
638 request = self._GetInput()
639 response = self._Output()
640 # VmTest does not return a value, checking mocked value is flagged by lint.
641 test_controller.VmTest(request, response, self.mock_call_config)
642 patch.assert_not_called()
643
Evan Hernandez4e388a52019-05-01 12:16:33 -0600644 def testTastAllOptions(self):
645 """Test VmTest for Tast with all options set."""
Alex Klein231d2da2019-07-22 16:44:45 -0600646 test_controller.VmTest(self._GetInput(), None, self.api_config)
647 self.assertCommandContains([
Achuith Bhandarkara9e9c3d2019-05-22 13:56:11 -0700648 'cros_run_test', '--debug', '--no-display', '--copy-on-write',
Evan Hernandez4e388a52019-05-01 12:16:33 -0600649 '--board', 'target',
650 '--image-path', '/path/to/image.bin',
651 '--tast', 'suite',
652 '--ssh-port', '1234',
653 '--private-key', '/path/to/id_rsa',
654 ])
655
656 def testAutotestAllOptions(self):
657 """Test VmTest for Autotest with all options set."""
658 input_proto = self._GetInput(test_harness=test_pb2.VmTestRequest.AUTOTEST)
Alex Klein231d2da2019-07-22 16:44:45 -0600659 test_controller.VmTest(input_proto, None, self.api_config)
660 self.assertCommandContains([
Achuith Bhandarkara9e9c3d2019-05-22 13:56:11 -0700661 'cros_run_test', '--debug', '--no-display', '--copy-on-write',
Evan Hernandez4e388a52019-05-01 12:16:33 -0600662 '--board', 'target',
663 '--image-path', '/path/to/image.bin',
664 '--autotest', 'suite',
665 '--ssh-port', '1234',
666 '--private-key', '/path/to/id_rsa',
Greg Edelstondcb0e912020-08-31 11:09:40 -0600667 '--test_that-args=--allow-chrome-crashes',
Evan Hernandez4e388a52019-05-01 12:16:33 -0600668 ])
669
670 def testMissingBuildTarget(self):
671 """Test VmTest dies when build_target not set."""
672 input_proto = self._GetInput(build_target=None)
673 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600674 test_controller.VmTest(input_proto, None, self.api_config)
Evan Hernandez4e388a52019-05-01 12:16:33 -0600675
676 def testMissingVmImage(self):
677 """Test VmTest dies when vm_image not set."""
Alex Klein311b8022019-06-05 16:00:07 -0600678 input_proto = self._GetInput(vm_path=None)
Evan Hernandez4e388a52019-05-01 12:16:33 -0600679 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600680 test_controller.VmTest(input_proto, None, self.api_config)
Evan Hernandez4e388a52019-05-01 12:16:33 -0600681
682 def testMissingTestHarness(self):
683 """Test VmTest dies when test_harness not specified."""
684 input_proto = self._GetInput(
685 test_harness=test_pb2.VmTestRequest.UNSPECIFIED)
686 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600687 test_controller.VmTest(input_proto, None, self.api_config)
Evan Hernandez4e388a52019-05-01 12:16:33 -0600688
689 def testMissingVmTests(self):
690 """Test VmTest dies when vm_tests not set."""
691 input_proto = self._GetInput(vm_tests=[])
692 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600693 test_controller.VmTest(input_proto, None, self.api_config)
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600694
Michael Mortensen82cd62d2019-12-01 14:58:54 -0700695 def testVmTest(self):
696 """Call VmTest with valid args and temp dir."""
697 request = self._GetInput()
698 response = self._Output()
699 patch = self.PatchObject(
700 cros_build_lib, 'run',
701 return_value=cros_build_lib.CommandResult(returncode=0))
702
703 test_controller.VmTest(request, response, self.api_config)
704 patch.assert_called()
705
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600706
Alex Klein231d2da2019-07-22 16:44:45 -0600707class MoblabVmTestTest(cros_test_lib.MockTestCase, api_config.ApiConfigMixin):
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600708 """Test the MoblabVmTest endpoint."""
709
710 @staticmethod
711 def _Payload(path):
712 return test_pb2.MoblabVmTestRequest.Payload(
713 path=common_pb2.Path(path=path))
714
715 @staticmethod
716 def _Output():
717 return test_pb2.MoblabVmTestResponse()
718
719 def _Input(self):
720 return test_pb2.MoblabVmTestRequest(
Evan Hernandeze1e05d32019-07-19 12:32:18 -0600721 chroot=common_pb2.Chroot(path=self.chroot_dir),
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600722 image_payload=self._Payload(self.image_payload_dir),
723 cache_payloads=[self._Payload(self.autotest_payload_dir)])
724
725 def setUp(self):
Evan Hernandeze1e05d32019-07-19 12:32:18 -0600726 self.chroot_dir = '/chroot'
727 self.chroot_tmp_dir = '/chroot/tmp'
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600728 self.image_payload_dir = '/payloads/image'
729 self.autotest_payload_dir = '/payloads/autotest'
730 self.builder = 'moblab-generic-vm/R12-3.4.5-67.890'
731 self.image_cache_dir = '/mnt/moblab/cache'
732 self.image_mount_dir = '/mnt/image'
733
Evan Hernandeze1e05d32019-07-19 12:32:18 -0600734 self.PatchObject(chroot_lib.Chroot, 'tempdir', osutils.TempDir)
Evan Hernandez655e8042019-06-13 12:50:44 -0600735
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600736 self.mock_create_moblab_vms = self.PatchObject(
737 test_service, 'CreateMoblabVm')
738 self.mock_prepare_moblab_vm_image_cache = self.PatchObject(
739 test_service, 'PrepareMoblabVmImageCache',
740 return_value=self.image_cache_dir)
741 self.mock_run_moblab_vm_tests = self.PatchObject(
742 test_service, 'RunMoblabVmTest')
743 self.mock_validate_moblab_vm_tests = self.PatchObject(
744 test_service, 'ValidateMoblabVmTest')
745
746 @contextlib.contextmanager
Alex Klein38c7d9e2019-05-08 09:31:19 -0600747 def MockLoopbackPartitions(*_args, **_kwargs):
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600748 mount = mock.MagicMock()
Evan Hernandez40ee7452019-06-13 12:51:43 -0600749 mount.Mount.return_value = [self.image_mount_dir]
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600750 yield mount
Alex Klein231d2da2019-07-22 16:44:45 -0600751
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600752 self.PatchObject(image_lib, 'LoopbackPartitions', MockLoopbackPartitions)
753
Alex Klein231d2da2019-07-22 16:44:45 -0600754 def testValidateOnly(self):
755 """Sanity check that a validate only call does not execute any logic."""
756 test_controller.MoblabVmTest(self._Input(), self._Output(),
757 self.validate_only_config)
758 self.mock_create_moblab_vms.assert_not_called()
759
Michael Mortensen7a7646d2019-12-12 15:36:14 -0700760 def testMockCall(self):
761 """Test mock call does not execute any logic."""
762 patch = self.PatchObject(key_value_store, 'LoadFile')
763
764 # MoblabVmTest does not return a value, checking mocked value is flagged by
765 # lint.
766 test_controller.MoblabVmTest(self._Input(), self._Output(),
767 self.mock_call_config)
768 patch.assert_not_called()
769
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600770 def testImageContainsBuilder(self):
771 """MoblabVmTest calls service with correct args."""
772 request = self._Input()
773 response = self._Output()
774
775 self.PatchObject(
Mike Frysingere652ba12019-09-08 00:57:43 -0400776 key_value_store, 'LoadFile',
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600777 return_value={cros_set_lsb_release.LSB_KEY_BUILDER_PATH: self.builder})
778
Alex Klein231d2da2019-07-22 16:44:45 -0600779 test_controller.MoblabVmTest(request, response, self.api_config)
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600780
781 self.assertEqual(
782 self.mock_create_moblab_vms.call_args_list,
Evan Hernandeze1e05d32019-07-19 12:32:18 -0600783 [mock.call(mock.ANY, self.chroot_dir, self.image_payload_dir)])
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600784 self.assertEqual(
785 self.mock_prepare_moblab_vm_image_cache.call_args_list,
786 [mock.call(mock.ANY, self.builder, [self.autotest_payload_dir])])
787 self.assertEqual(
788 self.mock_run_moblab_vm_tests.call_args_list,
Evan Hernandez655e8042019-06-13 12:50:44 -0600789 [mock.call(mock.ANY, mock.ANY, self.builder, self.image_cache_dir,
790 mock.ANY)])
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600791 self.assertEqual(
792 self.mock_validate_moblab_vm_tests.call_args_list,
793 [mock.call(mock.ANY)])
794
795 def testImageMissingBuilder(self):
796 """MoblabVmTest dies when builder path not found in lsb-release."""
797 request = self._Input()
798 response = self._Output()
799
Mike Frysingere652ba12019-09-08 00:57:43 -0400800 self.PatchObject(key_value_store, 'LoadFile', return_value={})
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600801
802 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600803 test_controller.MoblabVmTest(request, response, self.api_config)
David Wellingc1433c22021-06-25 16:29:48 +0000804
805
806class GetArtifactsTest(cros_test_lib.MockTempDirTestCase):
807 """Test GetArtifacts."""
808
809 CODE_COVERAGE_LLVM_ARTIFACT_TYPE = (
810 common_pb2.ArtifactsByService.Test.ArtifactType.CODE_COVERAGE_LLVM_JSON
811 )
George Engelbrecht764b1cd2021-06-18 17:01:07 -0600812 UNIT_TEST_ARTIFACT_TYPE = (
813 common_pb2.ArtifactsByService.Test.ArtifactType.UNIT_TESTS
814 )
David Wellingc1433c22021-06-25 16:29:48 +0000815
816 def setUp(self):
817 """Set up the class for tests."""
818 chroot_dir = os.path.join(self.tempdir, 'chroot')
819 osutils.SafeMakedirs(chroot_dir)
820 osutils.SafeMakedirs(os.path.join(chroot_dir, 'tmp'))
821 self.chroot = chroot_lib.Chroot(chroot_dir)
822
823 sysroot_path = os.path.join(chroot_dir, 'build', 'board')
824 osutils.SafeMakedirs(sysroot_path)
825 self.sysroot = sysroot_lib.Sysroot(sysroot_path)
826
Jack Neusc9707c32021-07-23 21:48:54 +0000827 self.build_target = build_target_lib.BuildTarget('board')
828
David Wellingc1433c22021-06-25 16:29:48 +0000829 def testReturnsEmptyListWhenNoOutputArtifactsProvided(self):
830 """Test empty list is returned when there are no output_artifacts."""
831 result = test_controller.GetArtifacts(
832 common_pb2.ArtifactsByService.Test(output_artifacts=[]),
Jack Neusc9707c32021-07-23 21:48:54 +0000833 self.chroot, self.sysroot, self.build_target, self.tempdir)
David Wellingc1433c22021-06-25 16:29:48 +0000834
835 self.assertEqual(len(result), 0)
836
837 def testShouldCallBundleCodeCoverageLlvmJsonForEachValidArtifact(self):
838 """Test BundleCodeCoverageLlvmJson is called on each valid artifact."""
Sean McAllister17eed8d2021-09-21 10:41:16 -0600839 BundleCodeCoverageLlvmJson_mock = (
840 self.PatchObject(
841 test_service,
842 'BundleCodeCoverageLlvmJson',
843 return_value='test'))
David Wellingc1433c22021-06-25 16:29:48 +0000844
845 test_controller.GetArtifacts(
846 common_pb2.ArtifactsByService.Test(output_artifacts=[
847 # Valid
848 common_pb2.ArtifactsByService.Test.ArtifactInfo(
849 artifact_types=[
850 self.CODE_COVERAGE_LLVM_ARTIFACT_TYPE
851 ]
852 ),
853
854 # Invalid
855 common_pb2.ArtifactsByService.Test.ArtifactInfo(
856 artifact_types=[
857 common_pb2.ArtifactsByService.Test.ArtifactType.UNIT_TESTS
858 ]
859 ),
860 ]),
Jack Neusc9707c32021-07-23 21:48:54 +0000861 self.chroot, self.sysroot, self.build_target, self.tempdir)
David Wellingc1433c22021-06-25 16:29:48 +0000862
863 BundleCodeCoverageLlvmJson_mock.assert_called_once()
864
865 def testShouldReturnValidResult(self):
866 """Test result contains paths and code_coverage_llvm_json type."""
867 self.PatchObject(test_service, 'BundleCodeCoverageLlvmJson',
Sean McAllister17eed8d2021-09-21 10:41:16 -0600868 return_value='test')
George Engelbrecht764b1cd2021-06-18 17:01:07 -0600869 self.PatchObject(test_service, 'BuildTargetUnitTestTarball',
Sean McAllister17eed8d2021-09-21 10:41:16 -0600870 return_value='unit_tests.tar')
David Wellingc1433c22021-06-25 16:29:48 +0000871
872 result = test_controller.GetArtifacts(
873 common_pb2.ArtifactsByService.Test(output_artifacts=[
874 # Valid
875 common_pb2.ArtifactsByService.Test.ArtifactInfo(
876 artifact_types=[
George Engelbrecht764b1cd2021-06-18 17:01:07 -0600877 self.UNIT_TEST_ARTIFACT_TYPE
878 ]
879 ),
880 common_pb2.ArtifactsByService.Test.ArtifactInfo(
881 artifact_types=[
David Wellingc1433c22021-06-25 16:29:48 +0000882 self.CODE_COVERAGE_LLVM_ARTIFACT_TYPE
883 ]
884 ),
885 ]),
Jack Neusc9707c32021-07-23 21:48:54 +0000886 self.chroot, self.sysroot, self.build_target, self.tempdir)
David Wellingc1433c22021-06-25 16:29:48 +0000887
George Engelbrecht764b1cd2021-06-18 17:01:07 -0600888 self.assertEqual(result[0]['paths'], ['unit_tests.tar'])
889 self.assertEqual(result[0]['type'], self.UNIT_TEST_ARTIFACT_TYPE)
890 self.assertEqual(result[1]['paths'], ['test'])
891 self.assertEqual(result[1]['type'], self.CODE_COVERAGE_LLVM_ARTIFACT_TYPE)