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): |
| 12 | """ VAPI test """ |
| 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): |
| 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 | e263685 | 2021-03-16 12:52:12 +0100 | [diff] [blame] | 25 | worker = Worker([executable, "vapi client", |
| 26 | self.get_api_segment_prefix()], self.logger) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 27 | worker.start() |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 28 | 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 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: |
| 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 Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 49 | executable = f"{config.vpp_build_dir}/vpp/bin/vapi_cpp_test" |
Klement Sekera | e263685 | 2021-03-16 12:52:12 +0100 | [diff] [blame] | 50 | worker = Worker([executable, "vapi client", |
| 51 | self.get_api_segment_prefix()], self.logger) |
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 |
| 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 | |
| 72 | if __name__ == '__main__': |
| 73 | unittest.main(testRunner=VppTestRunner) |