From 252a6bf91b747b18153d132267844b8796a9db17 Mon Sep 17 00:00:00 2001 From: pompolic <pompolic@special-circumstanc.es> Date: Tue, 28 Feb 2023 17:42:42 +0100 Subject: [PATCH] (WIP) Explicit test for where malloc calls should add the memory use --- .../integration/test_malloc_attribution.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 gdb-port/tests/integration/test_malloc_attribution.py diff --git a/gdb-port/tests/integration/test_malloc_attribution.py b/gdb-port/tests/integration/test_malloc_attribution.py new file mode 100644 index 0000000..3c3210e --- /dev/null +++ b/gdb-port/tests/integration/test_malloc_attribution.py @@ -0,0 +1,35 @@ +import unittest + +class TestMallocParserAttribution(unittest.TestCase): + def setUp(self): + self.a = Parser("a", 128) + self.b = Parser("b", 32) + self.top_level_parse = TopLevelParse() + self.top_level_parse.parser_objs[32] = self.b + self.top_level_parse.parser_objs[128] = self.a + # TODO: the above two lines simulate a side effect of enter_h_do_parse. could be avoided if self.a and self.b was assigned after the calls below + self.top_level_parse.enter_h_packrat_parse(self.a.address) + +#TODO: are we initializing from scratch for every test? + self.top_level_parse.enter_h_do_parse(400, 256, self.a.address) + self.top_level_parse.parse_virtual(self.a.address) + self.top_level_parse.enter_perform_lowlevel_parse(self.a.address) + + + def test_alloc_after_h_do_parse(self): + self.top_level_parse.enter_h_do_parse(400, 256, self.b.address) + self.top_level_parse.enter_h_arena_malloc_raw(150) + self.assertEqual(b.bytes_used[256], 150) + + def test_alloc_after_parse_virtual(self): + self.top_level_parse.enter_h_do_parse(400, 256, self.b.address) + self.top_level_parse.parse_virtual(self.b.address) + self.top_level_parse.enter_h_arena_malloc_raw(150) + self.assertEqual(b.bytes_used[256], 150) + + def test_alloc_after_enter_perform_lowlevel_parse(self): + self.top_level_parse.enter_h_do_parse(400, 256, self.b.address) + self.top_level_parse.parse_virtual(self.b.address) + self.top_level_parse.enter_perform_lowlevel_parse(self.b.address) + self.top_level_parse.enter_h_arena_malloc_raw(150) + self.assertEqual(b.bytes_used[256], 150) -- GitLab