blob: 9b4cad090a009129d3ab1c9d9079ec407708a516 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Klement Sekera8f2a4ea2017-05-04 06:15:18 +02002""" VAPI test """
3
Klement Sekera8f2a4ea2017-05-04 06:15:18 +02004import unittest
5import os
6import signal
Paul Vinciguerrabb3befc2020-12-07 02:46:31 +00007from framework import VppTestCase, VppTestRunner, Worker
Klement Sekera8f2a4ea2017-05-04 06:15:18 +02008
9
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020010class VAPITestCase(VppTestCase):
11 """ VAPI test """
12
Paul Vinciguerra8d991d92019-01-25 14:05:48 -080013 @classmethod
14 def setUpClass(cls):
15 super(VAPITestCase, cls).setUpClass()
16
17 @classmethod
18 def tearDownClass(cls):
19 super(VAPITestCase, cls).tearDownClass()
20
Klement Sekeradc15be22017-06-12 06:49:33 +020021 def test_vapi_c(self):
22 """ run C VAPI tests """
Damjan Mariona2d6d352021-05-25 18:29:24 +020023 var = "VPP_BUILD_DIR"
24 build_dir = os.getenv(var, None)
25 self.assertIsNotNone(build_dir,
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020026 "Environment variable `%s' not set" % var)
Damjan Mariona2d6d352021-05-25 18:29:24 +020027 executable = f"{build_dir}/vpp/bin/vapi_c_test"
Klement Sekerae2636852021-03-16 12:52:12 +010028 worker = Worker([executable, "vapi client",
29 self.get_api_segment_prefix()], self.logger)
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020030 worker.start()
Klement Sekeradc15be22017-06-12 06:49:33 +020031 timeout = 60
32 worker.join(timeout)
33 self.logger.info("Worker result is `%s'" % worker.result)
34 error = False
35 if worker.result is None:
36 try:
37 error = True
38 self.logger.error(
39 "Timeout! Worker did not finish in %ss" % timeout)
40 os.killpg(os.getpgid(worker.process.pid), signal.SIGTERM)
41 worker.join()
42 except:
Klement Sekeracae71342018-02-22 14:47:00 +010043 self.logger.debug("Couldn't kill worker-spawned process")
44 raise
Klement Sekeradc15be22017-06-12 06:49:33 +020045 if error:
46 raise Exception(
47 "Timeout! Worker did not finish in %ss" % timeout)
48 self.assert_equal(worker.result, 0, "Binary test return code")
49
50 def test_vapi_cpp(self):
51 """ run C++ VAPI tests """
Damjan Mariona2d6d352021-05-25 18:29:24 +020052 var = "VPP_BUILD_DIR"
53 build_dir = os.getenv(var, None)
54 self.assertIsNotNone(build_dir,
Klement Sekeradc15be22017-06-12 06:49:33 +020055 "Environment variable `%s' not set" % var)
Damjan Mariona2d6d352021-05-25 18:29:24 +020056 executable = f"{build_dir}/vpp/bin/vapi_cpp_test"
Klement Sekerae2636852021-03-16 12:52:12 +010057 worker = Worker([executable, "vapi client",
58 self.get_api_segment_prefix()], self.logger)
Klement Sekeradc15be22017-06-12 06:49:33 +020059 worker.start()
60 timeout = 120
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020061 worker.join(timeout)
62 self.logger.info("Worker result is `%s'" % worker.result)
63 error = False
64 if worker.result is None:
65 try:
66 error = True
67 self.logger.error(
68 "Timeout! Worker did not finish in %ss" % timeout)
69 os.killpg(os.getpgid(worker.process.pid), signal.SIGTERM)
70 worker.join()
71 except:
72 raise Exception("Couldn't kill worker-spawned process")
73 if error:
74 raise Exception(
75 "Timeout! Worker did not finish in %ss" % timeout)
76 self.assert_equal(worker.result, 0, "Binary test return code")
77
78
79if __name__ == '__main__':
80 unittest.main(testRunner=VppTestRunner)