tests: Add platform handling for FreeBSD
[vpp.git] / test / asf / test_perfmon.py
1 from asfframework import VppAsfTestCase, VppTestRunner
2 from vpp_qemu_utils import can_create_namespaces
3 from config import config
4 import unittest
5
6
7 @unittest.skipIf(
8     not can_create_namespaces("perfmon_chk"), "Test is not running with root privileges"
9 )
10 @unittest.skipIf("perfmon" in config.excluded_plugins, "Exclude Perfmon plugin tests")
11 class TestPerfmon(VppAsfTestCase):
12     """Simple perfmon test"""
13
14     @classmethod
15     def setUpClass(cls):
16         super(TestPerfmon, cls).setUpClass()
17
18     @classmethod
19     def tearDownClass(cls):
20         super(TestPerfmon, cls).tearDownClass()
21
22     def test_perfmon(self):
23         reply = self.vapi.cli("show perfmon active-bundle")
24         self.assertNotIn("context-switches", reply)
25
26         reply = self.vapi.cli("show perfmon bundle")
27         self.assertIn("context-switches", reply)
28
29         self.vapi.cli("perfmon start bundle context-switches type thread")
30         reply = self.vapi.cli("show perfmon active-bundle")
31         self.assertIn("name: context-switches", reply)
32
33         reply = self.vapi.cli("show perfmon statistics")
34         self.assertIn("per-thread context switches", reply)
35
36         reply = self.vapi.cli("show perfmon source linux verbose")
37         self.assertIn("description: Linux kernel performance counters", reply)
38         self.vapi.cli("perfmon reset")
39
40         reply = self.vapi.cli("show perfmon active-bundle")
41         self.assertNotIn("context-switches", reply)
42
43         self.vapi.cli("perfmon start bundle context-switches type thread")
44         self.vapi.cli("perfmon stop")
45
46
47 if __name__ == "__main__":
48     unittest.main(testRunner=VppTestRunner)