blob: 5dbe56ac6e2f3deac9b5dcada413c2110e0e5178 [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
Klement Sekerabe2c2a82019-09-02 15:19:41 +00007from framework import VppTestCase, running_on_centos, 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 """
Klement Sekerab8c72a42018-11-08 11:21:39 +010023 var = "TEST_DIR"
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)
Klement Sekerab8c72a42018-11-08 11:21:39 +010027 executable = "%s/build/vapi_test/vapi_c_test" % built_root
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020028 worker = Worker(
29 [executable, "vapi client", self.shm_prefix], self.logger)
30 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
Paul Vinciguerradefde0f2018-12-06 07:46:13 -080050 @unittest.skipIf(running_on_centos, "Centos's gcc can't compile our C++")
Klement Sekeradc15be22017-06-12 06:49:33 +020051 def test_vapi_cpp(self):
52 """ run C++ VAPI tests """
Klement Sekerab8c72a42018-11-08 11:21:39 +010053 var = "TEST_DIR"
Klement Sekeradc15be22017-06-12 06:49:33 +020054 built_root = os.getenv(var, None)
55 self.assertIsNotNone(built_root,
56 "Environment variable `%s' not set" % var)
Klement Sekerab8c72a42018-11-08 11:21:39 +010057 executable = "%s/build/vapi_test/vapi_cpp_test" % built_root
Klement Sekeradc15be22017-06-12 06:49:33 +020058 worker = Worker(
59 [executable, "vapi client", self.shm_prefix], self.logger)
60 worker.start()
61 timeout = 120
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020062 worker.join(timeout)
63 self.logger.info("Worker result is `%s'" % worker.result)
64 error = False
65 if worker.result is None:
66 try:
67 error = True
68 self.logger.error(
69 "Timeout! Worker did not finish in %ss" % timeout)
70 os.killpg(os.getpgid(worker.process.pid), signal.SIGTERM)
71 worker.join()
72 except:
73 raise Exception("Couldn't kill worker-spawned process")
74 if error:
75 raise Exception(
76 "Timeout! Worker did not finish in %ss" % timeout)
77 self.assert_equal(worker.result, 0, "Binary test return code")
78
79
80if __name__ == '__main__':
81 unittest.main(testRunner=VppTestRunner)