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 |
Paul Vinciguerra | bb3befc | 2020-12-07 02:46:31 +0000 | [diff] [blame] | 8 | from framework import VppTestCase, VppTestRunner, Worker |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 9 | |
| 10 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 11 | class VAPITestCase(VppTestCase): |
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 | |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 22 | def test_vapi_c(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 23 | """run C VAPI tests""" |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 24 | executable = f"{config.vpp_build_dir}/vpp/bin/vapi_c_test" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 25 | worker = Worker( |
| 26 | [executable, "vapi client", self.get_api_segment_prefix()], self.logger |
| 27 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 28 | worker.start() |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 29 | timeout = 60 |
| 30 | worker.join(timeout) |
| 31 | self.logger.info("Worker result is `%s'" % worker.result) |
| 32 | error = False |
| 33 | if worker.result is None: |
| 34 | try: |
| 35 | error = True |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 36 | self.logger.error("Timeout! Worker did not finish in %ss" % timeout) |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 37 | os.killpg(os.getpgid(worker.process.pid), signal.SIGTERM) |
| 38 | worker.join() |
| 39 | except: |
Klement Sekera | cae7134 | 2018-02-22 14:47:00 +0100 | [diff] [blame] | 40 | self.logger.debug("Couldn't kill worker-spawned process") |
| 41 | raise |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 42 | if error: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 43 | raise Exception("Timeout! Worker did not finish in %ss" % timeout) |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 44 | self.assert_equal(worker.result, 0, "Binary test return code") |
| 45 | |
| 46 | def test_vapi_cpp(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 47 | """run C++ VAPI tests""" |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 48 | executable = f"{config.vpp_build_dir}/vpp/bin/vapi_cpp_test" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 49 | worker = Worker( |
| 50 | [executable, "vapi client", self.get_api_segment_prefix()], self.logger |
| 51 | ) |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 52 | worker.start() |
| 53 | timeout = 120 |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 54 | 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 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 60 | self.logger.error("Timeout! Worker did not finish in %ss" % timeout) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 61 | os.killpg(os.getpgid(worker.process.pid), signal.SIGTERM) |
| 62 | worker.join() |
| 63 | except: |
| 64 | raise Exception("Couldn't kill worker-spawned process") |
| 65 | if error: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 66 | raise Exception("Timeout! Worker did not finish in %ss" % timeout) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 67 | self.assert_equal(worker.result, 0, "Binary test return code") |
| 68 | |
| 69 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 70 | if __name__ == "__main__": |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 71 | unittest.main(testRunner=VppTestRunner) |