Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH luajit] test: adapt tests checking debug line hook trace
@ 2021-09-24 16:27 Maxim Kokryashkin via Tarantool-patches
  2021-10-11 15:19 ` Sergey Kaplun via Tarantool-patches
  0 siblings, 1 reply; 2+ messages in thread
From: Maxim Kokryashkin via Tarantool-patches @ 2021-09-24 16:27 UTC (permalink / raw)
  To: tarantool-patches, imun, skaplun

The LuaJIT's virtual machine interprets the bytecode
following the return from function (i.e. the one succeeding
the call made) and located on the line other than that return
bytecode, as a new line trigger for line hooks, unlike Lua
does.
Here is an example (it is joined in one line intend):

debug.sethook(function(_, l) print("LINE: "..l) end, "l") loadstring("\n\ns=nil")() debug.sethook()

This chunk prints for LuaJIT:

LINE: 3
LINE: 1

But for Lua 5.1 it is only "LINE: 3" in the output.
See also https://github.com/tarantool/tarantool/issues/5693.
Considering implementation-defined behaviour difference
(see also https://luajit.org/status.html) test is disabled for
LuaJIT.

Closes tarantool/tarantool#5693
Part of tarantool/tarantool#5845
Part of tarantool/tarantool#4473
---
Issue: https://github.com/tarantool/tarantool/issues/5693
GitHub branch: https://github.com/tarantool/luajit/tree/fckxorg/gh-5693-PUC-Rio-debug-line-hook

 test/PUC-Rio-Lua-5.1-tests/db.lua | 54 ++++++++++++++++---------------
 1 file changed, 28 insertions(+), 26 deletions(-)

diff --git a/test/PUC-Rio-Lua-5.1-tests/db.lua b/test/PUC-Rio-Lua-5.1-tests/db.lua
index 56f59ea8..99efe8ef 100644
--- a/test/PUC-Rio-Lua-5.1-tests/db.lua
+++ b/test/PUC-Rio-Lua-5.1-tests/db.lua
@@ -8,6 +8,26 @@ do
 local a=1
 end
 
+-- The LuaJIT's virtual machine interprets the bytecode
+-- following the return from function (i.e. the one succeeding
+-- the call made) and located on the line other than that return
+-- bytecode, as a new line trigger for line hooks, unlike Lua
+-- does.
+-- Here is an example (it is joined in one line intend):
+--[[
+debug.sethook(function(_, l) print("LINE: "..l) end, "l") loadstring("\n\ns=nil")() debug.sethook()
+--]]
+-- This chunk prints for LuaJIT:
+--[[
+LINE: 3
+LINE: 1
+--]]
+-- But for Lua 5.1 it is only "LINE: 3" in the output.
+-- See also https://github.com/tarantool/tarantool/issues/5693.
+-- Considering implementation-defined behaviour difference
+-- (see also https://luajit.org/status.html) test is disabled for
+-- LuaJIT.
+-- This function is modified to correspond with LuaJIT's line triggers.
 function test (s, l, p)
   collectgarbage()   -- avoid gc during trace
   local function f (event, line)
@@ -16,7 +36,7 @@ function test (s, l, p)
     if p then print(l, line) end
     assert(l == line, "wrong trace!!")
   end
-  debug.sethook(f,"l"); loadstring(s)(); debug.sethook()
+  local cur_line = debug.getinfo(1).currentline; table.insert(l, 1, cur_line); table.insert(l, cur_line); debug.sethook(f,"l"); loadstring(s)(); debug.sethook()
   assert(table.getn(l) == 0)
 end
 
@@ -25,7 +45,7 @@ do
   local a = debug.getinfo(print)
   assert(a.what == "C" and a.short_src == "[C]")
   local b = debug.getinfo(test, "SfL")
-  assert(b.name == nil and b.what == "Lua" and b.linedefined == 11 and
+  assert(b.name == nil and b.what == "Lua" and b.linedefined == 31 and
          b.lastlinedefined == b.linedefined + 10 and
          b.func == test and not string.find(b.short_src, "%["))
   assert(b.activelines[b.linedefined + 1] and
@@ -95,26 +115,6 @@ repeat
   assert(g(f) == 'a')
 until 1
 
--- FIXME: The LuaJIT's virtual machine interprets the bytecode
--- following the return from function (i.e. the one succeeding
--- the call made) and located on the line other than that return
--- bytecode, as a new line trigger for line hooks, unlike Lua
--- does.
--- Here is an example (it is joined in one line intend):
---[[
-debug.sethook(function(_, l) print("LINE: "..l) end, "l") loadstring("\n\ns=nil")() debug.sethook()
---]]
--- This chunk prints for LuaJIT:
---[[
-LINE: 3
-LINE: 1
---]]
--- But for Lua 5.1 it is only "LINE: 3" in the output.
--- See also https://github.com/tarantool/tarantool/issues/5693.
--- Considering implementation-defined behaviour difference
--- (see also https://luajit.org/status.html) test is disabled for
--- LuaJIT.
---[=[
 test([[if
 math.sin(1)
 then
@@ -132,23 +132,25 @@ else
 end
 ]], {2,5,6})
 
+-- Test is adapted to the behaviour of LuaJIT.
 test([[a=1
 repeat
   a=a+1
 until a==3
-]], {1,3,4,3,4})
+]], {1,2,3,4,2,3,4})
 
 test([[ do
   return
 end
 ]], {2})
 
+-- Test is adapted to the behaviour of LuaJIT.
 test([[local a
 a=1
 while a<=3 do
   a=a+1
 end
-]], {2,3,4,3,4,3,4,3,5})
+]], {1,2,3,4,3,4,3,4,3,5})
 
 test([[while math.sin(1) do
   if math.sin(1)
@@ -168,8 +170,8 @@ test([[for i,v in pairs{'a','b'} do
 end
 ]], {1,2,1,2,1,3})
 
-test([[for i=1,4 do a=1 end]], {1,1,1,1,1})
---]=]
+-- Test is adapted to the behaviour of LuaJIT.
+test([[for i=1,4 do a=1 end]], {1,1,1,1})
 
 
 print'+'
-- 
2.33.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-11 15:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-24 16:27 [Tarantool-patches] [PATCH luajit] test: adapt tests checking debug line hook trace Maxim Kokryashkin via Tarantool-patches
2021-10-11 15:19 ` Sergey Kaplun via Tarantool-patches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox