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 | be2c2a8 | 2019-09-02 15:19:41 +0000 | [diff] [blame] | 7 | from framework import VppTestCase, running_on_centos, 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 | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 28 | worker = Worker( |
| 29 | [executable, "vapi client", self.shm_prefix], self.logger) |
| 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 | |
Paul Vinciguerra | defde0f | 2018-12-06 07:46:13 -0800 | [diff] [blame] | 50 | @unittest.skipIf(running_on_centos, "Centos's gcc can't compile our C++") |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 51 | def test_vapi_cpp(self): |
| 52 | """ run C++ VAPI tests """ |
Dave Wallace | f0797d1 | 2019-11-15 17:29:15 -0500 | [diff] [blame^] | 53 | var = "TEST_BR" |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 54 | built_root = os.getenv(var, None) |
| 55 | self.assertIsNotNone(built_root, |
| 56 | "Environment variable `%s' not set" % var) |
Dave Wallace | f0797d1 | 2019-11-15 17:29:15 -0500 | [diff] [blame^] | 57 | executable = "%s/vapi_test/vapi_cpp_test" % built_root |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 58 | worker = Worker( |
| 59 | [executable, "vapi client", self.shm_prefix], self.logger) |
| 60 | worker.start() |
| 61 | timeout = 120 |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 62 | worker.join(timeout) |
| 63 | self.logger.info("Worker result is `%s'" % worker.result) |
| 64 | error = False |
| 65 | if worker.result is None: |
| 66 | try: |
| 67 | error = True |
| 68 | self.logger.error( |
| 69 | "Timeout! Worker did not finish in %ss" % timeout) |
| 70 | os.killpg(os.getpgid(worker.process.pid), signal.SIGTERM) |
| 71 | worker.join() |
| 72 | except: |
| 73 | raise Exception("Couldn't kill worker-spawned process") |
| 74 | if error: |
| 75 | raise Exception( |
| 76 | "Timeout! Worker did not finish in %ss" % timeout) |
| 77 | self.assert_equal(worker.result, 0, "Binary test return code") |
| 78 | |
| 79 | |
| 80 | if __name__ == '__main__': |
| 81 | unittest.main(testRunner=VppTestRunner) |