创建测试大区

如果您或您的团队拥有非封闭测试或 需要自定义运行程序,您需要创建一个测试领域来执行这些测试。

以下是一个示例测试领域

// Copyright 2023 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.

// This realm installs various testing collections.
{
    include: [
        // Required: Include various test collections/realms.
        "//sdk/ctf/test_realm/meta/test-collection.shard.cml",
        "//src/devices/testing/devices_test_realm.shard.cml",
        "//src/lib/vulkan/vulkan_test_realm.shard.cml",
        "//src/media/testing/drm_test_realm.shard.cml",
        "//src/sys/component_manager/tests/capability_provider_vfs_compliance/vfs_compliance_test_realm.shard.cml",
        "//src/sys/testing/meta/chromium_test_realm.shard.cml",

        // Optional: Include optional runners.
        "//src/sys/testing/meta/runners/fuzz-test-runner.shard.cml",
        "//src/sys/testing/meta/runners/inspect-test-runner.shard.cml",
        "//src/sys/testing/meta/runners/netemul-test-runner.shard.cml",
        "//src/sys/testing/meta/runners/standard-test-runners.shard.cml",
        "//src/sys/testing/meta/runners/starnix-test-runner.shard.cml",
        "//src/sys/testing/meta/runners/stress-test-runner.shard.cml",

        // Required: Include various test collections/realms.
        "//src/sys/testing/meta/starnix-tests.shard.cml",
        "//src/sys/testing/meta/system-tests.shard.cml",
        "//src/sys/testing/meta/test-arch-tests.shard.cml",
        "//src/testing/system-validation/meta/system_validation_test_realm.shard.cml",

        // Required: Include other required shards.
        "sys/component/realm_builder.shard.cml",
        "syslog/client.shard.cml",
    ],
    expose: [
        // Required: Expose Realm protocol so that test manager can launch tests
        // in the realm.
        {
            protocol: "fuchsia.component.Realm",
            from: "framework",
        },
    ],

    // TODO(https://fxbug.dev/42063673): Move to corresponding runner and collection
    // files.
    environments: [
        {
            name: "test-env",
            extends: "realm",
            runners: [
                {
                    runner: "elf_test_runner",
                    from: "#elf_test_runner",
                },
                {
                    runner: "elf_test_ambient_exec_runner",
                    from: "#elf_test_ambient_exec_runner",
                },
                {
                    runner: "elf_test_create_raw_processes_runner",
                    from: "#elf_test_create_raw_processes_runner",
                },
                {
                    runner: "elf_test_create_raw_processes_ambient_exec_runner",
                    from: "#elf_test_create_raw_processes_ambient_exec_runner",
                },
                {
                    runner: "gtest_runner",
                    from: "#gtest_runner",
                },
                {
                    runner: "gunit_runner",
                    from: "#gunit_runner",
                },
                {
                    runner: "netemul_test_runner",
                    from: "#netemul_test_runner",
                },
                {
                    runner: "rust_test_runner",
                    from: "#rust_test_runner",
                },
                {
                    runner: "rust_test_create_raw_processes_runner",
                    from: "#rust_test_create_raw_processes_runner",
                },
                {
                    runner: "rust_test_next_vdso_runner",
                    from: "#rust_test_next_vdso_runner",
                },
                {
                    runner: "starnix_test_runner",
                    from: "#starnix_test_runners",
                },
                {
                    runner: "starnix_unit_test_runner",
                    from: "#starnix_test_runners",
                },
                {
                    runner: "inspect_test_runner",
                    from: "#inspect_test_runner",
                },
                {
                    runner: "go_test_runner",
                    from: "#go_test_runner",
                },
                {
                    runner: "stress_test_runner",
                    from: "#stress_test_runner",
                },
                {
                    runner: "realm_builder",
                    from: "#realm_builder_server",
                },
            ],
            resolvers: [
                {
                    resolver: "realm_builder_resolver",
                    from: "#realm_builder_server",
                    scheme: "realm-builder",
                },
            ],
            __stop_timeout_ms: 30000,
        },
    ],
}

指向文件的链接

必需部分

测试领域清单必须包含特定部分, 测试组件的执行。

测试集合

每个测试领域都必须有一个或多个测试集合,Test Manager 可在其中执行测试。在提供的示例测试领域中,我们使用了测试 创建集合您可以参阅系统测试 collection)作为示例,此类 API 可以运行各种非封闭 测试。

公开部分

每个测试领域都必须公开协议 fuchsia.component.Realm。此协议 为测试管理器提供了在域内启动组件的功能。

大区构建器

每个测试领域都必须包含 realm 构建器分片 这有助于测试管理器在集合内动态执行测试。

可选部分

测试运行者

虽然标准测试是可选的,但建议大多数测试领域都加入 运行程序,用于在领域内执行基本测试。在什么情况下 如果需要自定义测试运行程序,则可以在 测试集合的环境

与树内构建规则集成

在我们的构建规则中注册您的名称:

_type_moniker_map = {
  system = "/core/testing:system-tests"
  test_arch = "/core/testing:test-arch-tests"
  ...
  <new_type> = "/path/to/test/realm/moniker"
}

将新的 test_type 分配给测试:

// BUILD.gn
fuchsia_test_component("my_test") {
  component_name = "my_test"
  manifest = "meta/my_test.cml"
  deps = [ ":my_test_bin" ]
  test_type = "<new_type>"
}

现在,您可以使用 fx test 运行测试。

树外测试

集成测试脚本,以使用 Realm 名称调用 ffx test

ffx test run --realm "/path/to/test/realm/moniker" <test_url>