diff --git a/qemu/tests/cfg/enable_scatter_windows.cfg b/qemu/tests/cfg/enable_scatter_windows.cfg index d14236bde8..97528d41ad 100644 --- a/qemu/tests/cfg/enable_scatter_windows.cfg +++ b/qemu/tests/cfg/enable_scatter_windows.cfg @@ -10,13 +10,17 @@ driver_verifier = netkvm Win2016, Win2019, Win8..1, Win2012..r2: driver_verifier += " ndis" - installed_path = "C:\Program Files\Wireshark\tshark.exe" - check_installed_cmd = 'dir "${installed_path}"|findstr /I tshark.exe' + windump_name = "WinDump.exe" + windump_installed_path = "C:\\${windump_name}" + check_windump_installed_cmd = 'dir "${windump_installed_path}"' + windump_install_cmd = "xcopy WIN_UTILS:\\${windump_name} c:\ /y" x86_64: wireshark_name = "Wireshark-win64-1.10.1.exe" i386, i686: wireshark_name = "Wireshark-win32-1.10.1.exe" - install_wireshark_cmd = "xcopy WIN_UTILS:\${wireshark_name} c:\ /y && c:\${wireshark_name} /S" + wireshark_installed_path = "C:\Program Files\Wireshark\tshark.exe" + check_wireshark_installed_cmd = 'dir "${wireshark_installed_path}" | findstr /I tshark.exe' + wireshark_installation_cmd = "xcopy WIN_UTILS:\${wireshark_name} c:\ /y && c:\${wireshark_name} /S" autoit_name = "AutoIt3_%PROCESSOR_ARCHITECTURE%.exe" install_winpcap_cmd = "WIN_UTILS:\${autoit_name} WIN_UTILS:\install_winpcap.au3" @@ -27,6 +31,6 @@ query_version_cmd += "where (DeviceName like 'Red Hat VirtIO Ethernet Adapter') " query_version_cmd += "get DriverVersion /format:list" - run_wireshark_temp = 'start "" "${installed_path}" -n -w c:\temp.pcapng tcp and dst %s and src %s' - stop_wireshark_cmd = "taskkill /im tshark.exe /f" - parse_log_temp = '"${installed_path}" -2 -r c:\temp.pcapng -R "%s"' + run_windump_temp = 'start "" "${windump_installed_path}" -n -w c:\temp.pcap tcp and dst %s and src %s' + stop_windump_cmd = "taskkill /im ${windump_name} /f" + parse_log_temp = '"C:\Program Files\Wireshark\tshark.exe" -2 -r c:\temp.pcap -R "%s"' diff --git a/qemu/tests/enable_scatter_windows.py b/qemu/tests/enable_scatter_windows.py index 2027a717cf..f2f470b56f 100644 --- a/qemu/tests/enable_scatter_windows.py +++ b/qemu/tests/enable_scatter_windows.py @@ -26,6 +26,7 @@ def run(test, params, env): param params: the test params param env: test environment """ + def _is_process_finished(session, process_name): """ Check whether the target process is finished running @@ -41,38 +42,41 @@ def _is_process_finished(session, process_name): return False return process_name not in output - def _start_wireshark_session(): + def _start_windump_session(): """ - Start a wireshark session and log network traffic to a file + Start a WinDump session and log network traffic to a file """ - error_context.context("Start wireshark session", test.log.info) + error_context.context("Start WinDump session", test.log.info) session_serial = vm.wait_for_serial_login(timeout=timeout) guest_ip = vm.get_address() try: - run_wireshark_cmd = run_wireshark_temp % (host_ip, guest_ip) - status, output = session_serial.cmd_status_output(run_wireshark_cmd, - timeout=timeout) - + run_windump_cmd = run_windump_temp % (host_ip, guest_ip) + status, output = session_serial.cmd_status_output( + run_windump_cmd, timeout=timeout + ) if status: - test.error("Failed to start wireshark session, " - "status=%s, output=%s" % (status, output)) + test.error( + "Failed to start WinDump session, status=%s, output=%s" + % (status, output) + ) is_started = utils_misc.wait_for( - lambda: not _is_process_finished(session_serial, "tshark.exe"), 20, 5, 1) + lambda: not _is_process_finished(session_serial, windump_name), 20, 5, 1 + ) if not is_started: - test.error("Timeout when wait for wireshark start") + test.error("Timeout when waiting for WinDump to start") finally: session_serial.close() - def _stop_wireshark_session(): + def _stop_windump_session(): """ - Stop the running wireshark session + Stop the running WinDump session """ - error_context.context("Stop wireshark", test.log.info) - status, output = session.cmd_status_output(stop_wireshark_cmd, - timeout=timeout) + error_context.context("Stop WinDump", test.log.info) + status, output = session.cmd_status_output(stop_windump_cmd, timeout=timeout) if status: - test.error("Failed to stop wireshark: status=%s, output=%s" - % (status, output)) + test.error( + "Failed to stop WinDump: status=%s, output=%s" % (status, output) + ) def _parse_log_file(packet_filter): """ @@ -81,28 +85,29 @@ def _parse_log_file(packet_filter): param packet_filter: the filter to apply when dump packets return: the output of the parse result """ - error_context.context("Parse wireshark log file", test.log.info) + error_context.context("Parse captured packets using Wireshark", test.log.info) parse_log_cmd = parse_log_temp % packet_filter - status, output = session.cmd_status_output( - parse_log_cmd, timeout=timeout) - if status: - test.error("Failed to parse session log file," - " status=%s, output=%s" % (status, output)) + status, output = session.cmd_status_output(parse_log_cmd, timeout=timeout) + if status != 0: + test.error( + "Failed to parse session log file, status=%s, output=%s" + % (status, output) + ) return output def _get_traffic_log(packet_filter): """ - Use wireshark to log the file transfer network traffic, - and return the packets dump output. + Use WinDump to capture the file transfer network traffic, + and return the packet analysis output. - param packet_filter: the filter to apply when dump packets - return: the output of the parse result + :param packet_filter: The filter to apply when analyzing packets + :return: The output of the parse result """ - _start_wireshark_session() + _start_windump_session() error_context.context("Start file transfer", test.log.info) utils_test.run_file_transfer(test, params, env) time.sleep(30) - _stop_wireshark_session() + _stop_windump_session() return _parse_log_file(packet_filter) def _set_driver_param(index): @@ -122,15 +127,19 @@ def _get_driver_version(session): """ query_version_cmd = params["query_version_cmd"] output = session.cmd_output(query_version_cmd) - version_str = output.strip().split('=')[1] - version = version_str.split('.')[-1][0:3] + version_str = output.strip().split("=")[1] + version = version_str.split(".")[-1][0:3] return int(version) - timeout = params.get("timeout", 360) + timeout = int(params.get("timeout", 360)) driver_verifier = params["driver_verifier"] + windump_name = params.get("windump_name") + check_windump_installed_cmd = params.get("check_windump_installed_cmd") + windump_install_cmd = params.get("windump_install_cmd") wireshark_name = params.get("wireshark_name") - run_wireshark_temp = params.get("run_wireshark_temp") - stop_wireshark_cmd = params.get("stop_wireshark_cmd") + autoit_name = params.get("autoit_name") + run_windump_temp = params.get("run_windump_temp") + stop_windump_cmd = params.get("stop_windump_cmd") check_proc_temp = params.get("check_proc_temp") parse_log_temp = params.get("parse_log_temp") param_names = params.get("param_names").split() @@ -142,14 +151,14 @@ def _get_driver_version(session): session = vm.wait_for_login(timeout=timeout) # make sure to enter desktop - vm.send_key('meta_l-d') + vm.send_key("meta_l-d") time.sleep(30) - error_context.context("Check if the driver is installed and " - "verified", test.log.info) - session = utils_test.qemu.windrv_check_running_verifier(session, vm, - test, - driver_verifier, - timeout) + error_context.context( + "Check if the driver is installed and " "verified", test.log.info + ) + session = utils_test.qemu.windrv_check_running_verifier( + session, vm, test, driver_verifier, timeout + ) if _get_driver_version(session) > 189: param_names.append("*JumboPacket") @@ -158,35 +167,52 @@ def _get_driver_version(session): error_context.context("Install winpcap", test.log.info) install_winpcap_cmd = params.get("install_winpcap_cmd") - install_winpcap_cmd = utils_misc.set_winutils_letter( - session, install_winpcap_cmd) - status, output = session.cmd_status_output(install_winpcap_cmd, - timeout=timeout) + install_winpcap_cmd = utils_misc.set_winutils_letter(session, install_winpcap_cmd) + status, output = session.cmd_status_output(install_winpcap_cmd, timeout=timeout) if status: - test.error("Failed to install pcap, status=%s, output=%s" - % (status, output)) + test.error("Failed to install pcap, status=%s, output=%s" % (status, output)) test.log.info("Wait for pcap installation to complete") autoit_name = params.get("autoit_name") utils_misc.wait_for( - lambda: _is_process_finished(session, autoit_name), timeout, 20, 3) + lambda: _is_process_finished(session, autoit_name), timeout, 20, 3 + ) + + error_context.context("Check if WinDump is installed", test.log.info) + check_result = session.cmd_output(check_windump_installed_cmd) + if windump_name not in check_result: + error_context.context("Install WinDump", test.log.info) + windump_install_cmd = utils_misc.set_winutils_letter( + session, windump_install_cmd + ) + status, output = session.cmd_status_output(windump_install_cmd, timeout=timeout) + if status != 0: + test.error( + "Failed to install WinDump, status=%s, output=%s" % (status, output) + ) + else: + test.log.info("WinDump is already installed") error_context.context("Check if wireshark is installed", test.log.info) - check_installed_cmd = params.get("check_installed_cmd") - check_result = session.cmd_output(check_installed_cmd) + check_wireshark_installed_cmd = params.get("check_wireshark_installed_cmd") + check_result = session.cmd_output(check_wireshark_installed_cmd) if "tshark" not in check_result: error_context.context("Install wireshark", test.log.info) - install_wireshark_cmd = params.get("install_wireshark_cmd") - install_wireshark_cmd = utils_misc.set_winutils_letter( - session, install_wireshark_cmd) - status, output = session.cmd_status_output(install_wireshark_cmd, - timeout=timeout) + wireshark_installation_cmd = params.get("wireshark_installation_cmd") + wireshark_installation_cmd = utils_misc.set_winutils_letter( + session, wireshark_installation_cmd + ) + status, output = session.cmd_status_output( + wireshark_installation_cmd, timeout=timeout + ) if status: - test.error("Failed to install wireshark, status=%s, output=%s" - % (status, output)) + test.error( + "Failed to install wireshark, status=%s, output=%s" % (status, output) + ) test.log.info("Wait for wireshark installation to complete") utils_misc.wait_for( - lambda: _is_process_finished(session, wireshark_name), timeout, 20, 3) + lambda: _is_process_finished(session, wireshark_name), timeout, 20, 3 + ) else: test.log.info("Wireshark is already installed") session.close() @@ -197,7 +223,8 @@ def _get_driver_version(session): session = vm.wait_for_login(timeout=timeout) error_context.context( - "Log network traffic with scatter gather enabled", test.log.info) + "Log network traffic with scatter gather enabled", test.log.info + ) output = _get_traffic_log("frame.len>1514") test.log.info("Check length > 1514 packets") if "Len" not in output: @@ -210,7 +237,8 @@ def _get_driver_version(session): session = vm.wait_for_login(timeout=timeout) error_context.context( - "Log network traffic with scatter gather disabled", test.log.info) + "Log network traffic with scatter gather disabled", test.log.info + ) test.log.info("Check length > 1014 packets") output = _get_traffic_log("frame.len>1014") if "Len" in output: