blob: 56f157d6811189a3c65ed13723da0143b791e53e [file] [log] [blame]
# Copyright 2022 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.
import("//build/testing/host_test.gni")
# Defines a host test based on the contents of a test manifest.
#
# The test manifest should contain a JSON list of objects. Each object's schema is:
#
# test_name (required)
# The name of the host tool test.
# Type: string
#
# binary_path (required)
# The relative path to the binary in the CTS release from the root of the archive.
# e.g. host_x64/${tool} for //prebuilt/cts/canary/linux-x64/cts/host_x64/${tool}
# Type: string
#
# args (required)
# The command line arguments to pass to the tool.
# Type: list(strings)
#
# Parameters
#
# archive_dir (required)
# Path to directory containing host tools and host_test_manifest.json
# Type: string
#
# disabled_tests (optional)
# List of test names to disable.
# Type: list(strings)
#
# manifest_name (optional)
# The name of the manifest file. Defaults to "host_test_manifest.json"
# Type: string
template("prebuilt_host_test_manifest") {
assert(defined(invoker.archive_dir), "archive_dir must be defined")
assert(
is_host,
"prebuilt_host_test_manifest should only be used on the host. To fix this, wrap your target with `if (is_host) { ... }`")
manifest_name = "host_test_manifest.json"
if (defined(invoker.manifest_name)) {
manifest_name = invoker.manifest_name
}
manifest_path = "${invoker.archive_dir}/${manifest_name}"
manifest = read_file(manifest_path, "json")
test_targets = []
foreach(test, manifest) {
host_test_name = test.test_name
test_disabled = false
if (defined(invoker.disabled_tests)) {
foreach(disabled_test, invoker.disabled_tests) {
if (host_test_name == test.test_name) {
test_disabled = true
}
}
}
if (!test_disabled) {
host_test(host_test_name) {
forward_variables_from(invoker, "*")
binary_path = invoker.archive_dir + "/" + test.binary_path
args = test.args
# host_test assumes deps is defined.
if (!defined(deps)) {
deps = []
}
}
test_targets += [ ":${host_test_name}" ]
}
}
group(target_name) {
testonly = true
deps = test_targets
}
}