Skip to content

Commit b2fea54

Browse files
committed
Add a case for packet loss when slowly reusing memory buffers
Under various conditions, when the host-to-device packet rate is high, we lose packets in QEMU due to a lack of guest-allocated buffers. Look also at virtio-win/kvm-guest-drivers-windows#1012 Signed-off-by: wji <[email protected]>
1 parent 3f60e13 commit b2fea54

File tree

2 files changed

+192
-0
lines changed

2 files changed

+192
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
- netkvm_buffer_shortage:
2+
virt_test_type = qemu
3+
type = netkvm_buffer_shortage
4+
only Windows
5+
only virtio_net
6+
vhost = on
7+
timeout = 360
8+
cdroms += " virtio"
9+
vms += " vm2"
10+
image_snapshot = yes
11+
start_vm = yes
12+
start_vm_vm2 = no
13+
smp = 2
14+
queues = ${smp}
15+
vectors = 1024
16+
copy_dest = "C:\"
17+
dest_location = "pushd ${copy_dest}"
18+
nic_extra_params_nic1 = ",rx_queue_size=1024,tx_queue_size=256"
19+
nic_extra_params_type = "{'rx_queue_size': 'int', 'tx_queue_size': 'int'}"
20+
i386:
21+
psutil_whl = "psutil-6.1.1-cp37-abi3-win32.whl"
22+
x86_64:
23+
psutil_whl = "psutil-6.1.1-cp37-abi3-win_amd64.whl"
24+
s_py = '.\server.py'
25+
c_py = '.\client.py'
26+
port_num = 12345
27+
check_live_python = "tasklist | findstr /i python"
28+
c_pip_copy_cmd = 'xcopy "WIN_UTILS:\packet_loss_scripts\${psutil_whl}" ${copy_dest}'
29+
c_pip_cmd = "py -m pip install ${psutil_whl}"
30+
s_py_copy_cmd = 'xcopy "WIN_UTILS:\packet_loss_scripts\${s_py}" ${copy_dest}'
31+
s_py_cmd = "start cmd /c py ${s_py} ${port_num}"
32+
c_py_copy_cmd = 'xcopy "WIN_UTILS:\packet_loss_scripts\${c_py}" ${copy_dest}'
33+
c_py_cmd = "start cmd /c py ${c_py} 99999 %s ${port_num}"
34+
param_name = "MinRxBufferPercent"
35+
param_values = "0 25 50 75 100"

qemu/tests/netkvm_buffer_shortage.py

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import re
2+
3+
from virttest import env_process, error_context, utils_misc, utils_net
4+
5+
6+
@error_context.context_aware
7+
def run(test, params, env):
8+
"""
9+
Simulate high packet rate between host and device by running Python scripts
10+
on both server and client side. This test is executed on two VM guests:
11+
12+
1) Start a VM guest as the server.
13+
2) Start a VM guest as the client.
14+
3) Simulate buffer allocation issues on the server node.
15+
4) Use a Python script to connect the client to the server.
16+
5) Adjust the MinRxBufferPercent parameter to work around the issue.
17+
6) Ensure no BSOD occurs on the client node.
18+
19+
:param test: QEMU test object.
20+
:param params: Dictionary of test parameters.
21+
:param env: Dictionary of test environment details.
22+
"""
23+
24+
def analyze_ping_results(session, count, timeout):
25+
"""
26+
conduct a ping test to check the packet loss on slow memory buffer reallocation
27+
28+
:param session: Local executon hint or session to execute the ping command.
29+
:param count: Count of icmp packet.
30+
:param timeout: Timeout for the ping command.
31+
"""
32+
33+
status, output = utils_net.ping(
34+
s_vm_ip, session=c_session, count=count, timeout=timeout
35+
)
36+
if status != 0:
37+
test.fail("Ping failed, status: %s," " output: %s" % (status, output))
38+
pattern = r"(\d+)% loss"
39+
match = re.search(pattern, output)
40+
if match:
41+
return match.group(1)
42+
43+
def modify_and_analyze_params_result(vm, netkvmco_name, value):
44+
"""
45+
First set netkvm driver parameter 'param_name'
46+
to value 'param_value'. Then read the current and compare
47+
to 'param_value' to check identity Raised exception when
48+
checking netkvmco.exe setup was unsuccessful if something is wrong.
49+
50+
param vm: the selected vm
51+
param netkvmco_name: the netkvm driver parameter to modify
52+
param value: the value to set to
53+
"""
54+
55+
utils_net.set_netkvm_param_value(vm, netkvmco_name, value)
56+
cur_value = utils_net.get_netkvm_param_value(vm, netkvmco_name)
57+
if cur_value != value:
58+
test.fail(f"Current value '{cur_value}' was not equires '{value}'")
59+
60+
def check_and_restart_port(session, port, script_to_run):
61+
"""
62+
Check if a Python process is listening on the specified port.
63+
If not, restart the appropriate Python script (server or client).
64+
65+
param session: session to execute commands on the target machine.
66+
port: the port number to monitor.
67+
script_to_run: the path to the Python script to execute.
68+
"""
69+
70+
check_live_python = params.get("check_live_python")
71+
dest_location = params.get("dest_location")
72+
c_pip_copy_cmd = params.get("c_pip_copy_cmd")
73+
c_pip_cmd = params.get("c_pip_cmd")
74+
c_py_copy_cmd = params.get("c_py_copy_cmd")
75+
s_py_copy_cmd = params.get("s_py_copy_cmd")
76+
status, output = session.cmd_status_output(check_live_python, timeout=1200)
77+
if status == 0:
78+
return
79+
session.cmd(dest_location)
80+
if "server" in script_to_run:
81+
error_context.context(
82+
"Run python3 code runs on the server node", test.log.info
83+
)
84+
s_py_copy_cmd = utils_misc.set_winutils_letter(session, s_py_copy_cmd)
85+
session.cmd(s_py_copy_cmd)
86+
status, output = session.cmd_status_output(s_py_cmd, timeout=1200)
87+
if status != 0:
88+
test.fail("The server node failed to start.")
89+
else:
90+
error_context.context(
91+
"Run python3 code runs on the client node", test.log.info
92+
)
93+
c_pip_copy_cmd = utils_misc.set_winutils_letter(session, c_pip_copy_cmd)
94+
session.cmd(c_pip_copy_cmd)
95+
session.cmd(c_pip_cmd)
96+
c_py_copy_cmd = utils_misc.set_winutils_letter(session, c_py_copy_cmd)
97+
session.cmd(c_py_copy_cmd)
98+
status, output = session.cmd_status_output(c_py_cmd % s_vm_ip, timeout=1200)
99+
if status != 0:
100+
test.fail(
101+
"The client could not connect to the server node.", test.log.info
102+
)
103+
104+
timeout = params.get_numeric("login_timeout", 360)
105+
port_num = params.get("port_num")
106+
s_py_cmd = params.get("s_py_cmd")
107+
c_py_cmd = params.get("c_py_cmd")
108+
param_name = params.get("param_name")
109+
param_values = params.get("param_values")
110+
111+
s_vm_name = params["vms"].split()[0]
112+
s_vm = env.get_vm(s_vm_name)
113+
s_vm.verify_alive()
114+
s_session = s_vm.wait_for_serial_login(
115+
timeout=int(params.get("login_timeout", 360))
116+
)
117+
s_vm_ip = s_vm.get_address()
118+
119+
c_vm_name = params["vms"].split(s_vm_name)[1].strip()
120+
c_vm_params = params.object_params(c_vm_name)
121+
c_vm_params["nic_extra_params_nic1"] = ""
122+
c_vm_params["start_vm"] = "yes"
123+
env_process.preprocess_vm(test, c_vm_params, env, c_vm_name)
124+
c_vm = env.get_vm(c_vm_name)
125+
c_vm.verify_alive()
126+
c_session = c_vm.wait_for_serial_login(
127+
timeout=int(params.get("login_timeout", 360))
128+
)
129+
130+
ping_results = []
131+
error_context.context(
132+
"Open the NIC properties and change the values in the server node",
133+
test.log.info,
134+
)
135+
for value in param_values.split(" "):
136+
modify_and_analyze_params_result(vm=s_vm, netkvmco_name=param_name, value=value)
137+
check_and_restart_port(session=s_session, port=port_num, script_to_run=s_py_cmd)
138+
check_and_restart_port(session=c_session, port=port_num, script_to_run=c_py_cmd)
139+
ping_results.append(
140+
int(analyze_ping_results(session=c_session, count=100, timeout=timeout))
141+
)
142+
143+
error_context.context(
144+
"Get the packet loss percentage of the ping request", test.log.info
145+
)
146+
if sum(ping_results) != 0:
147+
if not all(
148+
ping_results[i] > ping_results[i + 1] for i in range(len(ping_results) - 1)
149+
):
150+
test.fail(
151+
"With the parameter, the number of lost packets should be "
152+
"less than without the parameter."
153+
)
154+
155+
error_context.context("no BSOD will occur on the client side", test.log.info)
156+
for value in param_values.split(" "):
157+
modify_and_analyze_params_result(vm=c_vm, netkvmco_name=param_name, value=value)

0 commit comments

Comments
 (0)