blob: 844a742a9a82079e701059334cb83c51530b2942 [file]
# Copyright 2019 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 PB.go.fuchsia.dev.fuchsia.tools.integration.fint.proto import (
set_artifacts as fint_set_artifacts_pb2,
)
from PB.recipes.fuchsia.fuchsia.spec import Fuchsia
from recipe_engine.recipe_api import Property
DEPS = [
"fuchsia/artifacts",
"fuchsia/build",
"fuchsia/buildbucket_util",
"fuchsia/checkout",
"fuchsia/git",
"fuchsia/testing_requests",
"fuchsia/testsharder",
"recipe_engine/assertions",
"recipe_engine/buildbucket",
"recipe_engine/json",
"recipe_engine/path",
"recipe_engine/properties",
"recipe_engine/step",
"recipe_engine/swarming",
]
PROPERTIES = {
"build_artifact_hash": Property(
kind=str, help="Hash for which build artifact may be downloaded", default="abc"
),
"device_type": Property(
kind=str,
help="Passed through to spec field Fuchsia.Test.device_type",
default="QEMU",
),
"pave": Property(
kind=bool, help="Passed through to spec field Fuchsia.Test.pave", default=True
),
"pool": Property(
kind=str,
help="Passed through to spec field Fuchsia.Test.pool",
default="fuchsia.tests",
),
"product": Property(
kind=str,
help="The product configuration of the build",
default="products/foo.gni",
),
"target_arch": Property(kind=str, help="target CPU for build", default="x64"),
"task_timeout_secs": Property(
kind=int,
help="Passed through to spec field Fuchsia.Test.timeout_secs",
default=0,
),
"test_on_gce": Property(kind=bool, help="Whether to run GCE shards", default=False),
"variants": Property(kind=list, help="GN variants", default=[]),
"zircon_args": Property(
kind=list, help="kernel command-line arguments", default=[]
),
"upload_results_from_swarming": Property(
kind=bool,
help="Whether test results were uploaded from swarming",
default=False,
),
"use_ffx_max": Property(
kind=bool, help="Whether to use the max ffx experiment level", default=False
),
"use_cas": Property(
kind=bool,
help="Whether to enable using CAS delivery of images and blobs",
default=False,
),
"use_product_bundle": Property(
kind=bool, help="Whether to use a product bundle from the shard", default=False
),
"use_tcg": Property(
kind=bool, help="Whether to use TCG (as opposed to KVM)", default=False
),
}
def RunSteps(
api,
device_type,
pave,
target_arch,
task_timeout_secs,
test_on_gce,
variants,
zircon_args,
upload_results_from_swarming,
pool,
product,
use_ffx_max,
use_cas,
use_product_bundle,
use_tcg,
):
unit_tests(api)
source_info = [
{
"name": "integration",
"remote": "https://fuchsia.googlesource.com/integration",
"revision": "a491082dc1b632bbcd60ba3618d20b503c2de738",
"relativePath": "integration",
},
]
# Intended to be a minimal amount of code to create a valid FuchsiaBuildResults object.
checkout_root = api.path.start_dir
checkout = api.checkout.CheckoutResults(
checkout_root,
project="integration",
snapshot_file=api.path.start_dir / "snapshot",
release_branch=None,
release_version="0.20200531.0.1",
source_info=source_info,
)
build_dir = checkout_root.joinpath("out", "not-default")
gn_results = api.build.gn_results(
build_dir,
fint_set_artifacts=fint_set_artifacts_pb2.SetArtifacts(
metadata=dict(
variants=variants,
product=product,
target_arch=target_arch,
board="boards/bar.gni",
optimize="release",
)
),
)
build_results = api.build.build_results(
checkout=checkout,
build_dir=build_dir,
gn_results=gn_results,
images=[
{
"name": "zircon-a",
"type": "zbi",
"path": "fuchsia.zbi",
"bootserver_pave": ["--boot"],
}
],
)
# Configure context of uploaded artifacts for test task construction.
api.artifacts.gcs_bucket = "fuchsia-artifacts"
api.artifacts.namespace = api.buildbucket_util.id
ffx_experiment_level = 0
if use_ffx_max:
ffx_experiment_level = 2
test_spec = Fuchsia.Test(
pave=pave,
pool=pool,
timeout_secs=task_timeout_secs,
swarming_grace_period_secs=30,
botanist_grace_period_secs=60,
default_service_account="default_service_account",
targets_serial=True,
zircon_args=zircon_args,
upload_results_from_swarming=upload_results_from_swarming,
gce_mediator=Fuchsia.Test.GCEMediator(
endpoint="gcem-endpoint",
cloud_project="gcem-cloud-project",
machine_shape="n2-standard-4",
),
ffx_experiment_level=ffx_experiment_level,
test_on_gce=test_on_gce,
use_cas=use_cas,
enable_sandboxing=True,
use_tcg=use_tcg,
)
shards = (
api.testsharder.Shard(
"NAME",
tests=[
{
"name": "TEST",
"label": "//path/to/test:test(//toolchain)",
"os": "linux",
"path": "/path/to/test",
}
],
deps=["path/to/a/dep"],
dimensions={"device_type": device_type},
netboot=not pave,
expects_ssh=pave,
service_account="foo@bar.com",
timeout_secs=1800,
pkg_repo="path/to/pkg/repo",
product_bundle="product_bundle" if use_product_bundle else "",
bootup_timeout_secs=600 if use_product_bundle else 0,
),
api.testsharder.Shard(
"NAME2",
tests=[
{
"name": "TEST2",
"label": "//path/to/test:test(//toolchain)",
"os": "linux",
"path": "/path/to/test",
}
],
deps=["path/to/a/dep"],
dimensions={"os": "Linux"},
netboot=not pave,
expects_ssh=pave,
service_account="foo@bar.com",
timeout_secs=1800,
pkg_repo="path/to/pkg/repo",
),
)
task_requests = api.testing_requests.task_requests(
shards, build_results, api.buildbucket.build, test_spec
)
task_requests_data = [r.to_jsonish() for r in task_requests]
api.step.empty("task requests").presentation.logs["requests"] = api.json.dumps(
task_requests_data, indent=2
)
def unit_tests(api):
assert api.testing_requests._get_catapult_dashboard_env_vars(
"example.fuchsia.global.ci", "example-core.x64-nuc", "refs/heads/main"
) == {
"CATAPULT_DASHBOARD_MASTER": "example.fuchsia.global.ci",
"CATAPULT_DASHBOARD_BOT": "example-core.x64-nuc",
}
assert api.testing_requests._get_catapult_dashboard_env_vars(
"example.fuchsia.global.ci",
"example-core.x64-nuc",
"refs/heads/releases/releasefoo",
) == {
"CATAPULT_DASHBOARD_MASTER": "example.fuchsia.global.ci.releasefoo",
"CATAPULT_DASHBOARD_BOT": "example-core.x64-nuc",
}
assert (
api.testing_requests._get_catapult_dashboard_env_vars(
"example.fuchsia.global.ci",
"example-core.x64-nuc",
"refs/heads/otherbranch",
)
== {}
)
# If Catapult upload names are not specified in the infra spec, the env
# vars should not get set.
assert (
api.testing_requests._get_catapult_dashboard_env_vars("", "", "refs/heads/main")
== {}
)
assert (
api.testing_requests._get_catapult_dashboard_env_vars(
"", "", "refs/heads/releases/releasefoo"
)
== {}
)
assert (
api.testing_requests._get_catapult_dashboard_env_vars(
"", "", "refs/heads/otherbranch"
)
== {}
)
# Test that the function raises an exception if only one of the two
# parameters is provided.
with api.assertions.assertRaises(ValueError):
api.testing_requests._get_catapult_dashboard_env_vars(
"global.ci", "", "refs/heads/main"
)
with api.assertions.assertRaises(ValueError):
api.testing_requests._get_catapult_dashboard_env_vars(
"", "core.x64-nuc", "refs/heads/main"
)
def GenTests(api):
# For coverage
api.testing_requests.task_requests_step_data(
[api.swarming.example_task_request_jsonish()], ""
)
yield api.buildbucket_util.test("not_emu_pave") + api.properties(
device_type="DEVICE TYPE",
task_timeout_secs=50, # Should override testsharder's computed shard timeout.
variants=["host-asan", "asan"],
zircon_args=["zircon_arg=true", "zircon_arg2=true"],
)
yield api.buildbucket_util.test("not_emu_netboot") + api.properties(
device_type="DEVICE TYPE",
product="products/bringup.gni",
pave=False,
variants=["host-asan", "asan"],
)
yield api.buildbucket_util.test("emu_bringup") + api.properties(
product="products/bringup.gni",
pave=False,
variants=["host-asan", "asan"],
)
yield api.buildbucket_util.test("qemu") + api.properties(
target_arch="x64",
zircon_args=["zircon_arg=true", "zircon_arg2=true"],
)
yield api.buildbucket_util.test("qemu_variants") + api.properties(
zircon_args=["zircon_arg=true", "zircon_arg2=true"],
variants=["host-asan", "asan"],
)
yield api.buildbucket_util.test("aemu_ffx") + api.properties(
device_type="AEMU",
use_product_bundle=True,
)
yield api.buildbucket_util.test("device_ffx") + api.properties(
device_type="DEVICE TYPE"
)
yield api.buildbucket_util.test("device_ffx_max_level") + api.properties(
device_type="DEVICE TYPE", use_ffx_max=True
)
yield api.buildbucket_util.test("upload_results_from_swarming") + api.properties(
device_type="DEVICE TYPE", upload_results_from_swarming=True
)
yield api.buildbucket_util.test("gce_not_enabled") + api.properties(
device_type="GCE", pool="fuchsia.dev.tests"
)
yield api.buildbucket_util.test("gce_dev") + api.properties(
test_on_gce=True,
device_type="GCE",
pool="fuchsia.dev.tests",
)
yield api.buildbucket_util.test("gce_prod") + api.properties(
test_on_gce=True,
device_type="GCE",
pool="fuchsia.tests",
)
yield api.buildbucket_util.test("cas_delivery_enabled") + api.properties(
use_cas=True
)
yield api.buildbucket_util.test("use_tcg_enabled") + api.properties(
target_arch="riscv64", use_tcg=True
)
sample_public_commit_message = """[roll] Roll fuchsia [test] This is a test commit
Sample public Commit
Original-Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/123456
Original-Revision: bbbb51a61bc81e41ce261661dab20ed032c81fc
GitOrigin-RevId: aaaac79496eb20fdf52d250437fda791562754ff
Change-Id: I1c8bba9e37aac395db3c83988ec27d8567ab5c89
"""
yield (
api.buildbucket_util.test(
"try_job_commit_id_public",
tryjob=True,
revision="base-revision",
repo="integration",
)
) + api.git.get_commit_message(
"shard NAME2.get commit msg", sample_public_commit_message
)
yield (
api.buildbucket_util.test(
"ci_commit_id_public",
tryjob=False,
revision="base-revision",
repo="integration",
)
) + api.git.get_commit_message(
"shard NAME2.get commit msg", sample_public_commit_message
)
yield (
api.buildbucket_util.test(
"try_job_commit_id_internal",
tryjob=True,
revision="base-revision",
repo="integration",
git_repo="https://turquoise-internal.googlesource.com/integration",
)
)
yield (
api.buildbucket_util.test(
"ci_commit_id_internal",
tryjob=False,
revision="base-revision",
repo="integration",
git_repo="https://turquoise-internal.googlesource.com/integration",
)
)
yield (
api.buildbucket_util.test(
"ci_commit_id_smart_integration",
tryjob=False,
revision="base-revision",
repo="smart-integration",
git_repo="https://turquoise-internal.googlesource.com/smart-integration",
)
) + api.git.get_commit_message(
"shard NAME2.get commit msg", sample_public_commit_message
)