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 ## assert() are used a lot in tests upstream, which may be optimised out leading to 22 ## unused-variable warning. 23 "-Wno-unused-variable", 24 "-Werror=old-style-cast", 25] 26 27# Some of the issues with DoNotOptimize only occur when optimization is enabled 28PER_SRC_COPTS = { 29 "donotoptimize_test.cc": ["-O3"], 30} 31 32TEST_ARGS = ["--benchmark_min_time=0.01s"] 33 34PER_SRC_TEST_ARGS = { 35 "user_counters_tabular_test.cc": ["--benchmark_counters_tabular=true"], 36 "repetitions_test.cc": [" --benchmark_repetitions=3"], 37 "spec_arg_test.cc": ["--benchmark_filter=BM_NotChosen"], 38 "spec_arg_verbosity_test.cc": ["--v=42"], 39 "complexity_test.cc": ["--benchmark_min_time=1000000x"], 40} 41 42cc_library( 43 name = "output_test_helper", 44 testonly = 1, 45 srcs = ["output_test_helper.cc"], 46 hdrs = ["output_test.h"], 47 copts = select({ 48 "//:windows": [], 49 "//conditions:default": TEST_COPTS, 50 }), 51 deps = [ 52 "//:benchmark", 53 "//:benchmark_internal_headers", 54 ], 55) 56 57# Tests that use gtest. These rely on `gtest_main`. 58[ 59 cc_test( 60 name = test_src[:-len(".cc")], 61 size = "small", 62 srcs = [test_src], 63 copts = select({ 64 "//:windows": [], 65 "//conditions:default": TEST_COPTS, 66 }) + PER_SRC_COPTS.get(test_src, []), 67 deps = [ 68 "//:benchmark", 69 "//:benchmark_internal_headers", 70 "@com_google_googletest//:gtest", 71 "@com_google_googletest//:gtest_main", 72 ], 73 ) 74 for test_src in glob(["*_gtest.cc"]) 75] 76 77# Tests that do not use gtest. These have their own `main` defined. 78[ 79 cc_test( 80 name = test_src[:-len(".cc")], 81 size = "small", 82 srcs = [test_src], 83 args = TEST_ARGS + PER_SRC_TEST_ARGS.get(test_src, []), 84 copts = select({ 85 "//:windows": [], 86 "//conditions:default": TEST_COPTS, 87 }) + PER_SRC_COPTS.get(test_src, []), 88 deps = [ 89 ":output_test_helper", 90 "//:benchmark", 91 "//:benchmark_internal_headers", 92 ], 93 # FIXME: Add support for assembly tests to bazel. 94 # See Issue #556 95 # https://github.com/google/benchmark/issues/556 96 ) 97 for test_src in glob( 98 ["*_test.cc"], 99 exclude = [ 100 "*_assembly_test.cc", 101 "cxx03_test.cc", 102 "link_main_test.cc", 103 ], 104 ) 105] 106 107cc_test( 108 name = "cxx03_test", 109 size = "small", 110 srcs = ["cxx03_test.cc"], 111 copts = TEST_COPTS + ["-std=c++03"], 112 target_compatible_with = select({ 113 "//:windows": ["@platforms//:incompatible"], 114 "//conditions:default": [], 115 }), 116 deps = [ 117 ":output_test_helper", 118 "//:benchmark", 119 "//:benchmark_internal_headers", 120 ], 121) 122 123cc_test( 124 name = "link_main_test", 125 size = "small", 126 srcs = ["link_main_test.cc"], 127 copts = select({ 128 "//:windows": [], 129 "//conditions:default": TEST_COPTS, 130 }), 131 deps = ["//:benchmark_main"], 132) 133