-
Notifications
You must be signed in to change notification settings - Fork 9
/
test.py
executable file
·344 lines (300 loc) · 16.5 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#!/usr/bin/env python3
"""
Copyright (C) 2021 Evtech Solutions, Ltd., dba 3D-P
Copyright (C) 2021 Neil Tallim <[email protected]>
This file is part of rperf.
rperf is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
rperf is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with rperf. If not, see <https://www.gnu.org/licenses/>.
"""
"""
This is a simple testing script to ensure basic correctness of rperf behaviour.
It doesn't test off-host connectivity (unless you've got a very unusual setup)
and it isn't concerned with probing limits. It just makes sure TCP, UDP, and
common options are functioning as expected.
"""
import argparse
import concurrent.futures
import json
import subprocess
import unittest
_RPERF_BINARY = "./target/release/rperf"
_DISPLAY_LOGS = False #whether to display rperf's logs on stderr while testing
def _run_rperf_client(address, args):
full_args = [_RPERF_BINARY, '-c', address, '-f', 'json',]
full_args.extend(args)
if _DISPLAY_LOGS:
result = subprocess.check_output(full_args)
else:
result = subprocess.check_output(full_args, stderr=subprocess.DEVNULL)
return json.loads(result)
def _run_rperf_client_hostname(args):
return _run_rperf_client('localhost', args)
def _run_rperf_client_ipv4(args):
return _run_rperf_client('127.0.0.1', args)
def _run_rperf_client_ipv6(args):
return _run_rperf_client('::1', args)
class TestIpv4(unittest.TestCase):
def setUp(self):
if _DISPLAY_LOGS:
self.server = subprocess.Popen((_RPERF_BINARY, '-s',))
else:
self.server = subprocess.Popen((_RPERF_BINARY, '-s',), stderr=subprocess.DEVNULL)
def tearDown(self):
self.server.terminate()
self.server.wait()
def test_tcp_forward(self):
result = _run_rperf_client_ipv4((
'-b', '500000', #keep it light, at 500kBps per stream
'-l', '4096', #try to send 4k of data at a time
'-O', '1', #omit the first second of data from summaries
'-P', '2', #two parallel streams
'-t', '2', #run for two seconds
))
self.assertTrue(result['success'])
self.assertEqual(result['config']['common']['family'], 'tcp')
self.assertEqual(result['config']['common']['streams'], 2)
self.assertEqual(result['config']['additional']['reverse'], False)
self.assertEqual(result['config']['additional']['ip_version'], 4)
self.assertEqual(result['summary']['bytes_received'], result['summary']['bytes_sent'])
self.assertAlmostEqual(result['summary']['bytes_received'], 1000000, delta=50000)
self.assertAlmostEqual(result['summary']['duration_receive'], 2.0, delta=0.1)
def test_tcp_reverse(self):
result = _run_rperf_client_ipv4((
'-R', #run in reverse mode
'-b', '500000', #keep it light, at 500kBps per stream
'-l', '4096', #try to send 4k of data at a time
'-O', '1', #omit the first second of data from summaries
'-P', '2', #two parallel streams
'-t', '2', #run for two seconds
))
self.assertTrue(result['success'])
self.assertEqual(result['config']['common']['family'], 'tcp')
self.assertEqual(result['config']['common']['streams'], 2)
self.assertEqual(result['config']['additional']['reverse'], True)
self.assertEqual(result['config']['additional']['ip_version'], 4)
self.assertEqual(result['summary']['bytes_received'], result['summary']['bytes_sent'])
self.assertAlmostEqual(result['summary']['bytes_received'], 1000000, delta=50000)
self.assertAlmostEqual(result['summary']['duration_receive'], 2.0, delta=0.1)
def test_udp_forward(self):
result = _run_rperf_client_ipv4((
'-u', #run UDP test
'-b', '500000', #keep it light, at 500kBps per stream
'-l', '1200', #try to send 1200 bytes of data at a time
'-O', '1', #omit the first second of data from summaries
'-P', '2', #two parallel streams
'-t', '2', #run for two seconds
))
self.assertTrue(result['success'])
self.assertEqual(result['config']['common']['family'], 'udp')
self.assertEqual(result['config']['common']['streams'], 2)
self.assertEqual(result['config']['additional']['reverse'], False)
self.assertEqual(result['config']['additional']['ip_version'], 4)
self.assertEqual(result['summary']['bytes_received'], result['summary']['bytes_sent'])
self.assertEqual(result['summary']['packets_received'], result['summary']['packets_sent'])
self.assertEqual(result['summary']['framed_packet_size'], 1228)
self.assertEqual(result['summary']['packets_duplicate'], 0)
self.assertEqual(result['summary']['packets_lost'], 0)
self.assertEqual(result['summary']['packets_out_of_order'], 0)
self.assertAlmostEqual(result['summary']['bytes_received'], 1000000, delta=50000)
self.assertAlmostEqual(result['summary']['duration_receive'], 2.0, delta=0.1)
def test_udp_reverse(self):
result = _run_rperf_client_ipv4((
'-u', #run UDP test
'-R', #run in reverse mode
'-b', '500000', #keep it light, at 500kBps per stream
'-l', '1200', #try to send 1200 bytes of data at a time
'-O', '1', #omit the first second of data from summaries
'-P', '2', #two parallel streams
'-t', '2', #run for two seconds
))
self.assertTrue(result['success'])
self.assertEqual(result['config']['common']['family'], 'udp')
self.assertEqual(result['config']['common']['streams'], 2)
self.assertEqual(result['config']['additional']['reverse'], True)
self.assertEqual(result['config']['additional']['ip_version'], 4)
self.assertEqual(result['summary']['bytes_received'], result['summary']['bytes_sent'])
self.assertEqual(result['summary']['packets_received'], result['summary']['packets_sent'])
self.assertEqual(result['summary']['framed_packet_size'], 1228)
self.assertEqual(result['summary']['packets_duplicate'], 0)
self.assertEqual(result['summary']['packets_lost'], 0)
self.assertEqual(result['summary']['packets_out_of_order'], 0)
self.assertAlmostEqual(result['summary']['bytes_received'], 1000000, delta=50000)
self.assertAlmostEqual(result['summary']['duration_receive'], 2.0, delta=0.1)
class TestIpv6(unittest.TestCase):
def setUp(self):
if _DISPLAY_LOGS:
self.server = subprocess.Popen((_RPERF_BINARY, '-s', '-6',))
else:
self.server = subprocess.Popen((_RPERF_BINARY, '-s', '-6'), stderr=subprocess.DEVNULL)
def tearDown(self):
self.server.terminate()
self.server.wait()
def test_tcp_forward(self):
result = _run_rperf_client_ipv6((
'-b', '500000', #keep it light, at 500kBps per stream
'-l', '4096', #try to send 4k of data at a time
'-O', '1', #omit the first second of data from summaries
'-t', '2', #run for two seconds
))
self.assertTrue(result['success'])
self.assertEqual(result['config']['common']['family'], 'tcp')
self.assertEqual(result['config']['common']['streams'], 1)
self.assertEqual(result['config']['additional']['reverse'], False)
self.assertEqual(result['config']['additional']['ip_version'], 6)
self.assertEqual(result['summary']['bytes_received'], result['summary']['bytes_sent'])
self.assertAlmostEqual(result['summary']['bytes_received'], 500000, delta=25000)
self.assertAlmostEqual(result['summary']['duration_receive'], 1.0, delta=0.1)
def test_tcp_reverse(self):
result = _run_rperf_client_ipv6((
'-R', #run in reverse mode
'-b', '500000', #keep it light, at 500kBps per stream
'-l', '4096', #try to send 4k of data at a time
'-O', '1', #omit the first second of data from summaries
'-t', '2', #run for two seconds
))
self.assertTrue(result['success'])
self.assertEqual(result['config']['common']['family'], 'tcp')
self.assertEqual(result['config']['common']['streams'], 1)
self.assertEqual(result['config']['additional']['reverse'], True)
self.assertEqual(result['config']['additional']['ip_version'], 6)
self.assertEqual(result['summary']['bytes_received'], result['summary']['bytes_sent'])
self.assertAlmostEqual(result['summary']['bytes_received'], 500000, delta=25000)
self.assertAlmostEqual(result['summary']['duration_receive'], 1.0, delta=0.1)
def test_udp_forward(self):
result = _run_rperf_client_ipv6((
'-u', #run UDP test
'-b', '500000', #keep it light, at 500kBps per stream
'-l', '1200', #try to send 1200 bytes of data at a time
'-t', '1', #run for one second
))
self.assertTrue(result['success'])
self.assertEqual(result['config']['common']['family'], 'udp')
self.assertEqual(result['config']['common']['streams'], 1)
self.assertEqual(result['config']['additional']['reverse'], False)
self.assertEqual(result['config']['additional']['ip_version'], 6)
self.assertEqual(result['summary']['bytes_received'], result['summary']['bytes_sent'])
self.assertEqual(result['summary']['packets_received'], result['summary']['packets_sent'])
self.assertEqual(result['summary']['framed_packet_size'], 1228)
self.assertEqual(result['summary']['packets_duplicate'], 0)
self.assertEqual(result['summary']['packets_lost'], 0)
self.assertEqual(result['summary']['packets_out_of_order'], 0)
self.assertAlmostEqual(result['summary']['bytes_received'], 500000, delta=25000)
self.assertAlmostEqual(result['summary']['duration_receive'], 1.0, delta=0.1)
def test_udp_reverse(self):
result = _run_rperf_client_ipv6((
'-u', #run UDP test
'-R', #run in reverse mode
'-b', '500000', #keep it light, at 500kBps per stream
'-l', '1200', #try to send 1200 bytes of data at a time
'-t', '1', #run for one seconds
))
self.assertTrue(result['success'])
self.assertEqual(result['config']['common']['family'], 'udp')
self.assertEqual(result['config']['common']['streams'], 1)
self.assertEqual(result['config']['additional']['reverse'], True)
self.assertEqual(result['config']['additional']['ip_version'], 6)
self.assertEqual(result['summary']['bytes_received'], result['summary']['bytes_sent'])
self.assertEqual(result['summary']['packets_received'], result['summary']['packets_sent'])
self.assertEqual(result['summary']['framed_packet_size'], 1228)
self.assertEqual(result['summary']['packets_duplicate'], 0)
self.assertEqual(result['summary']['packets_lost'], 0)
self.assertEqual(result['summary']['packets_out_of_order'], 0)
self.assertAlmostEqual(result['summary']['bytes_received'], 500000, delta=25000)
self.assertAlmostEqual(result['summary']['duration_receive'], 1.0, delta=0.1)
class TestMisc(unittest.TestCase):
def setUp(self):
if _DISPLAY_LOGS:
self.server = subprocess.Popen((_RPERF_BINARY, '-s', '-6', '-A', '0,1'))
else:
self.server = subprocess.Popen((_RPERF_BINARY, '-s', '-6', '-A', '0,1'), stderr=subprocess.DEVNULL)
def tearDown(self):
self.server.terminate()
self.server.wait()
def test_hostname(self):
result = _run_rperf_client_hostname((
'-N', #disable Nagle's algorithm
'-b', '500000', #keep it light, at 500kBps per stream
'-l', '4096', #try to send 4k of data at a time
'-O', '1', #omit the first second of data from summaries
'-t', '2', #run for two seconds
))
self.assertTrue(result['success'])
self.assertEqual(result['config']['common']['family'], 'tcp')
self.assertEqual(result['config']['common']['streams'], 1)
self.assertEqual(result['config']['additional']['reverse'], False)
self.assertEqual(result['summary']['bytes_received'], result['summary']['bytes_sent'])
self.assertAlmostEqual(result['summary']['bytes_received'], 500000, delta=25000)
self.assertAlmostEqual(result['summary']['duration_receive'], 1.0, delta=0.1)
def test_hostname_reverse(self):
result = _run_rperf_client_hostname((
'-N', #disable Nagle's algorithm
'-R', #run in reverse mode
'-b', '500000', #keep it light, at 500kBps per stream
'-l', '4096', #try to send 4k of data at a time
'-O', '1', #omit the first second of data from summaries
'-t', '2', #run for two seconds
))
self.assertTrue(result['success'])
self.assertEqual(result['config']['common']['family'], 'tcp')
self.assertEqual(result['config']['common']['streams'], 1)
self.assertEqual(result['config']['additional']['reverse'], True)
self.assertEqual(result['summary']['bytes_received'], result['summary']['bytes_sent'])
self.assertAlmostEqual(result['summary']['bytes_received'], 500000, delta=25000)
self.assertAlmostEqual(result['summary']['duration_receive'], 1.0, delta=0.1)
def test_ipv4_mapped_with_core_affinity(self):
result = _run_rperf_client_ipv4((
'-A', '2,3', #set CPU core-affinity to 2 and 3
'-b', '500000', #keep it light, at 500kBps per stream
'-l', '4096', #try to send 4k of data at a time
'-O', '1', #omit the first second of data from summaries
'-P', '2', #two parallel streams
'-t', '2', #run for two seconds
))
self.assertTrue(result['success'])
self.assertEqual(result['config']['common']['family'], 'tcp')
self.assertEqual(result['config']['common']['streams'], 2)
self.assertEqual(result['config']['additional']['reverse'], False)
self.assertEqual(result['config']['additional']['ip_version'], 4)
self.assertEqual(result['summary']['bytes_received'], result['summary']['bytes_sent'])
self.assertAlmostEqual(result['summary']['bytes_received'], 1000000, delta=50000)
self.assertAlmostEqual(result['summary']['duration_receive'], 2.0, delta=0.1)
def test_multiple_simultaneous_clients(self):
with concurrent.futures.ThreadPoolExecutor() as executor:
tcp_1_ipv4 = executor.submit(_run_rperf_client_ipv4, (
'-b', '100000', #keep it light, at 100kBps per stream
'-l', '4096', #try to send 4k of data at a time
'-t', '2', #run for two seconds
))
tcp_2_ipv6_reverse = executor.submit(_run_rperf_client_ipv6, (
'-R', #run in reverse mode
'-b', '100000', #keep it light, at 100kBps per stream
'-l', '4096', #try to send 4k of data at a time
'-t', '2', #run for two seconds
))
udp_1_ipv6 = executor.submit(_run_rperf_client_ipv6, (
'-u', #run UDP test
'-b', '100000', #keep it light, at 100kBps per stream
'-l', '1200', #try to send 1200 bytes of data at a time
'-t', '2', #run for two seconds
))
udp_2_hostname_reverse = executor.submit(_run_rperf_client_hostname, (
'-u', #run UDP test
'-R', #run in reverse mode
'-b', '100000', #keep it light, at 100kBps per stream
'-l', '1200', #try to send 1200 bytes of data at a time
'-t', '2', #run for two seconds
))
self.assertTrue(tcp_1_ipv4.result()['success'])
self.assertTrue(tcp_2_ipv6_reverse.result()['success'])
self.assertTrue(udp_1_ipv6.result()['success'])
self.assertTrue(udp_2_hostname_reverse.result()['success'])
if __name__ == '__main__':
unittest.main()