xref: /aosp_15_r20/build/bazel/rules/sh_test.bzl (revision 7594170e27e0732bc44b93d1440d87a54b6ffe7c)
1*7594170eSAndroid Build Coastguard Worker# Copyright (C) 2023 The Android Open Source Project
2*7594170eSAndroid Build Coastguard Worker#
3*7594170eSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
4*7594170eSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
5*7594170eSAndroid Build Coastguard Worker# You may obtain a copy of the License at
6*7594170eSAndroid Build Coastguard Worker#
7*7594170eSAndroid Build Coastguard Worker#      http://www.apache.org/licenses/LICENSE-2.0
8*7594170eSAndroid Build Coastguard Worker#
9*7594170eSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
10*7594170eSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
11*7594170eSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*7594170eSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
13*7594170eSAndroid Build Coastguard Worker# limitations under the License.
14*7594170eSAndroid Build Coastguard Worker
15*7594170eSAndroid Build Coastguard Worker"""sh_test macro for building shell tests with Bazel."""
16*7594170eSAndroid Build Coastguard Worker
17*7594170eSAndroid Build Coastguard Workerload(
18*7594170eSAndroid Build Coastguard Worker    "//build/bazel/rules/tradefed:tradefed.bzl",
19*7594170eSAndroid Build Coastguard Worker    "LANGUAGE_SHELL",
20*7594170eSAndroid Build Coastguard Worker    "TEST_DEP_SUFFIX",
21*7594170eSAndroid Build Coastguard Worker    "tradefed_test_suite",
22*7594170eSAndroid Build Coastguard Worker)
23*7594170eSAndroid Build Coastguard Worker
24*7594170eSAndroid Build Coastguard Workerdef sh_test(
25*7594170eSAndroid Build Coastguard Worker        name,
26*7594170eSAndroid Build Coastguard Worker        srcs,
27*7594170eSAndroid Build Coastguard Worker        data = [],
28*7594170eSAndroid Build Coastguard Worker        data_bins = [],
29*7594170eSAndroid Build Coastguard Worker        tags = [],
30*7594170eSAndroid Build Coastguard Worker        test_config = None,
31*7594170eSAndroid Build Coastguard Worker        template_test_config = None,
32*7594170eSAndroid Build Coastguard Worker        template_install_base = None,
33*7594170eSAndroid Build Coastguard Worker        template_configs = [],
34*7594170eSAndroid Build Coastguard Worker        visibility = None,
35*7594170eSAndroid Build Coastguard Worker        runs_on = [],
36*7594170eSAndroid Build Coastguard Worker        suffix = "",
37*7594170eSAndroid Build Coastguard Worker        **kwargs):
38*7594170eSAndroid Build Coastguard Worker    "Bazel macro to correspond with the sh_test Soong module."
39*7594170eSAndroid Build Coastguard Worker
40*7594170eSAndroid Build Coastguard Worker    test_dep_name = name + TEST_DEP_SUFFIX
41*7594170eSAndroid Build Coastguard Worker    native.sh_test(
42*7594170eSAndroid Build Coastguard Worker        name = test_dep_name,
43*7594170eSAndroid Build Coastguard Worker        srcs = srcs,
44*7594170eSAndroid Build Coastguard Worker        data = data,
45*7594170eSAndroid Build Coastguard Worker        tags = tags + ["manual"],
46*7594170eSAndroid Build Coastguard Worker        **kwargs
47*7594170eSAndroid Build Coastguard Worker    )
48*7594170eSAndroid Build Coastguard Worker
49*7594170eSAndroid Build Coastguard Worker    tradefed_test_suite(
50*7594170eSAndroid Build Coastguard Worker        name = name,
51*7594170eSAndroid Build Coastguard Worker        test_dep = test_dep_name,
52*7594170eSAndroid Build Coastguard Worker        # TODO(b/296964806): Handle auto_generate_test_config in tradefed Bazel rules.
53*7594170eSAndroid Build Coastguard Worker        data_bins = data_bins,
54*7594170eSAndroid Build Coastguard Worker        test_config = test_config,
55*7594170eSAndroid Build Coastguard Worker        template_configs = template_configs,
56*7594170eSAndroid Build Coastguard Worker        template_test_config = template_test_config,
57*7594170eSAndroid Build Coastguard Worker        template_install_base = template_install_base,
58*7594170eSAndroid Build Coastguard Worker        deviceless_test_config = "//build/make/core:shell_test_config_template.xml",
59*7594170eSAndroid Build Coastguard Worker        device_driven_test_config = "//build/make/core:shell_test_config_template.xml",
60*7594170eSAndroid Build Coastguard Worker        host_driven_device_test_config = "//build/make/core:shell_test_config_template.xml",
61*7594170eSAndroid Build Coastguard Worker        runs_on = runs_on,
62*7594170eSAndroid Build Coastguard Worker        tags = tags,
63*7594170eSAndroid Build Coastguard Worker        suffix = suffix,
64*7594170eSAndroid Build Coastguard Worker        test_language = LANGUAGE_SHELL,
65*7594170eSAndroid Build Coastguard Worker        visibility = visibility,
66*7594170eSAndroid Build Coastguard Worker    )
67