KVM test: virtio_console test v2
PATCH 1/1 KVM test: virtio_console test v2
From: Lukáš Doktor <[email protected]>
1) Starts VMs with the specified number of virtio console devices
2) Start smoke test
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.
Changes from v1:
* Style fixes
* Whitespace cleanup
* Docstring and message fixes
* ID for char devices can't be a simple number, fix it
Tested with Fedora 13 guest/host, -smp 1.
--- client/tests/kvm/scripts/console_switch.py | 218 ++++++++ client/tests/kvm/tests/virtio_console.py | 774 ++++++++++++++++++++++++++++ client/tests/kvm/tests_base.cfg.sample | 11 + 3 files changed, 1003 insertions(+), 0 deletions(-) create mode 100644 client/tests/kvm/scripts/console_switch.py create mode 100644 client/tests/kvm/tests/virtio_console.py
client/tests/kvm/scripts/console_switch.py new file +218 -0
@@ -0,0 +1,218 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +""" +Auxiliary script used to send data between ports on guests. + +@copyright: 2008-2009 Red Hat Inc. +@author: Jiri Zupka ([email protected]) +@author: Lukas Doktor ([email protected]) +""" +import threading +from threading import Thread +import os,time,select,re,random,sys,array + +files = dict() +ev = threading.Event() +threads = [] + +DEBUGPATH="/sys/kernel/debug" + + +class Switch(Thread): + """ + Create a thread which sends data between ports. + """ + def __init__(self, exitevent, in_files, out_files, cachesize=1): + """ + @param exitevent: Event to end switch. + @param in_files: Array of input files. + @param out_files: Array of output files. + @param cachesize: Block to receive and send. + """ + Thread.__init__(self) + + self.in_files = in_files + self.out_files = out_files + + self.cachesize = cachesize + self.exitevent = exitevent + + + def run(self): + while not self.exitevent.isSet(): + #TODO: Why select causes trouble? :-( + #ret = select.select(self.in_files,[],[],1.0) + data = "" + #if not ret[0] == []: + for desc in self.in_files: + data += os.read(desc, self.cachesize) + for desc in self.out_files: + os.write(desc, data) + + +class Sender(Thread): + """ + Creates thread which sends random blocks of data to the destination port. + """ + def __init__(self, port, length): + """ + @param port: Destination port. + @param length: Length of the random data block. + """ + Thread.__init__(self) + self.port = port + self.data = array.array('L') + for i in range(max(length/self.data.itemsize, 1)): + self.data.append(random.randrange(sys.maxint)) + + + def run(self): + while True: + os.write(self.port, self.data) + del threads[:] + + +def get_port_status(): + """ + Get info about ports from kernel debugfs. + + @return: ports dictionary of port properties + """ + ports = {} + + not_present_msg = "FAIL: There's no virtio-ports dir in debugfs" + if not os.path.ismount(DEBUGPATH): + os.system('mount -t debugfs none %s' % DEBUGPATH) + try: + if not os.path.isdir('%s/virtio-ports' % DEBUGPATH): + print not_present_msg + except: + print not_present_msg + else: + viop_names = os.listdir('%s/virtio-ports' % DEBUGPATH) + for name in viop_names: + f = open("%s/virtio-ports/%s" % (DEBUGPATH, name), 'r') + port = {} + for line in iter(f): + m = re.match("(\S+): (\S+)",line) + port[m.group(1)] = m.group(2) + + if (port['is_console'] == "yes"): + port["path"] = "/dev/hvc%s" % port["console_vtermno"] + # Console works like a serialport + else: + port["path"] = "/dev/%s" % name + ports[port['name']] = port + f.close() + + return ports + + +def open_device(in_files, ports): + """ + Open devices and return array of descriptors + + @param in_files: files array + @return: array of descriptor + """ + f = [] + + for item in in_files: + name = ports[item[0]]["path"] + if (not item[1] == ports[item[0]]["is_console"]): + print ports + print "FAIL: Host console is not like console on guest side\n" + + if (name in files): + f.append(files[name]) + else: + try: + files[name] = os.open(name, os.O_RDWR) + if (ports[item[0]]["is_console"] == "yes"): + print os.system("stty -F %s raw -echo" % + (ports[item[0]]["path"])) + print os.system("stty -F %s -a" % ports[item[0]]["path"]) + f.append(files[name]) + except Exception as inst: + print "FAIL: Failed to open file %s" % name + raise inst + return f + + +def start_switch(in_files,out_files,cachesize=1): + """ + Function that starts switch thread + (because there is a problem with opening one file multiple times). + + @param in_files: array of input files + @param out_files: array of output files + @param cachesize: cachesize + """ + ports = get_port_status() + + in_f = open_device(in_files, ports) + out_f = open_device(out_files, ports) + + s = Switch(ev, in_f, out_f, cachesize) + s.start() + threads.append(s) + + print "PASS: Start switch" + + +def end_switches(): + """ + Function end all running data switches. + """ + ev.set() + for th in threads: + print "join" + th.join(3.0) + ev.clear() + + del threads[:] + print "PASS: End switch" + + +def die(): + """ + Quit consoleswitch. + """ + for desc in files.itervalues(): + os.close(desc) + exit(0) + + +def sender_prepare(port, length): + """ + Prepares the sender thread. Requires a clean thread structure. + """ + del threads[:] + ports = get_port_status() + in_f = open_device([port], ports) + + threads.append(Sender(in_f[0], length)) + print "PASS: Sender prepare" + + +def sender_start(): + """ + Start sender data transfer. Requires sender_prepare to run first. + """ + threads[0].start() + print "PASS: Sender start" + + +def main(): + """ + Main (infinite) loop of console_switch. + """ + print "PASS: Start" + end = False + while not end: + str = raw_input() + exec str + + +if __name__ == "__main__": + main()
client/tests/kvm/tests/virtio_console.py new file +774 -0
774 lines not on this page · raw message
client/tests/kvm/tests_base.cfg.sample +11 -0
@@ -494,9 +494,20 @@ variants: ksm_mode = "serial" - ksm_parallel: ksm_mode = "parallel" + - iofuzz: type = iofuzz + - virtio_console: + vms = '' + type = virtio_console + # smoke params - $console_type:data_string + virtio_console_smoke = "serialport;console:Custom data" + # loopback params - '$source_console_type@buffer_length:$destination_console_type1@buffer_length:...:$loopback_buffer_length;...' + virtio_console_loopback = "serialport:serialport;serialport@1024:serialport@32:console@1024:console@8:16" + # perf params - $console_type@buffer_length:$test_duration + virtio_console_perf = "serialport;serialport@1000000:120;console@1024:60" + # This unit test module is for older branches of KVM that use the # kvmctl test harness (such as the code shipped with RHEL 5.x) - unit_test_kvmctl:
Signature · 6 lines
1.7.2.2 _______________________________________________ Autotest mailing list [email protected] http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
Dne 2.9.2010 04:58, Lucas Meneghel Rodrigues napsal(a):
Quoted 18 lines
From: Lukáš Doktor<[email protected]>
1) Starts VMs with the specified number of virtio console devices
2) Start smoke test
3) Start loopback test
4) Start performance testThis 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.Changes from v1:
* Style fixes
* Whitespace cleanup
* Docstring and message fixes
* ID for char devices can't be a simple number, fix it
Quoted 5 lines
Tested with Fedora 13 guest/host, -smp 1.
Signed-off-by Lukas Doktor<[email protected]>Signed-off-by Jiri Zupka<[email protected]>Signed-off-by Lucas Meneghel Rodrigues<[email protected]>
Thank you, Lucas, we are currently working on another version which is going to be more similar to Amit Shah's C tests in order to fasten further tests development. We'll use your comments and python style.
Regards,
Lukáš
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
Quoted 21 lines · Lukáš Doktor
Dne 2.9.2010 04:58, Lucas Meneghel Rodrigues napsal(a):
Quoted 20 lines
From: Lukáš Doktor<[email protected]>
1) Starts VMs with the specified number of virtio console devices
2) Start smoke test
3) Start loopback test
4) Start performance testThis 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.Changes from v1:
* Style fixes
* Whitespace cleanup
* Docstring and message fixes
* ID for char devices can't be a simple number, fix itTested with Fedora 13 guest/host, -smp 1.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Lukas Doktor<[email protected]>Signed-off-by Jiri Zupka<[email protected]>Signed-off-by Lucas Meneghel Rodrigues<[email protected]>Thank you, Lucas, we are currently working on another version which is going to be more similar to Amit Shah's C tests in order to fasten further tests development. We'll use your comments and python style.
Lukas, FYI, I have commited an updated version of the virtio-console test, see commits:
http://autotest.kernel.org/changeset/4775
http://autotest.kernel.org/changeset/4772
When sending your updated version, please send it as a diff over the upstream code, OK?
Thank you very much!
Quoted 6 lines
Regards,
Lukáš
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
I set up autotest and could run the test that's committed, seems to work well so far :-)
Just one note for the console case. I haven't explored the tests in detail yet, but this is what suddenly stood out:
Quoted 18 lines · Lucas Meneghel Rodrigues
client/tests/kvm/scripts/console_switch.py new file +18
-0+def get_port_status(): + """ + Get info about ports from kernel debugfs. + + @return: ports dictionary of port properties + """ + ports = {} + + not_present_msg = "FAIL: There's no virtio-ports dir in debugfs" + if not os.path.ismount(DEBUGPATH): + os.system('mount -t debugfs none %s' % DEBUGPATH) + try: + if not os.path.isdir('%s/virtio-ports' % DEBUGPATH): + print not_present_msg + except: + print not_present_msg + else: + viop_names = os.listdir('%s/virtio-ports' % DEBUGPATH)
client/tests/kvm/scripts/console_switch.py line 102
Quoted 10 lines
client/tests/kvm/scripts/console_switch.py new file +10
-0+ for name in viop_names: + f = open("%s/virtio-ports/%s" % (DEBUGPATH, name), 'r') + port = {} + for line in iter(f): + m = re.match("(\S+): (\S+)",line) + port[m.group(1)] = m.group(2) + + if (port['is_console'] == "yes"): + port["path"] = "/dev/hvc%s" % port["console_vtermno"] + # Console works like a serialport
No, it doesn't :-)
The 'console' ports hook up with hvc and you can then tie a tty with the hvc console. So you can do something like 'agetty /dev/hvc0 9600 vt100' and get a login shell on the host chardev.
So the interesting tests for console ports are to spawn two of them, and in two threads which run at the same time, do 'find /' in one and 'while true; do dmesg; done' in the other so that both threads are doing something. The 'find /' test had found an smp bug earlier and doing this in two different threads will help in finding any other locking issues in virtio_console or hvc or tty code.
Amit