[Tarantool-patches] [PATCH luajit 12/36] test: enable <misc/hook_active.lua> LuaJIT test

Sergey Bronnikov sergeyb at tarantool.org
Thu Aug 15 16:38:21 MSK 2024


Hi, Sergey

thanks for the patch! Please see my comments below.


On 14.08.2024 16:55, Sergey Kaplun wrote:
> This patch moves the aforementioned test from the <misc> to the <lang/>
> directory, includes it in <index>, and names the subtests.
+ changed formatting
>
> Part of tarantool/tarantool#9398
> ---
>   test/LuaJIT-tests/lang/hook_active.lua | 102 +++++++++++++++++++++++++
>   test/LuaJIT-tests/lang/index           |   1 +
>   test/LuaJIT-tests/misc/hook_active.lua |  95 -----------------------
>   3 files changed, 103 insertions(+), 95 deletions(-)
>   create mode 100644 test/LuaJIT-tests/lang/hook_active.lua
>   delete mode 100644 test/LuaJIT-tests/misc/hook_active.lua
>
> diff --git a/test/LuaJIT-tests/lang/hook_active.lua b/test/LuaJIT-tests/lang/hook_active.lua
> new file mode 100644
> index 00000000..c82670f5
> --- /dev/null
> +++ b/test/LuaJIT-tests/lang/hook_active.lua
> @@ -0,0 +1,102 @@
> +local ctest = require("libctest")
> +
> +local called = 0
> +local function clearhook() debug.sethook(nil, "", 0) end
> +
> +do --- Return from pcall with active hook must prepend true. FF pcall.
> +  called = 0
> +  debug.sethook(function() called=called+1; assert(pcall(function() end) == true); clearhook() end, "", 1)
add more spaces
> +  do local x = 1 end
> +  assert(called == 1)
> +end
> +
> +do --- Hook with special caught error must not unblock hooks. FF pcall.
> +  called = 0
> +  debug.sethook(function() called=called+1; pcall(nil); clearhook() end, "", 1)
add more spaces
> +  do local x = 1 end
> +  assert(called == 1)
> +end
> +
> +do --- Hook with caught error must not unblock hooks. FF pcall.
> +  called = 0
> +  local function p2() error("") end
> +  debug.sethook(function() called=called+1; pcall(p2); clearhook() end, "", 1)
add more spaces here and below
> +  do local x = 1 end
> +  assert(called == 1)
> +end
> +
> +do --- Hook with special caught error must not unblock hooks. C pcall.
> +  called = 0
> +  debug.sethook(function() called=called+1; ctest.pcall(nil); clearhook() end, "", 1)
add more spaces
> +  do local x = 1 end
> +  assert(called == 1)
> +end
> +
> +do --- Hook with caught error must not unblock hooks. C pcall
missed dot at the end
> +  called = 0
> +  local function p2() error("") end
> +  debug.sethook(function() called=called+1; ctest.pcall(p2); clearhook() end, "", 1)
> +  do local x = 1 end
> +  assert(called == 1)
> +end
> +
> +do --- Regular pcall must not block hooks.
> +  debug.sethook(function() called=called+1 end, "", 1)
add more spaces
> +  pcall(function() end)
> +  called = 0
> +  do local x = 1 end
> +  assert(called > 0)
> +  pcall(function() error("") end)
> +  called = 0
> +  do local x = 1 end
> +  assert(called > 0)
> +  ctest.pcall(function() end)
> +  called = 0
> +  do local x = 1 end
> +  assert(called > 0)
> +  ctest.pcall(function() error("") end)
> +  called = 0
> +  do local x = 1 end
> +  assert(called > 0)
> +  clearhook()
> +end
> +
> +do --- Hook with uncaught error must unblock hooks. FF pcall
missed dot at the end
> +  called = 0
> +  pcall(function()
> +    debug.sethook(function()
> +      local old = called
> +      called = 1
> +      if old == 0 then error("") end
> +    end, "", 1)
> +    do local x = 1 end
> +  end)
> +  assert(called == 1)
> +  called = 2
> +  do local x = 1 end
> +  assert(called == 1, "hook not unblocked after uncaught error")
> +  clearhook()
> +  called = 2
> +  do local x = 1 end
> +  assert(called == 2)
> +end
> +
> +do --- Hook with uncaught error must unblock hooks. C pcall
missed dot at the end
> +  called = 0
> +  ctest.pcall(function()
> +    debug.sethook(function()
> +      local old = called
> +      called = 1
> +      if old == 0 then error("") end
> +    end, "", 1)
> +    do local x = 1 end
> +  end)
> +  assert(called == 1)
> +  called = 2
> +  do local x = 1 end
> +  assert(called == 1, "hook not unblocked after uncaught error")
> +  clearhook()
> +  called = 2
> +  do local x = 1 end
> +  assert(called == 2)
> +end
> diff --git a/test/LuaJIT-tests/lang/index b/test/LuaJIT-tests/lang/index
> index 274425bf..8cecfa08 100644
> --- a/test/LuaJIT-tests/lang/index
> +++ b/test/LuaJIT-tests/lang/index
> @@ -8,6 +8,7 @@ compare_nan.lua
>   constant
>   dualnum.lua
>   for.lua
> +hook_active.lua
>   length.lua
>   lightud.lua
>   modulo.lua
> diff --git a/test/LuaJIT-tests/misc/hook_active.lua b/test/LuaJIT-tests/misc/hook_active.lua
> deleted file mode 100644
> index 37dfc379..00000000
> --- a/test/LuaJIT-tests/misc/hook_active.lua
> +++ /dev/null
> @@ -1,95 +0,0 @@
> -local ctest = require("ctest")
> -
> -local called = 0
> -local function clearhook() debug.sethook(nil, "", 0) end
> -
> --- Return from pcall with active hook must prepend true. FF pcall.
> -called = 0
> -debug.sethook(function() called=called+1; assert(pcall(function() end) == true); clearhook() end, "", 1)
> -do local x = 1 end
> -assert(called == 1)
> -
> --- Hook with special caught error must not unblock hooks. FF pcall.
> -called = 0
> -debug.sethook(function() called=called+1; pcall(nil); clearhook() end, "", 1)
> -do local x = 1 end
> -assert(called == 1)
> -
> --- Hook with caught error must not unblock hooks. FF pcall.
> -called = 0
> -local function p2() error("") end
> -debug.sethook(function() called=called+1; pcall(p2); clearhook() end, "", 1)
> -do local x = 1 end
> -assert(called == 1)
> -
> --- Hook with special caught error must not unblock hooks. C pcall.
> -called = 0
> -debug.sethook(function() called=called+1; ctest.pcall(nil); clearhook() end, "", 1)
> -do local x = 1 end
> -assert(called == 1)
> -
> --- Hook with caught error must not unblock hooks. C pcall
> -called = 0
> -local function p2() error("") end
> -debug.sethook(function() called=called+1; ctest.pcall(p2); clearhook() end, "", 1)
> -do local x = 1 end
> -assert(called == 1)
> -
> --- Regular pcall must not block hooks.
> -debug.sethook(function() called=called+1 end, "", 1)
> -pcall(function() end)
> -called = 0
> -do local x = 1 end
> -assert(called > 0)
> -pcall(function() error("") end)
> -called = 0
> -do local x = 1 end
> -assert(called > 0)
> -ctest.pcall(function() end)
> -called = 0
> -do local x = 1 end
> -assert(called > 0)
> -ctest.pcall(function() error("") end)
> -called = 0
> -do local x = 1 end
> -assert(called > 0)
> -clearhook()
> -
> --- Hook with uncaught error must unblock hooks. FF pcall
> -called = 0
> -pcall(function()
> -  debug.sethook(function()
> -    local old = called
> -    called = 1
> -    if old == 0 then error("") end
> -  end, "", 1)
> -  do local x = 1 end
> -end)
> -assert(called == 1)
> -called = 2
> -do local x = 1 end
> -assert(called == 1, "hook not unblocked after uncaught error")
> -clearhook()
> -called = 2
> -do local x = 1 end
> -assert(called == 2)
> -
> --- Hook with uncaught error must unblock hooks. C pcall
> -called = 0
> -ctest.pcall(function()
> -  debug.sethook(function()
> -    local old = called
> -    called = 1
> -    if old == 0 then error("") end
> -  end, "", 1)
> -  do local x = 1 end
> -end)
> -assert(called == 1)
> -called = 2
> -do local x = 1 end
> -assert(called == 1, "hook not unblocked after uncaught error")
> -clearhook()
> -called = 2
> -do local x = 1 end
> -assert(called == 2)
> -
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.tarantool.org/pipermail/tarantool-patches/attachments/20240815/33fe9bb9/attachment.htm>


More information about the Tarantool-patches mailing list