Skip to content

Commit

Permalink
test: fix LuaJIT-tests for old libc version
Browse files Browse the repository at this point in the history
The `strtod parsing` subtest in the <lib/base/tonumber_scan.lua> checks
the results yielded by the `strtod()` via FFI call. In GLibc versions
before 2.19 it returns an incorrect result for "0x1p-2075" [1]. This
patch skips this test for a smaller version of the libc installed.

[1]: https://sourceware.org/bugzilla/show_bug.cgi?id=16151

Reviewed-by: Maxim Kokryashkin <[email protected]>
Reviewed-by: Sergey Bronnikov <[email protected]>
Signed-off-by: Sergey Kaplun <[email protected]>
(cherry picked from commit af0f59d)
  • Loading branch information
Buristan committed Dec 12, 2024
1 parent a1e596e commit 623e55c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions test/LuaJIT-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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: <tonumber_scan.lua> 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 <LuaJIT-tests-deps>
Expand Down
4 changes: 3 additions & 1 deletion test/LuaJIT-tests/lib/base/tonumber_scan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions test/cmake/GetLibCVersion.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Get the libc version installed in the system.
macro(GetLibCVersion output)
find_program(ECHO echo)
if(NOT ECHO)
message(FATAL_ERROR "`echo' is not found")
endif()
# Try to directly parse the version.
execute_process(
COMMAND ${ECHO} "#include <gnu/libc-version.h>"
COMMAND ${CMAKE_C_COMPILER} -E -dM -
OUTPUT_VARIABLE LIB_C_INFO
ERROR_VARIABLE ERROR_MSG
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE RES
)

if(NOT RES EQUAL 0)
message(FATAL_ERROR
"gnu/libc-version preprocessing has failed: '${ERROR_MSG}'")
endif()

string(REGEX MATCH "__GLIBC__ ([0-9]+)" MATCH ${LIB_C_INFO})
if(MATCH)
set(GLIBC_MAJOR ${CMAKE_MATCH_1})
else()
message(FATAL_ERROR "Can't determine GLIBC_MAJOR version.")
endif()

string(REGEX MATCH "__GLIBC_MINOR__ ([0-9]+)" MATCH ${LIB_C_INFO})
if(MATCH)
set(GLIBC_MINOR ${CMAKE_MATCH_1})
else()
message(FATAL_ERROR "Can't determine GLIBC_MINOR version.")
endif()

set(${output} "${GLIBC_MAJOR}.${GLIBC_MINOR}")

unset(ECHO)
unset(CMAKE_MATCH_1)
unset(GLIBC_MAJOR)
unset(GLIBC_MINOR)
unset(MATCH)
unset(RES)
unset(ERROR_MSG)
unset(LIB_C_INFO)
endmacro()

0 comments on commit 623e55c

Please sign in to comment.