blob: 23d7e3d942ab4e97dcab0c7a5bc246c36827c319 [file] [log] [blame]
import("//build/python/python_binary.gni")
import("//build/rust/rustc_binary.gni")
import("//build/testing/host_test.gni")
import("//build/testing/host_test_data.gni")
# Declares a host-side antlion test.
#
# Examples
#
# ```
# antlion_host_test("sl4f_sanity_test") {
# main_source = "Sl4fSanityTest.py"
# }
#
# antlion_host_test("wlan_rvr_test_2g") {
# main_source = "WlanRvrTest.py"
# test_params = "rvr_settings.yaml"
# test_cases = [ "test_rvr_11n_2g_*" ]
# }
# ```
#
# Parameters
#
# main_source
# The .py file defining the antlion test.
# Type: path
#
# sources (optional)
# Other files that are used in the test.
# Type: list(path)
# Default: empty list
#
# test_params (optional)
# Path to a YAML file with additional test parameters. This will be provided
# to the test in the antlion config under the "test_params" key.
# Type: string
#
# test_cases (optional)
# List of test cases to run. Defaults to running all test cases.
# Type: list(string)
#
# deps
# environments
# visibility
template("antlion_host_test") {
assert(defined(invoker.main_source), "main_source is required")
#
# Define antlion test python_binary().
#
_python_binary_name = "${target_name}.pyz"
_python_binary_target = "${target_name}_python_binary"
python_binary(_python_binary_target) {
forward_variables_from(invoker,
[
"main_source",
"sources",
])
output_name = _python_binary_name
main_callable = "test_runner.main" # Mobly-specific entry point.
deps = [ "//third_party/antlion" ]
testonly = true
visibility = [ ":*" ]
}
_test_dir = "${root_out_dir}/test_data/" + get_label_info(target_name, "dir")
#
# Define antlion test host_test_data().
#
_host_test_data_target = "${target_name}_test_data"
host_test_data(_host_test_data_target) {
testonly = true
visibility = [ ":*" ]
sources = [ get_label_info(":${_python_binary_target}", "target_out_dir") +
"/${_python_binary_name}" ]
outputs = [ "${_test_dir}/${_python_binary_name}" ]
deps = [ ":${_python_binary_target}" ]
if (defined(invoker.deps)) {
deps += invoker.deps
}
}
#
# Define SSH binary host_test_data().
#
_host_test_data_ssh = "${target_name}_test_data_ssh"
host_test_data(_host_test_data_ssh) {
testonly = true
visibility = [ ":*" ]
sources = [ "//prebuilt/third_party/openssh-portable/${host_os}-${host_cpu}/bin/ssh" ]
outputs = [ "${_test_dir}/ssh" ]
}
#
# Define Mobly test params YAML host_test_data().
#
if (defined(invoker.test_params)) {
_host_test_data_test_params = "${target_name}_test_data_test_params"
host_test_data(_host_test_data_test_params) {
testonly = true
visibility = [ ":*" ]
sources = [ invoker.test_params ]
outputs = [ "${_test_dir}/${invoker.test_params}" ]
}
}
#
# Define FFX binary host_test_data().
#
_host_test_data_ffx = "${target_name}_test_data_ffx"
host_test_data(_host_test_data_ffx) {
testonly = true
visibility = [ ":*" ]
sources = [ get_label_info("//src/developer/ffx", "root_out_dir") + "/ffx" ]
outputs = [ "${_test_dir}/ffx" ]
deps = [ "//src/developer/ffx:ffx_bin($host_toolchain)" ]
}
#
# Define the antlion host_test() using antlion-runner.
#
host_test(target_name) {
forward_variables_from(invoker,
[
"environments",
"visibility",
])
binary_path = "${root_out_dir}/antlion-runner"
args = [
"--python-bin",
rebase_path(python_exe_src, root_build_dir),
"--antlion-pyz",
rebase_path("${_test_dir}/${_python_binary_name}", root_build_dir),
"--out-dir",
rebase_path("${_test_dir}", root_build_dir),
"--ffx-binary",
rebase_path("${_test_dir}/ffx", root_build_dir),
"--ssh-binary",
rebase_path("${_test_dir}/ssh", root_build_dir),
]
if (defined(invoker.test_cases)) {
args += invoker.test_cases
}
deps = [
":${_host_test_data_ffx}",
":${_host_test_data_ssh}",
":${_host_test_data_target}",
"//build/python:interpreter",
"//third_party/antlion/runner",
]
if (defined(invoker.test_params)) {
args += [
"--test-params",
rebase_path("${_test_dir}/${invoker.test_params}", root_build_dir),
]
deps += [ ":${_host_test_data_test_params}" ]
}
}
}