|
| 1 | +import re |
| 2 | + |
| 3 | +from virttest import error_context, utils_misc, utils_net, utils_test |
| 4 | +from virttest.utils_windows import virtio_win |
| 5 | + |
| 6 | + |
| 7 | +@error_context.context_aware |
| 8 | +def run(test, params, env): |
| 9 | + """ |
| 10 | + Test netkvm RX capacity with different RX queue sizes. |
| 11 | +
|
| 12 | + This test verifies that the RX queue size setting in QEMU matches |
| 13 | + the reported RxQueueSize in Windows guest when MaxRxBuffers is set. |
| 14 | +
|
| 15 | + Test steps: |
| 16 | + 1) Boot VM with specific rx_queue_size parameter |
| 17 | + 2) Set Init.MaxRxBuffers parameter using netkvmco.exe |
| 18 | + 3) Verify the parameter was set correctly |
| 19 | + 4) Check RxQueueSize using netkvm-wmi.cmd |
| 20 | + 5) Verify RxQueueSize matches expected value |
| 21 | +
|
| 22 | + :param test: QEMU test object |
| 23 | + :param params: Dictionary with the test parameters |
| 24 | + :param env: Dictionary with test environment |
| 25 | + """ |
| 26 | + |
| 27 | + def set_and_verify_rxcapacity(session, vm, test, value): |
| 28 | + """ |
| 29 | + Set RxCapacity parameter and verify it was set correctly. |
| 30 | +
|
| 31 | + :param session: VM session info |
| 32 | + :param vm: QEMU test object |
| 33 | + :param test: QEMU test object |
| 34 | + :param value: Value to set for RxCapacity |
| 35 | + """ |
| 36 | + error_context.context(f"Setting RxCapacity to {value}", test.log.info) |
| 37 | + utils_net.set_netkvm_param_value(vm, "RxCapacity", value) |
| 38 | + |
| 39 | + current_value = utils_net.get_netkvm_param_value(vm, "RxCapacity") |
| 40 | + if current_value != value: |
| 41 | + test.fail( |
| 42 | + f"Failed to set RxCapacity. Expected: {value}, Got: {current_value}" |
| 43 | + ) |
| 44 | + test.log.info("Successfully set RxCapacity to %s", value) |
| 45 | + |
| 46 | + def get_rxqueue_size_from_wmi(session, test, params): |
| 47 | + """ |
| 48 | + Get RxQueueSize from netkvm-wmi.cmd output. |
| 49 | +
|
| 50 | + :return: RxQueueSize value as integer |
| 51 | + """ |
| 52 | + netkvm_wmi_path = params.get("netkvm_wmi_path", "C:\\netkvm-wmi.cmd") |
| 53 | + wmi_cmd_copy_cmd = params.get("wmi_cmd_copy_cmd") |
| 54 | + wmi_cmd_copy_cmd = utils_misc.set_winutils_letter(session, wmi_cmd_copy_cmd) |
| 55 | + session.cmd(wmi_cmd_copy_cmd, timeout=30) |
| 56 | + |
| 57 | + error_context.context("Getting RxQueueSize from WMI", test.log.info) |
| 58 | + wmi_output = session.cmd_output(f"{netkvm_wmi_path} cfg", timeout=30) |
| 59 | + test.log.info("WMI output:\n%s", wmi_output) |
| 60 | + |
| 61 | + rx_queue_pattern = r"RxQueueSize=(\d+)" |
| 62 | + match = re.search(rx_queue_pattern, wmi_output) |
| 63 | + if not match: |
| 64 | + test.fail("Could not find RxQueueSize in WMI output") |
| 65 | + |
| 66 | + rx_queue_size = int(match.group(1)) |
| 67 | + test.log.info("Found RxQueueSize: %s", rx_queue_size) |
| 68 | + return rx_queue_size |
| 69 | + |
| 70 | + timeout = params.get_numeric("login_timeout", 360) |
| 71 | + expected_rx_queue_size = params.get_numeric("expected_rx_queue_size") |
| 72 | + rx_capacity_value = params.get("rx_capacity_value", "1024") |
| 73 | + |
| 74 | + vm_name = params["main_vm"] |
| 75 | + vm = env.get_vm(vm_name) |
| 76 | + vm.verify_alive() |
| 77 | + session = vm.wait_for_serial_login(timeout=timeout) |
| 78 | + |
| 79 | + virtio_win.prepare_netkvmco(vm) |
| 80 | + try: |
| 81 | + set_and_verify_rxcapacity(session, vm, test, rx_capacity_value) |
| 82 | + actual_rx_queue_size = get_rxqueue_size_from_wmi(session, test, params) |
| 83 | + error_context.context( |
| 84 | + f"Verifying RxQueueSize. Expected: {expected_rx_queue_size}, " |
| 85 | + f"Actual: {actual_rx_queue_size}", |
| 86 | + test.log.info, |
| 87 | + ) |
| 88 | + |
| 89 | + if actual_rx_queue_size != expected_rx_queue_size: |
| 90 | + test.fail( |
| 91 | + f"RxQueueSize mismatch. Expected: {expected_rx_queue_size}, " |
| 92 | + f"Got: {actual_rx_queue_size}" |
| 93 | + ) |
| 94 | + |
| 95 | + test.log.info( |
| 96 | + "SUCCESS: RxQueueSize %s matches expected value %s", |
| 97 | + actual_rx_queue_size, |
| 98 | + expected_rx_queue_size, |
| 99 | + ) |
| 100 | + |
| 101 | + error_context.context("Testing network connectivity", test.log.info) |
| 102 | + status, output = utils_net.ping( |
| 103 | + "223.5.5.5", count=10, timeout=60, session=session |
| 104 | + ) |
| 105 | + if status: |
| 106 | + test.fail(f"Ping test failed: {output}") |
| 107 | + |
| 108 | + package_lost = utils_test.get_loss_ratio(output) |
| 109 | + if package_lost != 0: |
| 110 | + test.fail(f"Ping test shows {package_lost}% packet loss") |
| 111 | + |
| 112 | + test.log.info("Network connectivity test passed") |
| 113 | + |
| 114 | + finally: |
| 115 | + session.close() |
0 commit comments