forked from dgubanovv/qa-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
heavy_load.py
201 lines (145 loc) · 6.39 KB
/
heavy_load.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
import os
import shutil
from time import sleep
import pytest
from perf.iperf import Iperf
from tools.command import Priority
from tools.cpu_monitor import CPUMonitor
from tools.iptables import IPTables
from tools.killer import Killer
from tools.prof import prof
from tools.receive_segment_coalescing import ReceiveSegmentCoalescing
if __package__ is None:
import sys
from os import path
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
from hload.heavyload import HeavyLoad
from infra.test_base import TestBase
from tools.constants import DIRECTION_RXTX, LINK_SPEED_10G
from tools.driver import Driver
from tools.log import get_atf_logger
from tools.ops import OpSystem
log = get_atf_logger()
def setup_module(module):
# import tools._test_setup # uncomment for manual test setup
os.environ["TEST"] = "heavy_load"
class TestHeavyLoad(TestBase):
@classmethod
def setup_class(cls):
super(TestHeavyLoad, cls).setup_class()
try:
cls.log_server_dir = cls.create_logs_dir_on_log_server()
with prof('install_firmwares'):
cls.install_firmwares()
with prof('dut.driver.install'):
cls.dut_driver = Driver(port=cls.dut_port, version=cls.dut_drv_version)
cls.dut_driver.install()
with prof('lkp.driver.install'):
cls.lkp_driver = Driver(port=cls.lkp_port, version=cls.lkp_drv_version, host=cls.lkp_hostname)
cls.lkp_driver.install()
with prof('set variable for TestHeavyLoad'):
cls.dut_ifconfig.set_ip_address(cls.DUT_IPV4_ADDR, cls.NETMASK_IPV4, None)
cls.lkp_ifconfig.set_ip_address(cls.LKP_IPV4_ADDR, cls.NETMASK_IPV4, None)
cls.dut_ifconfig.set_ipv6_address(cls.DUT_IPV6_ADDR, cls.DEFAULT_PREFIX_IPV6, None)
cls.lkp_ifconfig.set_ipv6_address(cls.LKP_IPV6_ADDR, cls.DEFAULT_PREFIX_IPV6, None)
cls.dut_ops = OpSystem()
cls.lkp_ops = OpSystem(host=cls.lkp_hostname)
ReceiveSegmentCoalescing(dut_hostname=cls.dut_hostname, lkp_hostname=cls.lkp_hostname).enable()
iptables = IPTables(dut_hostname=cls.dut_hostname, lkp_hostname=cls.lkp_hostname)
iptables.clean()
except Exception as e:
log.exception("Failed while setting up class")
raise e
def iperf_with_heavyload(self, time, priority):
Killer().kill("stress")
shift = time / 10
cpu_monitor = CPUMonitor()
load = HeavyLoad(timeout=time - 2 * shift, priority=priority)
args = {
'priority': priority,
'direction': DIRECTION_RXTX,
'speed': LINK_SPEED_10G,
'num_threads': 1,
'num_process': 4,
'time': time,
'timeout': time * 3 / 2,
'ipv': 4,
'buffer_len': 0,
'is_udp': False,
'dut': self.dut_hostname,
'lkp': self.lkp_hostname,
'lkp4': self.LKP_IPV4_ADDR,
'dut4': self.DUT_IPV4_ADDR,
'lkp6': self.LKP_IPV6_ADDR,
'dut6': self.DUT_IPV6_ADDR
}
for i in range(5):
Killer().kill("iperf3")
Killer(host=self.lkp_hostname).kill("iperf3")
cpu_monitor.run_async()
iperf = Iperf(**args)
iperf.run_async()
sleep(shift)
load.run_async()
sleep(time - 2 * shift)
load.join()
sleep(shift)
result = iperf.join()
cpu_monitor.join(timeout=1)
if result != Iperf.IPERF_OK:
continue
results = iperf.get_performance()
# print statistics
for res in results:
log.info(res)
cpu_monitor.report()
# check results
for res in results:
res.check()
# write csv file
with open('result.csv', 'wt') as f:
mm = len(results[0].bandwidth)
mm = min(mm, len(results[1].bandwidth)) if len(results) > 1 else mm
for i in range(mm):
text = '{}'.format(i)
for k in range(len(results)):
text += ';{}'.format(results[k].bandwidth[i])
f.write(text + '\n')
shutil.move('result.csv', self.test_log_dir)
break
else:
raise Exception("Failed to run iperf 5 times")
def test_traffic_1min_on_heavy_load_cpu_realtime(self):
self.iperf_with_heavyload(1 * 60, Priority.REALTIME)
def test_traffic_1min_on_heavy_load_cpu_low(self):
self.iperf_with_heavyload(1 * 60, Priority.LOW)
def test_traffic_1min_on_heavy_load_cpu_normal(self):
self.iperf_with_heavyload(1 * 60, Priority.NORMAL)
def test_traffic_1min_on_heavy_load_cpu_high(self):
self.iperf_with_heavyload(1 * 60, Priority.HIGH)
def test_traffic_10min_on_heavy_load_cpu_realtime(self):
self.iperf_with_heavyload(10 * 60, Priority.REALTIME)
def test_traffic_10min_on_heavy_load_cpu_low(self):
self.iperf_with_heavyload(10 * 60, Priority.LOW)
def test_traffic_10min_on_heavy_load_cpu_normal(self):
self.iperf_with_heavyload(10 * 60, Priority.NORMAL)
def test_traffic_10min_on_heavy_load_cpu_high(self):
self.iperf_with_heavyload(10 * 60, Priority.HIGH)
def test_traffic_5h_on_heavy_load_cpu_realtime(self):
self.iperf_with_heavyload(5 * 60 * 60, Priority.REALTIME)
def test_traffic_5h_on_heavy_load_cpu_low(self):
self.iperf_with_heavyload(5 * 60 * 60, Priority.LOW)
def test_traffic_5h_on_heavy_load_cpu_normal(self):
self.iperf_with_heavyload(5 * 60 * 60, Priority.NORMAL)
def test_traffic_5h_on_heavy_load_cpu_high(self):
self.iperf_with_heavyload(5 * 60 * 60, Priority.HIGH)
def test_traffic_10h_on_heavy_load_cpu_realtime(self):
self.iperf_with_heavyload(10 * 60 * 60, Priority.REALTIME)
def test_traffic_10h_on_heavy_load_cpu_low(self):
self.iperf_with_heavyload(10 * 60 * 60, Priority.LOW)
def test_traffic_10h_on_heavy_load_cpu_normal(self):
self.iperf_with_heavyload(10 * 60 * 60, Priority.NORMAL)
def test_traffic_10h_on_heavy_load_cpu_high(self):
self.iperf_with_heavyload(10 * 60 * 60, Priority.HIGH)
if __name__ == "__main__":
pytest.main([__file__, "-s", "-v"])