3 from asfframework import VppTestCase, VppTestRunner
4 from vpp_papi import VppEnum
9 class TestJsonApiTrace(VppTestCase):
10 """JSON API trace related tests"""
14 super(TestJsonApiTrace, cls).setUpClass()
17 self.vapi.cli("api trace free")
18 self.vapi.cli("api trace on")
19 self.vapi.cli("api trace tx on")
22 def tearDownClass(cls):
23 super(TestJsonApiTrace, cls).tearDownClass()
25 def test_json_api_trace_save(self):
26 self.vapi.show_version()
28 fname = "test_api_trace-%d.json" % self.vpp.pid
29 tmp_api_trace = "/tmp/%s" % fname
30 fpath = "%s/%s" % (self.tempdir, fname)
31 self.vapi.cli("api trace save-json {}".format(fname))
32 shutil.move(tmp_api_trace, fpath)
33 with open(fpath, encoding="utf-8") as f:
38 if o["_msgname"] == "show_version":
41 self.assertTrue(found)
42 self.assertEquals(o["_msgname"], "show_version")
44 def test_json_api_trace_replay(self):
45 fname = "/tmp/create_loop.json"
49 "_msgname": "create_loopback",
51 "mac_address": "00:00:00:00:00:00"
54 with open(fname, "w") as f:
56 self.vapi.cli("api trace replay-json {}".format(fname))
57 r = self.vapi.sw_interface_dump(name_filter="loop", name_filter_valid=True)
58 self.assertEqual(len(r), 1)
59 self.assertEqual(r[0].interface_name, "loop0")
62 if __name__ == "__main__":
63 unittest.main(testRunner=VppTestRunner)