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