2022-06-20 17:12:58 +08:00
|
|
|
set(CLANG_SUPPORTED_VERSION "5.0.0")
|
|
|
|
set(GCC_SUPPORTED_VERSION "5.5.0")
|
|
|
|
|
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
|
|
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL ${CLANG_SUPPORTED_VERSION})
|
|
|
|
message (WARNING
|
|
|
|
"Unsupported Clang version " ${CMAKE_CXX_COMPILER_VERSION}
|
|
|
|
". Expected is " ${CLANG_SUPPORTED_VERSION}
|
|
|
|
". Assembly tests may be broken.")
|
|
|
|
endif()
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
|
|
|
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL ${GCC_SUPPORTED_VERSION})
|
|
|
|
message (WARNING
|
|
|
|
"Unsupported GCC version " ${CMAKE_CXX_COMPILER_VERSION}
|
|
|
|
". Expected is " ${GCC_SUPPORTED_VERSION}
|
|
|
|
". Assembly tests may be broken.")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
message (WARNING "Unsupported compiler. Assembly tests may be broken.")
|
|
|
|
endif()
|
Add tests to verify assembler output -- Fix DoNotOptimize. (#530)
* 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
2018-03-24 06:10:47 +08:00
|
|
|
|
2018-05-14 22:02:49 +08:00
|
|
|
include(split_list)
|
Add tests to verify assembler output -- Fix DoNotOptimize. (#530)
* 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
2018-03-24 06:10:47 +08:00
|
|
|
|
|
|
|
set(ASM_TEST_FLAGS "")
|
|
|
|
check_cxx_compiler_flag(-O3 BENCHMARK_HAS_O3_FLAG)
|
|
|
|
if (BENCHMARK_HAS_O3_FLAG)
|
|
|
|
list(APPEND ASM_TEST_FLAGS -O3)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
check_cxx_compiler_flag(-g0 BENCHMARK_HAS_G0_FLAG)
|
|
|
|
if (BENCHMARK_HAS_G0_FLAG)
|
|
|
|
list(APPEND ASM_TEST_FLAGS -g0)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
check_cxx_compiler_flag(-fno-stack-protector BENCHMARK_HAS_FNO_STACK_PROTECTOR_FLAG)
|
|
|
|
if (BENCHMARK_HAS_FNO_STACK_PROTECTOR_FLAG)
|
|
|
|
list(APPEND ASM_TEST_FLAGS -fno-stack-protector)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
split_list(ASM_TEST_FLAGS)
|
|
|
|
string(TOUPPER "${CMAKE_CXX_COMPILER_ID}" ASM_TEST_COMPILER)
|
|
|
|
|
|
|
|
macro(add_filecheck_test name)
|
|
|
|
cmake_parse_arguments(ARG "" "" "CHECK_PREFIXES" ${ARGV})
|
|
|
|
add_library(${name} OBJECT ${name}.cc)
|
2022-02-14 18:48:53 +08:00
|
|
|
target_link_libraries(${name} PRIVATE benchmark::benchmark)
|
Add tests to verify assembler output -- Fix DoNotOptimize. (#530)
* 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
2018-03-24 06:10:47 +08:00
|
|
|
set_target_properties(${name} PROPERTIES COMPILE_FLAGS "-S ${ASM_TEST_FLAGS}")
|
|
|
|
set(ASM_OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${name}.s")
|
|
|
|
add_custom_target(copy_${name} ALL
|
2022-10-13 17:03:29 +08:00
|
|
|
COMMAND ${PROJECT_SOURCE_DIR}/tools/strip_asm.py
|
Add tests to verify assembler output -- Fix DoNotOptimize. (#530)
* 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
2018-03-24 06:10:47 +08:00
|
|
|
$<TARGET_OBJECTS:${name}>
|
|
|
|
${ASM_OUTPUT_FILE}
|
|
|
|
BYPRODUCTS ${ASM_OUTPUT_FILE})
|
|
|
|
add_dependencies(copy_${name} ${name})
|
|
|
|
if (NOT ARG_CHECK_PREFIXES)
|
|
|
|
set(ARG_CHECK_PREFIXES "CHECK")
|
|
|
|
endif()
|
|
|
|
foreach(prefix ${ARG_CHECK_PREFIXES})
|
|
|
|
add_test(NAME run_${name}_${prefix}
|
|
|
|
COMMAND
|
|
|
|
${LLVM_FILECHECK_EXE} ${name}.cc
|
|
|
|
--input-file=${ASM_OUTPUT_FILE}
|
|
|
|
--check-prefixes=CHECK,CHECK-${ASM_TEST_COMPILER}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
endforeach()
|
|
|
|
endmacro()
|
|
|
|
|