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