2022-06-13 16:45:20 +00:00
|
|
|
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
|
|
|
|
|
|
|
|
platform(
|
|
|
|
name = "windows",
|
|
|
|
constraint_values = [
|
|
|
|
"@platforms//os:windows",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2018-03-08 12:48:46 +00:00
|
|
|
TEST_COPTS = [
|
|
|
|
"-pedantic",
|
|
|
|
"-pedantic-errors",
|
|
|
|
"-std=c++11",
|
2018-04-03 22:12:47 +00:00
|
|
|
"-Wall",
|
2022-05-01 18:56:30 +00:00
|
|
|
"-Wconversion",
|
2018-04-03 22:12:47 +00:00
|
|
|
"-Wextra",
|
|
|
|
"-Wshadow",
|
2019-10-08 10:09:51 +00:00
|
|
|
# "-Wshorten-64-to-32",
|
2018-04-03 22:12:47 +00:00
|
|
|
"-Wfloat-equal",
|
|
|
|
"-fstrict-aliasing",
|
2023-10-20 12:51:32 +00:00
|
|
|
## assert() are used a lot in tests upstream, which may be optimised out leading to
|
|
|
|
## unused-variable warning.
|
|
|
|
"-Wno-unused-variable",
|
2018-03-23 11:45:15 +00:00
|
|
|
]
|
2018-03-08 12:48:46 +00:00
|
|
|
|
2022-06-13 16:45:20 +00:00
|
|
|
# Some of the issues with DoNotOptimize only occur when optimization is enabled
|
|
|
|
PER_SRC_COPTS = {
|
2018-04-03 22:12:47 +00:00
|
|
|
"donotoptimize_test.cc": ["-O3"],
|
2022-06-13 16:45:20 +00:00
|
|
|
}
|
2018-04-03 22:12:47 +00:00
|
|
|
|
2023-02-07 11:45:18 +00:00
|
|
|
TEST_ARGS = ["--benchmark_min_time=0.01s"]
|
2018-03-08 12:48:46 +00:00
|
|
|
|
2023-02-07 11:45:18 +00:00
|
|
|
PER_SRC_TEST_ARGS = {
|
2018-04-03 22:12:47 +00:00
|
|
|
"user_counters_tabular_test.cc": ["--benchmark_counters_tabular=true"],
|
2021-06-02 15:06:45 +00:00
|
|
|
"repetitions_test.cc": [" --benchmark_repetitions=3"],
|
2023-02-07 11:45:18 +00:00
|
|
|
"spec_arg_test.cc": ["--benchmark_filter=BM_NotChosen"],
|
|
|
|
"spec_arg_verbosity_test.cc": ["--v=42"],
|
|
|
|
}
|
2018-04-03 22:12:47 +00:00
|
|
|
|
2018-03-08 12:48:46 +00:00
|
|
|
cc_library(
|
|
|
|
name = "output_test_helper",
|
|
|
|
testonly = 1,
|
|
|
|
srcs = ["output_test_helper.cc"],
|
|
|
|
hdrs = ["output_test.h"],
|
2022-06-13 16:45:20 +00:00
|
|
|
copts = select({
|
|
|
|
"//:windows": [],
|
|
|
|
"//conditions:default": TEST_COPTS,
|
|
|
|
}),
|
2018-03-08 12:48:46 +00:00
|
|
|
deps = [
|
|
|
|
"//:benchmark",
|
|
|
|
"//:benchmark_internal_headers",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2023-08-24 12:43:50 +00:00
|
|
|
# Tests that use gtest. These rely on `gtest_main`.
|
2018-04-03 22:12:47 +00:00
|
|
|
[
|
2019-10-08 10:09:51 +00:00
|
|
|
cc_test(
|
|
|
|
name = test_src[:-len(".cc")],
|
|
|
|
size = "small",
|
|
|
|
srcs = [test_src],
|
2022-06-13 16:45:20 +00:00
|
|
|
copts = select({
|
|
|
|
"//:windows": [],
|
|
|
|
"//conditions:default": TEST_COPTS,
|
2023-02-07 11:45:18 +00:00
|
|
|
}) + PER_SRC_COPTS.get(test_src, []),
|
2019-10-08 10:09:51 +00:00
|
|
|
deps = [
|
|
|
|
"//:benchmark",
|
|
|
|
"//:benchmark_internal_headers",
|
|
|
|
"@com_google_googletest//:gtest",
|
2022-02-14 10:48:53 +00:00
|
|
|
"@com_google_googletest//:gtest_main",
|
2023-02-07 11:45:18 +00:00
|
|
|
],
|
2023-08-24 12:43:50 +00:00
|
|
|
)
|
|
|
|
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",
|
|
|
|
],
|
2019-10-08 10:09:51 +00:00
|
|
|
# FIXME: Add support for assembly tests to bazel.
|
|
|
|
# See Issue #556
|
|
|
|
# https://github.com/google/benchmark/issues/556
|
|
|
|
)
|
|
|
|
for test_src in glob(
|
2023-08-24 12:43:50 +00:00
|
|
|
["*_test.cc"],
|
2019-10-08 10:09:51 +00:00
|
|
|
exclude = [
|
|
|
|
"*_assembly_test.cc",
|
2022-06-13 16:45:20 +00:00
|
|
|
"cxx03_test.cc",
|
2019-10-08 10:09:51 +00:00
|
|
|
"link_main_test.cc",
|
|
|
|
],
|
|
|
|
)
|
2018-04-03 22:12:47 +00:00
|
|
|
]
|
2018-05-25 10:18:58 +00:00
|
|
|
|
2022-06-13 16:45:20 +00:00
|
|
|
cc_test(
|
|
|
|
name = "cxx03_test",
|
|
|
|
size = "small",
|
|
|
|
srcs = ["cxx03_test.cc"],
|
|
|
|
copts = TEST_COPTS + ["-std=c++03"],
|
2023-02-07 11:45:18 +00:00
|
|
|
target_compatible_with = select({
|
|
|
|
"//:windows": ["@platforms//:incompatible"],
|
|
|
|
"//conditions:default": [],
|
|
|
|
}),
|
2022-06-13 16:45:20 +00:00
|
|
|
deps = [
|
|
|
|
":output_test_helper",
|
|
|
|
"//:benchmark",
|
|
|
|
"//:benchmark_internal_headers",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2018-05-25 10:18:58 +00:00
|
|
|
cc_test(
|
|
|
|
name = "link_main_test",
|
|
|
|
size = "small",
|
|
|
|
srcs = ["link_main_test.cc"],
|
2022-06-13 16:45:20 +00:00
|
|
|
copts = select({
|
|
|
|
"//:windows": [],
|
|
|
|
"//conditions:default": TEST_COPTS,
|
|
|
|
}),
|
2018-05-25 10:18:58 +00:00
|
|
|
deps = ["//:benchmark_main"],
|
|
|
|
)
|