Filip Tehlar | b1c0b9a | 2022-02-22 15:19:20 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | """ Vpp HTTP tests """ |
| 3 | |
| 4 | import unittest |
Filip Tehlar | b1c0b9a | 2022-02-22 15:19:20 +0000 | [diff] [blame] | 5 | import http.client |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 6 | from asfframework import VppAsfTestCase, VppTestRunner |
Filip Tehlar | b1c0b9a | 2022-02-22 15:19:20 +0000 | [diff] [blame] | 7 | |
| 8 | |
| 9 | @unittest.skip("Requires root") |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 10 | class TestHttpTps(VppAsfTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 11 | """HTTP test class""" |
Filip Tehlar | b1c0b9a | 2022-02-22 15:19:20 +0000 | [diff] [blame] | 12 | |
| 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 22 | 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 Tehlar | b1c0b9a | 2022-02-22 15:19:20 +0000 | [diff] [blame] | 27 | self.vapi.session_enable_disable(is_enable=1) |
| 28 | |
| 29 | def test_http_tps(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 30 | fname = "test_file_1M" |
| 31 | self.vapi.cli("http tps uri tcp://0.0.0.0/8080") |
Filip Tehlar | b1c0b9a | 2022-02-22 15:19:20 +0000 | [diff] [blame] | 32 | con = http.client.HTTPConnection(f"{self.server_ip4}", 8080) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 33 | con.request("GET", f"/{fname}") |
Filip Tehlar | b1c0b9a | 2022-02-22 15:19:20 +0000 | [diff] [blame] | 34 | r = con.getresponse() |
| 35 | self.assertEqual(len(r.read()), 1 << 20) |
| 36 | |
| 37 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 38 | if __name__ == "__main__": |
Filip Tehlar | b1c0b9a | 2022-02-22 15:19:20 +0000 | [diff] [blame] | 39 | unittest.main(testRunner=VppTestRunner) |