From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 9C7F7257FFB; Mon, 13 Feb 2023 20:05:00 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9C7F7257FFB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1676307900; bh=rVClm+5DoMGUlCL26lzt2kcLpUxbA0ATk/+oxkRXH0Q=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=AsjjoaOhoCHpqC1JzUP4YYpyy9bK74yyZ4XOx3rxlGYHpfXlL92X0yHVLyEINbyp2 fqUYm3ma612QcB0dmUeW4zfkSaYLTrEzF0Blx5vRg4ckYdIIPEpjb24CoqFEb4m/AQ /XSCDCKC6GGKL2A9uWRrTqb8EQd6dIq6aNn8nzMQ= Received: from smtp46.i.mail.ru (smtp46.i.mail.ru [95.163.41.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 3B598257FF2 for ; Mon, 13 Feb 2023 20:03:30 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3B598257FF2 Received: by smtp46.i.mail.ru with esmtpa (envelope-from ) id 1pRcEj-00Ft6R-86; Mon, 13 Feb 2023 20:03:29 +0300 To: Sergey Kaplun , Maxim Kokryashkin Date: Mon, 13 Feb 2023 17:02:45 +0000 Message-Id: <73073fb24db65f59c8629f4f377faa9e52cb54af.1676304797.git.imun@tarantool.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9D95CB639AA8C08F8F243B0CF85050B97D7A3688F4DE55FE8182A05F538085040D04444A09E85596D688A88E6E6D61766D118B6EF06825BB1E8095E77C1DC277C X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE731D82F3F177D3BCDEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637DC5FF0CF1FFF13268638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D833D22582C66CEF6DD1FDC6B72091E960117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC317C7E487E00003AA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735200AC5B80A05675ACDCB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EECCD848CCB6FE560CCE99E4F20BAF2718D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE32D01283D1ACF37BAC0837EA9F3D19764C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637FB177F6A8366F17BEFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A5773F193363908434A59A189A3A238BDC3ADE3B5B44683C1A4EAF44D9B582CE87C8A4C02DF684249CC203C45FEA855C8F X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34AAC3D1FDB34D0488D2F5BA158BD276FD065654183A2536358AD05778725800B792D65E545587CB581D7E09C32AA3244C110A72FF8D87FD910D748E79B2E8F3D3CE0B41342B755BCD927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojgB/I+mAIlFFFbeexFosdww== X-Mailru-Sender: 2FEBA92C8E508479FE7B9A1DF348D531626392C2CE6982C616D3EBE5EE203691DBA41A8244BEFFC52326FE6F2A341ACE0FB9F97486540B4CD9E8847AB8CFED4D9ABF8A61C016C2CFB0DAF586E7D11B3E67EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 3/7] test: stop using utils.selfrun in tests X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Igor Munkin via Tarantool-patches Reply-To: Igor Munkin Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Unfortunately, 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 helper is introduced: it inherits some approaches from , but it's considered for more general use. Relates to tarantool/tarantool#8252 Signed-off-by: Igor Munkin --- .../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 --- 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 as an argument to + -- 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 +-- 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 --- 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 as an argument to + -- 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 +-- 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 - -- , so just return from this routine and proceed - -- the execution to the test payload, ... - if os.getenv('TEST_SELFRUN') then return end - - -- ... otherwise initialize , setup testing environment - -- and run this chunk via for each case in . - -- 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', '/?.lua', ';'), - unshiftenv('LUA_CPATH', '/?.', ';'), - unshiftenv((libext == 'dylib' and 'DYLD' or 'LD') .. '_LIBRARY_PATH', - '', ':'), - 'TEST_SELFRUN=1', - }, ' '), - } - - local cmd = string.gsub(' 2>&1