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 |
Paul Vinciguerra | bb3befc | 2020-12-07 02:46:31 +0000 | [diff] [blame] | 7 | from framework import VppTestCase, VppTestRunner, Worker |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 8 | |
| 9 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 10 | class VAPITestCase(VppTestCase): |
| 11 | """ VAPI test """ |
| 12 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 13 | @classmethod |
| 14 | def setUpClass(cls): |
| 15 | super(VAPITestCase, cls).setUpClass() |
| 16 | |
| 17 | @classmethod |
| 18 | def tearDownClass(cls): |
| 19 | super(VAPITestCase, cls).tearDownClass() |
| 20 | |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 21 | def test_vapi_c(self): |
| 22 | """ run C VAPI tests """ |
Dave Wallace | f0797d1 | 2019-11-15 17:29:15 -0500 | [diff] [blame] | 23 | var = "TEST_BR" |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 24 | built_root = os.getenv(var, None) |
| 25 | self.assertIsNotNone(built_root, |
| 26 | "Environment variable `%s' not set" % var) |
Dave Wallace | f0797d1 | 2019-11-15 17:29:15 -0500 | [diff] [blame] | 27 | executable = "%s/vapi_test/vapi_c_test" % built_root |
Klement Sekera | e263685 | 2021-03-16 12:52:12 +0100 | [diff] [blame] | 28 | worker = Worker([executable, "vapi client", |
| 29 | self.get_api_segment_prefix()], self.logger) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 30 | worker.start() |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 31 | timeout = 60 |
| 32 | worker.join(timeout) |
| 33 | self.logger.info("Worker result is `%s'" % worker.result) |
| 34 | error = False |
| 35 | if worker.result is None: |
| 36 | try: |
| 37 | error = True |
| 38 | self.logger.error( |
| 39 | "Timeout! Worker did not finish in %ss" % timeout) |
| 40 | os.killpg(os.getpgid(worker.process.pid), signal.SIGTERM) |
| 41 | worker.join() |
| 42 | except: |
Klement Sekera | cae7134 | 2018-02-22 14:47:00 +0100 | [diff] [blame] | 43 | self.logger.debug("Couldn't kill worker-spawned process") |
| 44 | raise |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 45 | if error: |
| 46 | raise Exception( |
| 47 | "Timeout! Worker did not finish in %ss" % timeout) |
| 48 | self.assert_equal(worker.result, 0, "Binary test return code") |
| 49 | |
| 50 | def test_vapi_cpp(self): |
| 51 | """ run C++ VAPI tests """ |
Dave Wallace | f0797d1 | 2019-11-15 17:29:15 -0500 | [diff] [blame] | 52 | var = "TEST_BR" |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 53 | built_root = os.getenv(var, None) |
| 54 | self.assertIsNotNone(built_root, |
| 55 | "Environment variable `%s' not set" % var) |
Dave Wallace | f0797d1 | 2019-11-15 17:29:15 -0500 | [diff] [blame] | 56 | executable = "%s/vapi_test/vapi_cpp_test" % built_root |
Klement Sekera | e263685 | 2021-03-16 12:52:12 +0100 | [diff] [blame] | 57 | worker = Worker([executable, "vapi client", |
| 58 | self.get_api_segment_prefix()], self.logger) |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 59 | worker.start() |
| 60 | timeout = 120 |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 61 | worker.join(timeout) |
| 62 | self.logger.info("Worker result is `%s'" % worker.result) |
| 63 | error = False |
| 64 | if worker.result is None: |
| 65 | try: |
| 66 | error = True |
| 67 | self.logger.error( |
| 68 | "Timeout! Worker did not finish in %ss" % timeout) |
| 69 | os.killpg(os.getpgid(worker.process.pid), signal.SIGTERM) |
| 70 | worker.join() |
| 71 | except: |
| 72 | raise Exception("Couldn't kill worker-spawned process") |
| 73 | if error: |
| 74 | raise Exception( |
| 75 | "Timeout! Worker did not finish in %ss" % timeout) |
| 76 | self.assert_equal(worker.result, 0, "Binary test return code") |
| 77 | |
| 78 | |
| 79 | if __name__ == '__main__': |
| 80 | unittest.main(testRunner=VppTestRunner) |