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 4BED52ADDE1; Mon, 27 Feb 2023 12:11:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4BED52ADDE1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1677489065; bh=MxTOa+ZmwxkKwWpGR995rVa1wXS08G/NfqT3zzohZ4c=; 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=bozYbQcW1FSuvZWN60pOgDyQrkIh6nSaCj0uPjliVK6++n0meBPGtXfROOKzO+19+ jJ+ELLCKAQQt3Esi6ivgZph6+R10JM2TlVY1lgLoyXrFjz8K4U0fqwcmoHI+4sI5fM UzHjo9tboWbw1RJKrnikedb5PHSxdQOc0su3ePHY= Received: from smtp31.i.mail.ru (smtp31.i.mail.ru [95.163.41.72]) (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 6E6292ADDE1 for ; Mon, 27 Feb 2023 12:10:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6E6292ADDE1 Received: by smtp31.i.mail.ru with esmtpa (envelope-from ) id 1pWZWF-002jL3-6Q; Mon, 27 Feb 2023 12:10:03 +0300 To: Sergey Kaplun , Maxim Kokryashkin Date: Mon, 27 Feb 2023 09:07:20 +0000 Message-Id: <23e688af9b21aa37b9b17994655ad78c98dbd951.1677236706.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: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD94A31EA4B0797EF2EE50B5111BED4E5A0F9C3BE6961C3C823182A05F5380850404C228DA9ACA6FE2776B22A79F292841AF97142B92E18FC5A9FAA8C8C30F8F3502CCF40E85E0AD5C8 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE76ABD3380F320B62CEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637EA3E6C6690B39D9B8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D851D4DC99F0CEB9811C8F14632AD9D2C0117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC4AFB60FD1831C04CA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735200AC5B80A05675ACD6FD1C55BDD38FC3FD2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EEB28585415E75ADA997A342136F30543AD8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE386A7C529F68B8E5CBA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE732FCE54C4D9A645443847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: 0D63561A33F958A559DF399D05555804AB363DFE61A064F4DA065E124E547C8D4EAF44D9B582CE87C8A4C02DF684249CC203C45FEA855C8F X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34AF12ADB97C97CD8921BC16248AE130D972D51020D2D3EA1F73DC5FCE3A495F9BC9219F55836328741D7E09C32AA3244C561AC94260D1C3759F76C3C3D9F94D3F3FD9C8CA1B0515E0927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojY+HhiuGRi+rb//h67UGZiA== X-Mailru-Sender: 2FEBA92C8E508479FE7B9A1DF348D5312400532989988835F3BEB903E4F036FC84355E15920591B32326FE6F2A341ACE0FB9F97486540B4CD9E8847AB8CFED4D9ABF8A61C016C2CFB0DAF586E7D11B3E67EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 2/5] 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. Signed-off-by: Igor Munkin --- .../gh-4427-ffi-sandwich.test.lua | 88 +++++++++++-------- .../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 | 87 ++++++++++-------- .../lj-flush-on-trace/script.lua | 23 +++++ test/tarantool-tests/utils.lua | 80 +++++++---------- 8 files changed, 200 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..06985dcd 100644 --- a/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua +++ b/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua @@ -3,52 +3,62 @@ 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) +-- runs %testname%/script.lua by +-- with the given environment, launch options and CLI arguments. +local script = utils.makecmd(arg, { + -- XXX: Apple tries their best to "protect their users from + -- malware". As a result SIP (see the link[1] below) has been + -- designed and released. Now, Apple developers are so + -- protected, that they can load nothing being not installed in + -- the system, since the environment is sanitized before the + -- child process is launched. In particular, environment + -- variables starting with DYLD_ and LD_ are unset for child + -- process. For more info, see the docs[2] below. + -- + -- The environment variable below is used by FFI machinery to + -- find the proper shared library. + -- + -- luacheck: push no max comment line length + -- + -- [1]: https://support.apple.com/en-us/HT204899 + -- [2]: https://developer.apple.com/library/archive/documentation/Security/Conceptual/System_Integrity_Protection_Guide/RuntimeProtections/RuntimeProtections.html + -- + -- luacheck: pop + 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..3351cc5a 100644 --- a/test/tarantool-tests/lj-flush-on-trace.test.lua +++ b/test/tarantool-tests/lj-flush-on-trace.test.lua @@ -3,51 +3,62 @@ 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) +-- runs %testname%/script.lua by +-- with the given environment, launch options and CLI arguments. +local script = utils.makecmd(arg, { + -- XXX: Apple tries their best to "protect their users from + -- malware". As a result SIP (see the link[1] below) has been + -- designed and released. Now, Apple developers are so + -- protected, that they can load nothing being not installed in + -- the system, since the environment is sanitized before the + -- child process is launched. In particular, environment + -- variables starting with DYLD_ and LD_ are unset for child + -- process. For more info, see the docs[2] below. + -- + -- The environment variable below is used by FFI machinery to + -- find the proper shared library. + -- + -- luacheck: push no max comment line length + -- + -- [1]: https://support.apple.com/en-us/HT204899 + -- [2]: https://developer.apple.com/library/archive/documentation/Security/Conceptual/System_Integrity_Protection_Guide/RuntimeProtections/RuntimeProtections.html + -- + -- luacheck: pop + 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..8355149b 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,42 @@ 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 = { +-- creates a command that runs %testname%/script.lua by +-- with the given environment, launch options +-- and CLI arguments. The function yields an object (i.e. table) +-- with the aforementioned parameters. To launch the command just +-- call the object. +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