From 271df03fa4b507d8ec608abd530616cb4b57616e Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 4 Apr 2017 18:14:09 +0300 Subject: unittests: Force GC, fix GC failures in typval_spec --- test/unit/eval/typval_spec.lua | 37 +++++++++++++++++++++++++++---------- test/unit/helpers.lua | 3 ++- 2 files changed, 29 insertions(+), 11 deletions(-) (limited to 'test/unit') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 258b5c4c1f..c477683038 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -460,6 +460,10 @@ describe('typval.c', function() eq(empty_list, typvalt2lua(l_tv)) eq({true, true, true}, {lws[1].lw_item == nil, lws[2].lw_item == nil, lws[3].lw_item == nil}) + lib.tv_list_watch_remove(l, lws[1]) + lib.tv_list_watch_remove(l, lws[2]) + lib.tv_list_watch_remove(l, lws[3]) + alloc_log:check({}) end) end) @@ -1090,9 +1094,13 @@ describe('typval.c', function() local function list_join(l, sep, ret) local ga = ga_alloc() eq(ret or OK, lib.tv_list_join(ga, l, sep)) - if ga.ga_data == nil then return '' - else return ffi.string(ga.ga_data) + local ret = '' + if ga.ga_data ~= nil then + ret = ffi.string(ga.ga_data) end + -- For some reason this is not working well in GC + lib.ga_clear(ffi.gc(ga, nil)) + return ret end itp('works', function() local l @@ -2659,7 +2667,8 @@ describe('typval.c', function() {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 0}, {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', 0}, }) do - local tv = typvalt(v[1], v[2]) + -- Using to_cstr, cannot free with tv_clear + local tv = ffi.gc(typvalt(v[1], v[2]), nil) alloc_log:check({}) local emsg = v[3] local ret = v[4] @@ -2687,7 +2696,8 @@ describe('typval.c', function() {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 0}, {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', 0}, }) do - local tv = typvalt(v[1], v[2]) + -- Using to_cstr, cannot free with tv_clear + local tv = ffi.gc(typvalt(v[1], v[2]), nil) alloc_log:check({}) local emsg = v[3] local ret = {v[4], not not emsg} @@ -2721,7 +2731,8 @@ describe('typval.c', function() {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', -1}, }) do lib.curwin.w_cursor.lnum = 46 - local tv = typvalt(v[1], v[2]) + -- Using to_cstr, cannot free with tv_clear + local tv = ffi.gc(typvalt(v[1], v[2]), nil) alloc_log:check({}) local emsg = v[3] local ret = v[4] @@ -2749,7 +2760,8 @@ describe('typval.c', function() {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, 'E907: Using a special value as a Float', 0}, {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_float(UNKNOWN)', 0}, }) do - local tv = typvalt(v[1], v[2]) + -- Using to_cstr, cannot free with tv_clear + local tv = ffi.gc(typvalt(v[1], v[2]), nil) alloc_log:check({}) local emsg = v[3] local ret = v[4] @@ -2780,7 +2792,9 @@ describe('typval.c', function() {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 'false'}, {lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', ''}, }) do - local tv = typvalt(v[1], v[2]) + -- Using to_cstr in place of Neovim allocated string, cannot + -- tv_clear() that. + local tv = ffi.gc(typvalt(v[1], v[2]), nil) alloc_log:check({}) local emsg = v[3] local ret = v[4] @@ -2821,7 +2835,8 @@ describe('typval.c', function() {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 'false'}, {lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', nil}, }) do - local tv = typvalt(v[1], v[2]) + -- Using to_cstr, cannot free with tv_clear + local tv = ffi.gc(typvalt(v[1], v[2]), nil) alloc_log:check({}) local emsg = v[3] local ret = v[4] @@ -2861,7 +2876,8 @@ describe('typval.c', function() {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 'false'}, {lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', ''}, }) do - local tv = typvalt(v[1], v[2]) + -- Using to_cstr, cannot free with tv_clear + local tv = ffi.gc(typvalt(v[1], v[2]), nil) alloc_log:check({}) local emsg = v[3] local ret = v[4] @@ -2902,7 +2918,8 @@ describe('typval.c', function() {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 'false'}, {lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', nil}, }) do - local tv = typvalt(v[1], v[2]) + -- Using to_cstr, cannot free with tv_clear + local tv = ffi.gc(typvalt(v[1], v[2]), nil) alloc_log:check({}) local emsg = v[3] local ret = v[4] diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 74f214a231..6d0de5c651 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -632,8 +632,9 @@ local function itp_child(wr, func) collectgarbage('stop') child_sethook(wr) local err, emsg = pcall(func) - debug.sethook() collectgarbage('restart') + collectgarbage() + debug.sethook() emsg = tostring(emsg) sc.write(wr, trace_end_msg) if not err then -- cgit From 654dd15bb8e82538942b1933b7f69c63d51b6608 Mon Sep 17 00:00:00 2001 From: ZyX Date: Thu, 6 Apr 2017 07:21:00 +0300 Subject: unittests: Fix testlint failure --- test/unit/eval/typval_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/unit') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index c477683038..4abd51d46d 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1091,9 +1091,9 @@ describe('typval.c', function() end) end) describe('join()', function() - local function list_join(l, sep, ret) + local function list_join(l, sep, join_ret) local ga = ga_alloc() - eq(ret or OK, lib.tv_list_join(ga, l, sep)) + eq(join_ret or OK, lib.tv_list_join(ga, l, sep)) local ret = '' if ga.ga_data ~= nil then ret = ffi.string(ga.ga_data) -- cgit From a83511d1a19d6277f8258f2c5b970c936f0bc56e Mon Sep 17 00:00:00 2001 From: ZyX Date: Thu, 6 Apr 2017 08:23:33 +0300 Subject: unittests: Move checking cores to check_child_err --- test/unit/helpers.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'test/unit') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 6d0de5c651..4b9f185156 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -655,6 +655,7 @@ end local function check_child_err(rd) local trace = {} + local did_traceline = false while true do local traceline = sc.read(rd, hook_msglen) if #traceline ~= hook_msglen then @@ -665,6 +666,7 @@ local function check_child_err(rd) end end if traceline == trace_end_msg then + did_traceline = true break end trace[#trace + 1] = traceline @@ -680,6 +682,13 @@ local function check_child_err(rd) error = error .. trace[i] end 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 + end assert.just_fail(error) end if res == '+\n' then @@ -765,11 +774,6 @@ local module = { child_cleanup_once = child_cleanup_once, sc = sc, } -return function(after_each) - if after_each then - after_each(function() - check_cores(Paths.test_luajit_prg) - end) - end +return function() return module end -- cgit From dc9722326e797453094b5d82decb5369b1086139 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Apr 2017 19:06:03 +0300 Subject: unittests: Do not alter p_enc in decode unit test --- test/unit/eval/decode_spec.lua | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'test/unit') diff --git a/test/unit/eval/decode_spec.lua b/test/unit/eval/decode_spec.lua index 0b2a423cd6..6145cf6358 100644 --- a/test/unit/eval/decode_spec.lua +++ b/test/unit/eval/decode_spec.lua @@ -72,7 +72,7 @@ describe('json_decode_string()', function() end itp('does not overflow in error messages', function() - local saved_p_enc = decode.p_enc + collectgarbage('restart') check_failure(']test', 1, 'E474: No container to close: ]') check_failure('[}test', 2, 'E474: Closing list with curly bracket: }') check_failure('{]test', 2, @@ -105,10 +105,6 @@ describe('json_decode_string()', function() check_failure('"\194"test', 3, 'E474: Only UTF-8 strings allowed: \194"') check_failure('"\252\144\128\128\128\128"test', 8, 'E474: Only UTF-8 code points up to U+10FFFF are allowed to appear unescaped: \252\144\128\128\128\128"') check_failure('"test', 1, 'E474: Expected string end: "') - decode.p_enc = to_cstr('latin1') - check_failure('"\\uABCD"test', 8, - 'E474: Failed to convert string "ꯍ" from UTF-8') - decode.p_enc = saved_p_enc check_failure('-test', 1, 'E474: Missing number after minus sign: -') check_failure('-1.test', 3, 'E474: Missing number after decimal dot: -1.') check_failure('-1.0etest', 5, 'E474: Missing exponent: -1.0e') -- cgit From 94c1af7c41d9303884b8d9f948b81b1db68e5ab1 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Apr 2017 04:23:11 +0300 Subject: unittests: Do not gc what is already freed --- test/unit/eval/typval_spec.lua | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'test/unit') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 4abd51d46d..e26e1c918f 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -237,24 +237,33 @@ describe('typval.c', function() list_watch(l, lis[4]), list_watch(l, lis[7]), } + alloc_log:check({ + a.list(l), + a.li(lis[1]), + a.li(lis[2]), + a.li(lis[3]), + a.li(lis[4]), + a.li(lis[5]), + a.li(lis[6]), + a.li(lis[7]), + }) lib.tv_list_item_remove(l, lis[4]) - ffi.gc(lis[4], lib.tv_list_item_free) + alloc_log:check({a.freed(lis[4])}) eq({lis[1], lis[5], lis[7]}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item}) lib.tv_list_item_remove(l, lis[2]) - ffi.gc(lis[2], lib.tv_list_item_free) + alloc_log:check({a.freed(lis[2])}) eq({lis[1], lis[5], lis[7]}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item}) lib.tv_list_item_remove(l, lis[7]) - ffi.gc(lis[7], lib.tv_list_item_free) + alloc_log:check({a.freed(lis[7])}) eq({lis[1], lis[5], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil}) lib.tv_list_item_remove(l, lis[1]) - ffi.gc(lis[1], lib.tv_list_item_free) + alloc_log:check({a.freed(lis[1])}) eq({lis[3], lis[5], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil}) - alloc_log:clear() lib.tv_list_watch_remove(l, lws[2]) lib.tv_list_watch_remove(l, lws[3]) lib.tv_list_watch_remove(l, lws[1]) -- cgit From 44cd4e63f58fe240b1d8259600a60757f1bd2ce8 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Apr 2017 04:31:02 +0300 Subject: unittests: Use Neovim memory allocation for vimconv_T Not sure whether this is going to fix things though, but core dump does not contain Neovim functions in stack in this case. --- test/unit/eval/typval_spec.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'test/unit') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index e26e1c918f..53ef299fce 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -743,10 +743,13 @@ describe('typval.c', function() collectgarbage() end) itp('copies list correctly and converts items', function() - local vc = ffi.gc(ffi.new('vimconv_T[1]'), function(vc) - lib.convert_setup(vc, nil, nil) - end) - -- UTF-8 ↔ latin1 conversions need no iconv + local vc = ffi.gc( + ffi.cast('vimconv_T*', lib.xcalloc(1, ffi.sizeof('vimconv_T'))), + function(vc) + lib.convert_setup(vc, nil, nil) + lib.xfree(vc) + end) + -- UTF-8 ↔ latin1 conversions needs no iconv eq(OK, lib.convert_setup(vc, to_cstr('utf-8'), to_cstr('latin1'))) local v = {{['«']='»'}, {'„'}, 1, '“', null_string, null_list, null_dict} -- cgit From bac870433b828ea3a850e61710b636c62ecaa5ed Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Apr 2017 04:36:23 +0300 Subject: unittests: Do not unref partial which is owned by Callback structure --- test/unit/eval/helpers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index fa76113756..5bc482216e 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -468,7 +468,7 @@ local function tbl2callback(tbl) data={funcref=eval.xstrdup(tbl.fref)}}}) elseif tbl.type == 'pt' then local pt = ffi.gc(ffi.cast('partial_T*', - eval.xcalloc(1, ffi.sizeof('partial_T'))), eval.partial_unref) + eval.xcalloc(1, ffi.sizeof('partial_T'))), nil) ret = ffi.new('Callback[1]', {{type=eval.kCallbackPartial, data={partial=populate_partial(pt, tbl.pt, {})}}}) else -- cgit From 233e71419ef18dcbf62425505a58d67169c1b4b1 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Apr 2017 04:40:11 +0300 Subject: unittests: Do not GC typval_T which is owned by a di --- test/unit/eval/typval_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/unit') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 53ef299fce..3631bddde2 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1528,7 +1528,7 @@ describe('typval.c', function() eq(s:sub(1, len), ffi.string(di.di_key)) alloc_log:check({a.di(di, len)}) if tv then - di.di_tv = tv + di.di_tv = ffi.gc(tv, nil) else di.di_tv.v_type = lib.VAR_UNKNOWN end @@ -1559,7 +1559,7 @@ describe('typval.c', function() alloc_log:check({a.dict(d)}) local di = ffi.gc(lib.tv_dict_item_alloc(''), nil) local tv = lua2typvalt('test') - di.di_tv = tv + di.di_tv = ffi.gc(tv, nil) alloc_log:check({a.di(di, ''), a.str(tv.vval.v_string, 'test')}) eq(OK, lib.tv_dict_add(d, di)) alloc_log:check({}) -- cgit From 8990490b50df651144658d0e68c7f582d7013376 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Apr 2017 04:47:38 +0300 Subject: unittests: Move allocating vimconv_T to a function --- test/unit/eval/typval_spec.lua | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'test/unit') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 3631bddde2..a1edfcfb7c 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -47,6 +47,15 @@ local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/memory.h', './src/nvim/eval.h', './src/nvim/vim.h', './src/nvim/globals.h') +local function vimconv_alloc() + return ffi.gc( + ffi.cast('vimconv_T*', lib.xcalloc(1, ffi.sizeof('vimconv_T'))), + function(vc) + lib.convert_setup(vc, nil, nil) + lib.xfree(vc) + end) +end + local function list_watch_alloc(li) return ffi.cast('listwatch_T*', ffi.new('listwatch_T[1]', {{lw_item=li}})) end @@ -743,12 +752,7 @@ describe('typval.c', function() collectgarbage() end) itp('copies list correctly and converts items', function() - local vc = ffi.gc( - ffi.cast('vimconv_T*', lib.xcalloc(1, ffi.sizeof('vimconv_T'))), - function(vc) - lib.convert_setup(vc, nil, nil) - lib.xfree(vc) - end) + local vc = vimconv_alloc() -- UTF-8 ↔ latin1 conversions needs no iconv eq(OK, lib.convert_setup(vc, to_cstr('utf-8'), to_cstr('latin1'))) @@ -2151,9 +2155,7 @@ describe('typval.c', function() collectgarbage() end) itp('copies dict correctly and converts items', function() - local vc = ffi.gc(ffi.new('vimconv_T[1]'), function(vc) - lib.convert_setup(vc, nil, nil) - end) + local vc = vimconv_alloc() -- UTF-8 ↔ latin1 conversions need no iconv eq(OK, lib.convert_setup(vc, to_cstr('utf-8'), to_cstr('latin1'))) -- cgit From 967fa96eb2ca263c0fefd9e9be74e9862e59d740 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 9 Apr 2017 03:39:37 +0300 Subject: unittests: Fix linter error --- test/unit/eval/decode_spec.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/eval/decode_spec.lua b/test/unit/eval/decode_spec.lua index 6145cf6358..0c444b33f2 100644 --- a/test/unit/eval/decode_spec.lua +++ b/test/unit/eval/decode_spec.lua @@ -2,7 +2,6 @@ local helpers = require('test.unit.helpers')(after_each) local itp = helpers.gen_itp(it) local cimport = helpers.cimport -local to_cstr = helpers.to_cstr local eq = helpers.eq local neq = helpers.neq local ffi = helpers.ffi -- cgit