blob: 5a04abe4de7e4fdaf313263907b506c80c3e85b9 [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 Sekerab23ffd72021-05-31 16:08:53 +02007from config import config
Paul Vinciguerrabb3befc2020-12-07 02:46:31 +00008from framework import VppTestCase, VppTestRunner, Worker
Klement Sekera8f2a4ea2017-05-04 06:15:18 +02009
10
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020011class VAPITestCase(VppTestCase):
12 """ VAPI test """
13
Paul Vinciguerra8d991d92019-01-25 14:05:48 -080014 @classmethod
15 def setUpClass(cls):
16 super(VAPITestCase, cls).setUpClass()
17
18 @classmethod
19 def tearDownClass(cls):
20 super(VAPITestCase, cls).tearDownClass()
21
Klement Sekeradc15be22017-06-12 06:49:33 +020022 def test_vapi_c(self):
23 """ run C VAPI tests """
Klement Sekerab23ffd72021-05-31 16:08:53 +020024 executable = f"{config.vpp_build_dir}/vpp/bin/vapi_c_test"
Klement Sekerae2636852021-03-16 12:52:12 +010025 worker = Worker([executable, "vapi client",
26 self.get_api_segment_prefix()], self.logger)
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020027 worker.start()
Klement Sekeradc15be22017-06-12 06:49:33 +020028 timeout = 60
29 worker.join(timeout)
30 self.logger.info("Worker result is `%s'" % worker.result)
31 error = False
32 if worker.result is None:
33 try:
34 error = True
35 self.logger.error(
36 "Timeout! Worker did not finish in %ss" % timeout)
37 os.killpg(os.getpgid(worker.process.pid), signal.SIGTERM)
38 worker.join()
39 except:
Klement Sekeracae71342018-02-22 14:47:00 +010040 self.logger.debug("Couldn't kill worker-spawned process")
41 raise
Klement Sekeradc15be22017-06-12 06:49:33 +020042 if error:
43 raise Exception(
44 "Timeout! Worker did not finish in %ss" % timeout)
45 self.assert_equal(worker.result, 0, "Binary test return code")
46
47 def test_vapi_cpp(self):
48 """ run C++ VAPI tests """
Klement Sekerab23ffd72021-05-31 16:08:53 +020049 executable = f"{config.vpp_build_dir}/vpp/bin/vapi_cpp_test"
Klement Sekerae2636852021-03-16 12:52:12 +010050 worker = Worker([executable, "vapi client",
51 self.get_api_segment_prefix()], self.logger)
Klement Sekeradc15be22017-06-12 06:49:33 +020052 worker.start()
53 timeout = 120
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020054 worker.join(timeout)
55 self.logger.info("Worker result is `%s'" % worker.result)
56 error = False
57 if worker.result is None:
58 try:
59 error = True
60 self.logger.error(
61 "Timeout! Worker did not finish in %ss" % timeout)
62 os.killpg(os.getpgid(worker.process.pid), signal.SIGTERM)
63 worker.join()
64 except:
65 raise Exception("Couldn't kill worker-spawned process")
66 if error:
67 raise Exception(
68 "Timeout! Worker did not finish in %ss" % timeout)
69 self.assert_equal(worker.result, 0, "Binary test return code")
70
71
72if __name__ == '__main__':
73 unittest.main(testRunner=VppTestRunner)