Skip to content

Commit

Permalink
[libc] Fix some missing features from the hermetic test support
Browse files Browse the repository at this point in the history
This patch addresses some of the flags and features that are currently
missing from the hermetic test support. This mostly just fixes the
`add_libc_test` option failing to find a few dependencies or missing
arguments from the previous unit test support.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D149629
  • Loading branch information
jhuber6 committed May 2, 2023
1 parent d755e10 commit 2353b52
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
15 changes: 9 additions & 6 deletions libc/cmake/modules/LLVMLibCTestRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ endif()
# ARGS <list of command line arguments to be passed to the test>
# ENV <list of environment variables to set before running the test>
# COMPILE_OPTIONS <list of special compile options for the test>
# LINK_LIBRARIES <list of linking libraries for this target>
# LOADER_ARGS <list of special args to loaders (like the GPU loader)>
# )
function(add_libc_hermetic_test test_name)
Expand All @@ -579,7 +580,7 @@ function(add_libc_hermetic_test test_name)
"HERMETIC_TEST"
"" # No optional arguments
"SUITE" # Single value arguments
"SRCS;HDRS;DEPENDS;ARGS;ENV;COMPILE_OPTIONS;LOADER_ARGS" # Multi-value arguments
"SRCS;HDRS;DEPENDS;ARGS;ENV;COMPILE_OPTIONS;LINK_LIBRARIES;LOADER_ARGS" # Multi-value arguments
${ARGN}
)

Expand Down Expand Up @@ -660,13 +661,15 @@ function(add_libc_hermetic_test test_name)
target_link_options(${fq_build_target_name} PRIVATE -nostdlib -static)
target_link_libraries(
${fq_build_target_name}
libc.startup.${LIBC_TARGET_OS}.crt1
LibcHermeticTestMain LibcHermeticTest
# The NVIDIA 'nvlink' linker does not currently support static libraries.
$<$<NOT:$<BOOL:${LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX}>>:${fq_target_name}.__libc__>)
PRIVATE
${HERMETIC_TEST_LINK_LIBRARIES}
libc.startup.${LIBC_TARGET_OS}.crt1
LibcHermeticTestMain LibcHermeticTest
# The NVIDIA 'nvlink' linker does not currently support static libraries.
$<$<NOT:$<BOOL:${LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX}>>:${fq_target_name}.__libc__>)
add_dependencies(${fq_build_target_name}
LibcHermeticTest
${HERMETIC_TEST_DEPENDS})
${fq_deps_list})

# Tests on the GPU require an external loader utility to launch the kernel.
if(TARGET libc.utils.gpu.loader)
Expand Down
14 changes: 6 additions & 8 deletions libc/test/UnitTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ add_library(
RoundingModeUtils.cpp
RoundingModeUtils.h
)
target_include_directories(LibcFPTestHelpers PUBLIC ${LIBC_SOURCE_DIR})
target_link_libraries(LibcFPTestHelpers LibcUnitTest)
add_dependencies(
LibcFPTestHelpers
LibcUnitTest
Expand All @@ -93,8 +91,6 @@ add_library(
MemoryMatcher.h
MemoryMatcher.cpp
)
target_include_directories(LibcMemoryHelpers PUBLIC ${LIBC_SOURCE_DIR})
target_link_libraries(LibcMemoryHelpers LibcUnitTest)
add_dependencies(
LibcMemoryHelpers
LibcUnitTest
Expand All @@ -106,8 +102,6 @@ add_library(
PrintfMatcher.h
PrintfMatcher.cpp
)
target_include_directories(LibcPrintfHelpers PUBLIC ${LIBC_SOURCE_DIR})
target_link_libraries(LibcPrintfHelpers LibcUnitTest)
add_dependencies(
LibcPrintfHelpers
LibcUnitTest
Expand All @@ -121,12 +115,16 @@ add_library(
ScanfMatcher.h
ScanfMatcher.cpp
)
target_include_directories(LibcScanfHelpers PUBLIC ${LIBC_SOURCE_DIR})
target_link_libraries(LibcScanfHelpers LibcUnitTest)
add_dependencies(
LibcScanfHelpers
LibcUnitTest
libc.src.__support.FPUtil.fp_bits
libc.src.stdio.scanf_core.core_structs
libc.test.UnitTest.string_utils
)

foreach(lib LibcFPTestHelpers 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()

0 comments on commit 2353b52

Please sign in to comment.