Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 2 | """ VAPI test """ |
| 3 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 4 | import unittest |
| 5 | import os |
| 6 | import signal |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 7 | from config import config |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 8 | from asfframework import VppAsfTestCase, VppTestRunner, Worker |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 9 | |
| 10 | |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 11 | class VAPITestCase(VppAsfTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 12 | """VAPI test""" |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 13 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 14 | @classmethod |
| 15 | def setUpClass(cls): |
| 16 | super(VAPITestCase, cls).setUpClass() |
| 17 | |
| 18 | @classmethod |
| 19 | def tearDownClass(cls): |
| 20 | super(VAPITestCase, cls).tearDownClass() |
| 21 | |
Stanislav Zaikin | dc4d21e | 2024-03-06 19:48:30 +0100 | [diff] [blame] | 22 | def run_vapi_c(self, path, transport): |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 23 | executable = f"{config.vpp_build_dir}/vpp/bin/vapi_c_test" |
Stanislav Zaikin | dc4d21e | 2024-03-06 19:48:30 +0100 | [diff] [blame] | 24 | worker = Worker([executable, "vapi client", path, transport], self.logger) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 25 | worker.start() |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 26 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 33 | self.logger.error("Timeout! Worker did not finish in %ss" % timeout) |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 34 | os.killpg(os.getpgid(worker.process.pid), signal.SIGTERM) |
| 35 | worker.join() |
| 36 | except: |
Klement Sekera | cae7134 | 2018-02-22 14:47:00 +0100 | [diff] [blame] | 37 | self.logger.debug("Couldn't kill worker-spawned process") |
| 38 | raise |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 39 | if error: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 40 | raise Exception("Timeout! Worker did not finish in %ss" % timeout) |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 41 | self.assert_equal(worker.result, 0, "Binary test return code") |
| 42 | |
Stanislav Zaikin | dc4d21e | 2024-03-06 19:48:30 +0100 | [diff] [blame] | 43 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 52 | """run C++ VAPI tests""" |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 53 | executable = f"{config.vpp_build_dir}/vpp/bin/vapi_cpp_test" |
Stanislav Zaikin | dc4d21e | 2024-03-06 19:48:30 +0100 | [diff] [blame] | 54 | worker = Worker([executable, "vapi client", path, transport], self.logger) |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 55 | worker.start() |
| 56 | timeout = 120 |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 57 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 63 | self.logger.error("Timeout! Worker did not finish in %ss" % timeout) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 64 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 69 | raise Exception("Timeout! Worker did not finish in %ss" % timeout) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 70 | self.assert_equal(worker.result, 0, "Binary test return code") |
| 71 | |
Stanislav Zaikin | dc4d21e | 2024-03-06 19:48:30 +0100 | [diff] [blame] | 72 | 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 Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 80 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 81 | if __name__ == "__main__": |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 82 | unittest.main(testRunner=VppTestRunner) |