blob: a5635ff356788ee62eb9505071eb537dd9ad5ae4 [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
Dave Wallace8800f732023-08-31 00:47:44 -04008from asfframework import VppAsfTestCase, VppTestRunner, Worker
Klement Sekera8f2a4ea2017-05-04 06:15:18 +02009
10
Dave Wallace8800f732023-08-31 00:47:44 -040011class VAPITestCase(VppAsfTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020012 """VAPI test"""
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020013
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
Stanislav Zaikindc4d21e2024-03-06 19:48:30 +010022 def run_vapi_c(self, path, transport):
Klement Sekerab23ffd72021-05-31 16:08:53 +020023 executable = f"{config.vpp_build_dir}/vpp/bin/vapi_c_test"
Stanislav Zaikindc4d21e2024-03-06 19:48:30 +010024 worker = Worker([executable, "vapi client", path, transport], self.logger)
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020025 worker.start()
Klement Sekeradc15be22017-06-12 06:49:33 +020026 timeout = 60
27 worker.join(timeout)
28 self.logger.info("Worker result is `%s'" % worker.result)
29 error = False
30 if worker.result is None:
31 try:
32 error = True
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020033 self.logger.error("Timeout! Worker did not finish in %ss" % timeout)
Klement Sekeradc15be22017-06-12 06:49:33 +020034 os.killpg(os.getpgid(worker.process.pid), signal.SIGTERM)
35 worker.join()
36 except:
Klement Sekeracae71342018-02-22 14:47:00 +010037 self.logger.debug("Couldn't kill worker-spawned process")
38 raise
Klement Sekeradc15be22017-06-12 06:49:33 +020039 if error:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020040 raise Exception("Timeout! Worker did not finish in %ss" % timeout)
Klement Sekeradc15be22017-06-12 06:49:33 +020041 self.assert_equal(worker.result, 0, "Binary test return code")
42
Stanislav Zaikindc4d21e2024-03-06 19:48:30 +010043 def test_vapi_c_shm(self):
44 """run C VAPI tests (over shared memory)"""
45 self.run_vapi_c(self.get_api_segment_prefix(), "shm")
46
47 def test_vapi_c_uds(self):
48 """run C VAPI tests (over unix domain socket)"""
49 self.run_vapi_c(self.get_api_sock_path(), "uds")
50
51 def run_vapi_cpp(self, path, transport):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020052 """run C++ VAPI tests"""
Klement Sekerab23ffd72021-05-31 16:08:53 +020053 executable = f"{config.vpp_build_dir}/vpp/bin/vapi_cpp_test"
Stanislav Zaikindc4d21e2024-03-06 19:48:30 +010054 worker = Worker([executable, "vapi client", path, transport], self.logger)
Klement Sekeradc15be22017-06-12 06:49:33 +020055 worker.start()
56 timeout = 120
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020057 worker.join(timeout)
58 self.logger.info("Worker result is `%s'" % worker.result)
59 error = False
60 if worker.result is None:
61 try:
62 error = True
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020063 self.logger.error("Timeout! Worker did not finish in %ss" % timeout)
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020064 os.killpg(os.getpgid(worker.process.pid), signal.SIGTERM)
65 worker.join()
66 except:
67 raise Exception("Couldn't kill worker-spawned process")
68 if error:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020069 raise Exception("Timeout! Worker did not finish in %ss" % timeout)
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020070 self.assert_equal(worker.result, 0, "Binary test return code")
71
Stanislav Zaikindc4d21e2024-03-06 19:48:30 +010072 def test_vapi_cpp_shm(self):
73 """run C++ VAPI tests (over shared memory)"""
74 self.run_vapi_cpp(self.get_api_segment_prefix(), "shm")
75
76 def test_vapi_cpp_uds(self):
77 """run C++ VAPI tests (over unix domain socket)"""
78 self.run_vapi_cpp(self.get_api_sock_path(), "uds")
79
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020080
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020081if __name__ == "__main__":
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020082 unittest.main(testRunner=VppTestRunner)