Skip to content

Commit 8fb12a9

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 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
1 parent c265b6a commit 8fb12a9

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-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

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Get the libc version installed in the system.
2+
# XXX: uses `LibRealPath`, so unsupported for OSX.
3+
macro(GetLibCVersion output)
4+
LibRealPath(libcpath "libc.so.6")
5+
6+
# Get the version from the library name.
7+
if(libcpath MATCHES "libc-([0-9]+\.[0-9]+)\.so")
8+
set(${output} ${CMAKE_MATCH_1})
9+
else()
10+
# Try to directly run the library and parse the version from
11+
# the output message.
12+
execute_process(
13+
COMMAND ${libcpath}
14+
OUTPUT_VARIABLE LIB_C_INFO
15+
ERROR_VARIABLE ERROR_MSG
16+
OUTPUT_STRIP_TRAILING_WHITESPACE
17+
RESULT_VARIABLE RES
18+
)
19+
20+
if(NOT RES EQUAL 0)
21+
message(FATAL_ERROR "Executing '${libcpath}' has failed: '${ERROR_MSG}'")
22+
endif()
23+
24+
if(LIB_C_INFO MATCHES "^.*stable release version ([0-9]+\.[0-9]+)")
25+
set(${output} ${CMAKE_MATCH_1})
26+
else()
27+
message(FATAL_ERROR "Can't determine libc version")
28+
endif()
29+
30+
unset(RES)
31+
unset(ERROR_MSG)
32+
unset(LIB_C_INFO)
33+
endif()
34+
unset(CMAKE_MATCH_1)
35+
endmacro()

0 commit comments

Comments
 (0)