Skip to content

Commit 9712cc9

Browse files
ImeevMAigormunkin
authored andcommitted
test: adjust LuaJIT test suite for Tarantool
This patch makes it possible to run LuaJIT test suite using Tarantool. It disables these tests from the LuaJIT test suite, because _G and some modules in Tarantool are different from _G and modules in LuaJIT: * 359 lib/contents.lua --- base * 364 lib/contents.lua --- string * 366 lib/contents.lua --- pre-5.2 table * 370 lib/contents.lua --- os * 371 lib/contents.lua --- debug * 372 lib/contents.lua --- package * 374 lib/contents.lua --- package.loaders * 375 lib/contents.lua --- package.loaded There is also some difference in Tarantool runtime (such as forbidden global variables usage by default), so testing environment need to be tweaked before the testing begins. For this purpose LUAJIT_TEST_INIT CMake variable is introduced. This variable accepts the name of the Lua script to be run prior to every test chunk. Resolves tarantool/tarantool#4064 Part of tarantool/tarantool#4473 Signed-off-by: Igor Munkin <imun@tarantool.org>
1 parent 464e145 commit 9712cc9

File tree

5 files changed

+70
-33
lines changed

5 files changed

+70
-33
lines changed

CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,24 @@ set(LUAJIT_TEST_BINARY ${LUAJIT_BINARY} CACHE STRING
288288
"Lua implementation to be used for tests. Default is 'luajit'."
289289
)
290290

291+
# FIXME: If LuaJIT is used in parent project, provide an option
292+
# to pass Lua code to be run before tests are started.
293+
# XXX: Attentive reader might point to LUA_INIT environment
294+
# variable, but this is less secure way to run the particular Lua
295+
# code. As a result the application to be run against LuaJIT test
296+
# can ignore it (for more info, see the following issue).
297+
# https://github.com/tarantool/tarantool/issues/5744
298+
# XXX: This variable is used as '-e' Lua runtime flag value and
299+
# the hack works since the code passed via '-e' is executed before
300+
# the code passed via Lua script, *but* both are executed in a
301+
# single environment. Hence, if this environment need to be
302+
# tweaked, the introduced option can be used.
303+
# XXX: The default behaviour is nop, so /dev/null is the best
304+
# option for this.
305+
set(LUAJIT_TEST_INIT "/dev/null" CACHE STRING
306+
"Lua code need to be run before tests are started. Default is nop."
307+
)
308+
291309
add_subdirectory(test)
292310

293311
# --- Misc rules ---------------------------------------------------------------

test/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ else()
3232
)
3333
endif()
3434

35+
set(LUAJIT_TEST_COMMAND "${LUAJIT_TEST_BINARY} -e dofile[[${LUAJIT_TEST_INIT}]]")
36+
separate_arguments(LUAJIT_TEST_COMMAND)
37+
3538
add_subdirectory(tarantool-tests)
3639
add_subdirectory(LuaJIT-tests)
3740

test/LuaJIT-tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ add_custom_target(LuaJIT-tests DEPENDS ${LUAJIT_TEST_BINARY})
66
add_custom_command(TARGET LuaJIT-tests
77
COMMENT "Running LuaJIT-tests"
88
COMMAND
9-
${LUAJIT_TEST_BINARY} ${CMAKE_CURRENT_SOURCE_DIR}/test.lua
9+
${LUAJIT_TEST_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR}/test.lua
1010
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
1111
)

test/LuaJIT-tests/lib/contents.lua

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ local function check(m, expected, exclude)
1818
end
1919
end
2020

21-
do --- base
22-
check(_G, "_G:_VERSION:arg:assert:collectgarbage:coroutine:debug:dofile:error:getmetatable:io:ipairs:load:loadfile:math:misc:next:os:package:pairs:pcall:print:rawequal:rawget:rawset:require:select:setmetatable:string:table:tonumber:tostring:type:xpcall", "rawlen:bit:bit32:jit:gcinfo:setfenv:getfenv:loadstring:unpack:module:newproxy")
23-
end
21+
-- Test is disabled, because _G and some modules in Tarantool
22+
-- are different from _G and modules in LuaJIT.
23+
-- do
24+
-- check(_G, "_G:_VERSION:arg:assert:collectgarbage:coroutine:debug:dofile:error:getmetatable:io:ipairs:load:loadfile:math:misc:next:os:package:pairs:pcall:print:rawequal:rawget:rawset:require:select:setmetatable:string:table:tonumber:tostring:type:xpcall", "rawlen:bit:bit32:jit:gcinfo:setfenv:getfenv:loadstring:unpack:module:newproxy")
25+
-- end
2426

2527
do --- pre-5.2 base +lua<5.2
2628
assert(gcinfo)
@@ -64,9 +66,11 @@ do --- 5.2 math +lua>=5.2
6466
assert(not math.log10)
6567
end
6668

67-
do --- string
68-
check(string, "byte:char:dump:find:format:gmatch:gsub:len:lower:match:rep:reverse:sub:upper", "gfind")
69-
end
69+
-- Test is disabled for the Tarantool's binary,
70+
-- see the comment above.
71+
-- do
72+
-- check(string, "byte:char:dump:find:format:gmatch:gsub:len:lower:match:rep:reverse:sub:upper", "gfind")
73+
-- end
7074

7175
do --- pre-5.2 string +lua<5.2 -compat5.2
7276
assert(not string.gfind)
@@ -76,9 +80,11 @@ do --- 5.2 string +lua>=5.2
7680
assert(not string.gfind)
7781
end
7882

79-
do --- pre-5.2 table +lua<5.2
80-
check(table, "concat:foreach:foreachi:getn:insert:maxn:move:remove:sort", "pack:unpack:setn:new")
81-
end
83+
-- Test is disabled for the Tarantool's binary,
84+
-- see the comment above.
85+
-- do
86+
-- check(table, "concat:foreach:foreachi:getn:insert:maxn:move:remove:sort", "pack:unpack:setn:new")
87+
-- end
8288

8389
do --- 5.2 table +lua>=5.2
8490
check(table, "concat:insert:pack:remove:sort:unpack")
@@ -102,19 +108,25 @@ do --- io file
102108
check(debug.getmetatable(io.stdin), "__gc:__index:__tostring:close:flush:lines:read:seek:setvbuf:write")
103109
end
104110

105-
do --- os
106-
check(os, "clock:date:difftime:execute:exit:getenv:remove:rename:setlocale:time:tmpname")
107-
end
111+
-- Test is disabled for the Tarantool's binary,
112+
-- see the comment above.
113+
-- do
114+
-- check(os, "clock:date:difftime:execute:exit:getenv:remove:rename:setlocale:time:tmpname")
115+
-- end
108116

109-
do --- debug
110-
check(debug, "debug:gethook:getinfo:getlocal:getmetatable:getregistry:getupvalue:sethook:setlocal:setmetatable:setupvalue:traceback", "getfenv:setfenv:upvalueid:upvaluejoin:getuservalue:setuservalue")
111-
end
117+
-- Test is disabled for the Tarantool's binary,
118+
-- see the comment above.
119+
-- do
120+
-- check(debug, "debug:gethook:getinfo:getlocal:getmetatable:getregistry:getupvalue:sethook:setlocal:setmetatable:setupvalue:traceback", "getfenv:setfenv:upvalueid:upvaluejoin:getuservalue:setuservalue")
121+
-- end
112122

113123
-- TODO: Check versional differences in debug library
114124

115-
do --- package
116-
check(package, "config:cpath:loaded:loadlib:path:preload", "searchpath:loaders:searchers:seeall")
117-
end
125+
-- Test is disabled for the Tarantool's binary,
126+
-- see the comment above.
127+
-- do
128+
-- check(package, "config:cpath:loaded:loadlib:path:preload", "searchpath:loaders:searchers:seeall")
129+
-- end
118130

119131
do --- pre-5.2 package +lua<5.2
120132
assert(package.loaders)
@@ -128,19 +140,23 @@ do --- 5.2 package +lua>=5.2
128140
assert(not package.seeall)
129141
end
130142

131-
do --- package.loaders
132-
check(package.loaders or package.searchers, "1:2:3:4")
133-
end
134-
135-
do --- package.loaded
136-
local loaded = {}
137-
for k, v in pairs(package.loaded) do
138-
if type(k) ~= "string" or (k:sub(1, 7) ~= "common." and k:sub(1, 4) ~= "jit.") then
139-
loaded[k] = v
140-
end
141-
end
142-
check(loaded, "_G:coroutine:debug:io:math:misc:misc.memprof:os:package:string:table", "bit:bit32:common:ffi:jit:table.new")
143-
end
143+
-- Test is disabled for the Tarantool's binary,
144+
-- see the comment above.
145+
-- do
146+
-- check(package.loaders or package.searchers, "1:2:3:4")
147+
-- end
148+
149+
-- Test is disabled for the Tarantool's binary,
150+
-- see the comment above.
151+
-- do
152+
-- local loaded = {}
153+
-- for k, v in pairs(package.loaded) do
154+
-- if type(k) ~= "string" or (k:sub(1, 7) ~= "common." and k:sub(1, 4) ~= "jit.") then
155+
-- loaded[k] = v
156+
-- end
157+
-- end
158+
-- check(loaded, "_G:coroutine:debug:io:math:misc:misc.memprof:os:package:string:table", "bit:bit32:common:ffi:jit:table.new")
159+
-- end
144160

145161
do --- bit +bit
146162
check(bit, "arshift:band:bnot:bor:bswap:bxor:lshift:rol:ror:rshift:tobit:tohex")

test/tarantool-tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ add_custom_command(TARGET tarantool-tests
8888
LUA_CPATH="${LUA_CPATH}\;\;"
8989
LD_LIBRARY_PATH="${LD_LIBRARY_PATH}"
9090
${PROVE} ${CMAKE_CURRENT_SOURCE_DIR}
91-
--exec ${LUAJIT_TEST_BINARY}
91+
--exec '${LUAJIT_TEST_COMMAND}'
9292
--ext ${LUA_TEST_SUFFIX}
9393
${LUA_TEST_FLAGS}
9494
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}

0 commit comments

Comments
 (0)