This is an archive of the discontinued LLVM Phabricator instance.

[libc][NFC] Put definitions of stdout and friends into their own object files.
ClosedPublic

Authored by sivachandra on Aug 17 2023, 8:58 AM.

Details

Summary

This is done so that tests which only require platform file but not the
platform streams can be run as unit tests. The tests which use platform
streams can only be hermetic tests to avoid conflicts with the
system-libc streams.

Fixes:
https://github.com/llvm/llvm-project/issues/64663
https://github.com/llvm/llvm-project/issues/63558

Diff Detail

Event Timeline

sivachandra created this revision.Aug 17 2023, 8:58 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 17 2023, 8:58 AM
sivachandra requested review of this revision.Aug 17 2023, 8:58 AM

Here's a list of changes I had to make to get all tests passing with a local build, I use glibc version 2.37

diff --git a/libc/test/src/__support/File/CMakeLists.txt b/libc/test/src/__support/File/CMakeLists.txt
index 5ef8de1d6f7a..8b00427ae1ae 100644
--- a/libc/test/src/__support/File/CMakeLists.txt
+++ b/libc/test/src/__support/File/CMakeLists.txt
@@ -34,6 +34,7 @@ foreach(target IN LISTS platform_file_targets)
         libc.src.__support.File.file
         libc.src.__support.File.${target}
         libc.include.stdio
+      HERMETIC_TEST_ONLY
     )
   endif()
 endforeach()
diff --git a/libc/test/src/stdio/CMakeLists.txt b/libc/test/src/stdio/CMakeLists.txt
index f29c21079959..ccdf778475ec 100644
--- a/libc/test/src/stdio/CMakeLists.txt
+++ b/libc/test/src/stdio/CMakeLists.txt
@@ -151,75 +151,6 @@ else()
  set(fprintf_test_copts "-DLIBC_COPT_PRINTF_USE_SYSTEM_FILE")
 endif()
 
-add_libc_unittest(
-  fprintf_test
-  SUITE
-    libc_stdio_unittests
-  SRCS
-    fprintf_test.cpp
-  DEPENDS
-    libc.src.stdio.fprintf
-    ${fprintf_test_deps}
-  COMPILE_OPTIONS
-    ${fprintf_test_copts}
-)
-
-add_libc_unittest(
-  printf_test
-  ${hermetic_test_only}
-  SUITE
-    libc_stdio_unittests
-  SRCS
-    printf_test.cpp
-  DEPENDS
-    libc.src.stdio.printf
-)
-
-add_fp_unittest(
-  vsprintf_test
-  UNIT_TEST_ONLY
-  SUITE
-    libc_stdio_unittests
-  SRCS
-    vsprintf_test.cpp
-  DEPENDS
-    libc.src.stdio.vsprintf
-)
-
-add_libc_unittest(
-  vsnprintf_test
-  SUITE
-    libc_stdio_unittests
-  SRCS
-    vsnprintf_test.cpp
-  DEPENDS
-    libc.src.stdio.vsnprintf
-)
-
-add_libc_unittest(
-  vfprintf_test
-  SUITE
-    libc_stdio_unittests
-  SRCS
-    vfprintf_test.cpp
-  DEPENDS
-    libc.src.stdio.vfprintf
-    ${fprintf_test_deps}
-  COMPILE_OPTIONS
-    ${fprintf_test_copts}
-)
-
-add_libc_unittest(
-  vprintf_test
-  ${hermetic_test_only}
-  SUITE
-    libc_stdio_unittests
-  SRCS
-    vprintf_test.cpp
-  DEPENDS
-    libc.src.stdio.vprintf
-)
-
 add_libc_unittest(
   fscanf_test
   SUITE
diff --git a/libc/test/src/unistd/CMakeLists.txt b/libc/test/src/unistd/CMakeLists.txt
index ceee888669b7..ca2b1b05ba18 100644
--- a/libc/test/src/unistd/CMakeLists.txt
+++ b/libc/test/src/unistd/CMakeLists.txt
@@ -429,16 +429,3 @@ add_libc_unittest(
     libc.include.unistd
     libc.src.unistd.sysconf
 )
-
-add_libc_unittest(
-  getopt_test
-  SUITE
-    libc_unistd_unittests
-  SRCS
-    getopt_test.cpp
-  DEPENDS
-    libc.src.unistd.getopt
-    libc.src.__support.CPP.array
-    libc.src.stdio.fopencookie
-    libc.src.stdio.fflush
-)

The platform file tests need to be made hermetic as they link in the libc file handle which overrides it. The other tests that fail are all the printf variants and getopt weirdly enough. I think the common factor here is fflush? Since when I ran the debugger it seemed to crash somewhere in that call to the system libc.

Mark more tests are hermetic only.

sivachandra edited the summary of this revision. (Show Details)Aug 17 2023, 9:48 AM
sivachandra edited the summary of this revision. (Show Details)Aug 17 2023, 9:56 AM

This also fixes the crash I'm seeing in rv32 with glibc 2.37

sivachandra edited the summary of this revision. (Show Details)

Remove the use of function static variables in getopt_test so that it can be a hermetic test.

jhuber6 accepted this revision.Aug 17 2023, 11:24 AM

Fixes all the issues, thanks.

This revision is now accepted and ready to land.Aug 17 2023, 11:24 AM