blob: 300e8208a87f6e79f65731928745ac27cb0a4b83 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Paul Vinciguerra59954822019-03-11 05:04:12 -07002
3import unittest
Paul Vinciguerra59954822019-03-11 05:04:12 -07004import psutil
5from vpp_papi.vpp_stats import VPPStats
6
Andrew Yourtchenko8dc0d482021-01-29 13:17:19 +00007from framework import tag_fixme_vpp_workers
Paul Vinciguerra59954822019-03-11 05:04:12 -07008from framework import VppTestCase, VppTestRunner
9
10
Andrew Yourtchenko8dc0d482021-01-29 13:17:19 +000011@tag_fixme_vpp_workers
Paul Vinciguerra59954822019-03-11 05:04:12 -070012class 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 Troan233e4682019-05-16 15:01:34 +020023 def test_set_errors(self):
24 """Test set errors"""
25 self.assertEqual(self.statistics.set_errors(), {})
26 self.assertEqual(self.statistics.get_counter('/err/ethernet-input/no'),
27 [0])
28
Paul Vinciguerra59954822019-03-11 05:04:12 -070029 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 Luongc79b32d2019-06-18 09:56:07 -070046
Ole Troan92e30822019-06-16 12:33:51 +020047 @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 Luongc79b32d2019-06-18 09:56:07 -070063 print('AFTER', before,
64 self.statistics.get_counter('/mem/statseg/used'))
65
Paul Vinciguerra59954822019-03-11 05:04:12 -070066
67if __name__ == '__main__':
68 unittest.main(testRunner=VppTestRunner)