Ole Troan | c27213a | 2016-08-31 14:50:49 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | from __future__ import print_function |
| 4 | import unittest, sys, time, threading, struct |
| 5 | import test_base |
| 6 | import vpp_papi |
| 7 | from ipaddress import * |
| 8 | |
| 9 | import glob, subprocess |
| 10 | class TestPAPI(unittest.TestCase): |
| 11 | @classmethod |
| 12 | def setUpClass(cls): |
| 13 | # |
| 14 | # Start main VPP process |
| 15 | cls.vpp_bin = glob.glob(test_base.scriptdir+'/../../../build-root/install-vpp*-native/vpp/bin/vpp')[0] |
| 16 | print("VPP BIN:", cls.vpp_bin) |
| 17 | cls.vpp = subprocess.Popen([cls.vpp_bin, "unix", "nodaemon"], stderr=subprocess.PIPE) |
| 18 | print('Started VPP') |
| 19 | # For some reason unless we let VPP start up the API cannot connect. |
| 20 | time.sleep(0.3) |
| 21 | @classmethod |
| 22 | def tearDownClass(cls): |
| 23 | cls.vpp.terminate() |
| 24 | |
| 25 | def setUp(self): |
| 26 | print("Connecting API") |
| 27 | r = vpp_papi.connect("test_papi") |
| 28 | self.assertEqual(r, 0) |
| 29 | |
| 30 | def tearDown(self): |
| 31 | r = vpp_papi.disconnect() |
| 32 | self.assertEqual(r, 0) |
| 33 | |
| 34 | # |
| 35 | # The tests themselves |
| 36 | # |
| 37 | |
| 38 | # |
| 39 | # Basic request / reply |
| 40 | # |
| 41 | def test_cli_request(self): |
| 42 | print(vpp_papi.cli_exec('show version verbose')) |
| 43 | #t = vpp_papi.cli_inband_request(len(cmd), cmd) |
| 44 | #print('T:',t) |
| 45 | #reply = t.reply[0].decode().rstrip('\x00') |
| 46 | #print(reply) |
| 47 | #program = t.program.decode().rstrip('\x00') |
| 48 | #self.assertEqual('vpe', program) |
| 49 | |
| 50 | |
| 51 | if __name__ == '__main__': |
| 52 | unittest.main() |