[Tarantool-patches] [PATCH luajit v2] test: adapt tests checking debug line hook trace

Максим Корякшин m.kokryashkin at tarantool.org
Tue Jan 25 01:02:12 MSK 2022


Hi, Sergey!
Thanks for the review!
 
Here is the new commit message:
==========================================================================
test: adapt tests checking debug line hook trace
 
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.
 
Those tests are adapted to LuaJIT behavior by changing assertions
considering line events that LuaJIT generates.
 
Part of tarantool/tarantool#5870
Resolves tarantool/tarantool#5693.
==========================================================================
 
And here is the diff:
==========================================================================
diff --git a/test/PUC-Rio-Lua-5.1-tests/db.lua b/test/PUC-Rio-Lua-5.1-tests/db.lua
index 120fc04c..36adc709 100644
--- a/test/PUC-Rio-Lua-5.1-tests/db.lua
+++ b/test/PUC-Rio-Lua-5.1-tests/db.lua
@@ -24,7 +24,8 @@ LINE: 1
 --]]
 -- But for Lua 5.1 it is only "LINE: 3" in the output.
 -- See also https://github.com/tarantool/tarantool/issues/5693.
--- This function is modified to correspond with LuaJIT's line triggers.
+-- 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)
@@ -33,11 +34,12 @@ function test (s, l, p)
     if p then print(l, line) end
     assert(l == line, "wrong trace!!")
   end
-  -- Despite `loadstring` and `debug.sethook` are on the same line, LuaJIT
-  -- generates separate line events for them. The test is adapted to LuaJIT
-  -- behavior by adding corresponding line numbers into the test table.
-  table.insert(l, 1, 41)
-  table.insert(l, 41)
+  -- Despite `loadstring` and `debug.sethook` are on the same
+  -- line, LuaJIT generates separate line events for them. The
+  -- test is adapted to LuaJIT behavior by adding corresponding
+  -- line numbers into the test table.
+  table.insert(l, 1, 43)
+  table.insert(l, 43)
   debug.sethook(f,"l"); loadstring(s)(); debug.sethook()
   assert(table.getn(l) == 0)
 end
@@ -47,8 +49,8 @@ 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 == 28 and
-         b.lastlinedefined == b.linedefined + 15 and
+  assert(b.name == nil and b.what == "Lua" and b.linedefined == 29 and
+         b.lastlinedefined == b.linedefined + 16 and
          b.func == test and not string.find(b.short_src, "%["))
   assert(b.activelines[b.linedefined + 1] and
          b.activelines[b.lastlinedefined])
@@ -172,8 +174,9 @@ test([[for i,v in pairs{'a','b'} do
 end
 ]], {1,2,1,2,1,3})
 
--- Test is adapted to the behaviour of LuaJIT, as it generates only four line
--- events, unlike Lua, which generates five of them.
+-- Test is adapted to the behaviour of LuaJIT, as it generates
+-- only four line events, unlike Lua, which generates five
+-- of them.
 test([[for i=1,4 do a=1 end]], {1,1,1,1})
==========================================================================
 
New CI branch:  https://github.com/tarantool/tarantool/tree/fckxorg/gh-5693-PUC-Rio-debug-line-hook-full-ci
 
Best regards,
Maxim Kokryashkin
> 
>>Hi, Maxim!
>>Thanks for the fixes!
>>
>>LGTM, except a few nits below.
>>
>>Am I right that this CI branch [1] is the latest one?
>>
>>Also, please align comments with linewidth 66 symbols.
>>
>>On 10.11.21, Maxim Kokryashkin wrote:
>>> 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 tarantool/tarantool#5693.
>>
>>Nit: this see also is excess (as far as this patch resolves the ticket).
>>
>>>
>>> Those tests are adapted to LuaJIT behavior by changing assertions
>>> considering line events that LuaJIT generates.
>>>
>>> Part of tarantool/tarantool#5870
>>
>>It's OK to mention that this patch "Resolves tarantool/tarantool#5693".
>>
>>> ---
>>> Changes in v2:
>>> - Fixed comments as per review by Sergey
>>> - Added some comments
>>>
>>> test/PUC-Rio-Lua-5.1-tests/db.lua | 57 +++++++++++++++++--------------
>>> 1 file changed, 31 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..120fc04c 100644
>>> --- a/test/PUC-Rio-Lua-5.1-tests/db.lua
>>> +++ b/test/PUC-Rio-Lua-5.1-tests/db.lua
>>> @@ -8,6 +8,23 @@ 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 .
>>> +-- 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,6 +33,11 @@ function test (s, l, p)
>>> if p then print(l, line) end
>>> assert(l == line, "wrong trace!!")
>>> end
>>> + -- Despite `loadstring` and `debug.sethook` are on the same line, LuaJIT
>>> + -- generates separate line events for them. The test is adapted to LuaJIT
>>> + -- behavior by adding corresponding line numbers into the test table.
>>> + table.insert(l, 1, 41)
>>> + table.insert(l, 41)
>>> debug.sethook(f,"l"); loadstring(s)(); debug.sethook()
>>> assert(table.getn(l) == 0)
>>> end
>>> @@ -25,8 +47,8 @@ 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
>>> - b.lastlinedefined == b.linedefined + 10 and
>>> + assert(b.name == nil and b.what == "Lua" and b.linedefined == 28 and
>>> + b.lastlinedefined == b.linedefined + 15 and
>>> b.func == test and not string.find(b.short_src, "%["))
>>> assert(b.activelines[b.linedefined + 1] and
>>> b.activelines[b.lastlinedefined])
>>> @@ -95,26 +117,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 +134,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 +172,9 @@ 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, as it generates only four line
>>> +-- events, unlike Lua, which generates five of them.
>>> +test([[for i=1,4 do a=1 end]], {1,1,1,1})
>>>
>>>
>>> print'+'
>>> --
>>> 2.33.0
>>>
>>
>>[1]:
>>https://github.com/tarantool/tarantool/tree/fckxorg/gh-5693-PUC-Rio-debug-line-hook
>>
>>--
>>Best regards,
>>Sergey Kaplun
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.tarantool.org/pipermail/tarantool-patches/attachments/20220125/92cb6336/attachment.htm>


More information about the Tarantool-patches mailing list