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[ 53 cc_test( 54 name = test_src[:-len(".cc")], 55 size = "small", 56 srcs = [test_src], 57 args = TEST_ARGS + PER_SRC_TEST_ARGS.get(test_src, []), 58 copts = select({ 59 "//:windows": [], 60 "//conditions:default": TEST_COPTS, 61 }) + PER_SRC_COPTS.get(test_src, []), 62 deps = [ 63 ":output_test_helper", 64 "//:benchmark", 65 "//:benchmark_internal_headers", 66 "@com_google_googletest//:gtest", 67 "@com_google_googletest//:gtest_main", 68 ], 69 # FIXME: Add support for assembly tests to bazel. 70 # See Issue #556 71 # https://github.com/google/benchmark/issues/556 72 ) 73 for test_src in glob( 74 ["*test.cc"], 75 exclude = [ 76 "*_assembly_test.cc", 77 "cxx03_test.cc", 78 "link_main_test.cc", 79 ], 80 ) 81] 82 83cc_test( 84 name = "cxx03_test", 85 size = "small", 86 srcs = ["cxx03_test.cc"], 87 copts = TEST_COPTS + ["-std=c++03"], 88 target_compatible_with = select({ 89 "//:windows": ["@platforms//:incompatible"], 90 "//conditions:default": [], 91 }), 92 deps = [ 93 ":output_test_helper", 94 "//:benchmark", 95 "//:benchmark_internal_headers", 96 "@com_google_googletest//:gtest", 97 "@com_google_googletest//:gtest_main", 98 ], 99) 100 101cc_test( 102 name = "link_main_test", 103 size = "small", 104 srcs = ["link_main_test.cc"], 105 copts = select({ 106 "//:windows": [], 107 "//conditions:default": TEST_COPTS, 108 }), 109 deps = ["//:benchmark_main"], 110) 111