3 from framework import VppTestCase, VppTestRunner
4 from vpp_papi import VppEnum
8 class TestJsonApiTrace(VppTestCase):
9 """JSON API trace related tests"""
13 super(TestJsonApiTrace, cls).setUpClass()
16 self.vapi.cli("api trace free")
17 self.vapi.cli("api trace on")
18 self.vapi.cli("api trace tx on")
21 def tearDownClass(cls):
22 super(TestJsonApiTrace, cls).tearDownClass()
24 def test_json_api_trace_save(self):
25 self.vapi.show_version()
27 fname = "test_api_trace-%d.json" % self.vpp.pid
28 tmp_api_trace = "/tmp/%s" % fname
29 fpath = "%s/%s" % (self.tempdir, fname)
30 self.vapi.cli("api trace save-json {}".format(fname))
31 os.rename(tmp_api_trace, fpath)
32 with open(fpath, encoding="utf-8") as f:
37 if o["_msgname"] == "show_version":
40 self.assertTrue(found)
41 self.assertEquals(o["_msgname"], "show_version")
43 def test_json_api_trace_replay(self):
44 fname = "/tmp/create_loop.json"
48 "_msgname": "create_loopback",
50 "mac_address": "00:00:00:00:00:00"
53 with open(fname, "w") as f:
55 self.vapi.cli("api trace replay-json {}".format(fname))
56 r = self.vapi.sw_interface_dump(name_filter="loop", name_filter_valid=True)
57 self.assertEqual(len(r), 1)
58 self.assertEqual(r[0].interface_name, "loop0")
61 if __name__ == "__main__":
62 unittest.main(testRunner=VppTestRunner)