blob: 2eb47b5901789be4a1f75de7a65ff18cecbb2d2e [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Klement Sekera8f2a4ea2017-05-04 06:15:18 +02002""" VAPI test """
3
Klement Sekera8f2a4ea2017-05-04 06:15:18 +02004import unittest
5import os
6import signal
Klement Sekerab23ffd72021-05-31 16:08:53 +02007from config import config
Pratikshya Prasai657bdf72022-08-18 11:09:38 -04008from asfframework import VppTestCase, VppTestRunner, Worker
Klement Sekera8f2a4ea2017-05-04 06:15:18 +02009
10
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020011class VAPITestCase(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020012 """VAPI test"""
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020013
Paul Vinciguerra8d991d92019-01-25 14:05:48 -080014 @classmethod
15 def setUpClass(cls):
16 super(VAPITestCase, cls).setUpClass()
17
18 @classmethod
19 def tearDownClass(cls):
20 super(VAPITestCase, cls).tearDownClass()
21
Klement Sekeradc15be22017-06-12 06:49:33 +020022 def test_vapi_c(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020023 """run C VAPI tests"""
Klement Sekerab23ffd72021-05-31 16:08:53 +020024 executable = f"{config.vpp_build_dir}/vpp/bin/vapi_c_test"
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020025 worker = Worker(
26 [executable, "vapi client", self.get_api_segment_prefix()], self.logger
27 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020028 worker.start()
Klement Sekeradc15be22017-06-12 06:49:33 +020029 timeout = 60
30 worker.join(timeout)
31 self.logger.info("Worker result is `%s'" % worker.result)
32 error = False
33 if worker.result is None:
34 try:
35 error = True
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020036 self.logger.error("Timeout! Worker did not finish in %ss" % timeout)
Klement Sekeradc15be22017-06-12 06:49:33 +020037 os.killpg(os.getpgid(worker.process.pid), signal.SIGTERM)
38 worker.join()
39 except:
Klement Sekeracae71342018-02-22 14:47:00 +010040 self.logger.debug("Couldn't kill worker-spawned process")
41 raise
Klement Sekeradc15be22017-06-12 06:49:33 +020042 if error:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020043 raise Exception("Timeout! Worker did not finish in %ss" % timeout)
Klement Sekeradc15be22017-06-12 06:49:33 +020044 self.assert_equal(worker.result, 0, "Binary test return code")
45
46 def test_vapi_cpp(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020047 """run C++ VAPI tests"""
Klement Sekerab23ffd72021-05-31 16:08:53 +020048 executable = f"{config.vpp_build_dir}/vpp/bin/vapi_cpp_test"
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020049 worker = Worker(
50 [executable, "vapi client", self.get_api_segment_prefix()], self.logger
51 )
Klement Sekeradc15be22017-06-12 06:49:33 +020052 worker.start()
53 timeout = 120
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020054 worker.join(timeout)
55 self.logger.info("Worker result is `%s'" % worker.result)
56 error = False
57 if worker.result is None:
58 try:
59 error = True
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020060 self.logger.error("Timeout! Worker did not finish in %ss" % timeout)
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020061 os.killpg(os.getpgid(worker.process.pid), signal.SIGTERM)
62 worker.join()
63 except:
64 raise Exception("Couldn't kill worker-spawned process")
65 if error:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020066 raise Exception("Timeout! Worker did not finish in %ss" % timeout)
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020067 self.assert_equal(worker.result, 0, "Binary test return code")
68
69
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020070if __name__ == "__main__":
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020071 unittest.main(testRunner=VppTestRunner)