def run(test, params, env): """ The rx/tx offload checksum test for windows 1) start vm 2) set the tx/rx offload checksum of the netkvm driver to tcp 3) restart nic, and run file transfer test 4) set the tx/rx offload checksum of the nekvm driver to disable 5) restart nic, and run file transfer test again param test: the test object param params: the test params param env: test environment """ def set_offload_checksum_windows(vm, is_tx, checksum_config): """ Set the tx or rx offload checksum to certain config, for the first nic on windows. param vm: the target vm param is_tx: True for tx setting, False for rx setting param checksum_config: the config for checksum settings, one of 'tcp' or 'disable' """ param = "Offload.TxChecksum" if is_tx else "Offload.RXCS" value = "1" if checksum_config == "tcp" else "0" utils_net.set_netkvm_param_value(vm, param, value) def start_test(checksum_config="tcp"): """ Start tx/tx offload checksum test. First set tx/rx offload checksum value to the driver, the restart the nic and run file transfertest, param config: the setting config for checksum, tcp or disable """ error_context.context( "Start set tx/rx checksum offload to %s" % checksum_config, logging.info) set_offload_checksum_windows(vm, True, checksum_config) set_offload_checksum_windows(vm, False, checksum_config) error_context.context("Start file transfer test", logging.info) utils_test.run_file_transfer(test, params, env) timeout = params.get("timeout", 360) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) error_context.context("Check if the driver is installed and " "verified", logging.info) driver_name = params.get("driver_name", "netkvm") session = utils_test.qemu.windrv_check_running_verifier( session, vm, test, driver_name, timeout) session.close() virtio_win.prepare_netkvmco(vm) start_test("tcp") start_test("disable")
def run(test, params, env): """ Change certain netkvm driver parameter value and check the setting result. 1) start vm 2) check and install wireshark and winpcap 3) enable netkvm driver TxLSO 4) start file transfer and use wireshark to log traffic, some packets length should over 1514 5) disable TxLSO and set MTU to 1000 6) start file transfer and log file transfer traffic again, no packet length should over 1014 param test: the test object param params: the test params param env: test environment """ def _is_process_finished(session, process_name): """ Check whether the target process is finished running param session: a guest session to send command param process_name: the target process name return: True if process does not exists, False if still exists """ check_proc_cmd = check_proc_temp % process_name status, output = session.cmd_status_output(check_proc_cmd) if status: return False return process_name not in output def _start_wireshark_session(): """ Start a wireshark session and log network traffic to a file """ error_context.context("Start wireshark session", logging.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) if status: test.error("Failed to start wireshark 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) if not is_started: test.error("Timeout when wait for wireshark start") finally: session_serial.close() def _stop_wireshark_session(): """ Stop the running wireshark session """ error_context.context("Stop wireshark", logging.info) status, output = session.cmd_status_output(stop_wireshark_cmd, timeout=timeout) if status: test.error("Failed to stop wireshark: status=%s, output=%s" % (status, output)) def _parse_log_file(packet_filter): """ Parse the log file generated by the previous wireshark session. param packet_filter: the filter to apply when dump packets return: the output of the parse result """ error_context.context("Parse wireshark log file", logging.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)) return output def _get_traffic_log(packet_filter): """ Use wireshark to log the file transfer network traffic, and return the packets dump output. param packet_filter: the filter to apply when dump packets return: the output of the parse result """ _start_wireshark_session() error_context.context("Start file transfer", logging.info) utils_test.run_file_transfer(test, params, env) time.sleep(30) _stop_wireshark_session() return _parse_log_file(packet_filter) def _set_driver_param(index): """ set the netkvm driver param's value. param index: the index of the list of target params """ param_name = param_names[index] param_value = param_values[index] utils_net.set_netkvm_param_value(vm, param_name, param_value) def _get_driver_version(session): """ Get current installed virtio driver version return: a int value of version, e.g. 191 """ 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] return int(version) timeout = params.get("timeout", 360) driver_verifier = params["driver_verifier"] wireshark_name = params.get("wireshark_name") run_wireshark_temp = params.get("run_wireshark_temp") stop_wireshark_cmd = params.get("stop_wireshark_cmd") check_proc_temp = params.get("check_proc_temp") parse_log_temp = params.get("parse_log_temp") param_names = params.get("param_names").split() param_values = params.get("param_values").split() vm = env.get_vm(params["main_vm"]) vm.verify_alive() host_ip = utils_net.get_host_ip_address(params) session = vm.wait_for_login(timeout=timeout) # make sure to enter desktop vm.send_key('meta_l-d') time.sleep(30) error_context.context("Check if the driver is installed and " "verified", logging.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") else: param_names.append("MTU") error_context.context("Install winpcap", logging.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) if status: test.error("Failed to install pcap, status=%s, output=%s" % (status, output)) logging.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) error_context.context("Check if wireshark is installed", logging.info) check_installed_cmd = params.get("check_installed_cmd") check_result = session.cmd_output(check_installed_cmd) if "tshark" not in check_result: error_context.context("Install wireshark", logging.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) if status: test.error("Failed to install wireshark, status=%s, output=%s" % (status, output)) logging.info("Wait for wireshark installation to complete") utils_misc.wait_for( lambda: _is_process_finished(session, wireshark_name), timeout, 20, 3) else: logging.info("Wireshark is already installed") session.close() virtio_win.prepare_netkvmco(vm) error_context.context("Enable scatter gather", logging.info) _set_driver_param(0) session = vm.wait_for_login(timeout=timeout) error_context.context("Log network traffic with scatter gather enabled", logging.info) output = _get_traffic_log("frame.len>1514") logging.info("Check length > 1514 packets") if "Len" not in output: test.fail("No packet length >= 1514, output=%s" % output) session.close() error_context.context("Disable scatter gather", logging.info) _set_driver_param(1) _set_driver_param(2) session = vm.wait_for_login(timeout=timeout) error_context.context("Log network traffic with scatter gather disabled", logging.info) logging.info("Check length > 1014 packets") output = _get_traffic_log("frame.len>1014") if "Len" in output: test.fail("Some packet length > 1014, output=%s" % output)
def run(test, params, env): """ The rx/tx offload checksum test for windows 1) start vm 2) set the netkvm driver parameter value 3) get the value and compare to target value 4) start ping test to check nic availability param test: the test object param params: the test params param env: test environment """ def start_test(param_name, param_value): """ Start test. First set netkvm driver parameter 'param_name' to value 'param_value'. Then read the current and compare to 'param_value' to check identity. Finally conduct a ping test to check the nic is avaliable. param param_name: the netkvm driver parameter to modify param param_value: the value to set to """ error_context.context("Start set %s to %s" % (param_name, param_value), logging.info) utils_net.set_netkvm_param_value(vm, param_name, param_value) logging.info("Check value after setting %s", param_name) cur_value = utils_net.get_netkvm_param_value(vm, param_name) if cur_value != param_value: err_msg = "Current value: %s is not equal to target value: %s" err_msg = err_msg % (cur_value, param_value) test.fail(err_msg) error_context.context("Start ping test", logging.info) guest_ip = vm.get_address() status, output = utils_test.ping(guest_ip, 10, timeout=15) if status: test.fail("Ping returns non-zero value %s" % output) package_lost = utils_test.get_loss_ratio(output) if package_lost != 0: test.fail("Ping test got %s package lost" % package_lost) def _get_driver_version(session): """ Get current installed virtio driver version return: a int value of version, e.g. 191 """ 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] return int(version) timeout = params.get("timeout", 360) param_names = params.get("param_names").split() param_values_default = params.get("param_values") vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) error_context.context("Check if the driver is installed and " "verified", logging.info) driver_name = params.get("driver_name", "netkvm") session = utils_test.qemu.windrv_check_running_verifier( session, vm, test, driver_name, timeout) driver_version = _get_driver_version(session) session.close() virtio_win.prepare_netkvmco(vm) if driver_version <= 189 and "*JumboPacket" in param_names: param_names.remove("*JumboPacket") elif driver_version > 189 and "MTU" in param_names: param_names.remove("MTU") for name in param_names: attr_name = "param_values_%s" % name param_values = params.get(attr_name, param_values_default) for value in param_values.split(): start_test(name, value)