From: Igor Munkin via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Sergey Kaplun <skaplun@tarantool.org>, Maxim Kokryashkin <m.kokryashkin@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH luajit 3/7] test: stop using utils.selfrun in tests Date: Mon, 13 Feb 2023 17:02:45 +0000 [thread overview] Message-ID: <73073fb24db65f59c8629f4f377faa9e52cb54af.1676304797.git.imun@tarantool.org> (raw) In-Reply-To: <cover.1676304797.git.imun@tarantool.org> Unfortunately, <utils.selfrun> is too complex to be maintained, so the corresponding tests are split into two files: the test itself and the script to be run by the test. As a result of the patch <utils.makecmd> helper is introduced: it inherits some approaches from <utils.selfrun>, but it's considered for more general use. Relates to tarantool/tarantool#8252 Signed-off-by: Igor Munkin <imun@tarantool.org> --- .../gh-4427-ffi-sandwich.test.lua | 69 ++++++++----------- .../gh-4427-ffi-sandwich/script.lua | 25 +++++++ .../lj-351-print-tostring-number.test.lua | 34 +++------ .../lj-351-print-tostring-number/script.lua | 9 +++ .../lj-586-debug-non-string-error.test.lua | 2 +- .../lj-flush-on-trace.test.lua | 68 ++++++++---------- .../lj-flush-on-trace/script.lua | 23 +++++++ test/tarantool-tests/utils.lua | 66 +++++------------- 8 files changed, 148 insertions(+), 148 deletions(-) create mode 100644 test/tarantool-tests/gh-4427-ffi-sandwich/script.lua create mode 100644 test/tarantool-tests/lj-351-print-tostring-number/script.lua create mode 100644 test/tarantool-tests/lj-flush-on-trace/script.lua diff --git a/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua b/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua index dd02130c..f4795db0 100644 --- a/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua +++ b/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua @@ -3,52 +3,43 @@ local utils = require('utils') -- Disabled on *BSD due to #4819. utils.skipcond(jit.os == 'BSD', 'Disabled due to #4819') -utils.selfrun(arg, { - { - arg = { - 1, -- hotloop (arg[1]) - 1, -- trigger (arg[2]) - }, - msg = 'Trace is aborted', - res = tostring(3), -- hotloop + trigger + 1 - test = 'is', - }, - { - arg = { - 1, -- hotloop (arg[1]) - 2, -- trigger (arg[2]) - }, - msg = 'Trace is recorded', - res = 'Lua VM re%-entrancy is detected while executing the trace', - test = 'like', - }, -}) - ------ Test payload. ---------------------------------------------- - -local cfg = { - hotloop = arg[1] or 1, - trigger = arg[2] or 1, -} +local tap = require('tap') -local ffi = require('ffi') -local ffisandwich = ffi.load('libsandwich') -ffi.cdef('int increment(struct sandwich *state, int i)') +local test = tap.test('gh-4427-ffi-sandwich') +test:plan(2) --- Save the current coroutine and set the value to trigger --- <increment> call the Lua routine instead of C implementation. -local sandwich = require('libsandwich')(cfg.trigger) +local script = utils.makecmd(arg, { + -- TODO: Leave another toxic comment regarding SIP on macOS. + env = { DYLD_LIBRARY_PATH = os.getenv('DYLD_LIBRARY_PATH') }, + redirect = '2>&1', +}) -- Depending on trigger and hotloop values the following contexts -- are possible: -- * if trigger <= hotloop -> trace recording is aborted -- * if trigger > hotloop -> trace is recorded but execution -- leads to panic -jit.opt.start("3", string.format("hotloop=%d", cfg.hotloop)) +local hotloop = 1 +local cases = { + abort = { + trigger = hotloop, + expected = '#4427 still works', + test = 'is', + message = 'Trace is aborted', + }, + panic = { + trigger = hotloop + 1, + expected = 'Lua VM re%-entrancy is detected while executing the trace', + test = 'like', + message = 'Trace is compiled', + }, +} -local res -for i = 0, cfg.trigger + cfg.hotloop do - res = ffisandwich.increment(sandwich, i) +for _, subtest in pairs(cases) do + local output = script(hotloop, subtest.trigger) + -- XXX: explicitly pass <test> as an argument to <testf> + -- to emulate test:is(...), test:like(...), etc. + test[subtest.test](test, output, subtest.expected, subtest.message) end --- Check the resulting value if panic didn't occur earlier. -print(res) + +os.exit(test:check() and 0 or 1) diff --git a/test/tarantool-tests/gh-4427-ffi-sandwich/script.lua b/test/tarantool-tests/gh-4427-ffi-sandwich/script.lua new file mode 100644 index 00000000..9ecd964e --- /dev/null +++ b/test/tarantool-tests/gh-4427-ffi-sandwich/script.lua @@ -0,0 +1,25 @@ +local hotloop = assert(arg[1], 'hotloop argument is missing') +local trigger = assert(arg[2], 'trigger argument is missing') + +local ffi = require('ffi') +local ffisandwich = ffi.load('libsandwich') +ffi.cdef('int increment(struct sandwich *state, int i)') + +-- Save the current coroutine and set the value to trigger +-- <increment> call the Lua routine instead of C implementation. +local sandwich = require('libsandwich')(trigger) + +-- Depending on trigger and hotloop values the following contexts +-- are possible: +-- * if trigger <= hotloop -> trace recording is aborted +-- * if trigger > hotloop -> trace is recorded but execution +-- leads to panic +jit.opt.start("3", string.format("hotloop=%d", hotloop)) + +local res +for i = 0, hotloop + trigger do + res = ffisandwich.increment(sandwich, i) +end +-- Check the resulting value if panic didn't occur earlier. +assert(res == hotloop + trigger + 1, 'res is calculated correctly') +io.write('#4427 still works') diff --git a/test/tarantool-tests/lj-351-print-tostring-number.test.lua b/test/tarantool-tests/lj-351-print-tostring-number.test.lua index da5b31be..72a9ec2b 100644 --- a/test/tarantool-tests/lj-351-print-tostring-number.test.lua +++ b/test/tarantool-tests/lj-351-print-tostring-number.test.lua @@ -1,4 +1,9 @@ -local utils = require('utils') +local tap = require('tap') + +local test = tap.test('lj-351-print-tostring-number') +test:plan(8) + +local script = require('utils').makecmd(arg) local cases = { {typename = 'nil', value = 'nil'}, @@ -15,27 +20,10 @@ local cases = { {typename = 'cdata', value = '1ULL'} } -local checks = {} - -for i, case in pairs(cases) do - checks[i] = { - arg = {('"%s"'):format(case.value), case.typename}, - msg = ('%s'):format(case.typename), - res = ('__tostring is reloaded for %s'):format(case.typename), - test = 'is', - } +for _, subtest in pairs(cases) do + local output = script(('"%s"'):format(subtest.value), subtest.typename) + test:is(output, ('__tostring is reloaded for %s'):format(subtest.typename), + ('subtest is OK for %s type'):format(subtest.typename)) end -utils.selfrun(arg, checks) - ------ Test payload. ---------------------------------------------- - -local test = [[ - local testvar = %s - debug.setmetatable(testvar, {__tostring = function(o) - return ('__tostring is reloaded for %s'):format(type(o)) - end}) - print(testvar) -]] - -pcall(load(test:format(unpack(arg)))) +os.exit(test:check() and 0 or 1) diff --git a/test/tarantool-tests/lj-351-print-tostring-number/script.lua b/test/tarantool-tests/lj-351-print-tostring-number/script.lua new file mode 100644 index 00000000..c3066f49 --- /dev/null +++ b/test/tarantool-tests/lj-351-print-tostring-number/script.lua @@ -0,0 +1,9 @@ +local test = [[ + local testvar = %s + debug.setmetatable(testvar, {__tostring = function(o) + return ('__tostring is reloaded for %s'):format(type(o)) + end}) + print(testvar) +]] + +pcall(load(test:format(unpack(arg)))) diff --git a/test/tarantool-tests/lj-586-debug-non-string-error.test.lua b/test/tarantool-tests/lj-586-debug-non-string-error.test.lua index f02353fe..dcb730a2 100644 --- a/test/tarantool-tests/lj-586-debug-non-string-error.test.lua +++ b/test/tarantool-tests/lj-586-debug-non-string-error.test.lua @@ -8,7 +8,7 @@ test:plan(1) -- that testing the debug interactive interface always ends with -- sending commands to another instance via stdin. However, the -- module with test helpers lacks the suitable routine. --- `utils.selfrun()` doesn't fit for this, since `debug.debug()` +-- `utils.makecmd()` doesn't fit for this, since `debug.debug()` -- captures `io.stdin` and waits at `fgets()` in debug busy loop. -- As it's already mentioned, such tests are not usual, so there -- is no need to introduce a new helper to utils module (at least diff --git a/test/tarantool-tests/lj-flush-on-trace.test.lua b/test/tarantool-tests/lj-flush-on-trace.test.lua index c46b93f0..cf92757c 100644 --- a/test/tarantool-tests/lj-flush-on-trace.test.lua +++ b/test/tarantool-tests/lj-flush-on-trace.test.lua @@ -3,51 +3,43 @@ local utils = require('utils') -- Disabled on *BSD due to #4819. utils.skipcond(jit.os == 'BSD', 'Disabled due to #4819') -utils.selfrun(arg, { - { - arg = { - 1, -- hotloop (arg[1]) - 1, -- trigger (arg[2]) - }, - msg = 'Trace is aborted', - res = 'OK', - test = 'is', - }, - { - arg = { - 1, -- hotloop (arg[1]) - 2, -- trigger (arg[2]) - }, - msg = 'Trace is recorded', - res = 'JIT mode change is detected while executing the trace', - test = 'like', - }, -}) - ------ Test payload. ---------------------------------------------- - -local cfg = { - hotloop = arg[1] or 1, - trigger = arg[2] or 1, -} +local tap = require('tap') -local ffi = require('ffi') -local ffiflush = ffi.load('libflush') -ffi.cdef('void flush(struct flush *state, int i)') +local test = tap.test('lj-flush-on-trace') +test:plan(2) --- Save the current coroutine and set the value to trigger --- <flush> call the Lua routine instead of C implementation. -local flush = require('libflush')(cfg.trigger) +local script = utils.makecmd(arg, { + -- TODO: Leave another toxic comment regarding SIP on macOS. + env = { DYLD_LIBRARY_PATH = os.getenv('DYLD_LIBRARY_PATH') }, + redirect = '2>&1', +}) -- Depending on trigger and hotloop values the following contexts -- are possible: -- * if trigger <= hotloop -> trace recording is aborted -- * if trigger > hotloop -> trace is recorded but execution -- leads to panic -jit.opt.start("3", string.format("hotloop=%d", cfg.hotloop)) +local hotloop = 1 +local cases = { + abort = { + trigger = hotloop, + expected = 'LJ flush still works', + test = 'is', + message = 'Trace is aborted', + }, + panic = { + trigger = hotloop + 1, + expected = 'JIT mode change is detected while executing the trace', + test = 'like', + message = 'Trace is compiled', + }, +} -for i = 0, cfg.trigger + cfg.hotloop do - ffiflush.flush(flush, i) +for _, subtest in pairs(cases) do + local output = script(hotloop, subtest.trigger) + -- XXX: explicitly pass <test> as an argument to <testf> + -- to emulate test:is(...), test:like(...), etc. + test[subtest.test](test, output, subtest.expected, subtest.message) end --- Panic didn't occur earlier. -print('OK') + +os.exit(test:check() and 0 or 1) diff --git a/test/tarantool-tests/lj-flush-on-trace/script.lua b/test/tarantool-tests/lj-flush-on-trace/script.lua new file mode 100644 index 00000000..d2c35534 --- /dev/null +++ b/test/tarantool-tests/lj-flush-on-trace/script.lua @@ -0,0 +1,23 @@ +local hotloop = assert(arg[1], 'hotloop argument is missing') +local trigger = assert(arg[2], 'trigger argument is missing') + +local ffi = require('ffi') +local ffiflush = ffi.load('libflush') +ffi.cdef('void flush(struct flush *state, int i)') + +-- Save the current coroutine and set the value to trigger +-- <flush> call the Lua routine instead of C implementation. +local flush = require('libflush')(trigger) + +-- Depending on trigger and hotloop values the following contexts +-- are possible: +-- * if trigger <= hotloop -> trace recording is aborted +-- * if trigger > hotloop -> trace is recorded but execution +-- leads to panic +jit.opt.start("3", string.format("hotloop=%d", hotloop)) + +for i = 0, trigger + hotloop do + ffiflush.flush(flush, i) +end +-- Panic didn't occur earlier. +io.write('LJ flush still works') diff --git a/test/tarantool-tests/utils.lua b/test/tarantool-tests/utils.lua index eb11d40d..41a7c22a 100644 --- a/test/tarantool-tests/utils.lua +++ b/test/tarantool-tests/utils.lua @@ -1,7 +1,6 @@ local M = {} local ffi = require('ffi') -local tap = require('tap') local bc = require('jit.bc') local bit = require('bit') @@ -44,55 +43,28 @@ function M.luacmd(args) return table.concat(args, ' ', idx + 1, -1) end -local function unshiftenv(variable, value, sep) - local envvar = os.getenv(variable) - return ('%s="%s%s"'):format(variable, value, - envvar and ('%s%s'):format(sep, envvar) or '') +local function makeenv(tabenv) + if tabenv == nil then return '' end + local flatenv = {} + for var, value in pairs(tabenv) do + table.insert(flatenv, ('%s=%s'):format(var, value)) + end + return table.concat(flatenv, ' ') end -function M.selfrun(arg, checks) - -- If TEST_SELFRUN is set, it means the test has been run via - -- <io.popen>, so just return from this routine and proceed - -- the execution to the test payload, ... - if os.getenv('TEST_SELFRUN') then return end - - -- ... otherwise initialize <tap>, setup testing environment - -- and run this chunk via <io.popen> for each case in <checks>. - -- XXX: The function doesn't return back from this moment. It - -- checks whether all assertions are fine and exits. - - local test = tap.test(arg[0]:match('/?(.+)%.test%.lua')) - - test:plan(#checks) - - local libext = package.cpath:match('?.(%a+);') - local vars = { +function M.makecmd(arg, opts) + return setmetatable({ LUABIN = M.luacmd(arg), - SCRIPT = arg[0], - PATH = arg[0]:gsub('%.test%.lua', ''), - SUFFIX = libext, - ENV = table.concat({ - unshiftenv('LUA_PATH', '<PATH>/?.lua', ';'), - unshiftenv('LUA_CPATH', '<PATH>/?.<SUFFIX>', ';'), - unshiftenv((libext == 'dylib' and 'DYLD' or 'LD') .. '_LIBRARY_PATH', - '<PATH>', ':'), - 'TEST_SELFRUN=1', - }, ' '), - } - - local cmd = string.gsub('<ENV> <LUABIN> 2>&1 <SCRIPT>', '%<(%w+)>', vars) - - for _, ch in pairs(checks) do - local testf = test[ch.test] - assert(testf, ("tap doesn't provide test.%s function"):format(ch.test)) - local proc = io.popen((cmd .. (' %s'):rep(#ch.arg)):format(unpack(ch.arg))) - local res = proc:read('*all'):gsub('^%s+', ''):gsub('%s+$', '') - -- XXX: explicitly pass <test> as an argument to <testf> - -- to emulate test:is(...), test:like(...), etc. - testf(test, res, ch.res, ch.msg) - end - - os.exit(test:check() and 0 or 1) + SCRIPT = opts and opts.script or arg[0]:gsub('%.test%.lua$', '/script.lua'), + ENV = opts and makeenv(opts.env) or '', + REDIRECT = opts and opts.redirect or '', + }, { + __call = function(self, ...) + local cmd = ('<ENV> <LUABIN> <REDIRECT> <SCRIPT>'):gsub('%<(%w+)>', self) + .. (' %s'):rep(select('#', ...)):format(...) + return io.popen(cmd):read('*all'):gsub('^%s+', ''):gsub('%s+$', '') + end + }) end function M.skipcond(condition, message) -- 2.30.2
next prev parent reply other threads:[~2023-02-13 17:05 UTC|newest] Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-02-13 17:02 [Tarantool-patches] [PATCH luajit 0/7] Adjust tests to be run when JIT is disabled Igor Munkin via Tarantool-patches 2023-02-13 17:02 ` [Tarantool-patches] [PATCH luajit 1/7] Minor fixes Igor Munkin via Tarantool-patches 2023-02-13 18:47 ` Sergey Kaplun via Tarantool-patches 2023-02-14 13:51 ` Maxim Kokryashkin via Tarantool-patches 2023-02-13 17:02 ` [Tarantool-patches] [PATCH luajit 2/7] build: fix build with JIT disabled Igor Munkin via Tarantool-patches 2023-02-13 18:53 ` Sergey Kaplun via Tarantool-patches 2023-02-27 9:15 ` Igor Munkin via Tarantool-patches 2023-02-28 8:16 ` Maxim Kokryashkin via Tarantool-patches 2023-02-14 13:53 ` Maxim Kokryashkin via Tarantool-patches 2023-02-13 17:02 ` Igor Munkin via Tarantool-patches [this message] 2023-02-15 8:08 ` [Tarantool-patches] [PATCH luajit 3/7] test: stop using utils.selfrun in tests Sergey Kaplun via Tarantool-patches 2023-02-27 9:16 ` Igor Munkin via Tarantool-patches 2023-02-27 9:28 ` Sergey Kaplun via Tarantool-patches 2023-02-15 21:43 ` Maxim Kokryashkin via Tarantool-patches 2023-02-27 9:16 ` Igor Munkin via Tarantool-patches 2023-02-28 8:18 ` Maxim Kokryashkin via Tarantool-patches 2023-02-13 17:02 ` [Tarantool-patches] [PATCH luajit 4/7] test: make skipcond helper more convenient Igor Munkin via Tarantool-patches 2023-02-15 8:46 ` Sergey Kaplun via Tarantool-patches 2023-02-27 9:18 ` Igor Munkin via Tarantool-patches 2023-02-27 10:09 ` Sergey Kaplun via Tarantool-patches 2023-02-28 8:27 ` Maxim Kokryashkin via Tarantool-patches 2023-02-15 22:08 ` Maxim Kokryashkin via Tarantool-patches 2023-02-13 17:02 ` [Tarantool-patches] [PATCH luajit 5/7] test: add skipcond for all JIT-related tests Igor Munkin via Tarantool-patches 2023-02-14 13:50 ` Sergey Kaplun via Tarantool-patches 2023-02-15 22:31 ` Maxim Kokryashkin via Tarantool-patches 2023-02-28 19:02 ` Igor Munkin via Tarantool-patches 2023-03-01 19:31 ` Maxim Kokryashkin via Tarantool-patches 2023-02-13 17:02 ` [Tarantool-patches] [PATCH luajit 6/7] test: fix lua-Harness " Igor Munkin via Tarantool-patches 2023-02-14 12:42 ` Sergey Kaplun via Tarantool-patches 2023-02-28 19:01 ` Igor Munkin via Tarantool-patches 2023-02-15 22:35 ` Maxim Kokryashkin via Tarantool-patches 2023-02-28 19:02 ` Igor Munkin via Tarantool-patches 2023-03-01 19:31 ` Maxim Kokryashkin via Tarantool-patches 2023-02-13 17:02 ` [Tarantool-patches] [PATCH luajit 7/7] ci: add nojit flavor for exotic builds Igor Munkin via Tarantool-patches 2023-02-13 19:14 ` Sergey Kaplun via Tarantool-patches 2023-02-15 21:18 ` Maxim Kokryashkin via Tarantool-patches 2023-02-27 9:36 ` [Tarantool-patches] [PATCH luajit 0/7] Adjust tests to be run when JIT is disabled Igor Munkin via Tarantool-patches 2023-02-28 19:05 ` Igor Munkin via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=73073fb24db65f59c8629f4f377faa9e52cb54af.1676304797.git.imun@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=imun@tarantool.org \ --cc=m.kokryashkin@tarantool.org \ --cc=skaplun@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH luajit 3/7] test: stop using utils.selfrun in tests' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox