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