[libc-commits] [libc] a7b347e - [libc][cmake] Fold add_integration_test into add_libc_test and clean up test options. (#234712)

via libc-commits libc-commits at lists.llvm.org
Fri Oct 23 07:56:47 PDT 2026


Author: lntue
Date: 2026-10-23T10:56:42-04:00
New Revision: a7b347ec208ad35ca83ad1dd314bea9d0c6c844a

URL: https://github.com/llvm/llvm-project/commit/a7b347ec208ad35ca83ad1dd314bea9d0c6c844a
DIFF: https://github.com/llvm/llvm-project/commit/a7b347ec208ad35ca83ad1dd314bea9d0c6c844a.diff

LOG: [libc][cmake] Fold add_integration_test into add_libc_test and clean up test options. (#234712)

- Add `INTEGRATION_TEST` to `LLVM_LIBC_OPTIONAL_ARGS` in
`LibcParseArguments.cmake`.
- Fold `add_integration_test` into `add_libc_test` / `create_libc_test`,
keeping `add_integration_test` as a thin convenience wrapper forwarding
`INTEGRATION_TEST` and `FULL_BUILD_ONLY`.
- Consolidate `_get_hermetic_test_compile_options_impl` and
`_get_hermetic_test_compile_options` into
`_get_common_test_compile_options_impl` and
`_get_common_test_compile_options`, precomputing mode-aware defaults
once at module load time.
- Precompute `LIBC_COMMON_TEST_LINK_OPTIONS` once via
`_get_common_test_link_options_impl` and cleanly separate compile
options from link options across `create_libc_test` and
`_link_libc_hermetic_test`, removing `_link_libc_overlay_test`.
- Explicitly pass `LINK_OPTIONS -mno-wavefrontsize64` and `LINK_OPTIONS
-mwavefrontsize64` alongside `COMPILE_OPTIONS` in
`libc/test/integration/startup/gpu/CMakeLists.txt`.

Assisted-by: Gemini

Added: 
    

Modified: 
    libc/benchmarks/gpu/CMakeLists.txt
    libc/cmake/modules/LLVMLibCTestRules.cmake
    libc/cmake/modules/LibcParseArguments.cmake
    libc/test/UnitTest/CMakeLists.txt
    libc/test/integration/startup/gpu/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/benchmarks/gpu/CMakeLists.txt b/libc/benchmarks/gpu/CMakeLists.txt
index 85e768ddf93adc..b67f8a7d862e68 100644
--- a/libc/benchmarks/gpu/CMakeLists.txt
+++ b/libc/benchmarks/gpu/CMakeLists.txt
@@ -54,7 +54,7 @@ function(add_benchmark_framework_library name)
     target_compile_definitions(${name} PRIVATE TARGET_SUPPORTS_CLOCK)
   endif()
 
-  _get_hermetic_test_compile_options(compile_options "" "")
+  _get_common_test_compile_options(compile_options "" "")
   target_include_directories(${name} PRIVATE ${LIBC_INCLUDE_DIR})
   target_compile_options(${name} PRIVATE ${compile_options} -nostdinc++)
 

diff  --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 1c7a4252a69d6b..4093a37e5c0838 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -8,8 +8,18 @@ function(_get_common_test_compile_options_impl output_var c_test)
   set(config_flags ${LIBC_COMPILE_OPTIONS_FROM_CONFIG})
   set(arch_flags ${LIBC_COMPILE_OPTIONS_FROM_ARCH})
 
-  # Death test executor is only available in Linux for now.
-  if(NOT ${LIBC_TARGET_OS} STREQUAL "linux")
+  # Tests guarded by LIBC_ADD_NULL_CHECKS use EXPECT_DEATH / ASSERT_DEATH to
+  # verify that passing nullptr triggers a crash (__builtin_trap). Executing
+  # death tests requires spawning a subprocess via LibcDeathTestExecutors
+  # (fork, pipe, poll, waitpid, kill, etc.), which is currently only supported
+  # on Linux. In full-build mode, "-DLIBC_ADD_NULL_CHECKS" was historically
+  # stripped (#142085) before LibcDeathTestExecutors was ported to hermetic
+  # mode (#211484).
+  # TODO: Once LibcDeathTestExecutors is unified with add_object_library and
+  # transitive DAG dependency resolution is in place, re-enable
+  # LIBC_ADD_NULL_CHECKS for full-build unit tests where LibcDeathTestExecutors
+  # and its dependencies are available.
+  if(NOT ${LIBC_TARGET_OS} STREQUAL "linux" OR LLVM_LIBC_FULL_BUILD)
     if(MSVC)
       list(REMOVE_ITEM config_flags "/DLIBC_ADD_NULL_CHECKS")
     else()
@@ -59,6 +69,16 @@ function(_get_common_test_compile_options_impl output_var c_test)
       if(NOT c_test)
         list(APPEND compile_options "-fno-rtti")
       endif()
+      # The GPU build requires overriding the default CMake triple and architecture.
+      if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
+        list(APPEND compile_options
+          -Wno-multi-gpu -nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto
+          -mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION})
+      elseif(LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
+        list(APPEND compile_options
+          -Wno-multi-gpu --cuda-path=${LIBC_CUDA_ROOT}
+          -nogpulib -march=${LIBC_GPU_TARGET_ARCHITECTURE} -fno-use-cxa-atexit)
+      endif()
     endif()
 
     if(LIBC_COMPILER_HAS_FIXED_POINT)
@@ -123,52 +143,92 @@ function(_get_common_test_compile_options output_var c_test flags)
     PARENT_SCOPE)
 endfunction()
 
-function(_get_hermetic_test_compile_options_impl output_var c_test)
-  if(c_test)
-    set(compile_options ${LIBC_COMMON_TEST_COMPILE_OPTIONS_C})
-  else()
-    set(compile_options ${LIBC_COMMON_TEST_COMPILE_OPTIONS_CPP})
-  endif()
-
-  # null check tests are death tests, remove from hermetic tests for now.
-  if(LIBC_ADD_NULL_CHECKS)
-    if(MSVC)
-      list(REMOVE_ITEM compile_options "/DLIBC_ADD_NULL_CHECKS")
-    else()
-      list(REMOVE_ITEM compile_options "-DLIBC_ADD_NULL_CHECKS")
+function(get_link_options link_options)
+  set(link_opts "")
+  foreach(opt IN LISTS ARGN)
+    if((NOT ${opt} MATCHES "^/D") AND (NOT ${opt} MATCHES "^-D"))
+      list(APPEND link_opts ${opt})
     endif()
-  endif()
-
-  # The GPU build requires overriding the default CMake triple and architecture.
-  if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
-    list(APPEND compile_options
-      -Wno-multi-gpu -nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto
-      -mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION})
-  elseif(LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
-    list(APPEND compile_options
-      -Wno-multi-gpu --cuda-path=${LIBC_CUDA_ROOT}
-      -nogpulib -march=${LIBC_GPU_TARGET_ARCHITECTURE} -fno-use-cxa-atexit)
-  endif()
-
-  set(${output_var} ${compile_options} PARENT_SCOPE)
+  endforeach()
+  set(${link_options} "${link_opts}" PARENT_SCOPE)
 endfunction()
-_get_hermetic_test_compile_options_impl(LIBC_HERMETIC_TEST_COMPILE_OPTIONS_CPP FALSE)
-_get_hermetic_test_compile_options_impl(LIBC_HERMETIC_TEST_COMPILE_OPTIONS_C TRUE)
 
-function(_get_hermetic_test_compile_options output_var c_test flags)
-  _get_compile_options_from_flags(compile_flags ${flags})
-  if(c_test)
-    set(hermetic_test_opts ${LIBC_HERMETIC_TEST_COMPILE_OPTIONS_C})
+function(_get_common_test_link_options_impl output_var)
+  if(LLVM_LIBC_FULL_BUILD)
+    if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
+      set(link_options
+        ${LIBC_COMPILE_OPTIONS_DEFAULT}
+        ${LIBC_LINK_OPTIONS_DEFAULT}
+        ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
+        -Wno-multi-gpu
+        -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE}
+        -flto
+        -nostdlib
+        -static
+        "-Wl,-mllvm,-amdhsa-code-object-version=${LIBC_GPU_CODE_OBJECT_VERSION}"
+      )
+    elseif(LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
+      set(link_options
+        ${LIBC_COMPILE_OPTIONS_DEFAULT}
+        ${LIBC_LINK_OPTIONS_DEFAULT}
+        ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
+        -Wno-multi-gpu
+        "-Wl,--suppress-stack-size-warning"
+        "-Wl,-mllvm,-nvptx-emit-init-fini-kernel"
+        -march=${LIBC_GPU_TARGET_ARCHITECTURE}
+        -nostdlib
+        -static
+        "--cuda-path=${LIBC_CUDA_ROOT}"
+      )
+    elseif(LIBC_CC_SUPPORTS_NOSTDLIBPP)
+      set(link_options
+        -nostartfiles
+        -nodefaultlibs
+        -nostdlib++
+        -static
+        ${LIBC_COMPILE_OPTIONS_DEFAULT}
+        ${LIBC_LINK_OPTIONS_DEFAULT}
+        ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
+      )
+      if(LIBC_ENABLE_COVERAGE)
+        list(APPEND link_options
+          -noprofilelib
+          -u__llvm_profile_runtime
+        )
+      endif()
+    else()
+      # Older version of gcc does not support `nostdlib++` flag.  We use
+      # `nostdlib` and link against libgcc_s, which cannot be linked statically.
+      set(link_options
+        -nostartfiles
+        -nodefaultlibs
+        -nostdlib
+        ${LIBC_COMPILE_OPTIONS_DEFAULT}
+        ${LIBC_LINK_OPTIONS_DEFAULT}
+        ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
+      )
+      if(LIBC_ENABLE_COVERAGE)
+        list(APPEND link_options
+          -noprofilelib
+          -u__llvm_profile_runtime
+        )
+      endif()
+    endif()
   else()
-    set(hermetic_test_opts ${LIBC_HERMETIC_TEST_COMPILE_OPTIONS_CPP})
+    set(link_options
+      ${LIBC_COMPILE_OPTIONS_DEFAULT}
+      ${LIBC_TEST_COMPILE_OPTIONS_DEFAULT}
+      ${LIBC_LINK_OPTIONS_DEFAULT}
+      ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
+    )
+    if(LLVM_LIBC_COMPILER_IS_GCC_COMPATIBLE)
+      list(APPEND link_options "-fpie")
+    endif()
   endif()
-  set(${output_var}
-    ${LIBC_COMPILE_OPTIONS_DEFAULT}
-    ${LIBC_TEST_COMPILE_OPTIONS_DEFAULT}
-    ${compile_flags}
-    ${hermetic_test_opts}
-    PARENT_SCOPE)
+  get_link_options(link_options ${link_options})
+  set(${output_var} ${link_options} PARENT_SCOPE)
 endfunction()
+_get_common_test_link_options_impl(LIBC_COMMON_TEST_LINK_OPTIONS)
 
 # This is a helper function and not a build rule. It is to be used by the
 # various test rules to generate the full list of object files
@@ -276,16 +336,6 @@ function(get_object_files_for_test result skipped_entrypoints_list)
 
 endfunction()
 
-function(get_link_options link_options)
-  set(link_opts "")
-  foreach(opt IN LISTS ARGN)
-    if((NOT ${opt} MATCHES "^/D") AND (NOT ${opt} MATCHES "^-D"))
-      list(APPEND link_opts ${opt})
-    endif()
-  endforeach()
-  set(${link_options} "${link_opts}" PARENT_SCOPE)
-endfunction()
-
 # Get libgcc_s to be used in hermetic and integration tests.
 if(NOT MSVC AND NOT LIBC_CC_SUPPORTS_NOSTDLIBPP)
   execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=libgcc_s.so.1
@@ -403,24 +453,31 @@ endfunction()
 # Helper function for create_libc_test: collects fully qualified dependencies
 # for a test target, including base test framework libraries, hermetic runtime
 # entrypoints, subprocess support, and coverage dependencies.
-function(_get_libc_test_dependencies output_var user_depends startup_target_dep is_c_test is_fp_test)
+function(_get_libc_test_dependencies output_var user_depends startup_target_dep is_c_test is_fp_test is_integration_test)
   get_fq_deps_list(fq_deps_list ${user_depends})
-  list(APPEND fq_deps_list
-    libc.src.__support.StringUtil.error_to_string
-    libc.test.UnitTest.ErrnoSetterMatcher
-    libc.test.UnitTest.LibcTest
-  )
-  if(is_c_test)
-    list(APPEND fq_deps_list libc.test.UnitTest.LibcCTest)
+  if(is_integration_test)
+    list(APPEND fq_deps_list
+      generate-libc-headers
+      libc.test.IntegrationTest.test
+    )
   else()
-    list(APPEND fq_deps_list libc.test.UnitTest.LibcDeathTestExecutors)
-  endif()
-  if(is_fp_test)
     list(APPEND fq_deps_list
-      libc.hdr.math_macros
-      libc.hdr.stdint_proxy
-      libc.test.UnitTest.FPTestHelpers
+      libc.src.__support.StringUtil.error_to_string
+      libc.test.UnitTest.ErrnoSetterMatcher
+      libc.test.UnitTest.LibcTest
     )
+    if(is_c_test)
+      list(APPEND fq_deps_list libc.test.UnitTest.LibcCTest)
+    else()
+      list(APPEND fq_deps_list libc.test.UnitTest.LibcDeathTestExecutors)
+    endif()
+    if(is_fp_test)
+      list(APPEND fq_deps_list
+        libc.hdr.math_macros
+        libc.hdr.stdint_proxy
+        libc.test.UnitTest.FPTestHelpers
+      )
+    endif()
   endif()
 
   if(LLVM_LIBC_FULL_BUILD)
@@ -432,40 +489,42 @@ function(_get_libc_test_dependencies output_var user_depends startup_target_dep
       libc.src.string.memset
       libc.src.strings.bcmp
       libc.src.strings.bzero
-      libc.test.UnitTest.HermeticTestUtils
     )
-    if(LIBC_TARGET_ARCHITECTURE_IS_AARCH64 AND NOT(LIBC_TARGET_OS_IS_BAREMETAL))
-      list(APPEND fq_deps_list libc.src.sys.auxv.getauxval)
-    endif()
-    if(LIBC_TEST_SUBPROCESS_TESTS AND NOT is_c_test)
-      list(APPEND fq_deps_list
-        libc.src.poll.poll
-        libc.src.signal.kill
-        libc.src.stdio.fflush
-        libc.src.stdio.stderr
-        libc.src.stdio.stdout
-        libc.src.stdlib.exit
-        libc.src.string.strsignal
-        libc.src.sys.wait.waitpid
-        libc.src.unistd.close
-        libc.src.unistd.fork
-        libc.src.unistd.pipe
-      )
-    endif()
-    if(NOT LLVM_LIBC_HERMETIC_TEST_USE_INTERNAL_STARTUP AND LIBC_TARGET_OS_IS_BAREMETAL)
-      # External baremetal startup objects still need libc's process startup and
-      # termination entrypoints, even when the test itself does not depend on them.
-      list(APPEND fq_deps_list
-        libc.src.stdlib.atexit
-        libc.src.stdlib.exit
-        libc.startup.baremetal.init
-      )
-    endif()
     if(libc.src.compiler.__stack_chk_fail IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
       list(APPEND fq_deps_list libc.src.compiler.__stack_chk_fail)
     endif()
-    if(libc.src.time.clock IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
-      list(APPEND fq_deps_list libc.src.time.clock)
+    if(NOT is_integration_test)
+      list(APPEND fq_deps_list libc.test.UnitTest.HermeticTestUtils)
+      if(LIBC_TARGET_ARCHITECTURE_IS_AARCH64 AND NOT(LIBC_TARGET_OS_IS_BAREMETAL))
+        list(APPEND fq_deps_list libc.src.sys.auxv.getauxval)
+      endif()
+      if(LIBC_TEST_SUBPROCESS_TESTS AND NOT is_c_test)
+        list(APPEND fq_deps_list
+          libc.src.poll.poll
+          libc.src.signal.kill
+          libc.src.stdio.fflush
+          libc.src.stdio.stderr
+          libc.src.stdio.stdout
+          libc.src.stdlib.exit
+          libc.src.string.strsignal
+          libc.src.sys.wait.waitpid
+          libc.src.unistd.close
+          libc.src.unistd.fork
+          libc.src.unistd.pipe
+        )
+      endif()
+      if(NOT LLVM_LIBC_HERMETIC_TEST_USE_INTERNAL_STARTUP AND LIBC_TARGET_OS_IS_BAREMETAL)
+        # External baremetal startup objects still need libc's process startup and
+        # termination entrypoints, even when the test itself does not depend on them.
+        list(APPEND fq_deps_list
+          libc.src.stdlib.atexit
+          libc.src.stdlib.exit
+          libc.startup.baremetal.init
+        )
+      endif()
+      if(libc.src.time.clock IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
+        list(APPEND fq_deps_list libc.src.time.clock)
+      endif()
     endif()
     if(LIBC_ENABLE_COVERAGE)
       _get_libc_coverage_dependencies(coverage_deps)
@@ -477,8 +536,8 @@ function(_get_libc_test_dependencies output_var user_depends startup_target_dep
 endfunction()
 
 # Helper function for create_libc_test: configures linking for full-build hermetic
-# tests by creating the static .__libc__ archive, setting hermetic/GPU link
-# options, and wiring link libraries and compiler runtime.
+# tests by creating the static .__libc__ archive and wiring link libraries and
+# compiler runtime.
 function(_link_libc_hermetic_test fq_target_name fq_build_target_name startup_target_dep link_object_files test_link_libraries)
   if(LIBC_ENABLE_COVERAGE)
     _get_libc_coverage_dependencies(coverage_deps)
@@ -505,51 +564,9 @@ function(_link_libc_hermetic_test fq_target_name fq_build_target_name startup_ta
     PROPERTIES ARCHIVE_OUTPUT_NAME ${fq_target_name}.libc)
 
   set(compiler_runtime "")
-  if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
-    target_link_options(${fq_build_target_name} PRIVATE
-      ${LIBC_COMPILE_OPTIONS_DEFAULT} -Wno-multi-gpu
-      -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto -nostdlib -static
-      "-Wl,-mllvm,-amdhsa-code-object-version=${LIBC_GPU_CODE_OBJECT_VERSION}")
-  elseif(LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
-    target_link_options(${fq_build_target_name} PRIVATE
-      ${LIBC_COMPILE_OPTIONS_DEFAULT} -Wno-multi-gpu
-      "-Wl,--suppress-stack-size-warning"
-      "-Wl,-mllvm,-nvptx-emit-init-fini-kernel"
-      -march=${LIBC_GPU_TARGET_ARCHITECTURE} -nostdlib -static
-      "--cuda-path=${LIBC_CUDA_ROOT}")
-  elseif(LIBC_CC_SUPPORTS_NOSTDLIBPP)
-    set(link_options
-      -nostartfiles
-      -nodefaultlibs
-      -nostdlib++
-      -static
-      ${LIBC_LINK_OPTIONS_DEFAULT}
-      ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
-    )
-    if(LIBC_ENABLE_COVERAGE)
-      list(APPEND link_options
-        -noprofilelib
-        -u__llvm_profile_runtime
-      )
-    endif()
-    target_link_options(${fq_build_target_name} PRIVATE ${link_options})
-  else()
-    # Older version of gcc does not support `nostdlib++` flag.  We use
-    # `nostdlib` and link against libgcc_s, which cannot be linked statically.
-    set(link_options
-      -nostartfiles
-      -nodefaultlibs
-      -nostdlib
-      ${LIBC_LINK_OPTIONS_DEFAULT}
-      ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
-    )
-    if(LIBC_ENABLE_COVERAGE)
-      list(APPEND link_options
-        -noprofilelib
-        -u__llvm_profile_runtime
-      )
-    endif()
-    target_link_options(${fq_build_target_name} PRIVATE ${link_options})
+  if(NOT LIBC_TARGET_ARCHITECTURE_IS_AMDGPU AND
+    NOT LIBC_TARGET_ARCHITECTURE_IS_NVPTX AND
+    NOT LIBC_CC_SUPPORTS_NOSTDLIBPP)
     list(APPEND compiler_runtime ${LIBGCC_S_LOCATION})
   endif()
 
@@ -577,21 +594,6 @@ function(_link_libc_hermetic_test fq_target_name fq_build_target_name startup_ta
   endif()
 endfunction()
 
-# Helper function for create_libc_test: configures linking for overlay mode tests
-# using host link options and linking object files and extra libraries.
-function(_link_libc_overlay_test fq_build_target_name compile_options link_object_files test_link_libraries)
-  get_link_options(link_options
-    ${compile_options}
-    ${LIBC_LINK_OPTIONS_DEFAULT}
-    ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
-  )
-  target_link_options(${fq_build_target_name} PRIVATE ${link_options})
-
-  set(link_libraries ${link_object_files})
-  list(APPEND link_libraries ${test_link_libraries})
-  target_link_libraries(${fq_build_target_name} PRIVATE ${link_libraries})
-endfunction()
-
 # Helper function for create_libc_test: sets up the post-build custom target
 # and command to run the test binary (handling emulators, argument passing,
 # and parameter files).
@@ -668,6 +670,15 @@ function(create_libc_test fq_target_name)
   get_target_property(suite_build_only ${TEST_SUITE} BUILD_ONLY)
 
   # 1. Validate build mode, target platform, and external library requirements
+  if(TEST_INTEGRATION_TEST)
+    set(supported_targets gpu linux)
+    if(NOT (${LIBC_TARGET_OS} IN_LIST supported_targets))
+      message(STATUS "Skipping ${fq_target_name} as it is not available on ${LIBC_TARGET_OS}.")
+      return()
+    endif()
+    set(TEST_FULL_BUILD_ONLY TRUE)
+  endif()
+
   if(TEST_NEED_MPC)
     set(TEST_NEED_MPFR TRUE)
     if(NOT LIBC_TESTS_CAN_USE_MPC)
@@ -758,6 +769,7 @@ function(create_libc_test fq_target_name)
     "${startup_target_dep}"
     "${TEST_C_TEST}"
     "${TEST_FP_TEST}"
+    "${TEST_INTEGRATION_TEST}"
   )
 
   if(SHOW_INTERMEDIATE_OBJECTS)
@@ -802,13 +814,7 @@ function(create_libc_test fq_target_name)
   target_include_directories(${fq_build_target_name} PRIVATE ${LIBC_SOURCE_DIR})
   target_include_directories(${fq_build_target_name} PRIVATE ${LIBC_BUILD_DIR})
 
-  if(LLVM_LIBC_FULL_BUILD)
-    _get_hermetic_test_compile_options(compile_options "${TEST_C_TEST}"
-      "${TEST_FLAGS}")
-  else()
-    _get_common_test_compile_options(compile_options "${TEST_C_TEST}"
-      "${TEST_FLAGS}")
-  endif()
+  _get_common_test_compile_options(compile_options "${TEST_C_TEST}" "${TEST_FLAGS}")
   target_compile_options(${fq_build_target_name} PRIVATE ${compile_options} ${TEST_COMPILE_OPTIONS})
 
   if(NOT TEST_CXX_STANDARD)
@@ -822,6 +828,12 @@ function(create_libc_test fq_target_name)
   )
 
   # 4. Configure linking
+  target_link_options(
+    ${fq_build_target_name}
+    PRIVATE
+    ${LIBC_COMMON_TEST_LINK_OPTIONS}
+    ${TEST_LINK_OPTIONS}
+  )
   if(LLVM_LIBC_FULL_BUILD)
     _link_libc_hermetic_test(
       ${fq_target_name}
@@ -831,11 +843,11 @@ function(create_libc_test fq_target_name)
       "${TEST_LINK_LIBRARIES}"
     )
   else()
-    _link_libc_overlay_test(
+    target_link_libraries(
       ${fq_build_target_name}
-      "${compile_options}"
-      "${link_object_files}"
-      "${TEST_LINK_LIBRARIES}"
+      PRIVATE
+        ${link_object_files}
+        ${TEST_LINK_LIBRARIES}
     )
   endif()
 
@@ -943,187 +955,11 @@ function(add_libc_fuzzer target_name)
 endfunction()
 
 
-# DEPRECATED: Use add_libc_test instead.
-#
-# Rule to add an integration test. An integration test is like a unit test
-# but does not use the system libc. Not even the startup objects from the
-# system libc are linked in to the final executable. The final exe is fully
-# statically linked. The libc that the final exe links to consists of only
-# the object files of the DEPENDS targets.
-#
-# Usage:
-#   add_integration_test(
-#     <target name>
-#     SUITE <the suite to which the test should belong>
-#     SRCS <src1.cpp> [src2.cpp ...]
-#     HDRS [hdr1.cpp ...]
-#     DEPENDS <list of entrypoint or other object targets>
-#     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 this target>
-#   )
-#
-# The DEPENDS list can be empty. If not empty, it should be a list of
-# targets added with add_entrypoint_object or add_object_library.
-function(add_integration_test test_name)
-  get_fq_target_name(${test_name} fq_target_name)
-  set(supported_targets gpu linux)
-  if(NOT (${LIBC_TARGET_OS} IN_LIST supported_targets))
-    message(STATUS "Skipping ${fq_target_name} as it is not available on ${LIBC_TARGET_OS}.")
-    return()
-  endif()
-  llvm_libc_parse_arguments(INTEGRATION_TEST ${ARGN})
-
-  if(NOT INTEGRATION_TEST_SUITE)
-    message(FATAL_ERROR "SUITE not specified for ${fq_target_name}")
-  endif()
-  if(NOT INTEGRATION_TEST_SRCS)
-    message(FATAL_ERROR "The SRCS list for add_integration_test is missing.")
-  endif()
-  if(NOT LLVM_LIBC_FULL_BUILD AND NOT TARGET libc.startup.${LIBC_TARGET_OS}.crt1)
-    message(FATAL_ERROR "The 'crt1' target for the integration test is missing.")
-  endif()
-
-  get_fq_target_name(${test_name}.libc fq_libc_target_name)
-
-  get_fq_deps_list(fq_deps_list ${INTEGRATION_TEST_DEPENDS})
-  list(APPEND fq_deps_list
-    # All integration tests use the operating system's startup object with the
-    # integration test object and need to inherit the same dependencies.
-    libc.startup.${LIBC_TARGET_OS}.crt1
-    libc.test.IntegrationTest.test
-    # We always add the memory functions objects. This is because the
-    # compiler's codegen can emit calls to the C memory functions.
-    libc.src.string.memcmp
-    libc.src.string.memcpy
-    libc.src.string.memmove
-    libc.src.string.memset
-    libc.src.strings.bcmp
-    libc.src.strings.bzero
-  )
-
-  if(libc.src.compiler.__stack_chk_fail IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
-    # __stack_chk_fail should always be included if supported to allow building
-    # libc with the stack protector enabled.
-    list(APPEND fq_deps_list libc.src.compiler.__stack_chk_fail)
-  endif()
-
-  list(REMOVE_DUPLICATES fq_deps_list)
-
-  # TODO: Instead of gathering internal object files from entrypoints,
-  # collect the object files with public names of entrypoints.
-  get_object_files_for_test(
-    link_object_files skipped_entrypoints_list ${fq_deps_list})
-  if(skipped_entrypoints_list)
-    if(LIBC_CMAKE_VERBOSE_LOGGING)
-      set(msg "Skipping integration test ${fq_target_name} as it has missing deps: "
-        "${skipped_entrypoints_list}.")
-      message(STATUS ${msg})
-    endif()
-    return()
-  endif()
-  list(REMOVE_DUPLICATES link_object_files)
-
-  # Make a library of all deps
-  add_library(
-    ${fq_target_name}.__libc__
-    STATIC
-    EXCLUDE_FROM_ALL
-      ${link_object_files}
-  )
-  set_target_properties(${fq_target_name}.__libc__
-    PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
-  set_target_properties(${fq_target_name}.__libc__
-    PROPERTIES ARCHIVE_OUTPUT_NAME ${fq_target_name}.libc)
-
-  set(fq_build_target_name ${fq_target_name}.__build__)
-  add_executable(
-    ${fq_build_target_name}
-    EXCLUDE_FROM_ALL
-    ${INTEGRATION_TEST_SRCS}
-    ${INTEGRATION_TEST_HDRS}
-  )
-  set_target_properties(${fq_build_target_name}
-    PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
-  target_include_directories(${fq_build_target_name} SYSTEM PRIVATE ${LIBC_INCLUDE_DIR})
-  target_include_directories(${fq_build_target_name} PRIVATE ${LIBC_SOURCE_DIR})
-
-  _get_hermetic_test_compile_options(compile_options "" "")
-  target_compile_options(${fq_build_target_name} PRIVATE
-    ${compile_options} ${INTEGRATION_TEST_COMPILE_OPTIONS})
-
-  set(compiler_runtime "")
-
-  if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
-    target_link_options(${fq_build_target_name} PRIVATE
-      ${LIBC_COMPILE_OPTIONS_DEFAULT} ${INTEGRATION_TEST_COMPILE_OPTIONS}
-      -Wno-multi-gpu -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto -nostdlib -static
-      "-Wl,-mllvm,-amdhsa-code-object-version=${LIBC_GPU_CODE_OBJECT_VERSION}")
-  elseif(LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
-    target_link_options(${fq_build_target_name} PRIVATE
-      ${LIBC_COMPILE_OPTIONS_DEFAULT} ${INTEGRATION_TEST_COMPILE_OPTIONS}
-      "-Wl,--suppress-stack-size-warning" -Wno-multi-gpu
-      "-Wl,-mllvm,-nvptx-emit-init-fini-kernel"
-      -march=${LIBC_GPU_TARGET_ARCHITECTURE} -nostdlib -static
-      "--cuda-path=${LIBC_CUDA_ROOT}")
-  elseif(LIBC_CC_SUPPORTS_NOSTDLIBPP)
-    set(link_options
-      -nostartfiles
-      -nodefaultlibs
-      -nostdlib++
-      -static
-      ${LIBC_LINK_OPTIONS_DEFAULT}
-      ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
-    )
-    target_link_options(${fq_build_target_name} PRIVATE ${link_options})
-  else()
-    # Older version of gcc does not support `nostdlib++` flag.  We use
-    # `nostdlib` and link against libgcc_s, which cannot be linked statically.
-    set(link_options
-      -nostartfiles
-      -nodefaultlibs
-      -nostdlib
-      ${LIBC_LINK_OPTIONS_DEFAULT}
-      ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
-    )
-    target_link_options(${fq_build_target_name} PRIVATE ${link_options})
-    list(APPEND compiler_runtime ${LIBGCC_S_LOCATION})
-  endif()
-  target_link_libraries(
-    ${fq_build_target_name}
-    libc.startup.${LIBC_TARGET_OS}.crt1
-    libc.test.IntegrationTest.test
-    ${fq_target_name}.__libc__
-    ${LIBC_TEST_BUILTINS_LIBRARY}
-    ${compiler_runtime}
-  )
-  if(LIBC_TEST_BUILTINS_TARGET)
-    target_link_libraries(${fq_build_target_name} $<TARGET_FILE:${LIBC_TEST_BUILTINS_TARGET}>)
-    add_dependencies(${fq_build_target_name} ${LIBC_TEST_BUILTINS_TARGET})
-  endif()
-  add_dependencies(${fq_build_target_name}
-    libc.test.IntegrationTest.test
-    ${INTEGRATION_TEST_DEPENDS})
-
-  _add_libc_test_runner(
-    ${fq_target_name}
-    ${fq_build_target_name}
-    "${INTEGRATION_TEST_ARGS}"
-    "${INTEGRATION_TEST_LOADER_ARGS}"
-    "${INTEGRATION_TEST_ENV}"
-  )
-  _register_libc_test_with_suite(
-    ${fq_target_name}
-    ${fq_build_target_name}
-    "${INTEGRATION_TEST_SUITE}"
-    FALSE
-  )
-endfunction()
-
 # A unified function to add a libc test.
 # FULL_BUILD_ONLY: skip test in overlay mode.
 # OVERLAY_ONLY: skip test in full build mode.
 # FP_TEST: add floating-point test helper dependencies.
+# INTEGRATION_TEST: link against IntegrationTest instead of UnitTest framework.
 # NEED_MPFR / NEED_MPFR_F80 / NEED_MPFR_F128: link against MPFR; tests requiring MPFR run only in overlay mode.
 # NEED_MPC: link against MPC and MPFR; tests requiring MPC run only in overlay mode.
 function(add_libc_test test_name)
@@ -1142,6 +978,15 @@ function(add_fp_unittest test_name)
   )
 endfunction()
 
+function(add_integration_test test_name)
+  add_libc_test(
+    ${test_name}
+    INTEGRATION_TEST
+    FULL_BUILD_ONLY
+    ${ARGN}
+  )
+endfunction()
+
 # Tests all implementations that can run on the target CPU.
 function(add_libc_multi_impl_test name suite)
   get_property(fq_implementations GLOBAL PROPERTY ${name}_implementations)

diff  --git a/libc/cmake/modules/LibcParseArguments.cmake b/libc/cmake/modules/LibcParseArguments.cmake
index b21eee60a9ce15..f564865f4de5e8 100644
--- a/libc/cmake/modules/LibcParseArguments.cmake
+++ b/libc/cmake/modules/LibcParseArguments.cmake
@@ -93,6 +93,7 @@ set(LLVM_LIBC_OPTIONAL_ARGS
   NEED_MPFR_F128
   NEED_MPC
   FP_TEST
+  INTEGRATION_TEST
   BUILD_ONLY
   ROOT
   PACKAGE_VARIANTS

diff  --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt
index a8f25e6cdcc6cf..c99666dde0eaf5 100644
--- a/libc/test/UnitTest/CMakeLists.txt
+++ b/libc/test/UnitTest/CMakeLists.txt
@@ -49,20 +49,17 @@ function(_create_unittest_framework_library fq_target_name)
     target_compile_definitions(${fq_target_name} PRIVATE TARGET_SUPPORTS_SIGNAL_CATCHING)
   endif()
 
+  _get_common_test_compile_options(compile_options "" "${TEST_LIB_FLAGS}")
   if(LLVM_LIBC_FULL_BUILD)
     target_include_directories(
       ${fq_target_name} SYSTEM PRIVATE ${LIBC_INCLUDE_DIR}
     )
-    _get_hermetic_test_compile_options(compile_options "" "${TEST_LIB_FLAGS}")
-    target_compile_options(${fq_target_name} PRIVATE ${compile_options} -nostdinc++)
-  else()
-    _get_common_test_compile_options(compile_options "" "${TEST_LIB_FLAGS}")
-
-    if(TEST_LIB_COMPILE_OPTIONS)
-      list(APPEND compile_options ${TEST_LIB_COMPILE_OPTIONS})
-    endif()
-    target_compile_options(${fq_target_name} PRIVATE ${compile_options})
+    list(APPEND compile_options -nostdinc++)
+  endif()
+  if(TEST_LIB_COMPILE_OPTIONS)
+    list(APPEND compile_options ${TEST_LIB_COMPILE_OPTIONS})
   endif()
+  target_compile_options(${fq_target_name} PRIVATE ${compile_options})
 
   if(fq_deps_list)
     add_dependencies(${fq_target_name} ${fq_deps_list})

diff  --git a/libc/test/integration/startup/gpu/CMakeLists.txt b/libc/test/integration/startup/gpu/CMakeLists.txt
index 35c957ade2b174..6d002b5a62630f 100644
--- a/libc/test/integration/startup/gpu/CMakeLists.txt
+++ b/libc/test/integration/startup/gpu/CMakeLists.txt
@@ -73,6 +73,8 @@ if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
       --threads 32
     COMPILE_OPTIONS
       -mno-wavefrontsize64
+    LINK_OPTIONS
+      -mno-wavefrontsize64
   )
 
   add_integration_test(
@@ -84,6 +86,8 @@ if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
       --threads 64
     COMPILE_OPTIONS
       -mwavefrontsize64
+    LINK_OPTIONS
+      -mwavefrontsize64
   )
 else()
   add_integration_test(


        


More information about the libc-commits mailing list