blob: 503fceebc7a7cb6dc0a5a1b0f733ae7274d6114f [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 mock_triage_sources_manifest(self):
"""Returns a mock triage_sources.json file."""
return ["../../config.triage", "../../other/config.triage"]
def create_shards(self, with_multipliers=False, nesting=None, with_skipped=False):
"""Returns mock step data for test shards.
This should be used by any test which expects to shard tests.
Args:
with_multipliers (bool): Whether to create multiplier shards.
nesting (str or None): Top-level step name under which the sharding
step is nested.
with_skipped (bool): Whether to create skipped 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"),
),
)
if with_skipped:
shards.append(
self.m.testsharder.shard(
name="unaffected:NUC",
tests=["test1", "test2"],
dimensions=dict(device_type="NUC"),
summary={
"tests": {
"test1": "PASSED",
"test2": "PASSED",
}
},
)
)
step_name = "create test shards"
if nesting: # pragma: no cover
step_name = f"{nesting}.{step_name}"
return self.m.testsharder.execute(step_name=step_name, 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,
"log_files": {"some_cmd_stdout": "/tmp/stdout.txt"},
}
final_kwargs.update(kwargs)
return jsonpb.ParseDict(final_kwargs, fint_build_artifacts_pb2.BuildArtifacts())
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)),
)
def load_skipped_shards(self):
return self.step_data(
"download test orchestration inputs.load skipped shards",
self.m.file.read_json(
[
{
"name": "unaffected:NUC",
"env_name": "NUC-x64",
"from_fuchsia": True,
"summary": {
"tests": {
"test1": "PASSED",
"test2": "PASSED",
},
},
}
]
),
)