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
|
2020-12-07 02:46:31 +00:00
|
|
|
from framework import VppTestCase, 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 """
|
2021-05-25 18:29:24 +02:00
|
|
|
var = "VPP_BUILD_DIR"
|
|
|
|
build_dir = os.getenv(var, None)
|
|
|
|
self.assertIsNotNone(build_dir,
|
2017-05-04 06:15:18 +02:00
|
|
|
"Environment variable `%s' not set" % var)
|
2021-05-25 18:29:24 +02:00
|
|
|
executable = f"{build_dir}/vpp/bin/vapi_c_test"
|
2021-03-16 12:52:12 +01:00
|
|
|
worker = Worker([executable, "vapi client",
|
|
|
|
self.get_api_segment_prefix()], self.logger)
|
2017-05-04 06:15:18 +02:00
|
|
|
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")
|
|
|
|
|
|
|
|
def test_vapi_cpp(self):
|
|
|
|
""" run C++ VAPI tests """
|
2021-05-25 18:29:24 +02:00
|
|
|
var = "VPP_BUILD_DIR"
|
|
|
|
build_dir = os.getenv(var, None)
|
|
|
|
self.assertIsNotNone(build_dir,
|
2017-06-12 06:49:33 +02:00
|
|
|
"Environment variable `%s' not set" % var)
|
2021-05-25 18:29:24 +02:00
|
|
|
executable = f"{build_dir}/vpp/bin/vapi_cpp_test"
|
2021-03-16 12:52:12 +01:00
|
|
|
worker = Worker([executable, "vapi client",
|
|
|
|
self.get_api_segment_prefix()], self.logger)
|
2017-06-12 06:49:33 +02:00
|
|
|
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)
|