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 D189D6DB02; Fri, 20 Aug 2021 10:07:33 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D189D6DB02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1629443253; bh=aKIQJHxACODQ362JpcIiknSdt4FB6+x4e5sEBTa1pto=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=mKP3sRTlpYBn7wmgmoMwdukh/b5hp7XcVdiM9n2zTtukKpdTBd01o06GoMiK2MaBw 8AG6criJchzxuTCUw6x+B1esaUrrtaHdeXuBwjM6aqgRWXM7oElb9cOliubdX9+dx0 19nQXvPdqWGaTjtaXknokF3ioT8qp/0ZJffYRKMk= Received: from smtp35.i.mail.ru (smtp35.i.mail.ru [94.100.177.95]) (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 99DEA6DB04 for ; Fri, 20 Aug 2021 10:07:08 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 99DEA6DB04 Received: by smtp35.i.mail.ru with esmtpa (envelope-from ) id 1mGycN-0000G3-3W; Fri, 20 Aug 2021 10:07:07 +0300 To: tarantool-patches@dev.tarantool.org, imun@tarantool.org, skaplun@tarantool.org Date: Fri, 20 Aug 2021 14:05:43 +0700 Message-Id: <20210820070546.115293-3-m.shishatskiy@tarantool.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210820070546.115293-1-m.shishatskiy@tarantool.org> References: <20210820070546.115293-1-m.shishatskiy@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD972FF4A7D76DB5E242D14FEF1BD8BF4AC182A05F5380850400884B30CDDD01CF165275486A1B88D85F60D0752DD76BFF4AF4169EBA3627C40 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE70993CE289E4873FDEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006377A079619B0C2EE308638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D82377B721B2A5E481D82BDF3CF745A943117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC60CDF180582EB8FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18CB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE140C956E756FBB7A7B089FF177BE8049D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE386A7C529F68B8E5CBA3038C0950A5D36B5C8C57E37DE458B0BC6067A898B09E46D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE7588D3C263EAE74EA731C566533BA786AA5CC5B56E945C8DA X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B5051D81CCDA47EB054DCAAF7F39C889F4DB X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CF160826E4E1956AEDDFDAB768A5579E6A655F7A721BB1DC99C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF836F5ADB0B4F9314699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D347130F804358653A673023552EB97F7AE0820C92514ABFD6C56F61B26A4BB6834D18892E61EFD8C941D7E09C32AA3244CD6523F970EAC7A5B6A964DAB775B73F2E646F07CC2D4F3D8927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojZWOt9KMsrmeBRw56ljSdTg== X-Mailru-Sender: 2317F5BEA8D613097CB8A225516EF02711B936E641EB0915E63576966A27CEA357B3E3CF0F942413FF6B26DEAE20951894E739346DD9ABB838AE394B99C5394F99323991B04ED3930F27244EEAA5B9A5AE208404248635DF X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit v3 2/5] test: separate memprof Lua API tests into subtests 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: Mikhail Shishatskiy via Tarantool-patches Reply-To: Mikhail Shishatskiy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" As the number of memprof test cases is expected to grow, memprof tests are separated into subtests to encapsulate test cases and be able to skip some of the subtests. Part of tarantool/tarantool#5814 --- Issue: https://github.com/tarantool/tarantool/issues/5814 Luajit branch: https://github.com/tarantool/luajit/tree/shishqa/gh-5814-group-allocations-on-trace-by-trace-number tarantool branch: https://github.com/tarantool/tarantool/tree/shishqa/gh-5814-group-allocations-on-trace-by-trace-number .../misclib-memprof-lapi.test.lua | 153 ++++++++++-------- 1 file changed, 83 insertions(+), 70 deletions(-) diff --git a/test/tarantool-tests/misclib-memprof-lapi.test.lua b/test/tarantool-tests/misclib-memprof-lapi.test.lua index 06d96b3b..dbf384ed 100644 --- a/test/tarantool-tests/misclib-memprof-lapi.test.lua +++ b/test/tarantool-tests/misclib-memprof-lapi.test.lua @@ -7,7 +7,7 @@ require("utils").skipcond( local tap = require("tap") local test = tap.test("misc-memprof-lapi") -test:plan(13) +test:plan(3) jit.off() jit.flush() @@ -86,85 +86,98 @@ local function check_alloc_report(alloc, line, function_line, nevents) return true end --- Not a directory. -local res, err, errno = misc.memprof.start(BAD_PATH) -test:ok(res == nil and err:match("No such file or directory")) -test:ok(type(errno) == "number") +-- Test profiler API. +test:test("base", function(subtest) + subtest:plan(6) --- Profiler is running. -res, err = misc.memprof.start(TMP_BINFILE) -assert(res, err) -res, err, errno = misc.memprof.start(TMP_BINFILE) -test:ok(res == nil and err:match("profiler is running already")) -test:ok(type(errno) == "number") + -- Not a directory. + local res, err, errno = misc.memprof.start(BAD_PATH) + subtest:ok(res == nil and err:match("No such file or directory")) + subtest:ok(type(errno) == "number") -res, err = misc.memprof.stop() -assert(res, err) + -- Profiler is running. + res, err = misc.memprof.start(TMP_BINFILE) + assert(res, err) + res, err, errno = misc.memprof.start(TMP_BINFILE) + subtest:ok(res == nil and err:match("profiler is running already")) + subtest:ok(type(errno) == "number") + + res, err = misc.memprof.stop() + assert(res, err) --- Profiler is not running. -res, err, errno = misc.memprof.stop() -test:ok(res == nil and err:match("profiler is not running")) -test:ok(type(errno) == "number") + -- Profiler is not running. + res, err, errno = misc.memprof.stop() + subtest:ok(res == nil and err:match("profiler is not running")) + subtest:ok(type(errno) == "number") +end) -- Test profiler output and parse. -res, err = pcall(generate_output, TMP_BINFILE) +test:test("output", function(subtest) + subtest:plan(7) + + local res, err = pcall(generate_output, TMP_BINFILE) --- Want to cleanup carefully if something went wrong. -if not res then + -- Want to cleanup carefully if something went wrong. + if not res then + os.remove(TMP_BINFILE) + error(err) + end + + local reader = bufread.new(TMP_BINFILE) + local symbols = symtab.parse(reader) + local events = memprof.parse(reader, symbols) + + -- We don't need it any more. os.remove(TMP_BINFILE) - error(err) -end -local reader = bufread.new(TMP_BINFILE) -local symbols = symtab.parse(reader) -local events = memprof.parse(reader, symbols) - --- We don't need it any more. -os.remove(TMP_BINFILE) - -local alloc = fill_ev_type(events, symbols, "alloc") -local free = fill_ev_type(events, symbols, "free") - --- Check allocation reports. The second argument is a line number --- of the allocation event itself. The third is a line number of --- the corresponding function definition. The last one is --- the number of allocations. --- 1 event - alocation of table by itself + 1 allocation --- of array part as far it is bigger than LJ_MAX_COLOSIZE (16). -test:ok(check_alloc_report(alloc, 27, 25, 2)) --- 100 strings allocations. -test:ok(check_alloc_report(alloc, 32, 25, 100)) - --- Collect all previous allocated objects. -test:ok(free.INTERNAL.num == 102) - --- Tests for leak-only option. --- See also https://github.com/tarantool/tarantool/issues/5812. -local heap_delta = process.form_heap_delta(events, symbols) -local tab_alloc_stats = heap_delta[form_source_line(27)] -local str_alloc_stats = heap_delta[form_source_line(32)] -test:ok(tab_alloc_stats.nalloc == tab_alloc_stats.nfree) -test:ok(tab_alloc_stats.dbytes == 0) -test:ok(str_alloc_stats.nalloc == str_alloc_stats.nfree) -test:ok(str_alloc_stats.dbytes == 0) + local alloc = fill_ev_type(events, symbols, "alloc") + local free = fill_ev_type(events, symbols, "free") + + -- Check allocation reports. The second argument is a line number + -- of the allocation event itself. The third is a line number of + -- the corresponding function definition. The last one is + -- the number of allocations. + -- 1 event - alocation of table by itself + 1 allocation + -- of array part as far it is bigger than LJ_MAX_COLOSIZE (16). + subtest:ok(check_alloc_report(alloc, 27, 25, 2)) + -- 100 strings allocations. + subtest:ok(check_alloc_report(alloc, 32, 25, 100)) + + -- Collect all previous allocated objects. + subtest:ok(free.INTERNAL.num == 102) + + -- Tests for leak-only option. + -- See also https://github.com/tarantool/tarantool/issues/5812. + local heap_delta = process.form_heap_delta(events, symbols) + local tab_alloc_stats = heap_delta[form_source_line(27)] + local str_alloc_stats = heap_delta[form_source_line(32)] + subtest:ok(tab_alloc_stats.nalloc == tab_alloc_stats.nfree) + subtest:ok(tab_alloc_stats.dbytes == 0) + subtest:ok(str_alloc_stats.nalloc == str_alloc_stats.nfree) + subtest:ok(str_alloc_stats.dbytes == 0) +end) -- Test for https://github.com/tarantool/tarantool/issues/5842. --- We are not interested in this report. -misc.memprof.start("/dev/null") --- We need to cause stack resize for local variables at function --- call. Let's create a new coroutine (all slots are free). --- It has 1 slot for dummy frame + 39 free slots + 5 extra slots --- (so-called red zone) + 2 * LJ_FR2 slots. So 50 local variables --- is enough. -local payload_str = "" -for i = 1, 50 do - payload_str = payload_str..("local v%d = %d\n"):format(i, i) -end -local f, errmsg = loadstring(payload_str) -assert(f, errmsg) -local co = coroutine.create(f) -coroutine.resume(co) -misc.memprof.stop() +test:test("stack-resize", function(subtest) + subtest:plan(0) + + -- We are not interested in this report. + misc.memprof.start("/dev/null") + -- We need to cause stack resize for local variables at function + -- call. Let's create a new coroutine (all slots are free). + -- It has 1 slot for dummy frame + 39 free slots + 5 extra slots + -- (so-called red zone) + 2 * LJ_FR2 slots. So 50 local variables + -- is enough. + local payload_str = "" + for i = 1, 50 do + payload_str = payload_str..("local v%d = %d\n"):format(i, i) + end + local f, errmsg = loadstring(payload_str) + assert(f, errmsg) + local co = coroutine.create(f) + coroutine.resume(co) + misc.memprof.stop() +end) jit.on() os.exit(test:check() and 0 or 1) -- 2.32.0