| # 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/testing/host_test.gni") | |
| import("//tools/devshell/test_runner/host_script_test_data_impl.gni") | |
| # Templates for defining host tests that are based which require | |
| # many runtime files. | |
| # | |
| # The two top level templates are: | |
| # | |
| # host_script_test_data | |
| # host_script_test | |
| # Define a data set for a host test. | |
| # | |
| # This rule is used to define a collection of files | |
| # that are copied to the output directory as runtime | |
| # test dependencies. The files can be sourced from anywhere | |
| # in the source tree, and are copied into the relative path | |
| # defined by `base_dir`. | |
| # | |
| # The copied files are also tagged with "test_runtime_deps" metadata. | |
| # | |
| # Parameters | |
| # | |
| # data_path: | |
| # the name of the relative subdirectory that is the destination | |
| # location of the files. | |
| # | |
| # data_deps | |
| # Optional: runtime dependencies for this rule. | |
| # | |
| # datasets: array of scopes | |
| # List of files to copy to the base_dir. Each scope defines 1 source directory. If files from | |
| # multiple directories are needed, then a scope should be defined for each one. | |
| # Each scope defines: | |
| # * source_base_dir - this is the source directory which contains all the files to copy. This | |
| # must be the dirname of the files listed. | |
| # * target_base_dir - this is the base_dir relative path of the files. A common best practice | |
| # is to make this mirror the source code layout. For example, if you are | |
| # needing files in //tools/devshell/tests/lib, then the target_base_dir should be | |
| # `tools/devshell/tests/lib`. This makes the relative position of files the same | |
| # as in the source tree. | |
| # * files - The list of source files to copy from soure_base_dir. | |
| # | |
| template("host_script_test_data") { | |
| forward_variables_from(invoker, | |
| [ | |
| "data_path", | |
| "datasets", | |
| "testonly", | |
| "data_deps", | |
| "visibility", | |
| ]) | |
| assert(defined(data_path) && data_path != "", "data_path is required.") | |
| dep_target_list = [] | |
| set_count = 0 | |
| foreach(set, datasets) { | |
| assert(defined(set.source_base_dir), | |
| "Error: source_base_dir not found for dataset entry $set") | |
| assert(defined(set.target_base_dir), | |
| "Error: target_base_dir not found for dataset entry $set") | |
| assert(defined(set.files), "Error: files not found for dataset entry $set") | |
| host_script_test_data_impl_data_set_copy("dataset_set$set_count") { | |
| data_path = invoker.data_path | |
| data = set | |
| } | |
| dep_target_list += [ ":dataset_set$set_count" ] | |
| set_count = set_count + 1 | |
| } | |
| group(target_name) { | |
| forward_variables_from(invoker, | |
| [ | |
| "testonly", | |
| "visibility", | |
| "public_deps", | |
| ]) | |
| if (!defined(data_deps)) { | |
| data_deps = dep_target_list | |
| } else { | |
| data_deps += dep_target_list | |
| } | |
| } | |
| } | |
| # Template for defining a host test which runs a testscript or a list of test | |
| # scripts. | |
| # | |
| # Parameters | |
| # test_script | |
| # Optional (mutually exclusive with test_script_list): this is the root relative path of the | |
| # test script to execute. The path cannot be absolute since the paths are not consistent from | |
| # desktop builds, and the CQ test environment. | |
| # test_script_list | |
| # Optional (mutually exclusive with test_script): root relative path to a newline-separated | |
| # list of test scripts to run in parallel using test_script_runner. | |
| # test_script_runner | |
| # Required when test_script_list is set: root relative path to the runner executable invoked | |
| # for each entry in test_script_list. | |
| # test_root | |
| # Optional: this is the root relative path to use as the CWD when running the test script. | |
| # This must be a part of the path of test_script (or test_script_runner / test_script_list). | |
| # | |
| # Standard GN parameters: data_deps | |
| template("host_script_test") { | |
| assert(defined(invoker.test_script) || defined(invoker.test_script_list), | |
| "Either test_script or test_script_list is required.") | |
| assert(!(defined(invoker.test_script) && defined(invoker.test_script_list)), | |
| "test_script and test_script_list are mutually exclusive.") | |
| if (defined(invoker.test_script)) { | |
| assert(invoker.test_script != "", "test_script must not be empty.") | |
| assert(!defined(invoker.test_script_runner), | |
| "test_script_runner cannot be set without test_script_list.") | |
| } | |
| if (defined(invoker.test_script_list)) { | |
| assert(invoker.test_script_list != "", | |
| "test_script_list must not be empty.") | |
| assert( | |
| defined(invoker.test_script_runner) && invoker.test_script_runner != "", | |
| "test_script_runner must be set and non-empty when test_script_list is set.") | |
| } | |
| # Only build this for host targets | |
| if (!is_linux) { | |
| not_needed(invoker, "*") | |
| group(target_name) { | |
| } | |
| } else { | |
| host_test(target_name) { | |
| forward_variables_from(invoker, | |
| [ | |
| "data_deps", | |
| "deps", | |
| "environments", | |
| "test_root", | |
| "test_script", | |
| "test_script_list", | |
| "test_script_runner", | |
| "visibility", | |
| ]) | |
| binary_path = "${root_out_dir}/host_runner" | |
| if (defined(test_script_list)) { | |
| args = [ | |
| "-runner=${test_script_runner}", | |
| "-scriptlist=${test_script_list}", | |
| ] | |
| } else { | |
| args = [ "-testscript=${test_script}" ] | |
| } | |
| if (defined(test_root)) { | |
| args += [ "--testroot=${test_root}" ] | |
| } | |
| if (!defined(deps)) { | |
| deps = [] | |
| } | |
| deps += [ "//tools/devshell/test_runner:host_runner" ] | |
| } | |
| } | |
| } |