From c540096e8680c9e2ea2ff6f7dc9aee4d1fb80673 Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Tue, 27 Jun 2017 19:40:54 -0300 Subject: [PATCH] topogen: add memory leak report configuration Allow memory leak to be configured from the configuration file. --- tests/topotests/GUIDELINES.md | 7 ++++++- tests/topotests/lib/topogen.py | 9 +++++++-- tests/topotests/pytest.ini | 8 ++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/topotests/GUIDELINES.md b/tests/topotests/GUIDELINES.md index 8c26c837b9..aeec70f8be 100644 --- a/tests/topotests/GUIDELINES.md +++ b/tests/topotests/GUIDELINES.md @@ -44,8 +44,13 @@ r1-zebra.out # zebra stdout output You can also run memory leak tests to get reports: ```shell +$ # Set the environment variable to apply to a specific test... $ sudo env TOPOTESTS_CHECK_MEMLEAK="/tmp/memleak_report_" pytest ospf-topo1/test_ospf_topo1.py -... +$ # ...or apply to all tests adding this line to the configuration file +$ echo 'memleak_path = /tmp/memleak_report_' >> pytest.ini +$ # You can also use your editor +$ $EDITOR pytest.ini +$ # After running tests you should see your files: $ ls /tmp/memleak_report_* memleak_report_test_ospf_topo1.txt ``` diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index ed0339d8f0..2b2ea5dcb5 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -123,6 +123,7 @@ class Topogen(object): 'frrdir': '/usr/lib/frr', 'quaggadir': '/usr/lib/quagga', 'routertype': 'frr', + 'memleak_path': None, } self.config = ConfigParser.ConfigParser(defaults) pytestini_path = os.path.join(CWD, '../pytest.ini') @@ -144,6 +145,7 @@ class Topogen(object): params['frrdir'] = self.config.get(self.CONFIG_SECTION, 'frrdir') params['quaggadir'] = self.config.get(self.CONFIG_SECTION, 'quaggadir') + params['memleak_path'] = self.config.get(self.CONFIG_SECTION, 'memleak_path') if not params.has_key('routertype'): params['routertype'] = self.config.get(self.CONFIG_SECTION, 'routertype') @@ -388,8 +390,11 @@ class TopoRouter(TopoGear): self.net = None self.name = name self.cls = cls + self.options = {} if not params.has_key('privateDirs'): params['privateDirs'] = self.PRIVATE_DIRS + + self.options['memleak_path'] = params.get('memleak_path', None) self.tgen.topo.addNode(self.name, cls=self.cls, **params) def __str__(self): @@ -472,9 +477,9 @@ class TopoRouter(TopoGear): testname: the test file name for identification NOTE: to run this you must have the environment variable - TOPOTESTS_CHECK_MEMLEAK set to the appropriated path. + TOPOTESTS_CHECK_MEMLEAK set or memleak_path configured in `pytest.ini`. """ - memleak_file = os.environ.get('TOPOTESTS_CHECK_MEMLEAK') + memleak_file = os.environ.get('TOPOTESTS_CHECK_MEMLEAK') or self.options['memleak_path'] if memleak_file is None: print "SKIPPED check on Memory leaks: Disabled (TOPOTESTS_CHECK_MEMLEAK undefined)" return diff --git a/tests/topotests/pytest.ini b/tests/topotests/pytest.ini index 1866bae1cf..9dbe3834c2 100644 --- a/tests/topotests/pytest.ini +++ b/tests/topotests/pytest.ini @@ -17,3 +17,11 @@ norecursedirs = .git example-test # Default router type to use. Possible values are: # 'frr' and 'quagga'. #routertype = frr + +# Memory leak test reports path +# Enables and add an output path to memory leak tests. +# Example: +# memleak_path = /tmp/memleak_ +# Output files will be named after the testname: +# /tmp/memleak_test_ospf_topo1.txt +#memleak_path = -- 2.39.5