• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
2
3platform(
4    name = "windows",
5    constraint_values = [
6        "@platforms//os:windows",
7    ],
8)
9
10TEST_COPTS = [
11    "-pedantic",
12    "-pedantic-errors",
13    "-std=c++11",
14    "-Wall",
15    "-Wconversion",
16    "-Wextra",
17    "-Wshadow",
18    #    "-Wshorten-64-to-32",
19    "-Wfloat-equal",
20    "-fstrict-aliasing",
21]
22
23# Some of the issues with DoNotOptimize only occur when optimization is enabled
24PER_SRC_COPTS = {
25    "donotoptimize_test.cc": ["-O3"],
26}
27
28TEST_ARGS = ["--benchmark_min_time=0.01s"]
29
30PER_SRC_TEST_ARGS = {
31    "user_counters_tabular_test.cc": ["--benchmark_counters_tabular=true"],
32    "repetitions_test.cc": [" --benchmark_repetitions=3"],
33    "spec_arg_test.cc": ["--benchmark_filter=BM_NotChosen"],
34    "spec_arg_verbosity_test.cc": ["--v=42"],
35}
36
37cc_library(
38    name = "output_test_helper",
39    testonly = 1,
40    srcs = ["output_test_helper.cc"],
41    hdrs = ["output_test.h"],
42    copts = select({
43        "//:windows": [],
44        "//conditions:default": TEST_COPTS,
45    }),
46    deps = [
47        "//:benchmark",
48        "//:benchmark_internal_headers",
49    ],
50)
51
52# Tests that use gtest.  These rely on `gtest_main`.
53[
54    cc_test(
55        name = test_src[:-len(".cc")],
56        size = "small",
57        srcs = [test_src],
58        copts = select({
59            "//:windows": [],
60            "//conditions:default": TEST_COPTS,
61        }) + PER_SRC_COPTS.get(test_src, []),
62        deps = [
63            "//:benchmark",
64            "//:benchmark_internal_headers",
65            "@com_google_googletest//:gtest",
66            "@com_google_googletest//:gtest_main",
67        ],
68    )
69    for test_src in glob(["*_gtest.cc"])
70]
71
72# Tests that do not use gtest.  These have their own `main` defined.
73[
74    cc_test(
75        name = test_src[:-len(".cc")],
76        size = "small",
77        srcs = [test_src],
78        args = TEST_ARGS + PER_SRC_TEST_ARGS.get(test_src, []),
79        copts = select({
80            "//:windows": [],
81            "//conditions:default": TEST_COPTS,
82        }) + PER_SRC_COPTS.get(test_src, []),
83        deps = [
84            ":output_test_helper",
85            "//:benchmark",
86            "//:benchmark_internal_headers",
87        ],
88        # FIXME: Add support for assembly tests to bazel.
89        # See Issue #556
90        # https://github.com/google/benchmark/issues/556
91    )
92    for test_src in glob(
93        ["*_test.cc"],
94        exclude = [
95            "*_assembly_test.cc",
96            "cxx03_test.cc",
97            "link_main_test.cc",
98        ],
99    )
100]
101
102cc_test(
103    name = "cxx03_test",
104    size = "small",
105    srcs = ["cxx03_test.cc"],
106    copts = TEST_COPTS + ["-std=c++03"],
107    target_compatible_with = select({
108        "//:windows": ["@platforms//:incompatible"],
109        "//conditions:default": [],
110    }),
111    deps = [
112        ":output_test_helper",
113        "//:benchmark",
114        "//:benchmark_internal_headers",
115    ],
116)
117
118cc_test(
119    name = "link_main_test",
120    size = "small",
121    srcs = ["link_main_test.cc"],
122    copts = select({
123        "//:windows": [],
124        "//conditions:default": TEST_COPTS,
125    }),
126    deps = ["//:benchmark_main"],
127)
128