blob: 84ce01061885bef213390a747234352d1afd48be [file] [log] [blame]
# 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.
import("//build/host.gni")
import("//build/python/python_binary.gni")
import("//build/python/python_host_test.gni")
assert(is_host)
binary_sources = [
"command.py",
"command_runner.py",
"execution_params.py",
"params.py",
]
binary_deps = []
python_binary("host_test_component_runner") {
testonly = true
main_source = "main.py"
sources = binary_sources + [ "main.py" ]
deps = binary_deps
}
main_module_tests = [
"params",
"execution_params",
"command",
"command_runner",
]
test_targets = []
test_dir = "$root_out_dir/test_data/host_test_component_runner"
test_data_dir = "$test_dir/test_data"
executable("exit") {
testonly = true
sources = [ "tests/exit.cc" ]
output_dir = test_data_dir
}
executable("output_mock") {
testonly = true
sources = [ "tests/output_mock.cc" ]
output_dir = test_data_dir
}
host_test_data("test_data") {
generated_executable_deps = [
":exit",
":output_mock",
]
sources = []
foreach(dep, generated_executable_deps) {
# get_target_outputs does not work on "executables", so need to use this
# hack.
sources += [ "$test_data_dir/" + get_label_info(dep, "name") ]
}
deps = generated_executable_deps
}
foreach(test_name, main_module_tests) {
target = "host_test_component_runner.${test_name}_test"
main_source = "tests/${test_name}_test.py"
python_host_test(target) {
main_source = main_source
main_callable = "unittest.main"
extra_args = [ "-v" ]
test_dir = "$test_dir"
sources = binary_sources
libraries = binary_deps
deps = [ ":test_data" ]
}
test_targets += [ ":${target}" ]
}
group("tests") {
testonly = true
deps = test_targets
}
# Copy the resulting .pyz for the host tool
copy("copy") {
testonly = true
deps = [ ":host_test_component_runner" ]
sources = [ "${target_out_dir}/host_test_component_runner.pyz" ]
outputs = [ "${root_out_dir}/host_test_component_runner.pyz" ]
}
# create a wrapper script to run python archive using prebuilt python.
action("host_test_component_script") {
testonly = true
script = "//build/testing/create_test.sh"
_script_file = "${root_out_dir}/host_test_component"
args = [
rebase_path(_script_file, root_build_dir),
rebase_path(python_exe_src, root_build_dir),
rebase_path("${root_out_dir}/host_test_component_runner.pyz",
root_build_dir),
]
outputs = [ _script_file ]
visibility = [ ":*" ]
}
group("host_test_component") {
testonly = true
deps = [
":copy",
":host_test_component_script",
]
}
host_test_data("test_deps") {
testonly = true
deps = [
":copy",
":host_test_component_script",
]
sources = [
"${root_out_dir}/host_test_component",
"${root_out_dir}/host_test_component_runner.pyz",
]
}