blob: d91099210d282e7c2cf5e595db0f2de8b5952ef8 [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 """
Dave Wallacef0797d12019-11-15 17:29:15 -050023 var = "TEST_BR"
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020024 built_root = os.getenv(var, None)
25 self.assertIsNotNone(built_root,
26 "Environment variable `%s' not set" % var)
Dave Wallacef0797d12019-11-15 17:29:15 -050027 executable = "%s/vapi_test/vapi_c_test" % built_root
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 """
Dave Wallacef0797d12019-11-15 17:29:15 -050052 var = "TEST_BR"
Klement Sekeradc15be22017-06-12 06:49:33 +020053 built_root = os.getenv(var, None)
54 self.assertIsNotNone(built_root,
55 "Environment variable `%s' not set" % var)
Dave Wallacef0797d12019-11-15 17:29:15 -050056 executable = "%s/vapi_test/vapi_cpp_test" % built_root
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)