Paul Vinciguerra | 5995482 | 2019-03-11 05:04:12 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python2.7 |
| 2 | |
| 3 | import unittest |
Ole Troan | 92e3082 | 2019-06-16 12:33:51 +0200 | [diff] [blame] | 4 | import time |
Paul Vinciguerra | 5995482 | 2019-03-11 05:04:12 -0700 | [diff] [blame] | 5 | import psutil |
| 6 | from vpp_papi.vpp_stats import VPPStats |
| 7 | |
| 8 | from framework import VppTestCase, VppTestRunner |
| 9 | |
| 10 | |
| 11 | class StatsClientTestCase(VppTestCase): |
| 12 | """Test Stats Client""" |
| 13 | |
| 14 | @classmethod |
| 15 | def setUpClass(cls): |
| 16 | super(StatsClientTestCase, cls).setUpClass() |
| 17 | |
| 18 | @classmethod |
| 19 | def tearDownClass(cls): |
| 20 | super(StatsClientTestCase, cls).tearDownClass() |
| 21 | |
Ole Troan | 233e468 | 2019-05-16 15:01:34 +0200 | [diff] [blame] | 22 | def test_set_errors(self): |
| 23 | """Test set errors""" |
| 24 | self.assertEqual(self.statistics.set_errors(), {}) |
| 25 | self.assertEqual(self.statistics.get_counter('/err/ethernet-input/no'), |
| 26 | [0]) |
| 27 | |
Paul Vinciguerra | 5995482 | 2019-03-11 05:04:12 -0700 | [diff] [blame] | 28 | def test_client_fd_leak(self): |
| 29 | """Test file descriptor count - VPP-1486""" |
| 30 | |
| 31 | cls = self.__class__ |
| 32 | p = psutil.Process() |
| 33 | initial_fds = p.num_fds() |
| 34 | |
| 35 | for _ in range(100): |
| 36 | stats = VPPStats(socketname=cls.stats_sock) |
| 37 | stats.disconnect() |
| 38 | |
| 39 | ending_fds = p.num_fds() |
| 40 | self.assertEqual(initial_fds, ending_fds, |
| 41 | "initial client side file descriptor count: %s " |
| 42 | "is not equal to " |
| 43 | "ending client side file descriptor count: %s" % ( |
| 44 | initial_fds, ending_fds)) |
Steven Luong | c79b32d | 2019-06-18 09:56:07 -0700 | [diff] [blame] | 45 | |
Ole Troan | 92e3082 | 2019-06-16 12:33:51 +0200 | [diff] [blame] | 46 | @unittest.skip("Manual only") |
| 47 | def test_mem_leak(self): |
| 48 | def loop(): |
| 49 | print('Running loop') |
| 50 | for i in range(50): |
| 51 | rv = self.vapi.papi.tap_create_v2(id=i, use_random_mac=1) |
| 52 | self.assertEqual(rv.retval, 0) |
| 53 | rv = self.vapi.papi.tap_delete_v2(sw_if_index=rv.sw_if_index) |
| 54 | self.assertEqual(rv.retval, 0) |
| 55 | |
| 56 | before = self.statistics.get_counter('/mem/statseg/used') |
| 57 | loop() |
| 58 | self.vapi.cli("memory-trace on stats-segment") |
| 59 | for j in range(100): |
| 60 | loop() |
| 61 | print(self.vapi.cli("show memory stats-segment verbose")) |
Steven Luong | c79b32d | 2019-06-18 09:56:07 -0700 | [diff] [blame] | 62 | print('AFTER', before, |
| 63 | self.statistics.get_counter('/mem/statseg/used')) |
| 64 | |
Paul Vinciguerra | 5995482 | 2019-03-11 05:04:12 -0700 | [diff] [blame] | 65 | |
| 66 | if __name__ == '__main__': |
| 67 | unittest.main(testRunner=VppTestRunner) |