xref: /aosp_15_r20/external/pigweed/pw_build/hil.gni (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2021 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15import("//build_overrides/pigweed.gni")
16
17import("$dir_pw_build/python.gni")
18
19# A hardware-in-the-loop (HIL) test.
20#
21# Use this template to declare an executable that implements a test requiring
22# exclusive access to a hardware device. The template ensures that all such
23# tests are executed serially.
24
25# The arguments to pass to this template largely depend on the specified
26# target_type . The only currently supported  target_type  is "python", which
27# causes this template to behave simlarly to a  pw_python_script . Aside from
28# the arguments explicitly listed below, refer to the  pw_python_script
29# template for information on what arguments are required or available.
30#
31# Args:
32#   action_args: Forwarded to the action.
33#   action_deps: Forwarded to the action.
34#   action_outputs: Forwarded to the action.
35#   target_type: The type of underlying target that implements the HIL
36#     test. Currently "python" is the only supported value, producing a
37#     "py_python_script". Support for other languages will be added in the
38#     future.
39template("pw_hil_test") {
40  assert(!defined(invoker.action), "Can't specify an action for a pw_hil_test")
41  assert(defined(invoker.target_type),
42         "pw_hil_test must specify the 'target_type'")
43  _args = []
44  if (defined(invoker.action_args)) {
45    _args += invoker.action_args
46  }
47  _outputs = []
48  if (defined(invoker.action_outputs)) {
49    _outputs += invoker.action_outputs
50  }
51  _deps = []
52  if (defined(invoker.action_deps)) {
53    _deps += invoker.action_deps
54  }
55
56  if (invoker.target_type == "python") {
57    pw_python_script(target_name) {
58      action = {
59        args = _args
60        pool = "$dir_pw_build/pool:pw_hil_test($default_toolchain)"
61        stamp = true
62        outputs = _outputs
63        deps = _deps
64
65        # We want the test stdout to be saved.
66        capture_output = false
67      }
68      forward_variables_from(invoker,
69                             "*",
70                             [
71                               "target_type",
72                               "action_args",
73                             ])
74    }
75  }
76}
77