2019-10-31 13:31:07 -05:00
|
|
|
#!/usr/bin/env python3
|
2017-05-04 06:15:18 +02:00
|
|
|
""" VAPI test """
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import os
|
|
|
|
import signal
|
2019-09-02 15:19:41 +00:00
|
|
|
from framework import VppTestCase, running_on_centos, VppTestRunner, Worker
|
2017-05-04 06:15:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
class VAPITestCase(VppTestCase):
|
|
|
|
""" VAPI test """
|
|
|
|
|
2019-01-25 14:05:48 -08:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(VAPITestCase, cls).setUpClass()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(VAPITestCase, cls).tearDownClass()
|
|
|
|
|
2017-06-12 06:49:33 +02:00
|
|
|
def test_vapi_c(self):
|
|
|
|
""" run C VAPI tests """
|
2019-11-15 17:29:15 -05:00
|
|
|
var = "TEST_BR"
|
2017-05-04 06:15:18 +02:00
|
|
|
built_root = os.getenv(var, None)
|
|
|
|
self.assertIsNotNone(built_root,
|
|
|
|
"Environment variable `%s' not set" % var)
|
2019-11-15 17:29:15 -05:00
|
|
|
executable = "%s/vapi_test/vapi_c_test" % built_root
|
2017-05-04 06:15:18 +02:00
|
|
|
worker = Worker(
|
|
|
|
[executable, "vapi client", self.shm_prefix], self.logger)
|
|
|
|
worker.start()
|
2017-06-12 06:49:33 +02:00
|
|
|
timeout = 60
|
|
|
|
worker.join(timeout)
|
|
|
|
self.logger.info("Worker result is `%s'" % worker.result)
|
|
|
|
error = False
|
|
|
|
if worker.result is None:
|
|
|
|
try:
|
|
|
|
error = True
|
|
|
|
self.logger.error(
|
|
|
|
"Timeout! Worker did not finish in %ss" % timeout)
|
|
|
|
os.killpg(os.getpgid(worker.process.pid), signal.SIGTERM)
|
|
|
|
worker.join()
|
|
|
|
except:
|
2018-02-22 14:47:00 +01:00
|
|
|
self.logger.debug("Couldn't kill worker-spawned process")
|
|
|
|
raise
|
2017-06-12 06:49:33 +02:00
|
|
|
if error:
|
|
|
|
raise Exception(
|
|
|
|
"Timeout! Worker did not finish in %ss" % timeout)
|
|
|
|
self.assert_equal(worker.result, 0, "Binary test return code")
|
|
|
|
|
2018-12-06 07:46:13 -08:00
|
|
|
@unittest.skipIf(running_on_centos, "Centos's gcc can't compile our C++")
|
2017-06-12 06:49:33 +02:00
|
|
|
def test_vapi_cpp(self):
|
|
|
|
""" run C++ VAPI tests """
|
2019-11-15 17:29:15 -05:00
|
|
|
var = "TEST_BR"
|
2017-06-12 06:49:33 +02:00
|
|
|
built_root = os.getenv(var, None)
|
|
|
|
self.assertIsNotNone(built_root,
|
|
|
|
"Environment variable `%s' not set" % var)
|
2019-11-15 17:29:15 -05:00
|
|
|
executable = "%s/vapi_test/vapi_cpp_test" % built_root
|
2017-06-12 06:49:33 +02:00
|
|
|
worker = Worker(
|
|
|
|
[executable, "vapi client", self.shm_prefix], self.logger)
|
|
|
|
worker.start()
|
|
|
|
timeout = 120
|
2017-05-04 06:15:18 +02:00
|
|
|
worker.join(timeout)
|
|
|
|
self.logger.info("Worker result is `%s'" % worker.result)
|
|
|
|
error = False
|
|
|
|
if worker.result is None:
|
|
|
|
try:
|
|
|
|
error = True
|
|
|
|
self.logger.error(
|
|
|
|
"Timeout! Worker did not finish in %ss" % timeout)
|
|
|
|
os.killpg(os.getpgid(worker.process.pid), signal.SIGTERM)
|
|
|
|
worker.join()
|
|
|
|
except:
|
|
|
|
raise Exception("Couldn't kill worker-spawned process")
|
|
|
|
if error:
|
|
|
|
raise Exception(
|
|
|
|
"Timeout! Worker did not finish in %ss" % timeout)
|
|
|
|
self.assert_equal(worker.result, 0, "Binary test return code")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(testRunner=VppTestRunner)
|