aboutsummaryrefslogtreecommitdiff
path: root/test/BUILD
blob: ea34fd464654561acd0301ed9244a1dd843fc371 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")

platform(
    name = "windows",
    constraint_values = [
        "@platforms//os:windows",
    ],
)

TEST_COPTS = [
    "-pedantic",
    "-pedantic-errors",
    "-std=c++11",
    "-Wall",
    "-Wconversion",
    "-Wextra",
    "-Wshadow",
    #    "-Wshorten-64-to-32",
    "-Wfloat-equal",
    "-fstrict-aliasing",
]

# Some of the issues with DoNotOptimize only occur when optimization is enabled
PER_SRC_COPTS = {
    "donotoptimize_test.cc": ["-O3"],
}

TEST_ARGS = ["--benchmark_min_time=0.01s"]

PER_SRC_TEST_ARGS = {
    "user_counters_tabular_test.cc": ["--benchmark_counters_tabular=true"],
    "repetitions_test.cc": [" --benchmark_repetitions=3"],
    "spec_arg_test.cc": ["--benchmark_filter=BM_NotChosen"],
    "spec_arg_verbosity_test.cc": ["--v=42"],
}

cc_library(
    name = "output_test_helper",
    testonly = 1,
    srcs = ["output_test_helper.cc"],
    hdrs = ["output_test.h"],
    copts = select({
        "//:windows": [],
        "//conditions:default": TEST_COPTS,
    }),
    deps = [
        "//:benchmark",
        "//:benchmark_internal_headers",
    ],
)

# Tests that use gtest.  These rely on `gtest_main`.
[
    cc_test(
        name = test_src[:-len(".cc")],
        size = "small",
        srcs = [test_src],
        copts = select({
            "//:windows": [],
            "//conditions:default": TEST_COPTS,
        }) + PER_SRC_COPTS.get(test_src, []),
        deps = [
            "//:benchmark",
            "//:benchmark_internal_headers",
            "@com_google_googletest//:gtest",
            "@com_google_googletest//:gtest_main",
        ],
    )
    for test_src in glob(["*_gtest.cc"])
]

# Tests that do not use gtest.  These have their own `main` defined.
[
    cc_test(
        name = test_src[:-len(".cc")],
        size = "small",
        srcs = [test_src],
        args = TEST_ARGS + PER_SRC_TEST_ARGS.get(test_src, []),
        copts = select({
            "//:windows": [],
            "//conditions:default": TEST_COPTS,
        }) + PER_SRC_COPTS.get(test_src, []),
        deps = [
            ":output_test_helper",
            "//:benchmark",
            "//:benchmark_internal_headers",
        ],
        # FIXME: Add support for assembly tests to bazel.
        # See Issue #556
        # https://github.com/google/benchmark/issues/556
    )
    for test_src in glob(
        ["*_test.cc"],
        exclude = [
            "*_assembly_test.cc",
            "cxx03_test.cc",
            "link_main_test.cc",
        ],
    )
]

cc_test(
    name = "cxx03_test",
    size = "small",
    srcs = ["cxx03_test.cc"],
    copts = TEST_COPTS + ["-std=c++03"],
    target_compatible_with = select({
        "//:windows": ["@platforms//:incompatible"],
        "//conditions:default": [],
    }),
    deps = [
        ":output_test_helper",
        "//:benchmark",
        "//:benchmark_internal_headers",
    ],
)

cc_test(
    name = "link_main_test",
    size = "small",
    srcs = ["link_main_test.cc"],
    copts = select({
        "//:windows": [],
        "//conditions:default": TEST_COPTS,
    }),
    deps = ["//:benchmark_main"],
)