xref: /aosp_15_r20/external/grpc-grpc/tools/bazelify_tests/test/portability_tests.bzl (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1# Copyright 2023 The gRPC Authors
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"""
16Generates portability tests.
17"""
18
19load("//tools/bazelify_tests:build_defs.bzl", "grpc_run_tests_harness_test")
20
21def _safe_language_name(name):
22    """Character '+' isn't allowed in bazel target name"""
23    return name.replace("+", "p")
24
25def generate_run_tests_portability_tests(name):
26    """Generates run_tests_py portability test targets.
27
28    Args:
29        name: Name of the test suite that will be generated.
30    """
31    test_names = []
32
33    # portability C x86
34    grpc_run_tests_harness_test(
35        name = "runtests_c_linux_dbg_x86_build_only",
36        args = ["-l c -c dbg --build_only"],
37        docker_image_version = "tools/dockerfile/test/cxx_debian11_x86.current_version",
38        size = "enormous",
39    )
40    test_names.append("runtests_c_linux_dbg_x86_build_only")
41
42    # C and C++ with no-exceptions on Linux
43    for language in ["c", "c++"]:
44        test_name = "runtests_%s_linux_dbg_noexcept_build_only" % _safe_language_name(language)
45        grpc_run_tests_harness_test(
46            name = test_name,
47            args = ["-l %s --config noexcept --build_only" % language],
48            docker_image_version = "tools/dockerfile/test/cxx_debian11_x64.current_version",
49            size = "enormous",
50        )
51        test_names.append(test_name)
52
53    # C and C++ under different compilers
54    for language in ["c", "c++"]:
55        compiler_configs = [
56            ["gcc_7", "", "tools/dockerfile/test/cxx_gcc_8_x64.current_version"],
57            ["gcc_12", "--cmake_configure_extra_args=-DCMAKE_CXX_STANDARD=20", "tools/dockerfile/test/cxx_gcc_12_x64.current_version"],
58            ["gcc10.2_openssl102", "--cmake_configure_extra_args=-DgRPC_SSL_PROVIDER=package", "tools/dockerfile/test/cxx_debian11_openssl102_x64.current_version"],
59            ["gcc10.2_openssl111", "--cmake_configure_extra_args=-DgRPC_SSL_PROVIDER=package", "tools/dockerfile/test/cxx_debian11_openssl111_x64.current_version"],
60            ["gcc_12_openssl309", "--cmake_configure_extra_args=-DgRPC_SSL_PROVIDER=package", "tools/dockerfile/test/cxx_debian12_openssl309_x64.current_version"],
61            ["gcc_musl", "", "tools/dockerfile/test/cxx_alpine_x64.current_version"],
62            ["clang_6", "--cmake_configure_extra_args=-DCMAKE_C_COMPILER=clang --cmake_configure_extra_args=-DCMAKE_CXX_COMPILER=clang++", "tools/dockerfile/test/cxx_clang_6_x64.current_version"],
63            ["clang_17", "--cmake_configure_extra_args=-DCMAKE_C_COMPILER=clang --cmake_configure_extra_args=-DCMAKE_CXX_COMPILER=clang++", "tools/dockerfile/test/cxx_clang_17_x64.current_version"],
64        ]
65
66        for compiler_name, args, docker_image_version in compiler_configs:
67            test_name = "runtests_%s_linux_dbg_%s_build_only" % (_safe_language_name(language), compiler_name)
68            grpc_run_tests_harness_test(
69                name = test_name,
70                args = ["-l %s -c dbg %s --build_only" % (language, args)],
71                docker_image_version = docker_image_version,
72                size = "enormous",
73            )
74            test_names.append(test_name)
75
76    # Python on alpine
77    grpc_run_tests_harness_test(
78        name = "runtests_python_linux_dbg_alpine",
79        args = [
80            "-l python -c dbg --compiler python_alpine",
81        ],
82        docker_image_version = "tools/dockerfile/test/python_alpine_x64.current_version",
83        size = "enormous",
84    )
85    test_names.append("runtests_python_linux_dbg_alpine")
86
87    # Generate test suite that allows easily running all portability tests.
88    native.test_suite(
89        name = name,
90        tests = [(":%s" % test_name) for test_name in test_names],
91    )
92