Parcourir la source

Meta+test262-runner: Check for signature of __assert_fail in CMake

Rather than trying to assume the only two C libraries on Linux are musl
and glibc, this solution fixes musl builds by explicitly checking for
the one C library function we are overwriting.

That being said, we should find another solution to retrieving this
error information from crashing tests. Possibly just overriding the
SIGABRT handler would work. The full solution might require checking
stderr as well as stdout in the test driver though.
Andrew Kaster il y a 2 ans
Parent
commit
c0542ed40b
2 fichiers modifiés avec 20 ajouts et 1 suppressions
  1. 16 0
      Meta/Lagom/CMakeLists.txt
  2. 4 1
      Tests/LibJS/test262-runner.cpp

+ 16 - 0
Meta/Lagom/CMakeLists.txt

@@ -497,6 +497,22 @@ if (BUILD_LAGOM)
         add_executable(test262-runner ../../Tests/LibJS/test262-runner.cpp)
         target_link_libraries(test262-runner LibJS LibCore)
 
+        if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
+            include(CheckCSourceCompiles)
+            # Check for musl's declaration of __assert_fail
+            check_c_source_compiles(
+                "
+                #include <assert.h>
+                __attribute__((__noreturn__)) void __assert_fail(char const* assertion, char const* file, int line, char const* function) {}
+                int main() {}
+                "
+                ASSERT_FAIL_HAS_INT
+            )
+        endif()
+        if (ASSERT_FAIL_HAS_INT OR EMSCRIPTEN)
+            target_compile_definitions(test262-runner PRIVATE ASSERT_FAIL_HAS_INT)
+        endif()
+
         add_executable(wasm ../../Userland/Utilities/wasm.cpp)
         target_link_libraries(wasm LibCore LibWasm LibLine LibMain)
 

+ 4 - 1
Tests/LibJS/test262-runner.cpp

@@ -556,13 +556,16 @@ static bool g_in_assert = false;
     exit(12);
 }
 
+// FIXME: Use a SIGABRT handler here instead of overriding internal libc assertion handlers.
+//        Fixing this will likely require updating the test driver as well to pull the assertion failure
+//        message out of stderr rather than from the json object printed to stdout.
 #ifdef AK_OS_SERENITY
 void __assertion_failed(char const* assertion)
 {
     handle_failed_assert(assertion);
 }
 #else
-#    ifdef AK_OS_EMSCRIPTEN
+#    ifdef ASSERT_FAIL_HAS_INT /* Set by CMake */
 extern "C" __attribute__((__noreturn__)) void __assert_fail(char const* assertion, char const* file, int line, char const* function)
 #    else
 extern "C" __attribute__((__noreturn__)) void __assert_fail(char const* assertion, char const* file, unsigned int line, char const* function)