Skip to content

Commit 623e55c

Browse files
committed
test: fix LuaJIT-tests for old libc version
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)
1 parent a1e596e commit 623e55c

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ separate_arguments(LUAJIT_TEST_COMMAND)
7373

7474
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
7575
include(AddTestLib)
76+
include(GetLibCVersion)
7677
include(LibRealPath)
7778

7879
# CTEST_FLAGS is used by CMake targets in test suites.

test/LuaJIT-tests/CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ if(CMAKE_C_FLAGS MATCHES "-march=skylake-avx512")
6262
list(APPEND LUAJIT_TEST_TAGS_EXTRA +avx512)
6363
endif()
6464

65+
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
66+
GetLibCVersion(LIBC_VERSION)
67+
# XXX: <tonumber_scan.lua> uses `strtod()`, old versions of
68+
# which have the bug [1] for "0x1p-2075" parsing. Add the skip
69+
# check for it.
70+
# [1]: https://sourceware.org/bugzilla/show_bug.cgi?id=16151
71+
list(APPEND LUAJIT_TEST_TAGS_EXTRA +libc=${LIBC_VERSION})
72+
endif()
73+
6574
set(TEST_SUITE_NAME "LuaJIT-tests")
6675

6776
# XXX: The call produces both test and target <LuaJIT-tests-deps>

test/LuaJIT-tests/lib/base/tonumber_scan.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ do --- tonumber parsing
186186
test_conv(tonumber)
187187
end
188188

189-
do --- strtod parsing
189+
-- Skip for the old libc version with the bug in the `strtod()`.
190+
-- See also https://sourceware.org/bugzilla/show_bug.cgi?id=16151.
191+
do --- strtod parsing -libc<2.19
190192
test_conv(function(s)
191193
local d = ffi.C.strtod(s, e)
192194
return (e[0][0] == 0 and #s ~= 0) and d or nil

test/cmake/GetLibCVersion.cmake

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Get the libc version installed in the system.
2+
macro(GetLibCVersion output)
3+
find_program(ECHO echo)
4+
if(NOT ECHO)
5+
message(FATAL_ERROR "`echo' is not found")
6+
endif()
7+
# Try to directly parse the version.
8+
execute_process(
9+
COMMAND ${ECHO} "#include <gnu/libc-version.h>"
10+
COMMAND ${CMAKE_C_COMPILER} -E -dM -
11+
OUTPUT_VARIABLE LIB_C_INFO
12+
ERROR_VARIABLE ERROR_MSG
13+
OUTPUT_STRIP_TRAILING_WHITESPACE
14+
RESULT_VARIABLE RES
15+
)
16+
17+
if(NOT RES EQUAL 0)
18+
message(FATAL_ERROR
19+
"gnu/libc-version preprocessing has failed: '${ERROR_MSG}'")
20+
endif()
21+
22+
string(REGEX MATCH "__GLIBC__ ([0-9]+)" MATCH ${LIB_C_INFO})
23+
if(MATCH)
24+
set(GLIBC_MAJOR ${CMAKE_MATCH_1})
25+
else()
26+
message(FATAL_ERROR "Can't determine GLIBC_MAJOR version.")
27+
endif()
28+
29+
string(REGEX MATCH "__GLIBC_MINOR__ ([0-9]+)" MATCH ${LIB_C_INFO})
30+
if(MATCH)
31+
set(GLIBC_MINOR ${CMAKE_MATCH_1})
32+
else()
33+
message(FATAL_ERROR "Can't determine GLIBC_MINOR version.")
34+
endif()
35+
36+
set(${output} "${GLIBC_MAJOR}.${GLIBC_MINOR}")
37+
38+
unset(ECHO)
39+
unset(CMAKE_MATCH_1)
40+
unset(GLIBC_MAJOR)
41+
unset(GLIBC_MINOR)
42+
unset(MATCH)
43+
unset(RES)
44+
unset(ERROR_MSG)
45+
unset(LIB_C_INFO)
46+
endmacro()

0 commit comments

Comments
 (0)