mirror of
https://github.com/google/benchmark.git
synced 2024-12-28 05:20:14 +08:00
7b03df7ff7
* Add tests to verify assembler output -- Fix DoNotOptimize. For things like `DoNotOptimize`, `ClobberMemory`, and even `KeepRunning()`, it is important exactly what assembly they generate. However, we currently have no way to test this. Instead it must be manually validated every time a change occurs -- including a change in compiler version. This patch attempts to introduce a way to test the assembled output automatically. It's mirrors how LLVM verifies compiler output, and it uses LLVM FileCheck to run the tests in a similar way. The tests function by generating the assembly for a test in CMake, and then using FileCheck to verify the // CHECK lines in the source file are found in the generated assembly. Currently, the tests only run on 64-bit x86 systems under GCC and Clang, and when FileCheck is found on the system. Additionally, this patch tries to improve the code gen from DoNotOptimize. This should probably be a separate change, but I needed something to test. * Disable assembly tests on Bazel for now * Link FIXME to github issue * Fix Tests on OS X * fix strip_asm.py to work on both Linux and OS X like targets
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
NEEDS_GTEST_MAIN = [
|
|
"statistics_test.cc",
|
|
]
|
|
|
|
TEST_COPTS = [
|
|
"-pedantic",
|
|
"-pedantic-errors",
|
|
"-std=c++11",
|
|
]
|
|
|
|
TEST_ARGS = ["--benchmark_min_time=0.01"]
|
|
|
|
cc_library(
|
|
name = "output_test_helper",
|
|
testonly = 1,
|
|
srcs = ["output_test_helper.cc"],
|
|
hdrs = ["output_test.h"],
|
|
copts = TEST_COPTS,
|
|
deps = [
|
|
"//:benchmark",
|
|
"//:benchmark_internal_headers",
|
|
],
|
|
)
|
|
|
|
[cc_test(
|
|
name = test_src[:-len(".cc")],
|
|
size = "small",
|
|
srcs = [test_src],
|
|
args = TEST_ARGS + ({
|
|
"user_counters_tabular_test.cc": ["--benchmark_counters_tabular=true"],
|
|
}).get(test_src, []),
|
|
copts = TEST_COPTS + ({
|
|
"cxx03_test.cc": ["-std=c++03"],
|
|
# Some of the issues with DoNotOptimize only occur when optimization is enabled
|
|
"donotoptimize_test.cc": ["-O3"],
|
|
}).get(test_src, []),
|
|
deps = [
|
|
":output_test_helper",
|
|
"//:benchmark",
|
|
"//:benchmark_internal_headers",
|
|
"@com_google_googletest//:gtest",
|
|
] + (
|
|
["@com_google_googletest//:gtest_main"] if (test_src in NEEDS_GTEST_MAIN) else []
|
|
),
|
|
# 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"])]
|