[Tarantool-patches] [PATCH luajit 3/3] test: adapt Lua 5.1 test suite for Tarantool

Sergey Kaplun skaplun at tarantool.org
Fri Mar 12 08:36:24 MSK 2021


In some insignificant details Tarantool's behaviour is not the same
as the behaviour of Lua 5.1.

`progname` is not edged by '"' to be able run other test suites.

Tests in the following files are disabled with corresponding comments:
* gc.lua
* main.lua
* pm.lua

See full list of disabled tests to adapt in
https://github.com/tarantool/tarantool/issues/5870.

Tests in the following files are adapted for testing with Tarantool's
out-of-source build:
* all.lua
* verybig.lua

Part of tarantool/tarantool#5845
Part of tarantool/tarantool#4473
---
 test/PUC-Lua-5.1-tests/CMakeLists.txt |  3 +++
 test/PUC-Lua-5.1-tests/all.lua        | 16 ++++++++++++----
 test/PUC-Lua-5.1-tests/gc.lua         |  9 ++++++---
 test/PUC-Lua-5.1-tests/main.lua       | 24 +++++++++++++++++-------
 test/PUC-Lua-5.1-tests/pm.lua         |  6 +++++-
 test/PUC-Lua-5.1-tests/verybig.lua    |  4 +++-
 6 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/test/PUC-Lua-5.1-tests/CMakeLists.txt b/test/PUC-Lua-5.1-tests/CMakeLists.txt
index 08bee36..1249cab 100644
--- a/test/PUC-Lua-5.1-tests/CMakeLists.txt
+++ b/test/PUC-Lua-5.1-tests/CMakeLists.txt
@@ -82,6 +82,9 @@ add_custom_command(TARGET PUC-Lua-5.1-tests
     # LUA_INIT="package.path='?\;'..package.path"
     # So use less preferable way for tests.
     LUA_PATH="${LUA_PATH}\;\;"
+    # XXX: Adapt to run test on readonly file systems
+    # with loadfile(CUR_SOURCE_DIR..filename).
+    CUR_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}
     ${LUAJIT_TEST_COMMAND} ${TEST_RUNNER}
   WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
 )
diff --git a/test/PUC-Lua-5.1-tests/all.lua b/test/PUC-Lua-5.1-tests/all.lua
index 8c4afac..52a6235 100755
--- a/test/PUC-Lua-5.1-tests/all.lua
+++ b/test/PUC-Lua-5.1-tests/all.lua
@@ -58,9 +58,13 @@ end
 --
 -- redefine dofile to run files through dump/undump
 --
-dofile = function (n)
+-- Adapt test for testing with Tarantool's out-of-source build
+-- on read only file system. CUR_SOURCE_DIR is set via CMake.
+local path_to_sources = os.getenv('CUR_SOURCE_DIR')..'/'
+dofile = function (n, prefix)
+  local pr = prefix or path_to_sources
   showmem()
-  local f = assert(loadfile(n))
+  local f = assert(loadfile(pr..n))
   local b = string.dump(f)
   f = assert(loadstring(b))
   return f()
@@ -77,7 +81,9 @@ do
   end
 end
 
-local f = assert(loadfile('gc.lua'))
+-- Adapt test for testing with Tarantool's out-of-source build
+-- on read only file system.
+local f = assert(loadfile(path_to_sources..'gc.lua'))
 f()
 dofile('db.lua')
 assert(dofile('calls.lua') == deep and deep)
@@ -88,7 +94,9 @@ assert(dofile('locals.lua') == 5)
 dofile('constructs.lua')
 dofile('code.lua')
 do
-  local f = coroutine.wrap(assert(loadfile('big.lua')))
+  -- Adapt test for testing with Tarantool's out-of-source build
+  -- on read only file system.
+  local f = coroutine.wrap(assert(loadfile(path_to_sources..'big.lua')))
   assert(f() == 'b')
   assert(f() == 'a')
 end
diff --git a/test/PUC-Lua-5.1-tests/gc.lua b/test/PUC-Lua-5.1-tests/gc.lua
index b767104..6c4097a 100644
--- a/test/PUC-Lua-5.1-tests/gc.lua
+++ b/test/PUC-Lua-5.1-tests/gc.lua
@@ -128,9 +128,12 @@ do
     local a = {}
   until gcinfo() > 1000
   collectgarbage"restart"
-  repeat
-    local a = {}
-  until gcinfo() < 1000
+  -- Tarantool has too much objects at start.
+  -- gcinfo() is always greater than 1000.
+  -- Test is disabled for Tarantool binary.
+  -- repeat
+  --   local a = {}
+  -- until gcinfo() < 1000
 end
 
 lim = 15
diff --git a/test/PUC-Lua-5.1-tests/main.lua b/test/PUC-Lua-5.1-tests/main.lua
index 12f3981..69eb5db 100644
--- a/test/PUC-Lua-5.1-tests/main.lua
+++ b/test/PUC-Lua-5.1-tests/main.lua
@@ -11,7 +11,7 @@ out = os.tmpname()
 do
   local i = 0
   while arg[i] do i=i-1 end
-  progname = '"'..arg[i+1]..'"'
+  progname = arg[i+1]
 end
 print(progname)
 
@@ -50,8 +50,10 @@ end
 -- test 2 files
 prepfile("print(1); a=2")
 prepfile("print(a)", otherprog)
-RUN("lua -l %s -l%s -lstring -l io %s > %s", prog, otherprog, otherprog, out)
-checkout("1\n2\n2\n")
+-- Test is disabled for Tarantool binary.
+-- See https://github.com/tarantool/tarantool/issues/5747.
+-- RUN("lua -l %s -l%s -lstring -l io %s > %s", prog, otherprog, otherprog, out)
+-- checkout("1\n2\n2\n")
 
 local a = [[
   assert(table.getn(arg) == 3 and arg[1] == 'a' and
@@ -63,7 +65,10 @@ local a = [[
 ]]
 a = string.format(a, progname)
 prepfile(a)
-RUN('lua "-e " -- %s a b c', prog)
+-- Tarantool has different command line argument parsing.
+-- For example it always set itself as arg[-1].
+-- Test is disabled for Tarantool binary.
+-- RUN('lua "-e " -- %s a b c', prog)
 
 -- test 'arg' availability in libraries
 -- LuaJIT v2.1.0-beta3 has extension from Lua 5.3:
@@ -85,8 +90,10 @@ prepfile[[print(({...})[30])]]
 RUN("lua %s %s > %s", prog, string.rep(" a", 30), out)
 checkout("a\n")
 
-RUN([[lua "-eprint(1)" -ea=3 -e "print(a)" > %s]], out)
-checkout("1\n3\n")
+-- Test is disabled for Tarantool binary.
+-- See https://github.com/tarantool/tarantool/issues/5747.
+-- RUN([[lua "-eprint(1)" -ea=3 -e "print(a)" > %s]], out)
+-- checkout("1\n3\n")
 
 prepfile[[
   print(
@@ -177,7 +184,10 @@ assert(not os.remove(out))
 
 RUN("lua -v")
 
-NoRun("lua -h")
+-- Tarantool returns zero status at exit with -h option, unlike
+-- Lua does.
+-- Test is disabled for Tarantool binary.
+-- NoRun("lua -h")
 NoRun("lua -e")
 NoRun("lua -e a")
 NoRun("lua -f")
diff --git a/test/PUC-Lua-5.1-tests/pm.lua b/test/PUC-Lua-5.1-tests/pm.lua
index 366a31c..6e1b403 100644
--- a/test/PUC-Lua-5.1-tests/pm.lua
+++ b/test/PUC-Lua-5.1-tests/pm.lua
@@ -207,7 +207,11 @@ function rev (s)
 end
 
 local x = string.rep('012345', 10)
-assert(rev(rev(x)) == x)
+-- The first Tarantool's fiber has only 512Kb of stack.
+-- It is not enough for this recursive call.
+-- See also https://github.com/tarantool/tarantool/issues/5782.
+-- Test is disabled for Tarantool binary.
+-- assert(rev(rev(x)) == x)
 
 
 -- gsub with tables
diff --git a/test/PUC-Lua-5.1-tests/verybig.lua b/test/PUC-Lua-5.1-tests/verybig.lua
index 59e0142..bfb95df 100644
--- a/test/PUC-Lua-5.1-tests/verybig.lua
+++ b/test/PUC-Lua-5.1-tests/verybig.lua
@@ -93,7 +93,9 @@ for s in string.gmatch(prog, "$([^$]+)") do
   if not n then io.write(s) else F[n]() end
 end
 io.close()
-result = dofile(file)
+-- Adapt test for testing with Tarantool's out-of-source build
+-- on read only file system.
+result = dofile(file, "")
 assert(os.remove(file))
 print'OK'
 return result
-- 
2.28.0



More information about the Tarantool-patches mailing list