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