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