[libc-commits] [libc] 107ce71 - [libc] Use real objects and archives in integration tests.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Thu Mar 24 00:03:11 PDT 2022


Author: Siva Chandra Reddy
Date: 2022-03-24T07:02:33Z
New Revision: 107ce71849bccb8749a9ff369f22641f092be432

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

LOG: [libc] Use real objects and archives in integration tests.

Previously, we used empty, non-ELF crti.o, crtn.o, libm.a and libc++.a
files. Instead, we now still use dummies but they are real ELF object
files and archives.

Added: 
    libc/loader/linux/crti.cpp
    libc/loader/linux/crtn.cpp
    libc/test/integration/dummy.cpp

Modified: 
    libc/cmake/modules/LLVMLibCTestRules.cmake
    libc/loader/linux/CMakeLists.txt
    libc/test/CMakeLists.txt
    libc/test/integration/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index edbeaaff8ac03..3bbebb0cc11a9 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -294,6 +294,11 @@ endfunction(add_libc_fuzzer)
 # 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)
+  if(NOT (${LIBC_TARGET_OS} STREQUAL "linux"))
+    message(STATUS "Skipping ${fq_target_name} as it is not available on ${LIBC_TARGET_OS}.")
+    return()
+  endif()
   cmake_parse_arguments(
     "INTEGRATION_TEST"
     "" # No optional arguments
@@ -301,7 +306,6 @@ function(add_integration_test test_name)
     "SRCS;HDRS;DEPENDS;ARGS;ENV" # Multi-value arguments
     ${ARGN}
   )
-  get_fq_target_name(${test_name} fq_target_name)
 
   if(NOT INTEGRATION_TEST_SUITE)
     message(FATAL_ERROR "SUITE not specified for ${fq_target_name}")
@@ -339,21 +343,23 @@ function(add_integration_test test_name)
   file(MAKE_DIRECTORY ${sysroot}/include)
   set(sysroot_lib ${sysroot}/lib)
   file(MAKE_DIRECTORY ${sysroot_lib})
-  # Add dummy crti.o, crtn.o, libm.a and libc++.a
-  file(TOUCH ${sysroot_lib}/crti.o)
-  file(TOUCH ${sysroot_lib}/crtn.o)
-  file(TOUCH ${sysroot_lib}/libm.a)
-  file(TOUCH ${sysroot_lib}/libc++.a)
-  # Copy the loader object
   get_target_property(loader_object_file ${INTEGRATION_TEST_LOADER} LOADER_OBJECT)
+  get_target_property(crti_object_file libc.loader.linux.crti LOADER_OBJECT)
+  get_target_property(crtn_object_file libc.loader.linux.crtn LOADER_OBJECT)
+  set(dummy_archive $<TARGET_PROPERTY:libc_integration_test_dummy,ARCHIVE_OUTPUT_DIRECTORY>/lib$<TARGET_PROPERTY:libc_integration_test_dummy,ARCHIVE_OUTPUT_NAME>.a)
   if(NOT loader_object_file)
     message(FATAL_ERROR "Missing LOADER_OBJECT property of ${INTEGRATION_TEST_LOADER}.")
   endif()
   set(loader_dst ${sysroot_lib}/${LIBC_TARGET_ARCHITECTURE}-linux-gnu/crt1.o)
   add_custom_command(
-    OUTPUT ${loader_dst}
+    OUTPUT ${loader_dst} ${sysroot}/lib/crti.o ${sysroot}/lib/crtn.o ${sysroot}/lib/libm.a ${sysroot}/lib/libc++.a
     COMMAND cmake -E copy ${loader_object_file} ${loader_dst}
-    DEPENDS ${INTEGRATION_TEST_LOADER}
+    COMMAND cmake -E copy ${crti_object_file} ${sysroot}/lib
+    COMMAND cmake -E copy ${crtn_object_file} ${sysroot}/lib
+    # We copy the dummy archive as libm.a and libc++.a as the compiler drivers expect them.
+    COMMAND cmake -E copy ${dummy_archive} ${sysroot}/lib/libm.a
+    COMMAND cmake -E copy ${dummy_archive} ${sysroot}/lib/libc++.a
+    DEPENDS ${INTEGRATION_TEST_LOADER} libc.loader.linux.crti libc.loader.linux.crtn libc_integration_test_dummy
   )
   add_custom_target(
     ${fq_target_name}.__copy_loader__
@@ -374,6 +380,8 @@ function(add_integration_test test_name)
     ${INTEGRATION_TEST_SRCS}
     ${INTEGRATION_TEST_HDRS}
   )
+  set_target_properties(${fq_target_name}
+      PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
   target_include_directories(
     ${fq_target_name}
     PRIVATE

diff  --git a/libc/loader/linux/CMakeLists.txt b/libc/loader/linux/CMakeLists.txt
index 1454abd9fabad..b803945097b57 100644
--- a/libc/loader/linux/CMakeLists.txt
+++ b/libc/loader/linux/CMakeLists.txt
@@ -71,3 +71,15 @@ add_loader_object(
   DEPENDS
     .${LIBC_TARGET_ARCHITECTURE}.crt1
 )
+
+add_loader_object(
+  crti
+  SRC
+    crti.cpp
+)
+
+add_loader_object(
+  crtn
+  SRC
+    crtn.cpp
+)

diff  --git a/libc/loader/linux/crti.cpp b/libc/loader/linux/crti.cpp
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/libc/loader/linux/crtn.cpp b/libc/loader/linux/crtn.cpp
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/libc/test/CMakeLists.txt b/libc/test/CMakeLists.txt
index 181d5cc336ecf..85f89024d0f63 100644
--- a/libc/test/CMakeLists.txt
+++ b/libc/test/CMakeLists.txt
@@ -18,4 +18,8 @@ if(NOT LLVM_LIBC_FULL_BUILD)
   return()
 endif()
 
+if(NOT (${LIBC_TARGET_OS} STREQUAL "linux"))
+  # Integration tests are currently only available for linux.
+  return()
+endif()
 add_subdirectory(integration)

diff  --git a/libc/test/integration/CMakeLists.txt b/libc/test/integration/CMakeLists.txt
index 336cf4fb23534..393084d122aad 100644
--- a/libc/test/integration/CMakeLists.txt
+++ b/libc/test/integration/CMakeLists.txt
@@ -1,5 +1,15 @@
 add_custom_target(libc-integration-tests)
 
+add_library(
+  libc_integration_test_dummy
+  STATIC
+  dummy.cpp
+)
+set_target_properties(libc_integration_test_dummy
+    PROPERTIES
+      ARCHIVE_OUTPUT_NAME dummy
+      ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+
 add_subdirectory(loader)
 add_subdirectory(scudo)
 add_subdirectory(src)

diff  --git a/libc/test/integration/dummy.cpp b/libc/test/integration/dummy.cpp
new file mode 100644
index 0000000000000..e69de29bb2d1d


        


More information about the libc-commits mailing list