From patchwork Wed Feb 9 10:43:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 543671 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p19AhMGL008303 for ; Wed, 9 Feb 2011 10:43:23 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753083Ab1BIKnT (ORCPT ); Wed, 9 Feb 2011 05:43:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36143 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752618Ab1BIKnS (ORCPT ); Wed, 9 Feb 2011 05:43:18 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p19AhGtM032689 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 9 Feb 2011 05:43:16 -0500 Received: from freedom.redhat.com (vpn-8-109.rdu.redhat.com [10.11.8.109]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p19AhDGZ027873; Wed, 9 Feb 2011 05:43:14 -0500 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, jzupka@redhat.com, ldoktor@redhat.com, Lucas Meneghel Rodrigues Subject: [PATCH] KVM test: Cleanup of virtio_console subtest Date: Wed, 9 Feb 2011 08:43:12 -0200 Message-Id: <1297248192-3348-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 09 Feb 2011 10:43:23 +0000 (UTC) diff --git a/client/tests/kvm/scripts/virtio_console_guest.py b/client/tests/kvm/scripts/virtio_console_guest.py index db67fc9..6626593 100755 --- a/client/tests/kvm/scripts/virtio_console_guest.py +++ b/client/tests/kvm/scripts/virtio_console_guest.py @@ -9,8 +9,8 @@ Auxiliary script used to send data between ports on guests. """ import threading from threading import Thread -import os, time, select, re, random, sys, array -import fcntl, subprocess, traceback, signal +import os, select, re, random, sys, array +import fcntl, traceback, signal DEBUGPATH = "/sys/kernel/debug" SYSFSPATH = "/sys/class/virtio-ports/" @@ -63,7 +63,7 @@ class VirtioGuest: """ ports = {} not_present_msg = "FAIL: There's no virtio-ports dir in debugfs" - if (not os.path.ismount(DEBUGPATH)): + if not os.path.ismount(DEBUGPATH): os.system('mount -t debugfs none %s' % (DEBUGPATH)) try: if not os.path.isdir('%s/virtio-ports' % (DEBUGPATH)): @@ -72,21 +72,20 @@ class VirtioGuest: print not_present_msg else: viop_names = os.listdir('%s/virtio-ports' % (DEBUGPATH)) - if (in_files != None): + if in_files is not None: dev_names = os.listdir('/dev') rep = re.compile(r"vport[0-9]p[0-9]+") - dev_names = filter(lambda x: rep.match(x) != None, dev_names) + dev_names = filter(lambda x: rep.match(x) is not None, dev_names) if len(dev_names) != len(in_files): - print ("FAIL: Not all ports are sucesfully inicailized"+ - " in /dev "+ - "only %d from %d." % (len(dev_names), - len(in_files))) + print ("FAIL: Not all ports were successfully initialized " + "in /dev, only %d from %d." % (len(dev_names), + len(in_files))) return if len(viop_names) != len(in_files): - print ("FAIL: No all ports are sucesfully inicailized " - "in debugfs only %d from %d." % (len(viop_names), - len(in_files))) + print ("FAIL: Not all ports were successfuly initialized " + "in debugfs, only %d from %d." % (len(viop_names), + len(in_files))) return for name in viop_names: @@ -101,35 +100,36 @@ class VirtioGuest: m = re.match("(\S+): (\S+)", line) port[m.group(1)] = m.group(2) - if (port['is_console'] == "yes"): + if port['is_console'] == "yes": port["path"] = "/dev/hvc%s" % (port["console_vtermno"]) # Console works like a serialport else: port["path"] = "/dev/%s" % name - if (not os.path.exists(port['path'])): + if not os.path.exists(port['path']): print "FAIL: %s not exist" % port['path'] sysfspath = SYSFSPATH + name - if (not os.path.isdir(sysfspath)): + if not os.path.isdir(sysfspath): print "FAIL: %s not exist" % (sysfspath) info_name = sysfspath + "/name" port_name = self._readfile(info_name).strip() - if (port_name != port["name"]): - print ("FAIL: Port info not match \n%s - %s\n%s - %s" % + if port_name != port["name"]: + print ("FAIL: Port info does not match " + "\n%s - %s\n%s - %s" % (info_name , port_name, "%s/virtio-ports/%s" % (DEBUGPATH, name), port["name"])) dev_ppath = DEVPATH + port_name - if not (os.path.exists(dev_ppath)): - print ("FAIL: Symlink " + dev_ppath + " not exist.") - if not (os.path.realpath(dev_ppath) != "/dev/name"): - print ("FAIL: Sumlink " + dev_ppath + " not correct.") + if not os.path.exists(dev_ppath): + print "FAIL: Symlink %s does not exist." % dev_ppath + if not os.path.realpath(dev_ppath) != "/dev/name": + print "FAIL: Symlink %s is not correct." % dev_ppath except AttributeError: - print ("In file " + open_db_file + - " are incorrect data\n" + "".join(file).strip()) - print ("FAIL: Fail file data.") + print ("Bad data on file %s:\n%s. " % + (open_db_file, "".join(file).strip())) + print "FAIL: Bad data on file %s." % open_db_file return ports[port['name']] = port @@ -142,10 +142,11 @@ class VirtioGuest: """ Check if port /dev/vport0p0 was created. """ - if os.path.exists("/dev/vport0p0"): - print "PASS: Port exist." + symlink = "/dev/vport0p0" + if os.path.exists(symlink): + print "PASS: Symlink %s exists." % symlink else: - print "FAIL: Device /dev/vport0p0 not exist." + print "FAIL: Symlink %s does not exist." % symlink def init(self, in_files): @@ -154,7 +155,7 @@ class VirtioGuest: """ self.ports = self._get_port_status(in_files) - if self.ports == None: + if self.ports is None: return for item in in_files: if (item[1] != self.ports[item[0]]["is_console"]): @@ -507,11 +508,11 @@ class VirtioGuest: """ descriptor = None path = self.ports[file]["path"] - if path != None: + if path is not None: if path in self.files.keys(): descriptor = self.files[path] del self.files[path] - if descriptor != None: + if descriptor is not None: try: os.close(descriptor) except Exception, inst: @@ -745,9 +746,9 @@ def main(): catch = virt.catching_signal() if catch: signal.signal(signal.SIGIO, virt) - elif catch == False: + elif catch is False: signal.signal(signal.SIGIO, signal.SIG_DFL) - if (catch != None): + if catch is not None: virt.use_config.set() print "PASS: guest_exit" diff --git a/client/tests/kvm/tests/virtio_console.py b/client/tests/kvm/tests/virtio_console.py index cbb19e4..bc40837 100644 --- a/client/tests/kvm/tests/virtio_console.py +++ b/client/tests/kvm/tests/virtio_console.py @@ -23,10 +23,10 @@ def run_virtio_console(test, params, env): 3) Start loopback test 4) Start performance test - This test uses an auxiliary script, console_switch.py, that is copied to - guests. This script has functions to send and write data to virtio console - ports. Details of each test can be found on the docstrings for the test_* - functions. + This test uses an auxiliary script, virtio_console_guest.py, that is copied + to guests. This script has functions to send and write data to virtio + console ports. Details of each test can be found on the docstrings for the + test_* functions. @param test: kvm test object @param params: Dictionary with the test parameters @@ -79,7 +79,7 @@ def run_virtio_console(test, params, env): @raise TestError: If collapse of test is fatal raise forward exception from subtest. """ - if args == None: + if args is None: args = [] res = [None, function.func_name, args] try: @@ -403,7 +403,7 @@ def run_virtio_console(test, params, env): if ret[0] and (not self.exitevent.isSet()): buf = self.port.recv(self.blocklen) if buf: - # Compare the recvd data with the control data + # Compare the received data with the control data for ch in buf: ch_ = self.buffer.popleft() if not ch == ch_: @@ -502,12 +502,12 @@ def run_virtio_console(test, params, env): """ data = vm_port.read_nonblocking() match = re.search("BUG:", data, re.MULTILINE) - if match == None: + if match is None: return None match = re.search(r"BUG:.*---\[ end trace .* \]---", data, re.DOTALL |re.MULTILINE) - if match == None: + if match is None: data += vm_port.read_until_last_line_matches( ["---\[ end trace .* \]---"],timeout) @@ -541,7 +541,7 @@ def run_virtio_console(test, params, env): data = "Timeout." kcrash_data = _search_kernel_crashlog(vm[3]) - if (kcrash_data != None): + if kcrash_data is not None: logging.error(kcrash_data) vm[4] = True @@ -581,7 +581,7 @@ def run_virtio_console(test, params, env): """ # in LOOP_NONE mode it might stuck in read/write match, tmp = _on_guest("virt.exit_threads()", vm, 10) - if match == None: + if match is None: logging.debug("Workaround the stuck thread on guest") # Thread is stucked in read/write for send_pt in send_pts: @@ -621,7 +621,6 @@ def run_virtio_console(test, params, env): consoles = [] serialports = [] tmp_dir = tempfile.mkdtemp(prefix="virtio-console-", dir="/tmp/") - #if not params.get('extra_params'): params['extra_params'] = '' if not spread: @@ -643,7 +642,7 @@ def run_virtio_console(test, params, env): % (i, i, i, pci)) for i in range(no_console, no_console + no_serialport): - # Spread seroal ports between multiple PCI devices (2 per a dev) + # Spread serial ports between multiple PCI devices (2 per each dev) if not i % 2 and spread: pci = "virtio-serial-pci%d" % (i / 2) params['extra_params'] += (" -device virtio-serial-pci,id=" @@ -672,7 +671,7 @@ def run_virtio_console(test, params, env): def _restore_vm(): """ - Restore old virtual machine when VM is destroied. + Restore old virtual machine when VM is destroyed. """ logging.debug("Booting guest %s", params.get("main_vm")) kvm_preprocessing.preprocess_vm(test, params, env, @@ -687,12 +686,12 @@ def run_virtio_console(test, params, env): 0, 2) except (error.TestFail): kernel_bug = _search_kernel_crashlog(vm.serial_console, 10) - if kernel_bug != None: + if kernel_bug is not None: logging.error(kernel_bug) raise kernel_bug = _search_kernel_crashlog(vm.serial_console, 10) - if kernel_bug != None: + if kernel_bug is not None: logging.error(kernel_bug) sserial = kvm_test_utils.wait_for_login(vm, 0, @@ -869,9 +868,9 @@ def run_virtio_console(test, params, env): on_guest("virt.recv('%s', 0, 1024, False)" % port.name, vm, 10) match, tmp = _on_guest("virt.send('%s', 10, True)" % port.name, vm, 10) - if match != None: + if match is not None: raise error.TestFail("Write on guest while host disconnected " - "didn't timed out.\nOutput:\n%s" + "didn't time out.\nOutput:\n%s" % tmp) port.open() @@ -897,9 +896,9 @@ def run_virtio_console(test, params, env): on_guest("virt.clean_port('%s'),1024" % port.name, vm, 10) match, tmp = _on_guest("virt.send('%s', (1024**3)*3, True, " "is_static=True)" % port.name, vm, 30) - if match != None: + if match is None: raise error.TestFail("Write on guest while host disconnected " - "didn't timed out.\nOutput:\n%s" + "didn't time out.\nOutput:\n%s" % tmp) time.sleep(20) @@ -912,8 +911,8 @@ def run_virtio_console(test, params, env): if (ret[0] != []): rlen += len(port.sock.recv(((4096)))) elif rlen != (1024**3*3): - raise error.TestFail("Not all data are received." - "Only %d from %d" % (rlen, 1024**3*3)) + raise error.TestFail("Not all data was received," + "only %d from %d" % (rlen, 1024**3*3)) on_guest("print 'PASS: nothing'", vm, 10) @@ -939,42 +938,41 @@ def run_virtio_console(test, params, env): loads.start() try: - sended1 = 0 + sent1 = 0 for i in range(1000000): - sended1 += port.sock.send("a") - except (socket.timeout): - logging.info("Send data to closed port timeouted.") + sent1 += port.sock.send("a") + except socket.timeout: + logging.info("Data sending to closed port timed out.") - logging.info("Sendes bytes to client: %d" % (sended1)) + logging.info("Bytes sent to client: %d" % (sent1)) logging.info("\n" + loads.get_cpu_status_string()[:-1]) on_guest('echo -n "PASS:"', vm, 10) - - logging.info("Open and then close port %s." % (port.name)) + logging.info("Open and then close port %s" % (port.name)) init_guest(vm, consoles) - #Test of live and open and close port again. + # Test of live and open and close port again _clean_ports(vm, consoles) on_guest("virt.close('%s')" % (port.name), vm, 10) - #With serialport it makes another behavior + # With serialport it is a different behavior on_guest("guest_exit()", vm, 10) port.sock.settimeout(20.0) loads.start() try: - sended2 = 0 + sent2 = 0 for i in range(40000): - sended2 = port.sock.send("a") - except (socket.timeout): - logging.info("Send data to closed port timeouted.") + sent2 = port.sock.send("a") + except socket.timeout: + logging.info("Data sending to closed port timed out.") - logging.info("Sendes bytes to client: %d" % (sended2)) + logging.info("Bytes sent to client: %d" % (sent2)) logging.info("\n" + loads.get_cpu_status_string()[:-1]) loads.stop() - if (sended1 != sended2): - logging.warning("Inconsis behavior first send %d and sec send %d" % - (sended1, sended2)) + if (sent1 != sent2): + logging.warning("Inconsistent behavior: First sent %d bytes and " + "second sent %d bytes" % (sent1, sent2)) port.sock.settimeout(None) (vm[0], vm[1], vm[3]) = _restore_vm() @@ -1000,7 +998,7 @@ def run_virtio_console(test, params, env): if match == 0: raise error.TestFail("Received data even when non were sent\n" "Data:\n%s" % tmp) - elif match != None: + elif match is not None: raise error.TestFail("Unexpected fail\nMatch: %s\nData:\n%s" % (match, tmp)) port.sock.sendall("1234567890") @@ -1025,7 +1023,7 @@ def run_virtio_console(test, params, env): if match == 0: raise error.TestFail("Received data even when non were sent\n" "Data:\n%s" % tmp) - elif match == None: + elif match is None: raise error.TestFail("Timed out, probably in blocking mode\n" "Data:\n%s" % tmp) elif match != 1: @@ -1087,9 +1085,9 @@ def run_virtio_console(test, params, env): on_guest("virt.clean_port('%s'),1024" % cname, vm, 2) - def tmax_serail_ports(vm, consoles): + def tmax_serial_ports(vm, consoles): """ - Test maximim count of ports in guest machine. + Test maximum count of ports in guest machine. @param vm: Target virtual machine [vm, session, tmp_dir, ser_session]. @param consoles: Consoles which should be close before rmmod. @@ -1107,7 +1105,7 @@ def run_virtio_console(test, params, env): def tmax_console_ports(vm, consoles): """ - Test maximim count of ports in guest machine. + Test maximum count of ports in guest machine. @param vm: Target virtual machine [vm, session, tmp_dir, ser_session]. @param consoles: Consoles which should be close before rmmod. @@ -1178,7 +1176,7 @@ def run_virtio_console(test, params, env): def tmigrate_offline(vm, consoles): """ - Let the machine migrate. Virtio_concoles should survive this. + Let the machine migrate. Virtio_consoles should survive this. @param vm: Target virtual machine [vm, session, tmp_dir, ser_session]. @param consoles: Consoles which should be close before rmmod. @@ -1444,14 +1442,14 @@ def run_virtio_console(test, params, env): # Check if python is still alive print "CLEANING" match, tmp = _on_guest("is_alive()", vm, 10) - if (match == None) or (match != 0): + if (match is None) or (match != 0): logging.error("Python died/is stucked/have remaining threads") logging.debug(tmp) try: if vm[4] == True: raise error.TestFail("Kernel crash.") match, tmp = _on_guest("guest_exit()", vm, 10) - if (match == None) or (match == 0): + if (match is None) or (match == 0): vm[1].close() vm[1] = kvm_test_utils.wait_for_login(vm[0], 0, float(params.get("boot_timeout", 5)), @@ -1487,7 +1485,7 @@ def run_virtio_console(test, params, env): match = _on_guest("virt.clean_port('%s'),1024" % cname, vm, 10)[0] - if (match == None) or (match != 0): + if (match is None) or (match != 0): raise error.TestFail("Virtio-console driver is irrepar" "ably blocked. Every comd end" " with sig KILL. Neither the " @@ -1570,10 +1568,10 @@ def run_virtio_console(test, params, env): @param params: Test parameters '$console_type:$data;...' """ subtest.headline("test_multiport:") - #Test Loopback + # Test Loopback subtest.do_test(tloopback, [vm, consoles, params[0]]) - #Test Performance + # Test Performance subtest.do_test(tperf, [vm, consoles, params[1]]) @@ -1586,9 +1584,9 @@ def run_virtio_console(test, params, env): @param consoles: Field of virtio ports with the minimum of 2 items. """ subtest.headline("test_destructive:") - #Test rmmod - subtest.do_test(trmmod,[vm, consoles]) - subtest.do_test(tmax_serail_ports, [vm, consoles]) + # Test rmmod + subtest.do_test(trmmod, [vm, consoles]) + subtest.do_test(tmax_serial_ports, [vm, consoles]) subtest.do_test(tmax_console_ports, [vm, consoles]) subtest.do_test(tmax_mix_serial_conosle_port, [vm, consoles]) subtest.do_test(tshutdown, [vm, consoles]) @@ -1604,21 +1602,21 @@ def run_virtio_console(test, params, env): no_serialports = 0 no_consoles = 0 # consoles required for Smoke test - if (tsmoke_params.count('serialport')): + if tsmoke_params.count('serialport'): no_serialports = max(2, no_serialports) - if (tsmoke_params.count('console')): + if tsmoke_params.count('console'): no_consoles = max(2, no_consoles) # consoles required for Loopback test for param in tloopback_params.split(';'): no_serialports = max(no_serialports, param.count('serialport')) no_consoles = max(no_consoles, param.count('console')) # consoles required for Performance test - if (tperf_params.count('serialport')): + if tperf_params.count('serialport'): no_serialports = max(1, no_serialports) - if (tperf_params.count('console')): + if tperf_params.count('console'): no_consoles = max(1, no_consoles) - if (no_serialports + no_consoles) == 0: + if no_serialports + no_consoles == 0: raise error.TestFail("No tests defined, probably incorrect " "configuration in tests_base.cfg") @@ -1639,13 +1637,13 @@ def run_virtio_console(test, params, env): init_guest(vm, consoles) subtest.set_cleanup_func(clean_ports, [vm, consoles]) - #Test Smoke + # Test Smoke test_smoke(subtest, vm, consoles, tsmoke_params) - #Test multiport functionality and performance. + # Test multiport functionality and performance. test_multiport(subtest, vm, consoles, [tloopback_params, tperf_params]) - #Test destructive test. + # Test destructive test. # Uses stronger clean up function (_cleanup_func, _cleanup_args) = subtest.get_cleanup_func() subtest.set_cleanup_func(clean_reload_vm, [vm, consoles])