blob: 8e77ecf3850ce81ddca41f2bbbbae93e98d561ae [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
from google.protobuf import json_format as jsonpb
from PB.go.fuchsia.dev.fuchsia.tools.integration.fint.proto import (
build_artifacts as fint_build_artifacts_pb2,
set_artifacts as fint_set_artifacts_pb2,
)
class FuchsiaBuildTestApi(recipe_test_api.RecipeTestApi):
def test(
self,
name,
tryjob=False,
properties=None,
create_shards=True,
with_multipliers=False,
status="success",
git_repo="https://fuchsia.googlesource.com/fuchsia",
affected_tests_no_work=None,
):
"""Returns a test case appropriate for yielding from GenTests().
Provides default property values for the common cases.
Args:
name: Test name.
packages (sequence[str]): A sequence of packages to pass to GN to build
properties (dict): A dict of properties to override for this test.
create_shards (bool): Whether to create test shards.
with_multipliers (bool): Whether to create multiplier shards. If true,
create_shards must also be true; otherwise, it will be ignored.
status (str): One of 'success' (default), 'failure', or
'infra_failure'. The result of the test case will be required to
match this.
git_repo (str): Repo URL to set in the BuildBucket input.
Returns:
TestData object.
"""
properties = dict(properties or {})
# Assemble the return value.
ret = self.m.status_check.test(name, status=status)
# Add buildbucket properties
if tryjob:
ret += self.m.buildbucket.try_build(project="fuchsia", git_repo=git_repo,)
if affected_tests_no_work is not None:
ret += self.step_data(
"find affected tests", self.m.json.output(affected_tests_no_work),
)
else:
ret += self.m.buildbucket.ci_build(project="fuchsia", git_repo=git_repo,)
ret += self.m.properties(**properties)
if create_shards:
shards = [
self.m.testsharder.shard(
name="Vim2",
tests=["test"],
dimensions=dict(device_type="Khadas Vim2 Max"),
),
]
if with_multipliers:
shards.append(
self.m.testsharder.shard(
name="multiplied:Vim2-test",
tests=["test"] * 2,
dimensions=dict(device_type="Khadas Vim2 Max"),
),
)
ret += self.create_shards_step_data(shards=shards)
return ret
def mock_triage_sources_manifest(self):
"""Returns a mock triage_sources.json file."""
return ["../../config.triage", "../../other/config.triage"]
def create_shards_step_data(self, shards):
"""Returns mock step data for test shards.
This should be used by any test which expects to shard tests.
Args:
shards (seq[api.testsharder.Shard]): A set of example shards which should
be used as step data for the result of invoking the testsharder.
Returns:
RecipeTestApi.step_data for the extract_results step.
"""
return self.m.testsharder.execute(step_name="create test shards", shards=shards)
def fint_build_artifacts_proto(self, **kwargs):
final_kwargs = {
"ninja_log_path": "/tmp/ninja_log.txt",
"ninja_compdb_path": "/tmp/ninja_compdb.json",
"ninja_graph_path": "/tmp/ninja_graph.dot",
"built_archives": [
{"name": "archive", "path": "build-archive.tgz", "type": "tgz"},
],
"built_images": [
{"name": "zircon-a", "type": "zbi", "path": "fuchsia.zbi"}
],
"ninja_duration_seconds": 15 * 60,
}
final_kwargs.update(kwargs)
proto = fint_build_artifacts_pb2.BuildArtifacts()
jsonpb.ParseDict(final_kwargs, proto)
return proto
def fint_build_artifacts(self, **kwargs):
proto = self.fint_build_artifacts_proto(**kwargs)
return self.step_data(
"build.read fint build artifacts", self.m.file.read_proto(proto)
)
def fint_set_artifacts(self, **kwargs):
kwargs.setdefault("use_goma", True)
return self.step_data(
"build.read fint set artifacts",
self.m.file.read_proto(fint_set_artifacts_pb2.SetArtifacts(**kwargs)),
)