blob: 6cf86ba0770e3d7a8f84283506bc1ca1b9640fa9 [file] [log] [blame]
# Copyright 2020 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/rust/rustc_test.gni")
import("//build/testing/host_test_data.gni")
import("//build/testing/test_spec.gni")
# Defines a host-side test for a triage configuration
#
# Packages a set of triage configuration files into a single test which
# runs all of the tests in the `test` section of the configuration file.
# This test will pass if all of the tests pass and fail if any of them fail.
#
# Parameters
#
# sources (required)
# The list of configuration files. These sources must be within source_dir.
#
# source_dir (optional)
# Directory containing the test sources.
# Defaults to "config".
#
# Example of usage:
#
# triage_config_test("some_test") {
# sources = [
# "bar.triage",
# "foo.triage",
# ]
# }
#
# Example of running:
#
# fx test some_test
#
template("triage_config_test") {
assert(defined(invoker.sources),
"triage_config_test() requires 'sources' be defined")
if (defined(invoker.source_dir)) {
config_source_dir = invoker.source_dir
} else {
config_source_dir = "config"
}
config_target_name = target_name + "_configs"
host_test_data(config_target_name) {
sources = []
foreach(config, invoker.sources) {
sources += [ "${config_source_dir}/${config}" ]
}
outputs =
[ "$target_gen_dir/runtime_deps/${target_name}/{{source_file_part}}" ]
}
runner_target_name = target_name + "_runner"
host_test_data(runner_target_name) {
sources = [ "${root_out_dir}/triage_config_test_runner" ]
deps = [ "//src/diagnostics/triage/build/triage_config_test_runner" ]
}
test_spec_target = target_name + "_spec"
# This is a dummy file that is generated as an output of this target,
# and only used to define the `path` in the test_spec. This is needed
# to ensure the test builds in CQ, which uses `path` as a Ninja target.
test_spec_file = "${target_name}.triage_config_test"
test_path = "${root_out_dir}/${test_spec_file}"
# Create a test spec to run this test
test_spec(test_spec_target) {
name = invoker.target_name
target = invoker.target_name
# This path needs to be passed like this because the test_spec
# will rebase the path against the root_build_dir and pass it
# along as a target to ninja.
path = test_path
config_files = get_target_outputs(":${config_target_name}")
command = [ rebase_path("${root_out_dir}/triage_config_test_runner",
root_build_dir) ]
foreach(file, config_files) {
command += [
"--config",
rebase_path(file, root_build_dir),
]
}
deps = [
":${config_target_name}",
":${runner_target_name}",
]
}
generated_file(test_spec_file) {
testonly = true
outputs = [ "${target_out_dir}/${test_spec_file}" ]
data_keys = [ "tests" ]
deps = [ ":$test_spec_target" ]
}
copy("${target_name}_copy_test_spec") {
testonly = true
sources = [ "${target_out_dir}/${test_spec_file}" ]
outputs = [ test_path ]
deps = [ ":${test_spec_file}" ]
}
group(target_name) {
testonly = true
deps = [ ":${target_name}_copy_test_spec($host_toolchain)" ]
}
}