blob: 1ffc6bb1998938798aae340f3a02487f596f07a5 [file] [log] [blame]
Alex Kleinc5403d62019-04-03 09:34:59 -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"""Test controller.
6
7Handles all testing related functionality, it is not itself a test.
8"""
9
Jack Neusc9707c32021-07-23 21:48:54 +000010import functools
Derek Beckett963901e2022-04-19 11:38:36 -070011import logging
Alex Kleina2e42c42019-04-17 16:13:19 -060012import os
Sean McAllister17eed8d2021-09-21 10:41:16 -060013import string
Sean McAllister3834fef2021-10-08 15:45:18 -060014import subprocess
Alex Kleina2e42c42019-04-17 16:13:19 -060015
Mike Frysinger1cc8f1f2022-04-28 22:40:40 -040016from chromite.third_party.google.protobuf import json_format
17
Alex Klein8cb365a2019-05-15 16:24:53 -060018from chromite.api import controller
Alex Klein076841b2019-08-29 15:19:39 -060019from chromite.api import faux
Alex Klein2b236722019-06-19 15:44:26 -060020from chromite.api import validate
Alex Kleina2e42c42019-04-17 16:13:19 -060021from chromite.api.controller import controller_util
Evan Hernandez4e388a52019-05-01 12:16:33 -060022from chromite.api.gen.chromite.api import test_pb2
David Wellingc1433c22021-06-25 16:29:48 +000023from chromite.api.gen.chromiumos import common_pb2
Sean McAllister3834fef2021-10-08 15:45:18 -060024from chromite.api.gen.chromiumos.build.api import container_metadata_pb2
Mike Frysinger1cc8f1f2022-04-28 22:40:40 -040025from chromite.api.metrics import deserialize_metrics_log
Mike Frysinger06a51c82021-04-06 11:39:17 -040026from chromite.lib import build_target_lib
George Engelbrecht764b1cd2021-06-18 17:01:07 -060027from chromite.lib import chroot_lib
Alex Kleina2e42c42019-04-17 16:13:19 -060028from chromite.lib import constants
Alex Kleinc5403d62019-04-03 09:34:59 -060029from chromite.lib import cros_build_lib
Ram Chandrasekare08e3ba2022-04-04 21:42:27 +000030from chromite.lib import goma_lib
Alex Kleinaef41942022-04-19 14:13:17 -060031from chromite.lib import metrics_lib
Alex Kleina2e42c42019-04-17 16:13:19 -060032from chromite.lib import osutils
Alex Kleinc5403d62019-04-03 09:34:59 -060033from chromite.lib import sysroot_lib
Alex Klein18a60af2020-06-11 12:08:47 -060034from chromite.lib.parser import package_info
Jack Neusc9707c32021-07-23 21:48:54 +000035from chromite.service import packages as packages_service
Alex Kleinc5403d62019-04-03 09:34:59 -060036from chromite.service import test
37
38
Michael Mortensen85d38402019-12-12 09:50:29 -070039@faux.empty_success
40@faux.empty_completed_unsuccessfully_error
Alex Klein231d2da2019-07-22 16:44:45 -060041def DebugInfoTest(input_proto, _output_proto, config):
Alex Kleinc5403d62019-04-03 09:34:59 -060042 """Run the debug info tests."""
43 sysroot_path = input_proto.sysroot.path
44 target_name = input_proto.sysroot.build_target.name
45
46 if not sysroot_path:
47 if target_name:
Mike Frysinger06a51c82021-04-06 11:39:17 -040048 sysroot_path = build_target_lib.get_default_sysroot_path(target_name)
Alex Kleinc5403d62019-04-03 09:34:59 -060049 else:
50 cros_build_lib.Die("The sysroot path or the sysroot's build target name "
51 'must be provided.')
52
53 # We could get away with out this, but it's a cheap check.
54 sysroot = sysroot_lib.Sysroot(sysroot_path)
55 if not sysroot.Exists():
56 cros_build_lib.Die('The provided sysroot does not exist.')
57
Alex Klein231d2da2019-07-22 16:44:45 -060058 if config.validate_only:
59 return controller.RETURN_CODE_VALID_INPUT
60
Alex Klein8cb365a2019-05-15 16:24:53 -060061 if test.DebugInfoTest(sysroot_path):
62 return controller.RETURN_CODE_SUCCESS
63 else:
64 return controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY
Alex Kleina2e42c42019-04-17 16:13:19 -060065
66
Michael Mortensen82cd62d2019-12-01 14:58:54 -070067def _BuildTargetUnitTestFailedResponse(_input_proto, output_proto, _config):
68 """Add failed packages to a failed response."""
69 packages = ['foo/bar', 'cat/pkg']
Alex Klein8ce5f522020-10-06 17:47:34 -060070 for pkg in packages:
71 pkg_info = package_info.parse(pkg)
72 pkg_info_msg = output_proto.failed_packages.add()
73 controller_util.serialize_package_info(pkg_info, pkg_info_msg)
Lizzy Presland4feb2372022-01-20 05:16:30 +000074 failed_pkg_data_msg = output_proto.failed_package_data.add()
75 controller_util.serialize_package_info(pkg_info, failed_pkg_data_msg.name)
76 failed_pkg_data_msg.log_path.path = '/path/to/%s/log' % pkg
Michael Mortensen82cd62d2019-12-01 14:58:54 -070077
78
Alex Klein0aecf472022-05-23 10:48:45 -060079@faux.empty_success
Michael Mortensen82cd62d2019-12-01 14:58:54 -070080@faux.error(_BuildTargetUnitTestFailedResponse)
Alex Klein64ac34c2020-09-23 10:21:33 -060081@validate.require_each('packages', ['category', 'package_name'])
Alex Klein231d2da2019-07-22 16:44:45 -060082@validate.validation_complete
Alex Kleinaef41942022-04-19 14:13:17 -060083@metrics_lib.collect_metrics
Alex Klein231d2da2019-07-22 16:44:45 -060084def BuildTargetUnitTest(input_proto, output_proto, _config):
Alex Kleina2e42c42019-04-17 16:13:19 -060085 """Run a build target's ebuild unit tests."""
Alex Kleinfa6ebdc2019-05-10 10:57:31 -060086 # Method flags.
Alex Klein38c7d9e2019-05-08 09:31:19 -060087 # An empty sysroot means build packages was not run. This is used for
88 # certain boards that need to use prebuilts (e.g. grunt's unittest-only).
Alex Kleinfa6ebdc2019-05-10 10:57:31 -060089 was_built = not input_proto.flags.empty_sysroot
90
Navil Perezc0b29a82020-07-07 14:17:48 +000091 # Packages to be tested.
92 packages_package_info = input_proto.packages
93 packages = []
Alex Klein18a60af2020-06-11 12:08:47 -060094 for package_info_msg in packages_package_info:
Alex Klein64ac34c2020-09-23 10:21:33 -060095 cpv = controller_util.PackageInfoToCPV(package_info_msg)
96 packages.append(cpv.cp)
Navil Perezc0b29a82020-07-07 14:17:48 +000097
Alex Kleinf2674462019-05-16 16:47:24 -060098 # Skipped tests.
Alex Klein157caf42021-07-01 14:36:43 -060099 blocklisted_package_info = input_proto.package_blocklist
Alex Kleinb64e5f82020-09-23 10:55:31 -0600100 blocklist = []
101 for package_info_msg in blocklisted_package_info:
102 blocklist.append(controller_util.PackageInfoToString(package_info_msg))
Alex Kleinf2674462019-05-16 16:47:24 -0600103
Navil Perez43fb45d2021-05-14 20:34:24 +0000104 # Allow call to filter out non-cros_workon packages from the input packages.
105 filter_only_cros_workon = input_proto.flags.filter_only_cros_workon
106
Navil Perez19dc4792020-09-10 19:06:17 +0000107 # Allow call to succeed if no tests were found.
108 testable_packages_optional = input_proto.flags.testable_packages_optional
109
Alex Klein26e472b2020-03-10 14:35:01 -0600110 build_target = controller_util.ParseBuildTarget(input_proto.build_target)
Alex Kleina2e42c42019-04-17 16:13:19 -0600111
David Burgera9c11872020-07-29 13:32:02 -0600112 code_coverage = input_proto.flags.code_coverage
113
Lizzy Presland4feb2372022-01-20 05:16:30 +0000114 sysroot = sysroot_lib.Sysroot(build_target.root)
115
Navil Perezc0b29a82020-07-07 14:17:48 +0000116 result = test.BuildTargetUnitTest(
117 build_target,
Navil Perezc0b29a82020-07-07 14:17:48 +0000118 packages=packages,
Alex Kleinb64e5f82020-09-23 10:55:31 -0600119 blocklist=blocklist,
David Burgera9c11872020-07-29 13:32:02 -0600120 was_built=was_built,
Navil Perez19dc4792020-09-10 19:06:17 +0000121 code_coverage=code_coverage,
Navil Perez43fb45d2021-05-14 20:34:24 +0000122 testable_packages_optional=testable_packages_optional,
123 filter_only_cros_workon=filter_only_cros_workon)
Alex Kleina2e42c42019-04-17 16:13:19 -0600124
Alex Klein38c7d9e2019-05-08 09:31:19 -0600125 if not result.success:
Lizzy Presland4feb2372022-01-20 05:16:30 +0000126 # Record all failed packages and retrieve log locations.
Lizzy Presland084c20f2022-03-30 19:13:50 +0000127 controller_util.retrieve_package_log_paths(result.failed_pkgs,
128 output_proto, sysroot)
Alex Kleinea0c89e2021-09-09 15:17:35 -0600129 if result.failed_pkgs:
Alex Klein38c7d9e2019-05-08 09:31:19 -0600130 return controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE
131 else:
132 return controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY
Alex Kleina2e42c42019-04-17 16:13:19 -0600133
Will Bradley59e0a152019-11-12 12:59:17 -0700134 deserialize_metrics_log(output_proto.events, prefix=build_target.name)
Alex Kleine3fc3ca2019-04-30 16:20:55 -0600135
136
C Shapiro91af1ce2021-06-17 12:42:09 -0500137SRC_DIR = os.path.join(constants.SOURCE_ROOT, 'src')
Sean McAllister020e3522021-08-25 12:38:02 -0600138PLATFORM_DEV_DIR = os.path.join(SRC_DIR, 'platform/dev')
139TEST_SERVICE_DIR = os.path.join(PLATFORM_DEV_DIR, 'src/chromiumos/test')
C Shapiro91af1ce2021-06-17 12:42:09 -0500140
141
C Shapiroe15660b2021-06-18 12:49:37 -0500142def _BuildTestServiceContainersResponse(input_proto, output_proto, _config):
143 """Fake success response"""
144 # pylint: disable=unused-argument
145 output_proto.results.append(test_pb2.TestServiceContainerBuildResult(
Sean McAllisterf5296912021-09-23 09:32:58 -0600146 success=test_pb2.TestServiceContainerBuildResult.Success()
C Shapiroe15660b2021-06-18 12:49:37 -0500147 ))
148
149
150def _BuildTestServiceContainersFailedResponse(
151 _input_proto, output_proto, _config):
152 """Fake failure response"""
153
154 # pylint: disable=unused-argument
155 output_proto.results.append(test_pb2.TestServiceContainerBuildResult(
Sean McAllisterf5296912021-09-23 09:32:58 -0600156 failure=test_pb2.TestServiceContainerBuildResult.Failure(
C Shapiroe15660b2021-06-18 12:49:37 -0500157 error_message='fake error'
158 )
159 ))
160
161
Sean McAllister17eed8d2021-09-21 10:41:16 -0600162@validate.constraint('valid docker tag')
163def _ValidDockerTag(tag):
164 """Check that a string meets requirements for Docker tag naming."""
165 # Tags can't start with period or dash
166 if tag[0] in '.-':
167 return "tag can't begin with '.' or '-'"
168
169 # Tags can only consist of [a-zA-Z0-9-_.]
170 allowed_chars = set(string.ascii_letters+string.digits+'-_.')
171 invalid_chars = set(tag) - allowed_chars
172 if invalid_chars:
Sean McAllisterd4b70fc2021-11-11 15:49:52 -0700173 return f'saw one or more invalid characters: [{"".join(invalid_chars)}]'
Sean McAllister17eed8d2021-09-21 10:41:16 -0600174
175 # Finally, max tag length is 128 characters
176 if len(tag) > 128:
177 return 'maximum tag length is 128 characters'
178
179
180@validate.constraint('valid docker label key')
181def _ValidDockerLabelKey(key):
182 """Check that a string meets requirements for Docker tag naming."""
183
184 # Label keys should start and end with a lowercase letter
185 lowercase = set(string.ascii_lowercase)
186 if not (key[0] in lowercase and key[-1] in lowercase):
187 return "label key doesn't start and end with lowercase letter"
188
189 # Label keys can have lower-case alphanumeric characters, period and dash
190 allowed_chars = set(string.ascii_lowercase+string.digits+'-.')
191 invalid_chars = set(key) - allowed_chars
192 if invalid_chars:
Sean McAllisterd4b70fc2021-11-11 15:49:52 -0700193 return f'saw one or more invalid characters: [{"".join(invalid_chars)}]'
Sean McAllister17eed8d2021-09-21 10:41:16 -0600194
195 # Repeated . and - aren't allowed
196 for char in '.-':
Sean McAllisterd4b70fc2021-11-11 15:49:52 -0700197 if char * 2 in key:
Sean McAllister4b0144c2021-11-18 08:35:59 -0700198 return f"'{char}' can\'t be repeated in label key"
Sean McAllister17eed8d2021-09-21 10:41:16 -0600199
200
C Shapiroe15660b2021-06-18 12:49:37 -0500201@faux.success(_BuildTestServiceContainersResponse)
202@faux.error(_BuildTestServiceContainersFailedResponse)
C Shapiro91af1ce2021-06-17 12:42:09 -0500203@validate.require('build_target.name')
204@validate.require('chroot.path')
Sean McAllister17eed8d2021-09-21 10:41:16 -0600205@validate.check_constraint('tags', _ValidDockerTag)
206@validate.check_constraint('labels', _ValidDockerLabelKey)
C Shapiro91af1ce2021-06-17 12:42:09 -0500207@validate.validation_complete
Sean McAllister15fa8332021-09-27 12:24:12 -0600208def BuildTestServiceContainers(
209 input_proto: test_pb2.BuildTestServiceContainersRequest,
210 output_proto: test_pb2.BuildTestServiceContainersResponse, _config):
C Shapiro91af1ce2021-06-17 12:42:09 -0500211 """Builds docker containers for all test services and pushes them to gcr.io"""
212 build_target = controller_util.ParseBuildTarget(input_proto.build_target)
213 chroot = controller_util.ParseChroot(input_proto.chroot)
C Shapiro91af1ce2021-06-17 12:42:09 -0500214 sysroot = sysroot_lib.Sysroot(build_target.root)
215
Sean McAllister15fa8332021-09-27 12:24:12 -0600216 tags = ','.join(input_proto.tags)
217 labels = (
Lizzy Preslandb2d60642021-11-12 01:41:58 +0000218 f'{key}={value}' for key, value in input_proto.labels.items()
Sean McAllister15fa8332021-09-27 12:24:12 -0600219 )
220
Derek Beckett344b5a82022-05-09 17:21:45 -0700221 build_script = os.path.join(
222 TEST_SERVICE_DIR, 'python/src/docker_libs/cli/build-dockerimages.py')
223 human_name = 'Service Builder'
Sean McAllister15fa8332021-09-27 12:24:12 -0600224
Derek Beckett344b5a82022-05-09 17:21:45 -0700225 with osutils.TempDir(prefix='test_container') as tempdir:
226 result_file = 'metadata.jsonpb'
227 output_path = os.path.join(tempdir, result_file)
228 # Note that we use an output file instead of stdout to avoid any issues
229 # with maintaining stdout hygiene. Stdout and stderr are combined to
230 # form the error log in response to any errors.
231 cmd = [build_script, chroot.path, sysroot.path]
Sean McAllistere6a4ae22021-10-21 13:17:08 -0600232
Derek Beckett344b5a82022-05-09 17:21:45 -0700233 if input_proto.HasField('repository'):
234 cmd += ['--host', input_proto.repository.hostname]
235 cmd += ['--project', input_proto.repository.project]
Sean McAllistere6a4ae22021-10-21 13:17:08 -0600236
Derek Beckett344b5a82022-05-09 17:21:45 -0700237 cmd += ['--tags', tags]
238 cmd += ['--output', output_path]
Derek Beckettb28b5372022-04-15 13:08:32 -0700239
Derek Beckett344b5a82022-05-09 17:21:45 -0700240 # Translate generator to comma separated string.
241 ct_labels = ','.join(labels)
242 cmd += ['--labels', ct_labels]
243 cmd += ['--build_all']
244 cmd += ['--upload']
Derek Beckettcbe64c82022-05-05 15:00:18 -0700245
Derek Beckett344b5a82022-05-09 17:21:45 -0700246 cmd_result = cros_build_lib.run(cmd, check=False,
247 stderr=subprocess.STDOUT,
248 stdout=True)
Derek Becketta8d9fd22022-04-27 10:44:52 -0700249
Derek Beckett344b5a82022-05-09 17:21:45 -0700250 if cmd_result.returncode != 0:
251 # When failing, just record a fail response with the builder name.
252 logging.debug('%s build failed.\nStdout:\n%s\nStderr:\n%s',
253 human_name, cmd_result.stdout, cmd_result.stderr)
Sean McAllister3834fef2021-10-08 15:45:18 -0600254 result = test_pb2.TestServiceContainerBuildResult()
255 result.name = human_name
Derek Beckett344b5a82022-05-09 17:21:45 -0700256 image_info = container_metadata_pb2.ContainerImageInfo()
257 result.failure.CopyFrom(
258 test_pb2.TestServiceContainerBuildResult.Failure(
259 error_message=cmd_result.stdout
260 )
261 )
Sean McAllister3834fef2021-10-08 15:45:18 -0600262 output_proto.results.append(result)
C Shapiro91af1ce2021-06-17 12:42:09 -0500263
Derek Beckett344b5a82022-05-09 17:21:45 -0700264 else:
265 logging.debug('%s build succeeded.\nStdout:\n%s\nStderr:\n%s',
266 human_name, cmd_result.stdout, cmd_result.stderr)
267 files = os.listdir(tempdir)
268 # Iterate through the tempdir to output metadata files.
269 for file in files:
270 if result_file in file:
271 output_path = os.path.join(tempdir, file)
272
273 # build-dockerimages.py will append the service name to outputfile
274 # with an underscore.
275 human_name = file.split('_')[-1]
276
277 result = test_pb2.TestServiceContainerBuildResult()
278 result.name = human_name
279 image_info = container_metadata_pb2.ContainerImageInfo()
280 json_format.Parse(osutils.ReadFile(output_path), image_info)
281 result.success.CopyFrom(
282 test_pb2.TestServiceContainerBuildResult.Success(
283 image_info=image_info
284 )
285 )
286 output_proto.results.append(result)
287
C Shapiro91af1ce2021-06-17 12:42:09 -0500288
Michael Mortensen7a860eb2019-12-03 20:25:15 -0700289@faux.empty_success
290@faux.empty_completed_unsuccessfully_error
Alex Klein231d2da2019-07-22 16:44:45 -0600291@validate.validation_complete
292def ChromiteUnitTest(_input_proto, _output_proto, _config):
Alex Kleine3fc3ca2019-04-30 16:20:55 -0600293 """Run the chromite unit tests."""
Mike Frysinger4975e5a2021-04-13 17:06:09 -0400294 if test.ChromiteUnitTest():
Alex Klein8cb365a2019-05-15 16:24:53 -0600295 return controller.RETURN_CODE_SUCCESS
296 else:
297 return controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY
Evan Hernandez4e388a52019-05-01 12:16:33 -0600298
299
Greg Edelstonf3fc8b62020-03-17 14:20:24 -0600300@faux.empty_success
301@faux.empty_completed_unsuccessfully_error
302@validate.validation_complete
303def ChromitePytest(_input_proto, _output_proto, _config):
304 """Run the chromite unit tests."""
Mike Frysinger4975e5a2021-04-13 17:06:09 -0400305 # TODO(vapier): Delete this stub.
306 return controller.RETURN_CODE_SUCCESS
Greg Edelstonf3fc8b62020-03-17 14:20:24 -0600307
308
Sloan Johnson9fdd5312022-03-02 00:55:26 +0000309@faux.empty_success
310@faux.empty_completed_unsuccessfully_error
311@validate.validation_complete
312def RulesCrosUnitTest(_input_proto, _output_proto, _config):
313 """Run the rules_cros unit tests."""
314 if test.RulesCrosUnitTest():
315 return controller.RETURN_CODE_SUCCESS
316 else:
317 return controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY
318
319
Michael Mortensenc28d6f12019-10-03 13:34:51 -0600320@faux.all_empty
321@validate.require('sysroot.path', 'sysroot.build_target.name', 'chrome_root')
322@validate.validation_complete
323def SimpleChromeWorkflowTest(input_proto, _output_proto, _config):
324 """Run SimpleChromeWorkflow tests."""
325 if input_proto.goma_config.goma_dir:
326 chromeos_goma_dir = input_proto.goma_config.chromeos_goma_dir or None
Ram Chandrasekare08e3ba2022-04-04 21:42:27 +0000327 goma = goma_lib.Goma(
Michael Mortensenc28d6f12019-10-03 13:34:51 -0600328 input_proto.goma_config.goma_dir,
329 input_proto.goma_config.goma_client_json,
330 stage_name='BuildApiTestSimpleChrome',
331 chromeos_goma_dir=chromeos_goma_dir)
332 else:
333 goma = None
334 return test.SimpleChromeWorkflowTest(input_proto.sysroot.path,
335 input_proto.sysroot.build_target.name,
336 input_proto.chrome_root,
337 goma)
338
339
Alex Klein076841b2019-08-29 15:19:39 -0600340@faux.all_empty
Alex Klein2b236722019-06-19 15:44:26 -0600341@validate.require('build_target.name', 'vm_path.path', 'test_harness',
342 'vm_tests')
Alex Klein231d2da2019-07-22 16:44:45 -0600343@validate.validation_complete
344def VmTest(input_proto, _output_proto, _config):
Evan Hernandez4e388a52019-05-01 12:16:33 -0600345 """Run VM tests."""
Alex Klein2b236722019-06-19 15:44:26 -0600346 build_target_name = input_proto.build_target.name
347 vm_path = input_proto.vm_path.path
Alex Kleinc05f3d12019-05-29 14:16:21 -0600348
Evan Hernandez4e388a52019-05-01 12:16:33 -0600349 test_harness = input_proto.test_harness
Evan Hernandez4e388a52019-05-01 12:16:33 -0600350
351 vm_tests = input_proto.vm_tests
Evan Hernandez4e388a52019-05-01 12:16:33 -0600352
Achuith Bhandarkara9e9c3d2019-05-22 13:56:11 -0700353 cmd = ['cros_run_test', '--debug', '--no-display', '--copy-on-write',
Alex Klein2b236722019-06-19 15:44:26 -0600354 '--board', build_target_name, '--image-path', vm_path,
Evan Hernandez4e388a52019-05-01 12:16:33 -0600355 '--%s' % test_pb2.VmTestRequest.TestHarness.Name(test_harness).lower()]
356 cmd.extend(vm_test.pattern for vm_test in vm_tests)
357
358 if input_proto.ssh_options.port:
359 cmd.extend(['--ssh-port', str(input_proto.ssh_options.port)])
360
361 if input_proto.ssh_options.private_key_path:
Alex Kleinaa705412019-06-04 15:00:30 -0600362 cmd.extend(['--private-key', input_proto.ssh_options.private_key_path.path])
Evan Hernandez4e388a52019-05-01 12:16:33 -0600363
364 # TODO(evanhernandez): Find a nice way to pass test_that-args through
365 # the build API. Or obviate them.
366 if test_harness == test_pb2.VmTestRequest.AUTOTEST:
Greg Edelstondcb0e912020-08-31 11:09:40 -0600367 cmd.append('--test_that-args=--allow-chrome-crashes')
Evan Hernandez4e388a52019-05-01 12:16:33 -0600368
369 with osutils.TempDir(prefix='vm-test-results.') as results_dir:
370 cmd.extend(['--results-dir', results_dir])
Mike Frysinger45602c72019-09-22 02:15:11 -0400371 cros_build_lib.run(cmd, kill_timeout=10 * 60)
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600372
373
Alex Klein076841b2019-08-29 15:19:39 -0600374@faux.all_empty
Alex Klein4bc8f4f2019-08-16 14:53:30 -0600375@validate.validation_complete
376def CrosSigningTest(_input_proto, _output_proto, _config):
377 """Run the cros-signing unit tests."""
378 test_runner = os.path.join(constants.SOURCE_ROOT, 'cros-signing', 'signer',
379 'run_tests.py')
Mike Frysingerf5a3b2d2019-12-12 14:36:17 -0500380 result = cros_build_lib.run([test_runner], check=False)
Alex Klein4bc8f4f2019-08-16 14:53:30 -0600381
382 return result.returncode
David Wellingc1433c22021-06-25 16:29:48 +0000383
384
385def GetArtifacts(in_proto: common_pb2.ArtifactsByService.Test,
Sean McAllisterf5296912021-09-23 09:32:58 -0600386 chroot: chroot_lib.Chroot, sysroot_class: sysroot_lib.Sysroot,
387 build_target: build_target_lib.BuildTarget,
388 output_dir: str) -> list:
David Wellingc1433c22021-06-25 16:29:48 +0000389 """Builds and copies test artifacts to specified output_dir.
390
391 Copies test artifacts to output_dir, returning a list of (output_dir: str)
392 paths to the desired files.
393
394 Args:
395 in_proto: Proto request defining reqs.
396 chroot: The chroot class used for these artifacts.
397 sysroot_class: The sysroot class used for these artifacts.
Jack Neusc9707c32021-07-23 21:48:54 +0000398 build_target: The build target used for these artifacts.
David Wellingc1433c22021-06-25 16:29:48 +0000399 output_dir: The path to write artifacts to.
400
401 Returns:
402 A list of dictionary mappings of ArtifactType to list of paths.
403 """
404 generated = []
George Engelbrecht764b1cd2021-06-18 17:01:07 -0600405
406 artifact_types = {
Sean McAllisterf5296912021-09-23 09:32:58 -0600407 in_proto.ArtifactType.CODE_COVERAGE_LLVM_JSON:
408 test.BundleCodeCoverageLlvmJson,
409 in_proto.ArtifactType.HWQUAL: functools.partial(
410 test.BundleHwqualTarball,
411 build_target.name, packages_service.determine_full_version()),
George Engelbrecht764b1cd2021-06-18 17:01:07 -0600412 }
413
David Wellingc1433c22021-06-25 16:29:48 +0000414 for output_artifact in in_proto.output_artifacts:
George Engelbrecht764b1cd2021-06-18 17:01:07 -0600415 for artifact_type, func in artifact_types.items():
416 if artifact_type in output_artifact.artifact_types:
417 paths = func(chroot, sysroot_class, output_dir)
418 if paths:
419 generated.append({
420 'paths': [paths] if isinstance(paths, str) else paths,
421 'type': artifact_type,
422 })
423
David Wellingc1433c22021-06-25 16:29:48 +0000424 return generated