-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc] Add a convenience CMake function `add_unittest_framework_libra…
…ry`. This function is used to add unit test and hermetic test framework libraries. It avoids the duplicated code to add compile options to each every test framework libraries. Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D150727
- Loading branch information
Siva Chandra Reddy
committed
May 17, 2023
1 parent
42987df
commit 4dc205f
Showing
3 changed files
with
153 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,144 +1,162 @@ | ||
set(libc_test_srcs_common | ||
CmakeFilePath.cpp | ||
LibcTest.cpp | ||
LibcTestMain.cpp | ||
TestLogger.cpp | ||
LibcTest.h | ||
Test.h | ||
TestLogger.h | ||
) | ||
|
||
set(libc_death_test_srcs ExecuteFunction.h) | ||
if(${LIBC_TARGET_OS} STREQUAL "linux") | ||
list(APPEND libc_death_test_srcs | ||
LibcDeathTestExecutors.cpp ExecuteFunctionUnix.cpp) | ||
endif() | ||
function(add_unittest_framework_library name) | ||
cmake_parse_arguments( | ||
"TEST_LIB" | ||
"" # No optional arguments | ||
"" # No single value arguments | ||
"SRCS;HDRS;DEPENDS" # Multi value arguments | ||
${ARGN} | ||
) | ||
if(NOT TEST_LIB_SRCS) | ||
message(FATAL_ERROR "'add_unittest_framework_library' requires SRCS; for " | ||
"header only libraries, use 'add_header_library'") | ||
endif() | ||
|
||
# The Nvidia 'nvlink' linker does not support static libraries. | ||
if(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX) | ||
set(library_type OBJECT) | ||
else() | ||
set(library_type STATIC) | ||
endif() | ||
# The Nvidia 'nvlink' linker does not support static libraries. | ||
if(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX) | ||
set(library_type OBJECT) | ||
else() | ||
set(library_type STATIC) | ||
endif() | ||
|
||
add_library( | ||
LibcUnitTest | ||
${library_type} | ||
EXCLUDE_FROM_ALL | ||
${libc_test_srcs_common} | ||
${libc_death_test_srcs} | ||
) | ||
foreach(lib IN ITEMS ${name}.unit ${name}.hermetic) | ||
add_library( | ||
${lib} | ||
${library_type} | ||
EXCLUDE_FROM_ALL | ||
${TEST_LIB_SRCS} | ||
${TEST_LIB_HDRS} | ||
) | ||
target_include_directories(${lib} PUBLIC ${LIBC_SOURCE_DIR}) | ||
target_compile_options(${lib} PRIVATE -fno-exceptions -fno-rtti) | ||
endforeach() | ||
target_include_directories(${name}.hermetic PRIVATE ${LIBC_BUILD_DIR}/include) | ||
target_compile_options(${name}.hermetic | ||
PRIVATE ${LIBC_HERMETIC_TEST_COMPILE_OPTIONS} -ffreestanding -nostdinc++) | ||
|
||
add_library( | ||
LibcHermeticTest | ||
${library_type} | ||
EXCLUDE_FROM_ALL | ||
${libc_test_srcs_common} | ||
HermeticTestUtils.cpp | ||
) | ||
if(TEST_LIB_DEPENDS) | ||
foreach(dep IN LISTS ${TEST_LIB_DEPENDS}) | ||
if(TARGET ${dep}.unit) | ||
add_dependencies(${name}.unit ${dep}.unit) | ||
else() | ||
add_dependencies(${name}.unit ${dep}) | ||
endif() | ||
if(TARGET ${dep}.hermetic) | ||
add_dependencies(${name}.hermetic ${dep}.hermetic) | ||
else() | ||
add_dependencies(${name}.hermetic ${dep}) | ||
endif() | ||
endforeach() | ||
endif() | ||
endfunction() | ||
|
||
foreach(lib LibcUnitTest LibcHermeticTest) | ||
target_include_directories(${lib} PUBLIC ${LIBC_SOURCE_DIR}) | ||
target_compile_options(${lib} PRIVATE -fno-exceptions -fno-rtti) | ||
add_dependencies(${lib} | ||
add_unittest_framework_library( | ||
LibcTest | ||
SRCS | ||
CmakeFilePath.cpp | ||
LibcTest.cpp | ||
LibcTestMain.cpp | ||
TestLogger.cpp | ||
HDRS | ||
LibcTest.h | ||
Test.h | ||
TestLogger.h | ||
DEPENDS | ||
libc.src.__support.c_string | ||
libc.src.__support.CPP.string | ||
libc.src.__support.CPP.string_view | ||
libc.src.__support.CPP.type_traits | ||
libc.src.__support.OSUtil.osutil | ||
libc.src.__support.uint128 | ||
) | ||
endforeach() | ||
) | ||
|
||
set(libc_death_test_srcs LibcDeathTestExecutors.cpp) | ||
if(${LIBC_TARGET_OS} STREQUAL "linux") | ||
list(APPEND libc_death_test_srcs ExecuteFunctionUnix.cpp) | ||
endif() | ||
|
||
target_include_directories(LibcHermeticTest PRIVATE ${LIBC_BUILD_DIR}/include) | ||
target_compile_options(LibcHermeticTest | ||
PRIVATE ${LIBC_HERMETIC_TEST_COMPILE_OPTIONS} -ffreestanding -nostdlib -nostdlib++) | ||
add_unittest_framework_library( | ||
LibcDeathTestExecutors | ||
SRCS | ||
${libc_death_test_srcs} | ||
HDRS | ||
ExecuteFunction.h | ||
) | ||
|
||
add_unittest_framework_library( | ||
LibcHermeticTestSupport | ||
SRCS | ||
HermeticTestUtils.cpp | ||
) | ||
|
||
add_header_library( | ||
string_utils | ||
HDRS | ||
StringUtils.h | ||
StringUtils.h | ||
DEPENDS | ||
libc.src.__support.CPP.string | ||
libc.src.__support.CPP.type_traits | ||
) | ||
|
||
add_library( | ||
add_unittest_framework_library( | ||
LibcFPTestHelpers | ||
FPMatcher.h | ||
RoundingModeUtils.cpp | ||
RoundingModeUtils.h | ||
) | ||
add_dependencies( | ||
LibcFPTestHelpers | ||
LibcUnitTest | ||
libc.test.UnitTest.string_utils | ||
libc.src.__support.FPUtil.fp_bits | ||
libc.src.__support.FPUtil.fenv_impl | ||
libc.test.UnitTest.string_utils | ||
) | ||
add_library( | ||
LibcFPExceptionHelpers | ||
FPExceptMatcher.cpp | ||
FPExceptMatcher.h | ||
SRCS | ||
RoundingModeUtils.cpp | ||
HDRS | ||
FPMatcher.h | ||
RoundingModeUtils.h | ||
DEPENDS | ||
LibcTest | ||
libc.test.UnitTest.string_utils | ||
libc.src.__support.FPUtil.fp_bits | ||
libc.src.__support.FPUtil.fenv_impl | ||
libc.test.UnitTest.string_utils | ||
) | ||
add_dependencies( | ||
|
||
add_unittest_framework_library( | ||
LibcFPExceptionHelpers | ||
LibcUnitTest | ||
libc.src.__support.FPUtil.fp_bits | ||
libc.src.__support.FPUtil.fenv_impl | ||
SRCS | ||
FPExceptMatcher.cpp | ||
HDRS | ||
FPExceptMatcher.h | ||
DEPENDS | ||
LibcTest | ||
libc.src.__support.FPUtil.fp_bits | ||
libc.src.__support.FPUtil.fenv_impl | ||
) | ||
|
||
add_library( | ||
add_unittest_framework_library( | ||
LibcMemoryHelpers | ||
${library_type} | ||
MemoryMatcher.h | ||
MemoryMatcher.cpp | ||
) | ||
add_dependencies( | ||
LibcMemoryHelpers | ||
LibcUnitTest | ||
libc.src.__support.CPP.span | ||
SRCS | ||
MemoryMatcher.cpp | ||
HDRS | ||
MemoryMatcher.h | ||
DEPENDS | ||
LibcTest | ||
libc.src.__support.CPP.span | ||
) | ||
|
||
add_library( | ||
LibcPrintfHelpers | ||
PrintfMatcher.h | ||
PrintfMatcher.cpp | ||
) | ||
add_dependencies( | ||
add_unittest_framework_library( | ||
LibcPrintfHelpers | ||
LibcUnitTest | ||
libc.src.__support.FPUtil.fp_bits | ||
libc.src.stdio.printf_core.core_structs | ||
libc.test.UnitTest.string_utils | ||
SRCS | ||
PrintfMatcher.cpp | ||
HDRS | ||
PrintfMatcher.h | ||
DEPENDS | ||
LibcTest | ||
libc.src.__support.FPUtil.fp_bits | ||
libc.src.stdio.printf_core.core_structs | ||
libc.test.UnitTest.string_utils | ||
) | ||
|
||
add_library( | ||
add_unittest_framework_library( | ||
LibcScanfHelpers | ||
ScanfMatcher.h | ||
ScanfMatcher.cpp | ||
) | ||
add_dependencies( | ||
LibcScanfHelpers | ||
LibcUnitTest | ||
libc.src.__support.FPUtil.fp_bits | ||
libc.src.stdio.scanf_core.core_structs | ||
libc.test.UnitTest.string_utils | ||
SRCS | ||
ScanfMatcher.cpp | ||
HDRS | ||
ScanfMatcher.h | ||
DEPENDS | ||
LibcTest | ||
libc.src.__support.FPUtil.fp_bits | ||
libc.src.stdio.scanf_core.core_structs | ||
libc.test.UnitTest.string_utils | ||
) | ||
|
||
foreach(lib LibcFPTestHelpers LibcFPExceptionHelpers LibcMemoryHelpers | ||
LibcPrintfHelpers LibcScanfHelpers) | ||
target_include_directories(${lib} PUBLIC ${LIBC_SOURCE_DIR}) | ||
target_compile_options(${lib} PRIVATE -fno-exceptions -fno-rtti) | ||
target_link_libraries(${lib} LibcUnitTest) | ||
endforeach() | ||
|
||
# The GPU needs these flags applied to override the system triple. | ||
if(LIBC_TARGET_ARCHITECTURE_IS_GPU) | ||
foreach(lib LibcMemoryHelpers) | ||
target_include_directories(${lib} PRIVATE ${LIBC_BUILD_DIR}/include) | ||
target_compile_options(${lib} | ||
PRIVATE ${LIBC_HERMETIC_TEST_COMPILE_OPTIONS} -ffreestanding -nostdlib -nostdlib++) | ||
endforeach() | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters