blob: b5820fa181bf71a59d0a5eb14c02450f56194fa3 [file] [log] [blame]
Klement Sekera8f2a4ea2017-05-04 06:15:18 +02001#!/usr/bin/env python
2""" VAPI test """
3
Klement Sekera8f2a4ea2017-05-04 06:15:18 +02004import unittest
5import os
6import signal
7import subprocess
8from threading import Thread
9from log import single_line_delim
Klement Sekerad3e671e2017-09-29 12:36:37 +020010from framework import VppTestCase, running_extended_tests, \
Neale Ranns812ed392017-10-16 04:20:13 -070011 running_on_centos, VppTestRunner, Worker
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020012
13
14@unittest.skipUnless(running_extended_tests(), "part of extended tests")
15class VAPITestCase(VppTestCase):
16 """ VAPI test """
17
Klement Sekeradc15be22017-06-12 06:49:33 +020018 def test_vapi_c(self):
19 """ run C VAPI tests """
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020020 var = "BR"
21 built_root = os.getenv(var, None)
22 self.assertIsNotNone(built_root,
23 "Environment variable `%s' not set" % var)
Klement Sekeradc15be22017-06-12 06:49:33 +020024 executable = "%s/vapi_test/vapi_c_test" % built_root
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020025 worker = Worker(
26 [executable, "vapi client", self.shm_prefix], self.logger)
27 worker.start()
Klement Sekeradc15be22017-06-12 06:49:33 +020028 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:
40 raise Exception("Couldn't kill worker-spawned process")
41 if error:
42 raise Exception(
43 "Timeout! Worker did not finish in %ss" % timeout)
44 self.assert_equal(worker.result, 0, "Binary test return code")
45
Klement Sekerad3e671e2017-09-29 12:36:37 +020046 @unittest.skipIf(running_on_centos(), "Centos's gcc can't compile our C++")
Klement Sekeradc15be22017-06-12 06:49:33 +020047 def test_vapi_cpp(self):
48 """ run C++ VAPI tests """
49 var = "BR"
50 built_root = os.getenv(var, None)
51 self.assertIsNotNone(built_root,
52 "Environment variable `%s' not set" % var)
53 executable = "%s/vapi_test/vapi_cpp_test" % built_root
54 worker = Worker(
55 [executable, "vapi client", self.shm_prefix], self.logger)
56 worker.start()
57 timeout = 120
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020058 worker.join(timeout)
59 self.logger.info("Worker result is `%s'" % worker.result)
60 error = False
61 if worker.result is None:
62 try:
63 error = True
64 self.logger.error(
65 "Timeout! Worker did not finish in %ss" % timeout)
66 os.killpg(os.getpgid(worker.process.pid), signal.SIGTERM)
67 worker.join()
68 except:
69 raise Exception("Couldn't kill worker-spawned process")
70 if error:
71 raise Exception(
72 "Timeout! Worker did not finish in %ss" % timeout)
73 self.assert_equal(worker.result, 0, "Binary test return code")
74
75
76if __name__ == '__main__':
77 unittest.main(testRunner=VppTestRunner)