2019-03-11 05:04:12 -07:00
|
|
|
#!/usr/bin/env python2.7
|
|
|
|
|
|
|
|
import unittest
|
2019-06-16 12:33:51 +02:00
|
|
|
import time
|
2019-03-11 05:04:12 -07:00
|
|
|
import psutil
|
|
|
|
from vpp_papi.vpp_stats import VPPStats
|
|
|
|
|
|
|
|
from framework import VppTestCase, VppTestRunner
|
|
|
|
|
|
|
|
|
|
|
|
class StatsClientTestCase(VppTestCase):
|
|
|
|
"""Test Stats Client"""
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(StatsClientTestCase, cls).setUpClass()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(StatsClientTestCase, cls).tearDownClass()
|
|
|
|
|
2019-05-16 15:01:34 +02:00
|
|
|
def test_set_errors(self):
|
|
|
|
"""Test set errors"""
|
|
|
|
self.assertEqual(self.statistics.set_errors(), {})
|
|
|
|
self.assertEqual(self.statistics.get_counter('/err/ethernet-input/no'),
|
|
|
|
[0])
|
|
|
|
|
2019-03-11 05:04:12 -07:00
|
|
|
def test_client_fd_leak(self):
|
|
|
|
"""Test file descriptor count - VPP-1486"""
|
|
|
|
|
|
|
|
cls = self.__class__
|
|
|
|
p = psutil.Process()
|
|
|
|
initial_fds = p.num_fds()
|
|
|
|
|
|
|
|
for _ in range(100):
|
|
|
|
stats = VPPStats(socketname=cls.stats_sock)
|
|
|
|
stats.disconnect()
|
|
|
|
|
|
|
|
ending_fds = p.num_fds()
|
|
|
|
self.assertEqual(initial_fds, ending_fds,
|
|
|
|
"initial client side file descriptor count: %s "
|
|
|
|
"is not equal to "
|
|
|
|
"ending client side file descriptor count: %s" % (
|
|
|
|
initial_fds, ending_fds))
|
2019-06-16 12:33:51 +02:00
|
|
|
@unittest.skip("Manual only")
|
|
|
|
def test_mem_leak(self):
|
|
|
|
def loop():
|
|
|
|
print('Running loop')
|
|
|
|
for i in range(50):
|
|
|
|
rv = self.vapi.papi.tap_create_v2(id=i, use_random_mac=1)
|
|
|
|
self.assertEqual(rv.retval, 0)
|
|
|
|
rv = self.vapi.papi.tap_delete_v2(sw_if_index=rv.sw_if_index)
|
|
|
|
self.assertEqual(rv.retval, 0)
|
|
|
|
|
|
|
|
before = self.statistics.get_counter('/mem/statseg/used')
|
|
|
|
loop()
|
|
|
|
self.vapi.cli("memory-trace on stats-segment")
|
|
|
|
for j in range(100):
|
|
|
|
loop()
|
|
|
|
print(self.vapi.cli("show memory stats-segment verbose"))
|
|
|
|
print('AFTER', before, self.statistics.get_counter('/mem/statseg/used'))
|
2019-03-11 05:04:12 -07:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(testRunner=VppTestRunner)
|