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