xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/build/test.bzl (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1"""Tools for building QUICHE tests."""
2
3load("@bazel_skylib//lib:dicts.bzl", "dicts")
4load("@bazel_skylib//lib:paths.bzl", "paths")
5
6def test_suite_from_source_list(name, srcs, **kwargs):
7    """
8    Generates a test target for every individual test source file specified.
9
10    Args:
11        name: the name of the resulting test_suite target.
12        srcs: the list of source files from which the test targets are generated.
13        **kwargs: other arguments that are passed to the cc_test rule directly.s
14    """
15
16    tests = []
17    for sourcefile in srcs:
18        if not sourcefile.endswith("_test.cc"):
19            fail("All source files passed to test_suite_from_source_list() must end with _test.cc")
20        test_name, _ = paths.split_extension(paths.basename(sourcefile))
21        extra_kwargs = {}
22        if test_name == "end_to_end_test":
23            extra_kwargs["shard_count"] = 16
24        native.cc_test(
25            name = test_name,
26            srcs = [sourcefile],
27            **dicts.add(kwargs, extra_kwargs)
28        )
29        tests.append(test_name)
30    native.test_suite(name = name, tests = tests)
31