[libc] Fix some missing features from the hermetic test support
authorJoseph Huber <jhuber6@vols.utk.edu>
Tue, 2 May 2023 11:39:14 +0000 (06:39 -0500)
committerJoseph Huber <jhuber6@vols.utk.edu>
Tue, 2 May 2023 14:40:24 +0000 (09:40 -0500)
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

libc/cmake/modules/LLVMLibCTestRules.cmake
libc/test/UnitTest/CMakeLists.txt

index 51ed882..a99274c 100644 (file)
@@ -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)
@@ -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}
   )
 
@@ -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)
index c1f6d0d..0335a81 100644 (file)
@@ -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
@@ -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
@@ -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
@@ -121,8 +115,6 @@ add_library(
   ScanfMatcher.h
   ScanfMatcher.cpp
 )
-target_include_directories(LibcScanfHelpers PUBLIC ${LIBC_SOURCE_DIR})
-target_link_libraries(LibcScanfHelpers LibcUnitTest)
 add_dependencies(
   LibcScanfHelpers
   LibcUnitTest
@@ -130,3 +122,9 @@ add_dependencies(
   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()