[libc-commits] [libc] c9da035 - [libc] Convert the api-test in to an integration test.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Fri Nov 4 00:10:00 PDT 2022


Author: Siva Chandra Reddy
Date: 2022-11-04T07:09:18Z
New Revision: c9da0352a3a5480492b3c99b165240862a6eb646

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

LOG: [libc] Convert the api-test in to an integration test.

It used to pass but showed an annoying message about _start not being
available. That will not happen anymore.

Added: 
    

Modified: 
    libc/cmake/modules/LLVMLibCTestRules.cmake
    libc/test/src/CMakeLists.txt
    libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp

Removed: 
    


################################################################################
diff  --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 131bbad7c9c64..5eb3d4e67b78d 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -436,24 +436,6 @@ function(add_integration_test test_name)
       libc.utils.IntegrationTest.test)
   list(REMOVE_DUPLICATES fq_deps_list)
 
-  # We don't want memory functions to be dependencies on integration tests.
-  # Memory functions should be tested using unittests. The main reason
-  # however is that compiler codegen can emit calls to memory functions. So,
-  # we add them explicitly to the integration test libc.a (see below). Adding
-  # explicit deps on the memory functions can potentially cause duplicate
-  # symbol errors.
-  set(memory_funcs "bcmp;bzero;memcmp;memcpy;memmove;memset")
-  foreach(dep IN LISTS fq_deps_list)
-    get_target_property(name ${dep} ENTRYPOINT_NAME)
-    if(NOT name)
-      continue()
-    endif()
-    list(FIND memory_funcs ${name} loc)
-    if(${loc} GREATER_EQUAL 0)
-      message(FATAL_ERROR "Memory function ${name} cannot be a dependency "
-                          "for integration tests.")
-    endif()
-  endforeach()
   # TODO: Instead of gathering internal object files from entrypoints,
   # collect the object files with public names of entrypoints.
   get_object_files_for_test(

diff  --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt
index bb5bbb1e5b34d..c4f0aab5a3808 100644
--- a/libc/test/src/CMakeLists.txt
+++ b/libc/test/src/CMakeLists.txt
@@ -88,42 +88,28 @@ add_custom_command(
           ${LIBC_TARGET}
 )
 
-add_executable(
-  libc-api-test
-  EXCLUDE_FROM_ALL
-  ${public_test}
+add_custom_target(libc-api-test)
+set(
+  allocator_entrypoints 
+    libc.src.stdlib.malloc
+    libc.src.stdlib.calloc
+    libc.src.stdlib.realloc
+    libc.src.stdlib.aligned_alloc
+    libc.src.stdlib.free
 )
-# Blank out default include directories to prevent accidentally including
-# system headers or our own internal headers.
-set_target_properties(
-  libc-api-test
-  PROPERTIES
-  INCLUDE_DIRECTORIES ""
+set(api-test-entrypoints ${TARGET_LLVMLIBC_ENTRYPOINTS})
+list(REMOVE_ITEM api-test-entrypoints ${allocator_entrypoints})
+add_integration_test(
+  api-test
+  SUITE
+    libc-api-test
+  SRCS
+    ${public_test}
+  LOADER
+    libc.loader.linux.crt1
+  DEPENDS
+    ${api-test-entrypoints}
 )
-target_link_libraries(libc-api-test ${LIBC_TARGET})
-
-# Only include we need is the include for cpp::IsSame and our generated
-# public headers.
-target_include_directories(
-  libc-api-test BEFORE
-  PRIVATE
-    "${LIBC_SOURCE_DIR}/src/__support/CPP"
-    "${LIBC_BUILD_DIR}/include"
-)
-target_compile_options(
-  libc-api-test
-  PRIVATE
-  -ffreestanding
-)
-target_link_options(
-  libc-api-test
-  PRIVATE "-nostdlib"
-)
-set(library_files)
-foreach(library_name IN LISTS "llvmlibc")
-  get_target_property(library_file ${library_name} "LIBRARY_FILE")
-  list(APPEND library_files ${library_file})
-endforeach()
 
 if(COMPILER_RESOURCE_DIR AND LLVM_LIBC_ENABLE_LINTING)
   add_custom_target(
@@ -143,8 +129,3 @@ if(COMPILER_RESOURCE_DIR AND LLVM_LIBC_ENABLE_LINTING)
   )
   add_dependencies(libc-api-test libc-api-test-tidy)
 endif()
-
-target_link_libraries(libc-api-test
-  PRIVATE
-  ${library_files}
-)

diff  --git a/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp b/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp
index cd1e61b2f35a1..340f79ac9d14d 100644
--- a/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp
+++ b/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp
@@ -22,7 +22,7 @@ llvm::cl::list<std::string>
 } // anonymous namespace
 
 bool TestGeneratorMain(llvm::raw_ostream &OS, llvm::RecordKeeper &records) {
-  OS << "#include \"type_traits.h\"\n";
+  OS << "#include \"src/__support/CPP/type_traits.h\"\n";
   llvm_libc::APIIndexer G(records);
   std::unordered_set<std::string> headerFileSet;
   for (const auto &entrypoint : EntrypointNamesOption) {
@@ -45,7 +45,7 @@ bool TestGeneratorMain(llvm::raw_ostream &OS, llvm::RecordKeeper &records) {
 
   OS << '\n';
 
-  OS << "int main() {\n";
+  OS << "extern \"C\" int main() {\n";
   for (const auto &entrypoint : EntrypointNamesOption) {
     auto match = G.FunctionSpecMap.find(entrypoint);
     if (match == G.FunctionSpecMap.end()) {


        


More information about the libc-commits mailing list