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 2B8446F856; Tue, 24 Nov 2026 17:23:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2B8446F856 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1795530182; bh=6pjlUSiklgb7fqfYhzeZg0WcI8LjO2/6Q7tpu45BiM8=; 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=xkjep12cJ9z3Y+8k8TIlxeMFEra7B1Sj49ye6tjKLlWsmaHnpvDL03Ybp9xQUccKT CHZ3yo1Jbyew+ceisEz8+TNiIJKlIqfL2v1mI3FWkx2RCXIIqVI2JD0f34zJ6tEO7d XFQeCrV3kMa7V1+9RbAx+xM4MN3kMYyzakDSq7SQ= Received: from send242.i.mail.ru (send242.i.mail.ru [95.163.59.81]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 9EC446F856 for ; Tue, 24 Nov 2026 17:22:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9EC446F856 Received: by exim-smtp-56bb8ff957-dctjt with esmtpa (envelope-from ) id 1xVrPj-000000002sc-0ARI; Tue, 24 Nov 2026 17:22:31 +0300 To: Sergey Kaplun , Sergey Bronnikov Date: Tue, 24 Nov 2026 17:22:25 +0300 Message-ID: <48dc0df395bb6c6b22924cf95bbf45dc70a4a09c.1795529449.git.e.temirgaleev@tarantool.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9DFC18640EC982097B2FAA77ED009938F58C736F079745916182A05F5380850402CB330BAF970A2573DE06ABAFEAF6705A894662C51FE04ECB1581956376A59BA83EA1B0D5B4973F7 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7D9C4478D0B876341EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637F88016AB904663428638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B26A10C1C797E2B7C52E070BE324C7D3C4C3ADE222A8B2F07BF6B57BC7E64490611E7FA7ABCAF51C92176DF2183F8FC7C0CB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A127C277FBC8AE2E8B9FC99A4BA45EE8B4D81D268191BDAD3D3666184CF4C3C14F3FC91FA280E0CE3D1A620F70A64A45A98AA50765F7900637F9425D8FA97DB4396D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637B8FC44DDD98D6489EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A532A5D8722AF87FEA5002B1117B3ED696E111E8A59357BFABA13BD6A4B0E00B96823CB91A9FED034534781492E4B8EEAD5C5DFC4BFF39B799F36E2E0160E5C55395B8A2A0B6518DF68C46860778A80D548E8926FB43031F38 X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE191716CD42B3DD1D34CAB70F9BE574AE9C625B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D659BBDDA821CEEF47619771402DA0C8234C991401C40420C51569A14949117372A758831DE65BE43336B8341EE9D5BE9A0AB0197A28E98A3F38D6FDF57D9C0C4EF6E8120D4224F1DFA7C7CEAA0681F5848F4C41F94D744909CEEF9E35A692215F79327F81E6EEE0AEB67A0F9F91F029B6AF33F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXOcIETfglQORZ0zpDET4Zrk3igikrdHlWBiTkGLuVRw9e+eya20PhEY= X-Mailru-Sender: 015BA6FC0EFA223AFF5DE35D6D355F437C77173CFBC70B460841F56765D88C40DAD02459DC5417554282EA08EAAFFB078C34D365DA2E1307B60569B44082A3A3197AF8DA6C69D34BA7BD66BEAC8CCB0C4198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit v4 1/2] test: refactor utils.exec.makecmd 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: Evgeniy Temirgaleev via Tarantool-patches Reply-To: Evgeniy Temirgaleev Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Temir Galeev The 'utils.exec.makecmd()' was refactored. The common 'utils.exec.makecmd_exec()' added to allow executing arbitrary commands and the 'makecmd()' is implemented on top of it. The command object's 'LUABIN' field renamed to 'BIN', the 'SCRIPT' field with script filename replaced with 'PERMARGS' field, containing all command arguments, which are passed on every call, and the 'trace' callback option is added for additional processing of the generated command and it output. Also added the 'makecmd_tap_trace()' and 'test_data()' helpers. Test [1] was refactored to use 'makecmd()' as usual. Test [2] was refactored to use common 'makecmd_exec()'. 1. test/tarantool-tests/lj-962-stack-overflow-report.test.lua 2. test/tarantool-tests/lj-586-debug-non-string-error.test.lua Initially the patch for exec utils was prepared for tests in the follow up 'Improve CLI signal handling on POSIX' patch. After it's test simplification, the shell script helper was wiped out, but the refactoring was already done. --- .../lj-586-debug-non-string-error.test.lua | 34 ++++----- .../commands.lua | 2 + .../lj-962-stack-overflow-report.test.lua | 6 +- test/tarantool-tests/utils/exec.lua | 72 +++++++++++++++---- 4 files changed, 81 insertions(+), 33 deletions(-) create mode 100644 test/tarantool-tests/lj-586-debug-non-string-error/commands.lua 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 67869708..fe2b4b87 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 @@ -6,20 +6,18 @@ test:plan(1) -- XXX: This is quite an exotic test case in that point of view -- 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.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 --- for now). Hence, we use `utils.luacmd()` function to obtain the --- interpreter command, run `debug.debug()` with it, send two --- commands via pipeline to the launched process, capture its --- stdout and stderr and test the resulting output against the --- expected one. +-- sending commands to another instance via stdin. +-- Since `debug.debug()` captures `io.stdin` and waits at +-- `fgets()` in debug busy loop, we use `utils.exec.luacmd()` +-- function to obtain the interpreter command, run +-- `debug.debug()` with it, send two commands from the +-- `utils.exec.test_data('commands.lua')` file redirecting it to +-- the process stdin, capture its stdout and stderr and test the +-- resulting output against the expected one. -- -- Debugger prompt. local ldb = 'lua_debug> ' +-- The magic number is passed via MAGIC environment variable. local magic = 42 local luabin = utils.exec.luacmd(arg) local stderr = { @@ -37,11 +35,13 @@ local stderr = { -- errors are yielded before the magic given to `print()` command local expected = table.concat(stderr)..magic -local cmd = ([[cat <&1 -error({}) -print(%d) -EOF]]):format(luabin, magic) - -local res = io.popen(cmd):read('*all'):gsub('%s+$', '') +local dbg_commands_file = utils.exec.test_data(arg, 'commands.lua') +local command = utils.exec.makecmd_exec(luabin, { + env = {MAGIC = magic}, + redirect = ('2>&1 <%s'):format(dbg_commands_file), + args = {'-e', "'debug.debug()'"}, + trace = utils.exec.makecmd_tap_trace(test), +}) +local res = command() test:ok(res == expected, 'handle non-string error in debug.debug()') test:done(true) diff --git a/test/tarantool-tests/lj-586-debug-non-string-error/commands.lua b/test/tarantool-tests/lj-586-debug-non-string-error/commands.lua new file mode 100644 index 00000000..a27aaee7 --- /dev/null +++ b/test/tarantool-tests/lj-586-debug-non-string-error/commands.lua @@ -0,0 +1,2 @@ +error({}) +print(tonumber(os.getenv('MAGIC'))) diff --git a/test/tarantool-tests/lj-962-stack-overflow-report.test.lua b/test/tarantool-tests/lj-962-stack-overflow-report.test.lua index 848f4ead..14ffea10 100644 --- a/test/tarantool-tests/lj-962-stack-overflow-report.test.lua +++ b/test/tarantool-tests/lj-962-stack-overflow-report.test.lua @@ -4,8 +4,8 @@ local tap = require('tap') local test = tap.test('lj-962-stack-overflow-report') test:plan(1) -local LUABIN = require('utils').exec.luabin(arg) -local SCRIPT = arg[0]:gsub('%.test%.lua$', '/script.lua') -local output = io.popen(LUABIN .. ' 2>&1 ' .. SCRIPT, 'r'):read('*all') +local utils = require('utils') +local script = utils.exec.makecmd(arg, {redirect = '2>&1'}) +local output = script() test:like(output, 'stack overflow', 'stack overflow reported correctly') test:done(true) diff --git a/test/tarantool-tests/utils/exec.lua b/test/tarantool-tests/utils/exec.lua index 49f8ef06..1b79bd63 100644 --- a/test/tarantool-tests/utils/exec.lua +++ b/test/tarantool-tests/utils/exec.lua @@ -22,6 +22,7 @@ end local function makeenv(tabenv) if tabenv == nil then return '' end + assert(type(tabenv) == 'table') local flatenv = {} for var, value in pairs(tabenv) do if var == 'LD_PRELOAD' then @@ -43,33 +44,78 @@ local function makeenv(tabenv) return table.concat(flatenv, ' ') end --- 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) +-- creates a command that runs given binary +-- with the given environment, launch options and zero or +-- more permanent arguments. +-- The function yields an object (i.e. table) with the +-- aforementioned parameters. To launch the command just call +-- the object. Additional arguments which may vary from call +-- to call are the `__call` args. +-- Pass opts.trace function(event, value) for additional +-- command/output processing. +function M.makecmd_exec(bin, opts) + assert(type(bin) == 'string') + opts = opts or {} + assert(type(opts) == 'table') + local redirect = opts.redirect or '' + assert(type(redirect) == 'string') + local perm_args = opts.args or {} + assert(type(perm_args) == 'table') + assert(opts.trace == nil or type(opts.trace) == 'function') return setmetatable({ - LUABIN = M.luacmd(arg), - 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 '', + BIN = bin, + ENV = makeenv(opts.env), + REDIRECT = redirect, + PERMARGS = table.concat(perm_args, ' '), + trace = opts.trace, }, { __call = function(self, ...) -- This line just makes the command for by the -- following steps: -- 1. Replace the placeholders with the corresponding values - -- given to the command constructor (e.g. script, env). + -- given to the command constructor (e.g. bin, env). -- 2. Join all CLI arguments given to the __call metamethod. -- 3. Concatenate the results of step 1 and step 2 to obtain -- the resulting command. - local cmd = ('