blob: 64f911c7bfaa810070888e307a2a86871c7c661d [file] [log] [blame]
Filip Tehlarb1c0b9a2022-02-22 15:19:20 +00001#!/usr/bin/env python3
2""" Vpp HTTP tests """
3
4import unittest
Filip Tehlarb1c0b9a2022-02-22 15:19:20 +00005import http.client
Dave Wallace8800f732023-08-31 00:47:44 -04006from asfframework import VppAsfTestCase, VppTestRunner
Filip Tehlarb1c0b9a2022-02-22 15:19:20 +00007
8
9@unittest.skip("Requires root")
Dave Wallace8800f732023-08-31 00:47:44 -040010class TestHttpTps(VppAsfTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020011 """HTTP test class"""
Filip Tehlarb1c0b9a2022-02-22 15:19:20 +000012
13 @classmethod
14 def setUpClass(cls):
15 super(TestHttpTps, cls).setUpClass()
16
17 @classmethod
18 def tearDownClass(cls):
19 super(TestHttpTps, cls).tearDownClass()
20
21 def setUp(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020022 self.client_ip4 = "172.0.0.2"
23 self.server_ip4 = "172.0.0.1"
24 self.vapi.cli(f"create tap id 0 host-ip4-addr {self.client_ip4}/24")
25 self.vapi.cli(f"set int ip addr tap0 {self.server_ip4}/24")
26 self.vapi.cli("set int state tap0 up")
Filip Tehlarb1c0b9a2022-02-22 15:19:20 +000027 self.vapi.session_enable_disable(is_enable=1)
28
29 def test_http_tps(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020030 fname = "test_file_1M"
31 self.vapi.cli("http tps uri tcp://0.0.0.0/8080")
Filip Tehlarb1c0b9a2022-02-22 15:19:20 +000032 con = http.client.HTTPConnection(f"{self.server_ip4}", 8080)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020033 con.request("GET", f"/{fname}")
Filip Tehlarb1c0b9a2022-02-22 15:19:20 +000034 r = con.getresponse()
35 self.assertEqual(len(r.read()), 1 << 20)
36
37
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020038if __name__ == "__main__":
Filip Tehlarb1c0b9a2022-02-22 15:19:20 +000039 unittest.main(testRunner=VppTestRunner)