Skip to content

Commit 2e46808

Browse files
authored
Merge pull request autotest#4062 from yanglei-rh/2445
2 parents b6a1655 + 4df4c4f commit 2e46808

File tree

2 files changed

+162
-0
lines changed

2 files changed

+162
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
- passt_stability_tests:
2+
virt_test_type = qemu
3+
vhost_nic1 = ""
4+
nettype_nic1 = user:passt
5+
net_port_forwards = TCP@10001 UDP@10001
6+
type = passt_stability_tests
7+
fw_stop_cmd = systemctl stop firewalld || nft flush ruleset || iptables -F
8+
check_iperf_cmd = pgrep -f %s
9+
iperf_version = iperf-2.1.9
10+
host_iperf_file = iperf-2.1.9.tar.gz
11+
linux_compile_cmd = tar zxf %s -C %s > /dev/null ; cd %s ; ./configure > /dev/null; make > /dev/null
12+
catch_data = local 127.0.0.1 port 5001 connected with 127.0.0.1
13+
parallel_num = 8
14+
receive_cmd = socat -u TCP-LISTEN:10001,reuseaddr OPEN:/tmp/iperf-2.1.9.tar.gz,create
15+
sent_cmd = socat -u FILE:%s TCP:localhost:10001
16+
iperf_client_options= 'setsid %s -c %s -T s1 -P 8 -w 256k -t 200'
17+
iperf_server_options = 'numactl --cpunodebind=0 %s -s -P 8 -w 256k -t 300'
18+
variants:
19+
- with_tcp:
20+
- with_udp:
21+
iperf_client_options += ' -u'
22+
iperf_server_options += ' -u'

qemu/tests/passt_stability_tests.py

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import os
2+
import re
3+
import shutil
4+
import time
5+
6+
from aexpect import ShellCmdError
7+
from avocado.utils import process
8+
9+
from virttest import data_dir
10+
from virttest import utils_net
11+
from virttest import utils_misc
12+
from virttest import error_context
13+
14+
15+
@error_context.context_aware
16+
def run(test, params, env):
17+
"""
18+
passt stability tests
19+
20+
1) Boot up VM with passt backend
21+
2) Prepare the iperf environment
22+
3) Select host to start iperf server, guest as client
23+
4) Execute iperf tests, analyze the result
24+
5) Finish test and cleanup host environment
25+
26+
:param test: QEMU test object.
27+
:param params: Dictionary with the test parameters.
28+
:param env: Dictionary with test environment.
29+
"""
30+
def transfer_iperf_package():
31+
receive_cmd = params.get("receive_cmd")
32+
serial_session.sendline(receive_cmd)
33+
time.sleep(5)
34+
sent_cmd = params.get("sent_cmd")
35+
process.run(sent_cmd % host_iperf_src_path)
36+
37+
def iperf_compile(src_path, dst_path, serial_session=None):
38+
"""Compile iperf and return its binary file path."""
39+
iperf_version = params["iperf_version"]
40+
iperf_source_path = os.path.join(dst_path, iperf_version)
41+
compile_cmd = params["linux_compile_cmd"] % (src_path, dst_path,
42+
iperf_source_path)
43+
try:
44+
if serial_session:
45+
test.log.info("Compiling %s in guest...", iperf_version)
46+
serial_session.sendline(compile_cmd)
47+
else:
48+
test.log.info("Compiling %s in host...", iperf_version)
49+
process.run(compile_cmd, shell=True, verbose=False)
50+
except (process.CmdError, ShellCmdError) as err_msg:
51+
test.log.error(err_msg)
52+
test.error("Failed to compile iperf")
53+
else:
54+
iperf_bin_name = re.sub(r'[-2]', '', iperf_version.split('.')[0])
55+
return os.path.join(iperf_source_path, 'src', iperf_bin_name)
56+
57+
def iperf_server_start():
58+
"""Start iperf server"""
59+
info_text = "Start iperf server session in %s with cmd: %s"
60+
iperf_server_cmd = iperf_server_options % host_iperf_bin
61+
try:
62+
test.log.info(info_text, "host", iperf_server_cmd)
63+
server_output = process.system_output(iperf_server_cmd, timeout=300, verbose=False).decode()
64+
except Exception as err_msg:
65+
test.log.error(str(err_msg))
66+
test.error("Failed to start iperf session")
67+
else:
68+
test.log.debug("Full connection server log:\n%s", server_output)
69+
catch_data = params["catch_data"]
70+
parallel_cur = len(re.findall(catch_data, server_output))
71+
parallel_exp = int(params.get("parallel_num", 0))
72+
if not parallel_cur:
73+
test.fail("iperf client not connected to server")
74+
elif parallel_exp and parallel_cur != parallel_exp:
75+
test.fail("Number of parallel threads running(%d) is "
76+
"inconsistent with expectations(%d)"
77+
% (parallel_cur, parallel_exp))
78+
test.log.info("iperf client successfully connected to server")
79+
80+
def iperf_client_start():
81+
""""Start iperf client"""
82+
info_text = "Start iperf client session in %s with cmd: %s"
83+
iperf_client_cmd = iperf_client_options % (guest_iperf_bin, client_getway)
84+
test.log.info(info_text, "guest", iperf_client_cmd)
85+
serial_session.sendline(iperf_client_cmd)
86+
87+
def is_iperf_running(name_pattern, session=None):
88+
if session:
89+
check_iperf_cmd = params["check_iperf_cmd"] % name_pattern
90+
status = serial_session.cmd_status(check_iperf_cmd, safe=True)
91+
else:
92+
status = process.system("pgrep -f %s" % name_pattern,
93+
ignore_status=True, verbose=False)
94+
return status == 0
95+
96+
login_timeout = params.get_numeric("login_timeout", 360)
97+
fw_stop_cmd = params["fw_stop_cmd"]
98+
tmp_dir = params.get("tmp_dir", "/tmp")
99+
iperf_deps_dir = data_dir.get_deps_dir("iperf")
100+
host_iperf_file = params["host_iperf_file"]
101+
host_iperf_src_path = os.path.join(iperf_deps_dir, host_iperf_file)
102+
103+
vm = env.get_vm(params["main_vm"])
104+
vm.verify_alive()
105+
serial_session = vm.wait_for_serial_login(timeout=login_timeout)
106+
serial_session.cmd_output_safe(fw_stop_cmd)
107+
108+
client_getway = utils_net.get_default_gateway()
109+
transfer_iperf_package()
110+
host_iperf_bin = iperf_compile(host_iperf_src_path, tmp_dir)
111+
guest_iperf_file = params.get('guest_iperf_file', host_iperf_file)
112+
guest_iperf_path = params.get('guest_iperf_path', tmp_dir)
113+
guest_iperf_src_path = os.path.join(guest_iperf_path, guest_iperf_file)
114+
guest_iperf_bin = iperf_compile(guest_iperf_src_path, tmp_dir, serial_session)
115+
iperf_server_options = params.get('iperf_server_options')
116+
iperf_client_options = params.get('iperf_client_options')
117+
118+
try:
119+
bg_server = utils_misc.InterruptedThread(iperf_server_start)
120+
bg_client = utils_misc.InterruptedThread(iperf_client_start)
121+
bg_server.start()
122+
if not utils_misc.wait_for(lambda: is_iperf_running(host_iperf_bin), 5, 2):
123+
test.error("Failed to start iperf server.")
124+
error_context.context("iperf server has started.", test.log.info)
125+
bg_client.start()
126+
127+
error_context.context("iperf client has started.", test.log.info)
128+
if not utils_misc.wait_for(lambda: is_iperf_running(guest_iperf_bin, serial_session), 5, 2):
129+
test.error("Failed to start iperf client.")
130+
utils_misc.wait_for(lambda: not is_iperf_running(host_iperf_bin),
131+
330, 0, 30,
132+
"Waiting for iperf test to finish.")
133+
bg_server.join(timeout=60)
134+
bg_client.join(timeout=60)
135+
136+
finally:
137+
test.log.info("Cleanup host environment...")
138+
process.run('pkill -9 -f %s' % host_iperf_bin, verbose=False, ignore_status=True)
139+
shutil.rmtree(host_iperf_bin.rsplit('/', 2)[0], ignore_errors=True)
140+
serial_session.close()

0 commit comments

Comments
 (0)