diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0db2dd8ba5..be02d2e49c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -73,6 +73,7 @@ separate_arguments(LUAJIT_TEST_COMMAND) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(AddTestLib) +include(GetLibCVersion) include(LibRealPath) # CTEST_FLAGS is used by CMake targets in test suites. diff --git a/test/LuaJIT-tests/CMakeLists.txt b/test/LuaJIT-tests/CMakeLists.txt index 019762e025..d0771e144b 100644 --- a/test/LuaJIT-tests/CMakeLists.txt +++ b/test/LuaJIT-tests/CMakeLists.txt @@ -62,6 +62,15 @@ if(CMAKE_C_FLAGS MATCHES "-march=skylake-avx512") list(APPEND LUAJIT_TEST_TAGS_EXTRA +avx512) endif() +if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin") + GetLibCVersion(LIBC_VERSION) + # XXX: uses `strtod()`, old versions of + # which have the bug [1] for "0x1p-2075" parsing. Add the skip + # check for it. + # [1]: https://sourceware.org/bugzilla/show_bug.cgi?id=16151 + list(APPEND LUAJIT_TEST_TAGS_EXTRA +libc=${LIBC_VERSION}) +endif() + set(TEST_SUITE_NAME "LuaJIT-tests") # XXX: The call produces both test and target diff --git a/test/LuaJIT-tests/lib/base/tonumber_scan.lua b/test/LuaJIT-tests/lib/base/tonumber_scan.lua index e2dcd4d0c0..ac7d68a4d8 100644 --- a/test/LuaJIT-tests/lib/base/tonumber_scan.lua +++ b/test/LuaJIT-tests/lib/base/tonumber_scan.lua @@ -186,7 +186,9 @@ do --- tonumber parsing test_conv(tonumber) end -do --- strtod parsing +-- Skip for the old libc version with the bug in the `strtod()`. +-- See also https://sourceware.org/bugzilla/show_bug.cgi?id=16151. +do --- strtod parsing -libc<2.19 test_conv(function(s) local d = ffi.C.strtod(s, e) return (e[0][0] == 0 and #s ~= 0) and d or nil diff --git a/test/cmake/GetLibCVersion.cmake b/test/cmake/GetLibCVersion.cmake new file mode 100644 index 0000000000..fd05fa6d89 --- /dev/null +++ b/test/cmake/GetLibCVersion.cmake @@ -0,0 +1,35 @@ +# Get the libc version installed in the system. +# XXX: uses `LibRealPath`, so unsupported for OSX. +macro(GetLibCVersion output) + LibRealPath(libcpath "libc.so.6") + + # Get the version from the library name. + if(libcpath MATCHES "libc-([0-9]+\.[0-9]+)\.so") + set(${output} ${CMAKE_MATCH_1}) + else() + # Try to directly run the library and parse the version from + # the output message. + execute_process( + COMMAND ${libcpath} + OUTPUT_VARIABLE LIB_C_INFO + ERROR_VARIABLE ERROR_MSG + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE RES + ) + + if(NOT RES EQUAL 0) + message(FATAL_ERROR "Executing '${libcpath}' has failed: '${ERROR_MSG}'") + endif() + + if(LIB_C_INFO MATCHES "^.*stable release version ([0-9]+\.[0-9]+)") + set(${output} ${CMAKE_MATCH_1}) + else() + message(FATAL_ERROR "Can't determine libc version") + endif() + + unset(RES) + unset(ERROR_MSG) + unset(LIB_C_INFO) + endif() + unset(CMAKE_MATCH_1) +endmacro()