[Tarantool-patches] [PATCH luajit 24/25] test: enable <catch_wrap.lua> LuaJIT test

Sergey Kaplun skaplun at tarantool.org
Fri Jan 19 14:32:47 MSK 2024


This patch moves the <catch_wrap.lua> test from the <misc> to <lang>
directory, includes it in <index>, and names subtests. Also, since the
tests may be shuffled, `cp.wrapon()` and `cp.wrapoff()` are used for
each test separately. Also, this patch adds a workaround for the
internal ASAN bug, see details in the comment in the <CMakeLists.txt>.

Part of tarantool/tarantool#9398
---
 test/LuaJIT-tests/CMakeLists.txt              | 16 ++++++++++
 .../{misc => lang}/catch_wrap.lua             | 29 +++++++++++++------
 test/LuaJIT-tests/lang/index                  |  1 +
 3 files changed, 37 insertions(+), 9 deletions(-)
 rename test/LuaJIT-tests/{misc => lang}/catch_wrap.lua (74%)

diff --git a/test/LuaJIT-tests/CMakeLists.txt b/test/LuaJIT-tests/CMakeLists.txt
index c52bcc71..8ecfe3f6 100644
--- a/test/LuaJIT-tests/CMakeLists.txt
+++ b/test/LuaJIT-tests/CMakeLists.txt
@@ -24,6 +24,22 @@ else()
   list(APPEND LUAJIT_TESTS_ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}")
 endif()
 
+if(LUAJIT_USE_ASAN)
+  # When running LuaJIT-tests under ASAN, the internal ASAN check
+  # failed:
+  # AddressSanitizer: CHECK failed: asan_interceptors.cpp:356
+  # "((__interception::real___cxa_throw)) != (0)" (0x0, 0x0)
+  # This is a workaround suggested at
+  # https://github.com/google/sanitizers/issues/934.
+  execute_process(
+    COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=libstdc++.so
+    OUTPUT_VARIABLE LIB_STDCPP
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+  )
+  # Fortunately, we are not interested in macOS here.
+  list(APPEND LUAJIT_TESTS_ENV LD_PRELOAD="${LIB_STDCPP}")
+endif()
+
 add_custom_command(TARGET LuaJIT-tests
   COMMENT "Running LuaJIT-tests"
   COMMAND
diff --git a/test/LuaJIT-tests/misc/catch_wrap.lua b/test/LuaJIT-tests/lang/catch_wrap.lua
similarity index 74%
rename from test/LuaJIT-tests/misc/catch_wrap.lua
rename to test/LuaJIT-tests/lang/catch_wrap.lua
index 7f656bcc..fa54cd67 100644
--- a/test/LuaJIT-tests/misc/catch_wrap.lua
+++ b/test/LuaJIT-tests/lang/catch_wrap.lua
@@ -1,45 +1,56 @@
-
 local cp = require("cpptest")
-cp.wrapon()
 
-do
+local unwind
+
+do --- catch, no error
+  cp.wrapon()
   local a, b = pcall(cp.catch, function() return "x" end)
   assert(a == true and b == "x")
+  cp.wrapoff()
 end
 
-do
+do --- pcall throw
+  cp.wrapon()
   local a, b = pcall(function() cp.throw("foo") end)
   assert(a == false and b == "foo")
+  cp.wrapoff()
 end
 
-local unwind
-do
+do --- catch throw
+  cp.wrapon()
   local a, b = pcall(cp.catch, function() cp.throw("foo") end)
   unwind = a
   assert((a == false and b == "foo") or (a == true and b == "catch ..."))
+  cp.wrapoff()
 end
 
-do
+do --- alloc, no error
+  cp.wrapon()
   local st = cp.alloc(function() return cp.isalloc() end)
   assert(st == true)
   assert(cp.isalloc() == false)
+  cp.wrapoff()
 end
 
-do
+do --- throw in alloc
+  cp.wrapon()
   local a, b = pcall(cp.alloc, function()
     assert(cp.isalloc() == true)
     return "foo", cp.throw
   end)
   assert(a == false and b == "foo")
   assert(cp.isalloc() == false)
+  cp.wrapoff()
 end
 
-do
+do --- error in alloc
+  cp.wrapon()
   local a, b = pcall(cp.alloc, function()
     assert(cp.isalloc() == true)
     return "foo", error
   end)
   assert(a == false and b == "foo")
   if unwind then assert(cp.isalloc() == false) end
+  cp.wrapoff()
 end
 
diff --git a/test/LuaJIT-tests/lang/index b/test/LuaJIT-tests/lang/index
index dc0c2e14..87b0c5a0 100644
--- a/test/LuaJIT-tests/lang/index
+++ b/test/LuaJIT-tests/lang/index
@@ -1,6 +1,7 @@
 andor.lua
 api_call.lua
 assignment.lua
+catch_wrap.lua
 compare.lua
 compare_nan.lua
 constant
-- 
2.43.0



More information about the Tarantool-patches mailing list