blob: 767de91111ff8c8eff0fd05fcf2e879a98f4b173 [file] [log] [blame]
# Copyright 2018 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from recipe_engine import recipe_test_api
class FuchsiaTestApi(recipe_test_api.RecipeTestApi):
DEFAULT_GCS_BUCKET = '###fuchsia-build###'
def test(self,
name,
clear_default_properties=False,
clear_default_steps=False,
tryjob=False,
expect_failure=False,
properties=None,
bb_build=None,
status='success',
steps=(),
output_dir_contents=None,
tests_json=None): # pragma: no cover
"""Returns a test case appropriate for yielding from GenTests().
Provides default property values for the common cases.
Args:
name: Test name.
clear_default_properties: If true, does not provide default values.
However, setting tryjob=True does still add the tryjob-related
properties. Buildbucket properties are always added.
clear_default_steps: If true, does not automatically add steps
based on the input properties.
tryjob: If true, adds tryjob-related properties.
expect_failure: If true, the test is expected to fail before
completion, so certain common steps shouldn't be expected to happen.
properties: A required dict of properties to override for this test.
steps: An optional sequence of RecipeTestApi.step_data objects to append to
the output of this function.
status: One of 'success' (default), 'failure', or 'infra_failure'. The
result of the test case will be required to match this.
tests_json: A list of dictionaries of the form that would be found in
tests.json (passed to api.testing.test_step_data)
Returns:
TestData object.
"""
properties = properties or {}
# Tests shouldn't try to create their own tryjob environment, in the same way
# that cr-buildbucket builders shouldn't specify tryjob-related properties.
if 'tryjob' in properties:
raise ValueError('Test "%s": Do not specify a "tryjob" property; '
'use the tryjob arg.' % name) # pragma: no cover
project = properties.get('project', 'fuchsia')
if clear_default_properties:
final_properties = {}
else:
final_properties = dict(
manifest='manifest/minimal',
remote='https://fuchsia.googlesource.com/integration',
project='integration',
target='x64',
packages=['//bundles/buildbot:core'],
)
if 'buildbucket' in properties:
# Re-evaluate this restriction if a test really needs to specify its
# own buildbucket properties.
raise ValueError('Test "%s": Do not specify a "buildbucket" property; '
'the test API should provide it.' %
name) # pragma: no cover
if not tryjob:
final_properties['gcs_bucket'] = FuchsiaTestApi.DEFAULT_GCS_BUCKET
# Provided properties override the defaults.
final_properties.update(properties)
# Add implicit steps.
extra_steps = []
if not clear_default_steps:
# Don't add these if the test is expected to raise an exception;
# the recipes engine will complain that these steps aren't consumed.
get_bool = lambda flag, name: \
final_properties.get(name, final_properties.get(flag+'.'+name, False))
run_tests = get_bool('build', 'run_tests')
on_device = final_properties.get('device_type', 'QEMU') != 'QEMU'
on_device = on_device or final_properties.get('test.device_type',
'QEMU') != 'QEMU'
if run_tests and not expect_failure:
outputs = ['out.tar'] if on_device else ['output.fs']
extra_steps.append(
self.m.testing.task_step_data([
self.m.swarming.task_result(
id='1', name='test', outputs=outputs),
]))
extra_steps.append(
self.m.testing.test_step_data(
tests_json=tests_json,
qemu=not on_device,
output_dir_contents=output_dir_contents))
# Assemble the return value.
ret = self.m.status_check.test(name, status=status)
ret += self.m.properties(**final_properties)
# Add buildbucket properties
git_repo = 'https://fuchsia.googlesource.com/' + project
if tryjob:
if not bb_build:
bb_build = self.m.buildbucket.try_build_message(
project=project, git_repo=git_repo)
ret += self.m.buildbucket.build(bb_build)
else:
if not bb_build:
bb_build = self.m.buildbucket.ci_build_message(
project=project, git_repo=git_repo)
ret += self.m.buildbucket.build(bb_build)
for s in extra_steps:
ret += s
for s in steps:
# Provided steps override implicit steps.
ret += s
return ret