| # 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 |
| |
| # A dummy option for a ZBI test to choose its own QEMU kernel to be used. |
| QEMU_KERNEL_OVERRIDE_LABEL_FUCHSIA = "//build/images:qemu_kernel_override" |
| QEMU_KERNEL_OVERRIDE_LABEL_ZIRCON = "//zircon/kernel:qemu_kernel_override" |
| |
| |
| class FuchsiaBuildTestApi(recipe_test_api.RecipeTestApi): |
| def test( |
| self, |
| name, |
| target="x64", |
| variants=(), |
| build_type="debug", |
| product="products/core.gni", |
| board="boards/x64.gni", |
| 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. |
| target (str): A build target (e.g., 'x64' or 'arm64'). |
| build_type (str): A build type (e.g., 'debug' or 'release') |
| variants (sequence[str]): Variant selectors to pass to GN. |
| packages (sequence[str]): A sequence of packages to pass to GN to build |
| product (str): A product to pass to GN to build. |
| board (str): A board 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. |
| """ |
| final_properties = { |
| "target": target, |
| "variants": list(variants), |
| "build_type": build_type, |
| "product": product, |
| "board": board, |
| } |
| # Provided properties override the defaults. |
| properties = properties or {} |
| final_properties.update(properties) |
| |
| # 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( |
| "affected tests.read no work status", |
| self.m.json.output(affected_tests_no_work), |
| ) |
| else: |
| final_properties["gcs_bucket"] = "###fuchsia-build###" |
| ret += self.m.buildbucket.ci_build(project="fuchsia", git_repo=git_repo,) |
| |
| ret += self.m.properties(**final_properties) |
| |
| if create_shards: |
| shards = [ |
| self.m.testsharder.shard( |
| name="Vim2", |
| tests=[self.m.testsharder.test("test", os="linux"),], |
| dimensions=dict(device_type="Khadas Vim2 Max"), |
| ), |
| ] |
| if with_multipliers: |
| shards.append( |
| self.m.testsharder.shard( |
| name="multiplied:Vim2-test", |
| tests=[ |
| self.m.testsharder.test("test", os="linux") |
| for _ in range(2) |
| ], |
| dimensions=dict(device_type="Khadas Vim2 Max"), |
| ), |
| ) |
| ret += self.create_shards_step_data(shards=shards) |
| return ret |
| |
| def mock_image_manifest(self): |
| """Returns a mock image manifest. |
| |
| Args: |
| arch (str): The target architecture of the build. |
| """ |
| return self.m.json.output( |
| [ |
| { |
| "name": "zircon-a", |
| "type": "zbi", |
| "path": "fuchsia.zbi", |
| "bootserver_pave": ["--boot", "--zircona"], |
| }, |
| {"name": "storage-full", "type": "blk", "path": "fvm.blk",}, |
| { |
| "name": "storage-sparse", |
| "type": "blk", |
| "path": "fvm.sparse.blk", |
| "bootserver_pave": ["--fvm"], |
| }, |
| { |
| "name": "efi", |
| "type": "blk", |
| "path": "fuchsia.esp.blk", |
| "bootserver_pave": ["--efi"], |
| }, |
| { |
| "name": "netboot", |
| "type": "zbi", |
| "path": "netboot.zbi", |
| "bootserver_netboot": ["--boot"], |
| }, |
| {"name": "qemu-kernel", "path": "multiboot.bin", "type": "kernel"}, |
| { |
| "name": "zircon-r", |
| "type": "zbi", |
| "path": "zircon-r.zbi", |
| "bootserver_pave": ["--zircon-r"], |
| }, |
| { |
| "name": "zircon-r", |
| "type": "zbi", |
| "path": "zedboot.zbi", |
| "bootserver_pave_zedboot": ["--zircona"], |
| }, |
| { |
| # This entry is relevant to zbi_test.py in which mock_zbi_test |
| # below is used with override=True. |
| "name": "qemu-kernel-override-fuchsia", |
| "path": "multiboot-override-fuchsia.bin", |
| "type": "bin", |
| "label": QEMU_KERNEL_OVERRIDE_LABEL_FUCHSIA, |
| }, |
| { |
| # This entry is relevant to zbi_test.py in which mock_zbi_test |
| # below is used with override=True. |
| "name": "qemu-kernel-override-zircon", |
| "path": "../default.zircon/multiboot-override-zircon.bin", |
| "type": "bin", |
| "label": QEMU_KERNEL_OVERRIDE_LABEL_ZIRCON, |
| }, |
| {"name": "paver-script", "path": "pave.sh", "type": "script",}, |
| { |
| "name": "uefi-disk", |
| "path": "obj/build/images/uefi_disk.img", |
| "type": "blk", |
| }, |
| ] |
| ) |
| |
| def mock_test_spec_manifest(self): |
| """Returns a mock manifest of test specs in a build.""" |
| return self.m.json.output( |
| [ |
| { |
| "test": { |
| "name": "foo_tests", |
| "label": "//public/lib/foo:foo_tests(//some/toolchain)", |
| "os": "linux", |
| "path": "path/on/disk/to/test", |
| } |
| }, |
| { |
| "test": { |
| "name": "bar_unittests", |
| "label": "//lib/bar:bar_unittests(//some/toolchain)", |
| "os": "fuchsia", |
| "path": "path/on/fuchsia/to/test", |
| } |
| }, |
| ] |
| ) |
| |
| def mock_tool_paths_manifest(self): |
| prebuilt_tools = [ |
| "bazel", |
| "cargo", |
| "clang-doc", |
| "clang-format-diff", |
| "clang-format", |
| "clang-tidy-diff", |
| "clang-tidy", |
| "dart", |
| "dartfmt", |
| "gn", |
| "go", |
| "gofmt", |
| "llvm-cov", |
| "llvm-profdata", |
| "llvm-symbolizer", |
| "ninja", |
| "rustc", |
| "rustdoc", |
| "rustfmt", |
| "yapf", |
| ] |
| built_zircon_tools = [ |
| "bootserver", |
| "fidl-format", |
| "fidl-lint", |
| "fvm", |
| "minfs", |
| "zbi", |
| ] |
| built_tools = [ |
| "affectedtests", |
| "artifactory", |
| "blobstats", |
| "bootserver_new", |
| "botanist", |
| "buildstats", |
| "check-licenses", |
| "cmc", |
| "covargs", |
| "debroot", |
| "doc-checker", |
| "formatjson5", |
| "ninjatrace", |
| "resultdb", |
| "seriallistener", |
| "size_checker", |
| "symbolize", |
| "tefmocheck", |
| "testrunner", |
| "testsharder", |
| "triage", |
| ] |
| |
| def tool_entry(tool_name, os, cpu, path): |
| return { |
| "cpu": cpu, |
| "label": "//tools/%s" % tool_name, |
| "name": tool_name, |
| "os": os, |
| "path": path, |
| } |
| |
| entries = [] |
| for os in ["linux", "mac"]: |
| for cpu in ["x64", "arm64"]: |
| for tool in prebuilt_tools: |
| entries.append( |
| tool_entry( |
| tool, |
| os, |
| cpu, |
| "../../prebuilt/third_party/%s/%s_%s/%s" |
| % (tool, os, cpu, tool), |
| ) |
| ) |
| for tool in built_zircon_tools: |
| entries.append( |
| tool_entry( |
| tool, |
| os, |
| cpu, |
| "../default.zircon/host-%s-%s/%s" % (os, cpu, tool), |
| ) |
| ) |
| for tool in built_tools: |
| entries.append( |
| tool_entry(tool, os, cpu, "%s_%s/%s" % (os, cpu, tool)) |
| ) |
| entries.append( |
| tool_entry("perfcompare", os, cpu, "../../examplepath/perfcompare") |
| ) |
| return self.m.json.output(entries) |
| |
| def mock_triage_sources_manifest(self): |
| """Returns a mock triage_sources.json file.""" |
| return self.m.json.output(["../../config.triage", "../../other/config.triage",]) |
| |
| def mock_zircon_instructions(self): |
| """Returns a mock zircon.json file.""" |
| return self.m.json.output( |
| { |
| "dir": "../default.zircon", |
| "targets": ["legacy-host_tests", "manifest-$cpu"], |
| } |
| ) |
| |
| def create_shards_step_data(self, shards): |
| """Returns mock step data for test shards. |
| |
| This should be used by any test which calls api.fuchsia.test*() and 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 mock_zbi_test(self, target, override=False, zircon=False): |
| ret = { |
| "cpu": target, |
| "name": "zbi-test-{}".format(target), |
| "type": "zbi", |
| "success_string": "purple monkey dishwasher", |
| "path": "zbi-test-{}.zbi".format(target), |
| "device_types": ["QEMU", "AEMU", "DEVICE_TYPE"], |
| "timeout": 60, |
| } |
| if zircon: |
| ret["path"] = "../default.zircon/" + ret["path"] |
| if override: # pragma: no cover |
| ret["qemu_kernel_label"] = ( |
| QEMU_KERNEL_OVERRIDE_LABEL_ZIRCON |
| if zircon |
| else QEMU_KERNEL_OVERRIDE_LABEL_FUCHSIA |
| ) |
| return ret |