Skip to content

Commit

Permalink
topogen: add memory leak report configuration
Browse files Browse the repository at this point in the history
Allow memory leak to be configured from the configuration file.
  • Loading branch information
rzalamena committed Jul 5, 2017
1 parent 4d10cfc commit 421cb2d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
7 changes: 6 additions & 1 deletion GUIDELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
9 changes: 7 additions & 2 deletions lib/topogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def _load_config(self):
'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')
Expand All @@ -144,6 +145,7 @@ def add_router(self, name=None, cls=topotest.Router, **params):

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')

Expand Down Expand Up @@ -388,8 +390,11 @@ def __init__(self, tgen, cls, name, **params):
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):
Expand Down Expand Up @@ -472,9 +477,9 @@ def report_memory_leaks(self, testname):
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
Expand Down
8 changes: 8 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 =

0 comments on commit 421cb2d

Please sign in to comment.