Skip to content
Snippets Groups Projects
Commit ca5384e2 authored by Gleb Kashkin's avatar Gleb Kashkin Committed by Igor Munkin
Browse files

test: refactor dbgr test with `it` helper

`console_debugger_session_test.lua` can be simplified and made more
stable with interactive_tarantool helper. With the new
`read_untill_prompt()` helper function, dbgr prompt can be used as
end-of-output marker instead of '...' in yaml-outputting main console.
This way, popen results are unambiguous and no retries are required.
At the same time, dbgr prompt is now expected with every result, thus
there is no need for an extra check. But `continue` command usually
reaches the end of the script and exits debugger, thus
'<END_OF_EXECUTION>' marker was introduced.
Empty stderr and header check were moved to interactive_tarantool helper.
This patch breaks the test without debugger readline support patch,
that is next in the patchset.

Part of #7738

NO_CHANGELOG=test refactoring
NO_DOC=test refactoring

(cherry picked from commit 72008443)
parent bdc622e9
No related branches found
No related tags found
No related merge requests found
local t = require('luatest') local t = require('luatest')
local popen = require('popen')
local tnt = require('tarantool')
local fio = require('fio') local fio = require('fio')
local it = require('test.interactive_tarantool')
local function unescape(s) local function unescape(s)
return s and s:gsub('[\27\155][][()#;?%d]*[A-PRZcf-ntqry=><~]', '') or '' return s and s:gsub('[\27\155][][()#;?%d]*[A-PRZcf-ntqry=><~]', '') or ''
...@@ -11,17 +10,7 @@ local function trim(s) ...@@ -11,17 +10,7 @@ local function trim(s)
return s and s:gsub('%s+$', '') or '' return s and s:gsub('%s+$', '') or ''
end end
local function tarantool_path(arg)
local index = -2
-- arg[-1] is guaranteed to be non-null
while arg[index] do index = index - 1 end
return arg[index + 1]
end
local TARANTOOL_PATH = tarantool_path(arg)
local DEBUGGER = 'luadebug' local DEBUGGER = 'luadebug'
local dbg_header = tnt.package .. " debugger " .. tnt.version
local dbg_prompt = DEBUGGER .. '>' local dbg_prompt = DEBUGGER .. '>'
local dbg_failed_bp = 'command expects argument in format filename:NN or ' .. local dbg_failed_bp = 'command expects argument in format filename:NN or ' ..
'filename+NN, where NN should be a positive number.' 'filename+NN, where NN should be a positive number.'
...@@ -146,17 +135,17 @@ local sequences = { ...@@ -146,17 +135,17 @@ local sequences = {
12 | os.exit(0) 12 | os.exit(0)
]], ]],
{ ['\t'] = '' }, -- \t is a special value for start { ['\t'] = '' }, -- \t is a special value for start
{ ['n'] = dbg_prompt }, { ['n'] = '' },
{ ['s'] = dbg_prompt }, { ['s'] = '' },
{ ['n'] = dbg_prompt }, { ['n'] = '' },
{ ['n'] = dbg_prompt }, { ['n'] = '' },
{ ['p'] = 'expects argument, but none received' }, { ['p'] = 'expects argument, but none received' },
{ ['p obj'] = 'obj => {"tzoffset" = "+0300", "hour" = 3}' }, { ['p obj'] = 'obj => {"tzoffset" = "+0300", "hour" = 3}' },
{ ['n'] = dbg_prompt }, { ['n'] = '' },
{ ['p ymd'] = 'ymd => false' }, { ['p ymd'] = 'ymd => false' },
{ ['w'] = 'local hms = false' }, { ['w'] = 'local hms = false' },
{ ['bogus;'] = 'is not recognized.' }, { ['bogus;'] = 'is not recognized.' },
{ ['h'] = dbg_prompt }, { ['h'] = '' },
{ ['t'] = '=> builtin/datetime.lua' }, { ['t'] = '=> builtin/datetime.lua' },
{ ['u'] = '{file}:3 in chunk at' }, { ['u'] = '{file}:3 in chunk at' },
-- FIXME (gh-8190) - we should not show calling side at luadebug.lua -- FIXME (gh-8190) - we should not show calling side at luadebug.lua
...@@ -165,15 +154,15 @@ local sequences = { ...@@ -165,15 +154,15 @@ local sequences = {
{ ['d'] = '{file}:3 in chunk at' }, { ['d'] = '{file}:3 in chunk at' },
{ ['d'] = 'Inspecting frame: builtin/datetime.lua' }, { ['d'] = 'Inspecting frame: builtin/datetime.lua' },
{ ['l'] = 'obj => {"tzoffset" = "+0300", "hour" = 3}' }, { ['l'] = 'obj => {"tzoffset" = "+0300", "hour" = 3}' },
{ ['f'] = dbg_prompt }, { ['f'] = '' },
{ ['n'] = dbg_prompt }, { ['n'] = '' },
{ ['p T'] = 'T => 1970-01-01T03:00:00+0300' }, { ['p T'] = 'T => 1970-01-01T03:00:00+0300' },
{ ['n'] = dbg_prompt }, { ['n'] = '' },
{ [''] = dbg_prompt }, { [''] = '' },
{ [''] = dbg_prompt }, { [''] = '' },
{ [''] = dbg_prompt }, { [''] = '' },
{ ['p S'] = 'S => "1970-01-01T0300+0300"' }, { ['p S'] = 'S => "1970-01-01T0300+0300"' },
{ ['c'] = '' }, { ['c'] = '<END_OF_EXECUTION>' },
}, },
-- partial sequence with successful breakpoints added -- partial sequence with successful breakpoints added
...@@ -193,12 +182,12 @@ local sequences = { ...@@ -193,12 +182,12 @@ local sequences = {
12 | os.exit(0) 12 | os.exit(0)
]], ]],
{ ['\t'] = '' }, -- \t is a special value for start { ['\t'] = '' }, -- \t is a special value for start
{ ['b +9'] = dbg_prompt }, { ['b +9'] = '' },
{ ['c'] = '{file}:9' }, { ['c'] = '{file}:9' },
{ ['n'] = dbg_prompt }, { ['n'] = '' },
{ ['p S'] = 'S => "1970-01-01T0300+0300"' }, { ['p S'] = 'S => "1970-01-01T0300+0300"' },
{ ['p T'] = 'T => 1970-01-01T03:00:00+0300' }, { ['p T'] = 'T => 1970-01-01T03:00:00+0300' },
{ ['c'] = '' }, { ['c'] = '<END_OF_EXECUTION>' },
}, },
-- partial sequence with failed breakpoint addsitions -- partial sequence with failed breakpoint addsitions
...@@ -267,21 +256,23 @@ local sequences = { ...@@ -267,21 +256,23 @@ local sequences = {
}, },
} }
local function run_debug_session(cmdline, sequence, tmpfile, header) local function run_debug_session(sequence, tmpfile, flags)
local short_src = fio.basename(tmpfile) local short_src = fio.basename(tmpfile)
--[[ --[[
repeat multiple times to check all command aliases repeat multiple times to check all command aliases
]] ]]
for i = 1, MAX_ALIASES_COUNT do for i = 1, MAX_ALIASES_COUNT do
local fh = popen.new(cmdline, { local args
stdout = popen.opts.PIPE, if flags then
stderr = popen.opts.PIPE, args = {flags, tmpfile}
stdin = popen.opts.PIPE, else
}) args = {tmpfile}
t.assert_is_not(fh, nil) end
-- for -d option we expect debugger banner in the stderr, local expect_header = type(flags) == 'string' and flags:find("-d")
-- but for self invoke debugger there is no extra header. local child = it.new_debugger({args = args,
local first = header ~= nil expect_header = expect_header})
debuglog(child:read_until_prompt(dbg_prompt))
for _, row in pairs(sequence) do for _, row in pairs(sequence) do
local cmd, expected = next(row) local cmd, expected = next(row)
-- interpret template strings {file} -- interpret template strings {file}
...@@ -290,36 +281,22 @@ local function run_debug_session(cmdline, sequence, tmpfile, header) ...@@ -290,36 +281,22 @@ local function run_debug_session(cmdline, sequence, tmpfile, header)
if cmd ~= '' then if cmd ~= '' then
local key, arg = get_key_arg_pair(cmd) local key, arg = get_key_arg_pair(cmd)
arg = arg and (' ' .. arg) or '' arg = arg and (' ' .. arg) or ''
cmd = get_cmd_alias(key, i) .. arg .. '\n' cmd = get_cmd_alias(key, i) .. arg
else -- '' empty command - repeat prior one
cmd = cmd .. '\n'
end end
fh:write(cmd) debuglog('Execute command: "' .. trim(cmd) .. '"')
debuglog('Execute command: "'..trim(cmd)..'"') child:execute_command(cmd)
end end
local result if expected == '<END_OF_EXECUTION>' then
local clean_cmd = trim(cmd) t.assert_error_msg_contains('Unexpected EOF',
-- there should be empty stderr - check it before stdout child.read_until_prompt, child)
local errout = fh:read({ timeout = 0.05, stderr = true})
debuglog('stderr output: ', trim(errout))
if first and errout then
-- we do not expect anything on stderr
-- with exception of initial debugger header
t.assert_str_contains(trim(errout), header, false)
first = false
else else
t.assert(errout == nil or trim(errout) == '') local res = trim(unescape(child:read_until_prompt(dbg_prompt)))
end debuglog(res)
repeat t.assert_str_contains(res, expected)
result = trim(unescape(fh:read({ timeout = 0.5 })))
debuglog('stdout output:', result)
until result ~= '' or result ~= clean_cmd
if expected ~= '' then
t.assert_str_contains(result, expected, false)
end end
end end
fh:close() child:close()
end end
debuglog('Delete temporary file ', tmpfile) debuglog('Delete temporary file ', tmpfile)
os.remove(tmpfile) os.remove(tmpfile)
...@@ -334,8 +311,7 @@ g.test_debugger = function(cg) ...@@ -334,8 +311,7 @@ g.test_debugger = function(cg)
local tmpfile = table.remove(sequence, 1) local tmpfile = table.remove(sequence, 1)
t.assert(type(tmpfile) == 'string') t.assert(type(tmpfile) == 'string')
local cmd = { TARANTOOL_PATH, '-d', tmpfile } run_debug_session(sequences[scenario_name], tmpfile, '-d')
run_debug_session(cmd, sequences[scenario_name], tmpfile, dbg_header)
end end
local g_self = t.group('self-debug') local g_self = t.group('self-debug')
...@@ -352,10 +328,10 @@ local shorter_sequence = { ...@@ -352,10 +328,10 @@ local shorter_sequence = {
8 | os.exit(0) 8 | os.exit(0)
]], ]],
{ ['\t'] = '' }, -- \t is a special value for start { ['\t'] = '' }, -- \t is a special value for start
{ ['n'] = dbg_prompt }, { ['n'] = '' },
{ ['s'] = dbg_prompt }, { ['s'] = '' },
{ ['n'] = dbg_prompt }, { ['n'] = '' },
{ ['n'] = dbg_prompt }, { ['n'] = '' },
{ ['p'] = 'expects argument, but none received' }, { ['p'] = 'expects argument, but none received' },
{ ['p obj'] = 'obj => {"tzoffset" = "+0300", "hour" = 3}' }, { ['p obj'] = 'obj => {"tzoffset" = "+0300", "hour" = 3}' },
{ ['u'] = '{file}:5 in chunk at' }, { ['u'] = '{file}:5 in chunk at' },
...@@ -363,7 +339,7 @@ local shorter_sequence = { ...@@ -363,7 +339,7 @@ local shorter_sequence = {
{ ['d'] = 'Inspecting frame: builtin/datetime.lua' }, { ['d'] = 'Inspecting frame: builtin/datetime.lua' },
{ ['l'] = 'obj => {"tzoffset" = "+0300", "hour" = 3}' }, { ['l'] = 'obj => {"tzoffset" = "+0300", "hour" = 3}' },
{ ['f'] = '{file}:6 in chunk at' }, { ['f'] = '{file}:6 in chunk at' },
{ ['c'] = '' }, { ['c'] = '<END_OF_EXECUTION>' },
} }
-- `tarantool debug-self-target.lua`, where -- `tarantool debug-self-target.lua`, where
...@@ -372,6 +348,5 @@ g_self.test_debug_self_invoke = function() ...@@ -372,6 +348,5 @@ g_self.test_debug_self_invoke = function()
local tmpfile = table.remove(shorter_sequence, 1) local tmpfile = table.remove(shorter_sequence, 1)
t.assert(type(tmpfile) == 'string') t.assert(type(tmpfile) == 'string')
local cmd = { TARANTOOL_PATH, tmpfile } run_debug_session(shorter_sequence, tmpfile)
run_debug_session(cmd, shorter_sequence, tmpfile)
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment