From 190c8516f534499f89d610fc78a20c025386b2f2 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 26 Sep 2017 23:13:55 +0300 Subject: unittests: Add a way to print trace on regular error --- test/unit/helpers.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'test/unit/helpers.lua') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 4b9f185156..a629fca9a2 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -698,7 +698,14 @@ local function check_child_err(rd) local len_s = sc.read(rd, 5) local len = tonumber(len_s) neq(0, len) - local err = sc.read(rd, len + 1) + local err = '' + if os.getenv('NVIM_TEST_TRACE_ON_ERROR') == '1' and #trace ~= 0 then + err = '\nTest failed, trace:\n' .. tracehelp + for _, traceline in ipairs(trace) do + err = err .. traceline + end + end + err = err .. sc.read(rd, len + 1) assert.just_fail(err) end -- cgit From 919223c23ae3c8c904f35e7d605b1cf14d44a5f0 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 3 Sep 2017 19:57:24 +0300 Subject: unittests: Move some functions into helpers modules --- test/unit/helpers.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/unit/helpers.lua') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index a629fca9a2..a5ca7b069b 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -760,6 +760,29 @@ end cimport('./src/nvim/types.h', './src/nvim/main.h', './src/nvim/os/time.h') +local function conv_enum(etab, eval) + local n = tonumber(eval) + return etab[n] or n +end + +local function array_size(arr) + return ffi.sizeof(arr) / ffi.sizeof(arr[0]) +end + +local function kvi_size(kvi) + return array_size(kvi.init_array) +end + +local function kvi_init(kvi) + kvi.capacity = kvi_size(kvi) + kvi.items = kvi.init_array + return kvi +end + +local function kvi_new(ct) + return kvi_init(ffi.new(ct)) +end + local module = { cimport = cimport, cppimport = cppimport, @@ -780,6 +803,11 @@ local module = { child_call_once = child_call_once, child_cleanup_once = child_cleanup_once, sc = sc, + conv_enum = conv_enum, + array_size = array_sive, + kvi_size = kvi_size, + kvi_init = kvi_init, + kvi_new = kvi_new, } return function() return module -- cgit From 430e516d3ac1235c1ee3009a8a36089bf278440e Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 3 Sep 2017 21:58:16 +0300 Subject: viml/parser/expressions: Start creating expressions parser Currently supported nodes: - Register as it is one of the simplest value nodes (even numbers are not that simple with that dot handling). - Plus, both unary and binary. - Parenthesis, both nesting and calling. Note regarding unit tests: it stores data for AST in highlighting in strings in place of tables because luassert fails to do a good job at representing big tables. Squashing a bunch of data into a single string simply yields more readable result. --- test/unit/helpers.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/unit/helpers.lua') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index a5ca7b069b..d3d14a5ca2 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -783,6 +783,31 @@ local function kvi_new(ct) return kvi_init(ffi.new(ct)) end +local function make_enum_conv_tab(lib, values, skip_pref, set_cb) + child_call_once(function() + local ret = {} + for _, v in ipairs(values) do + local str_v = v + if v:sub(1, #skip_pref) == skip_pref then + str_v = v:sub(#skip_pref + 1) + end + ret[tonumber(lib[v])] = str_v + end + set_cb(ret) + end) +end + +local function ptr2addr(ptr) + return tonumber(ffi.cast('intptr_t', ffi.cast('void *', ptr))) +end + +local s = ffi.new('char[64]', {0}) + +local function ptr2key(ptr) + ffi.C.snprintf(s, ffi.sizeof(s), '%p', ffi.cast('void *', ptr)) + return ffi.string(s) +end + local module = { cimport = cimport, cppimport = cppimport, @@ -808,6 +833,9 @@ local module = { kvi_size = kvi_size, kvi_init = kvi_init, kvi_new = kvi_new, + make_enum_conv_tab = make_enum_conv_tab, + ptr2addr = ptr2addr, + ptr2key = ptr2key, } return function() return module -- cgit From 252a76db80dd846f9ccac4d7001697c12c009826 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 16 Oct 2017 03:06:34 +0300 Subject: unittests: Free everything and check for memory leaks Also improves error reporting. --- test/unit/helpers.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'test/unit/helpers.lua') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index d3d14a5ca2..68ce9eed62 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -315,7 +315,7 @@ local function alloc_log_new() eq(exp, self.log) self:clear() end - function log:clear_tmp_allocs() + function log:clear_tmp_allocs(clear_null_frees) local toremove = {} local allocs = {} for i, v in ipairs(self.log) do @@ -327,6 +327,8 @@ local function alloc_log_new() if v.func == 'free' then toremove[#toremove + 1] = i end + elseif clear_null_frees and v.args[1] == self.null then + toremove[#toremove + 1] = i end if v.func == 'realloc' then allocs[tostring(v.ret)] = i @@ -779,6 +781,12 @@ local function kvi_init(kvi) return kvi end +local function kvi_destroy(kvi) + if kvi.items ~= kvi.init_array then + lib.xfree(kvi.items) + end +end + local function kvi_new(ct) return kvi_init(ffi.new(ct)) end @@ -830,6 +838,7 @@ local module = { sc = sc, conv_enum = conv_enum, array_size = array_sive, + kvi_destroy = kvi_destroy, kvi_size = kvi_size, kvi_init = kvi_init, kvi_new = kvi_new, -- cgit From 3ecb95298ffd9ef6ee681876f2d32553fd222b96 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 30 Oct 2017 01:48:32 +0300 Subject: tests: Fix testlint errors --- test/unit/helpers.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/unit/helpers.lua') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 68ce9eed62..96aa505739 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -791,7 +791,7 @@ local function kvi_new(ct) return kvi_init(ffi.new(ct)) end -local function make_enum_conv_tab(lib, values, skip_pref, set_cb) +local function make_enum_conv_tab(m, values, skip_pref, set_cb) child_call_once(function() local ret = {} for _, v in ipairs(values) do @@ -799,7 +799,7 @@ local function make_enum_conv_tab(lib, values, skip_pref, set_cb) if v:sub(1, #skip_pref) == skip_pref then str_v = v:sub(#skip_pref + 1) end - ret[tonumber(lib[v])] = str_v + ret[tonumber(m[v])] = str_v end set_cb(ret) end) @@ -837,7 +837,7 @@ local module = { child_cleanup_once = child_cleanup_once, sc = sc, conv_enum = conv_enum, - array_size = array_sive, + array_size = array_size, kvi_destroy = kvi_destroy, kvi_size = kvi_size, kvi_init = kvi_init, -- cgit From bbb21e5dd3891727c272ffd3aa4ce2a4841a1f0b Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 11 Nov 2017 23:50:37 +0300 Subject: unittests: Add a way to show some custom messages only when crashed --- test/unit/helpers.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'test/unit/helpers.lua') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 96aa505739..2c148630dd 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -529,9 +529,13 @@ local hook_numlen = 5 local hook_msglen = 1 + 1 + 1 + (1 + hook_fnamelen) + (1 + hook_sfnamelen) + (1 + hook_numlen) + 1 local tracehelp = dedent([[ + Trace: either in the format described below or custom debug output starting + with `>`. Latter lines still have the same width in byte. + ┌ Trace type: _r_eturn from function , function _c_all, _l_ine executed, │ _t_ail return, _C_ount (should not actually appear), - │ _s_aved from previous run for reference. + │ _s_aved from previous run for reference, _>_ for custom debug + │ output. │┏ Function type: _L_ua function, _C_ function, _m_ain part of chunk, │┃ function that did _t_ail call. │┃┌ Function name type: _g_lobal, _l_ocal, _m_ethod, _f_ield, _u_pvalue, @@ -629,7 +633,17 @@ end local trace_end_msg = ('E%s\n'):format((' '):rep(hook_msglen - 2)) +local _debug_log + +local debug_log = only_separate(function(...) + return _debug_log(...) +end) + local function itp_child(wr, func) + _debug_log = function(s) + s = s:sub(1, hook_msglen - 2) + sc.write(wr, '>' .. s .. (' '):rep(hook_msglen - 2 - #s) .. '\n') + end init() collectgarbage('stop') child_sethook(wr) @@ -845,6 +859,7 @@ local module = { make_enum_conv_tab = make_enum_conv_tab, ptr2addr = ptr2addr, ptr2key = ptr2key, + debug_log = debug_log, } return function() return module -- cgit From 7c20f60b88b1df97af8ea4a6a5b9727c72748ec1 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 19 Nov 2017 21:46:54 +0300 Subject: unittests: Avoid infinite cycle somewhere because of init failure --- test/unit/helpers.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'test/unit/helpers.lua') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 2c148630dd..7689c1824b 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -644,13 +644,15 @@ local function itp_child(wr, func) s = s:sub(1, hook_msglen - 2) sc.write(wr, '>' .. s .. (' '):rep(hook_msglen - 2 - #s) .. '\n') end - init() - collectgarbage('stop') - child_sethook(wr) - local err, emsg = pcall(func) - collectgarbage('restart') - collectgarbage() - debug.sethook() + local err, emsg = pcall(init) + if err then + collectgarbage('stop') + child_sethook(wr) + err, emsg = pcall(func) + collectgarbage('restart') + collectgarbage() + debug.sethook() + end emsg = tostring(emsg) sc.write(wr, trace_end_msg) if not err then -- cgit From 59f4bd435c6754f475dfb61bb6c881ce914b17e6 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 29 Nov 2017 10:07:12 -0500 Subject: unittest: Ignore _Float128 types in ffi When building with certain GCC versions, a _Float128 type is present when setting up the ffi for unit tests. ./test/unit/helpers.lua:256: declaration specifier expected near '_Float128' at line 396 /usr/bin/luajit: /usr/share/lua/5.1/busted/runner.lua:99: attempt to concatenate local 'message' (a table value) stack traceback: /usr/share/lua/5.1/busted/runner.lua:99: in function 'fn' /usr/share/lua/5.1/mediator.lua:103: in function 'publish' /usr/share/lua/5.1/busted/modules/helper_loader.lua:21: in function 'helperLoader' /usr/share/lua/5.1/busted/runner.lua:147: in function /usr/bin/busted:3: in main chunk [C]: at 0x004044a0 CMake Error at /<>/cmake/RunTests.cmake:53 (message): Running unit tests failed with error: 1. Since this is being pulled in by a dependency, not directly used by nvim, just ignore the type. Closes #7423 --- test/unit/helpers.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/unit/helpers.lua') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 4b9f185156..ac5e394a54 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -138,6 +138,7 @@ local function filter_complex_blocks(body) for line in body:gmatch("[^\r\n]+") do if not (string.find(line, "(^)", 1, true) ~= nil or string.find(line, "_ISwupper", 1, true) + or string.find(line, "_Float128") or string.find(line, "msgpack_zone_push_finalizer") or string.find(line, "msgpack_unpacker_reserve_buffer") or string.find(line, "UUID_NULL") -- static const uuid_t UUID_NULL = {...} -- cgit From 0b4054e043257137ccfd3b2207da48910ce32a5f Mon Sep 17 00:00:00 2001 From: ZyX Date: Thu, 30 Nov 2017 11:44:48 +0300 Subject: unittests: Reduce memory used by vim_str2nr test --- test/unit/helpers.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/unit/helpers.lua') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index c26b1c1bcb..b1e709c444 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -675,6 +675,7 @@ end local function check_child_err(rd) local trace = {} local did_traceline = false + local maxtrace = tonumber(os.getenv('NVIM_TEST_MAXTRACE')) or 1024 while true do local traceline = sc.read(rd, hook_msglen) if #traceline ~= hook_msglen then @@ -689,6 +690,7 @@ local function check_child_err(rd) break end trace[#trace + 1] = traceline + table.remove(trace, maxtrace + 1) end local res = sc.read(rd, 2) if #res ~= 2 then -- cgit From 32689aa5bed472ca981f323439b98e0911b403b9 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 24 Dec 2017 17:13:42 +0300 Subject: unittests: Remove start of trace, not end --- test/unit/helpers.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test/unit/helpers.lua') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index b1e709c444..589e026e5f 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -690,7 +690,9 @@ local function check_child_err(rd) break end trace[#trace + 1] = traceline - table.remove(trace, maxtrace + 1) + if #trace > maxtrace then + table.remove(trace, 1) + end end local res = sc.read(rd, 2) if #res ~= 2 then -- cgit From 2923e8533d1e28f9e771d2b4a7d279bfa266a480 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 24 Dec 2017 17:42:23 +0300 Subject: unittests: Do gc after reporting error, not before Reason: test may contain cleanup at the endwhich is needed for GC to work properly, but is not done if test fails. With collectgarbage() in former position it would crash when collecting garbage. --- test/unit/helpers.lua | 73 ++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 36 deletions(-) (limited to 'test/unit/helpers.lua') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 589e026e5f..87c838dece 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -650,8 +650,6 @@ local function itp_child(wr, func) collectgarbage('stop') child_sethook(wr) err, emsg = pcall(func) - collectgarbage('restart') - collectgarbage() debug.sethook() end emsg = tostring(emsg) @@ -662,14 +660,15 @@ local function itp_child(wr, func) end sc.write(wr, ('-\n%05u\n%s'):format(#emsg, emsg)) deinit() - sc.close(wr) - sc.exit(1) else sc.write(wr, '+\n') deinit() - sc.close(wr) - sc.exit(0) end + collectgarbage('restart') + collectgarbage() + sc.write(wr, '$\n') + sc.close(wr) + sc.exit(err and 0 or 1) end local function check_child_err(rd) @@ -695,41 +694,43 @@ local function check_child_err(rd) end end local res = sc.read(rd, 2) - if #res ~= 2 then - local error - if #trace == 0 then - error = '\nTest crashed, no trace available\n' - else - error = '\nTest crashed, trace:\n' .. tracehelp - for i = 1, #trace do - error = error .. trace[i] + if #res == 2 then + local err = '' + if res ~= '+\n' then + eq('-\n', res) + local len_s = sc.read(rd, 5) + local len = tonumber(len_s) + neq(0, len) + if os.getenv('NVIM_TEST_TRACE_ON_ERROR') == '1' and #trace ~= 0 then + err = '\nTest failed, trace:\n' .. tracehelp + for _, traceline in ipairs(trace) do + err = err .. traceline + end end + err = err .. sc.read(rd, len + 1) end - if not did_traceline then - error = error .. '\nNo end of trace occurred' - end - local cc_err, cc_emsg = pcall(check_cores, Paths.test_luajit_prg, true) - if not cc_err then - error = error .. '\ncheck_cores failed: ' .. cc_emsg + local eres = sc.read(rd, 2) + if eres ~= '$\n' then + if #trace == 0 then + err = '\nTest crashed, no trace available\n' + else + err = '\nTest crashed, trace:\n' .. tracehelp + for i = 1, #trace do + err = err .. trace[i] + end + end + if not did_traceline then + err = err .. '\nNo end of trace occurred' + end + local cc_err, cc_emsg = pcall(check_cores, Paths.test_luajit_prg, true) + if not cc_err then + err = err .. '\ncheck_cores failed: ' .. cc_emsg + end end - assert.just_fail(error) - end - if res == '+\n' then - return - end - eq('-\n', res) - local len_s = sc.read(rd, 5) - local len = tonumber(len_s) - neq(0, len) - local err = '' - if os.getenv('NVIM_TEST_TRACE_ON_ERROR') == '1' and #trace ~= 0 then - err = '\nTest failed, trace:\n' .. tracehelp - for _, traceline in ipairs(trace) do - err = err .. traceline + if err ~= '' then + assert.just_fail(err) end end - err = err .. sc.read(rd, len + 1) - assert.just_fail(err) end local function itp_parent(rd, pid, allow_failure) -- cgit From 158f8b7ce3051127918148f7f8e9892a4c9ae34f Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sun, 25 Feb 2018 04:23:12 -0500 Subject: unittest: Ignore all _Float-prefixed types (#8067) Previously, we ignored only _Float128. But glibc 2.27 added _Float32 and _Float32x. Rather than play whack-a-mole, ignore everything. --- test/unit/helpers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/unit/helpers.lua') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 87c838dece..5cc2be50b1 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -138,7 +138,7 @@ local function filter_complex_blocks(body) for line in body:gmatch("[^\r\n]+") do if not (string.find(line, "(^)", 1, true) ~= nil or string.find(line, "_ISwupper", 1, true) - or string.find(line, "_Float128") + or string.find(line, "_Float") or string.find(line, "msgpack_zone_push_finalizer") or string.find(line, "msgpack_unpacker_reserve_buffer") or string.find(line, "UUID_NULL") -- static const uuid_t UUID_NULL = {...} -- cgit