Tarantool development patches archive
 help / color / mirror / Atom feed
From: Mikhail Shishatskiy via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: tarantool-patches@dev.tarantool.org, imun@tarantool.org,
	skaplun@tarantool.org
Subject: [Tarantool-patches] [PATCH luajit v3 2/5] test: separate memprof Lua API tests into subtests
Date: Fri, 20 Aug 2021 14:05:43 +0700	[thread overview]
Message-ID: <20210820070546.115293-3-m.shishatskiy@tarantool.org> (raw)
In-Reply-To: <20210820070546.115293-1-m.shishatskiy@tarantool.org>

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


  parent reply	other threads:[~2021-08-20  7:07 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-20  7:05 [Tarantool-patches] [PATCH luajit v3 0/4] memprof: group allocations on traces by trace number Mikhail Shishatskiy via Tarantool-patches
2021-08-20  7:05 ` [Tarantool-patches] [PATCH luajit v3 1/5] core: add const to lj_debug_line proto parameter Mikhail Shishatskiy via Tarantool-patches
2021-09-16 15:29   ` Igor Munkin via Tarantool-patches
2021-08-20  7:05 ` Mikhail Shishatskiy via Tarantool-patches [this message]
2021-09-16 15:29   ` [Tarantool-patches] [PATCH luajit v3 2/5] test: separate memprof Lua API tests into subtests Igor Munkin via Tarantool-patches
2021-08-20  7:05 ` [Tarantool-patches] [PATCH luajit v3 3/5] memprof: dump traceno if allocate from trace Mikhail Shishatskiy via Tarantool-patches
2021-09-16 15:32   ` Igor Munkin via Tarantool-patches
2021-09-29 19:21     ` Mikhail Shishatskiy via Tarantool-patches
2021-08-20  7:05 ` [Tarantool-patches] [PATCH luajit v3 4/5] memprof: extend symtab with info about traces Mikhail Shishatskiy via Tarantool-patches
2021-09-16 15:32   ` Igor Munkin via Tarantool-patches
2021-09-29 19:21     ` Mikhail Shishatskiy via Tarantool-patches
2021-08-20  7:05 ` [Tarantool-patches] [PATCH luajit v3 5/5] luajit: change order of modules Mikhail Shishatskiy via Tarantool-patches
2021-09-16 15:32   ` Igor Munkin via Tarantool-patches
2021-09-29 20:07 ` [Tarantool-patches] [PATCH luajit v4 0/4] memprof: group allocations on traces by traceno Mikhail Shishatskiy via Tarantool-patches
2021-09-29 20:07   ` [Tarantool-patches] [PATCH luajit v4 1/4] test: separate memprof Lua API tests into subtests Mikhail Shishatskiy via Tarantool-patches
2021-10-27 13:56     ` Igor Munkin via Tarantool-patches
2021-10-27 15:07     ` Sergey Kaplun via Tarantool-patches
2021-09-29 20:07   ` [Tarantool-patches] [PATCH luajit v4 2/4] memprof: refactor location parsing Mikhail Shishatskiy via Tarantool-patches
2021-10-27 13:56     ` Igor Munkin via Tarantool-patches
     [not found]       ` <20211104130010.mcvnra6e4yl5moo2@surf.localdomain>
2021-11-10 15:38         ` Igor Munkin via Tarantool-patches
2021-09-29 20:07   ` [Tarantool-patches] [PATCH luajit v4 3/4] memprof: group allocations on traces by traceno Mikhail Shishatskiy via Tarantool-patches
2021-10-27 13:56     ` Igor Munkin via Tarantool-patches
     [not found]       ` <20211104130156.f2botlihlfhwd3yh@surf.localdomain>
2021-11-11 15:34         ` Igor Munkin via Tarantool-patches
2021-09-29 20:07   ` [Tarantool-patches] [PATCH luajit v4 4/4] memprof: add info about trace start to symtab Mikhail Shishatskiy via Tarantool-patches
2021-11-01 16:31     ` Igor Munkin via Tarantool-patches
     [not found]       ` <20211104130228.x6qcne5xeh544hm7@surf.localdomain>
2021-11-12 13:34         ` Igor Munkin via Tarantool-patches
2021-11-17  8:17           ` Sergey Kaplun via Tarantool-patches
2021-11-22 15:11           ` Mikhail Shishatskiy via Tarantool-patches
2021-11-24 12:42             ` Mikhail Shishatskiy via Tarantool-patches
2021-11-24 16:44             ` Igor Munkin via Tarantool-patches
2022-01-27 23:29   ` [Tarantool-patches] [PATCH luajit v4 0/4] memprof: group allocations on traces by traceno Igor Munkin via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210820070546.115293-3-m.shishatskiy@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imun@tarantool.org \
    --cc=m.shishatskiy@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit v3 2/5] test: separate memprof Lua API tests into subtests' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox