Add qemu-test for automated testing
cover Add qemu-test for automated testing
This patch provides a relatively simple method for exercising various features of qemu by interacting with the guest via serial and qemu via the monitor that individual developers can use to validate that their changes haven't broken feature/function. Such tests need to be very accessable and easy-to-use to encourge there use by users/developers. As a bonus, in-tree make test is trivially integrated into higher-level test frameworks such as autotest.
Using such interfaces the guest requirements are very low (serial login) and thus we can execute tests across a large number of differing guests. Writing new test cases should also be fairly simple, for example, the host_shutdown.py test logic is as follows:
def run_test(vm):
vm.wait_for_boot()
vm.login()
vm.guest_command("echo pressing power button") output = vm.monitor_command('system_powerdown') if vm.wait_for_shutdown(): return 1
There is a configuration file (tests/qemu-test/CONFIG) which can be used to provide per-distro overrides for various functions. The current defaults have been tested against: RHEL5, openSUSE 11, Ubuntu 8.04, and Fedora 9 w.r.t the regular expressions used for login, and prompt.
Getting started is relatively simple for someone familiar with configuring a guest for serial login and boot output via serial. Once completed, add a file to tests/qemu-test/images like the following:
% cat images/rhel5.2 DISK="/home/rharper/work/images/rhel5.2_x86_64_10G.qcow2" COMMAND="qemu-system-x86_64 -m 512 -smp 2 -net tap -net nic,model=e1000
-net nic,model=rtl8139 -drive file=${DISK},if=ide,boot=on
-vnc none"You can omit the COMMAND variable and a default qemu command will be run instead (see run.sh). For additional guest image or config just add a new file in the images dir.
To run the tests, at the toplevel run:
% make qemu-test
Some additional parameters can be passed through to run.sh to control how we execute qemu-test: TESTS, ARGS, and IMAGEDIR. By default, run.sh will execute each test (*.py) in tests/qemu-test/. If you want to restrict that list to something more specific, you can pass a space separated list to the make command:
% make qemu-test TESTS="reboot.py networking.py"
ARGS allows you to specific what parameters are passed to the qemu-system command. You can either modify the default args in tests/qemu-test/run.sh or override them via the command line
IMAGEDIR is a relative path where the image input files are located. It defaults to 'images' in tests/qemu-test, but if you have a specific directory you want to specify, for example tests/qemu-test/images.i386, this can be done with:
% make qemu-test IMAGEDIR="images.i386"
Output of the run will be logged to qemu/${TARGET_ARCH}_test_results.out. This includes all data generated during the run and the results, each test run will include whether it passed or failed, the testname, and the name of the image in which the test was run. Some sample output:
% head -n 10 i386-softmmu_test_results.out
Running Test:migrate.py on Image:ubuntu-6.06
Using default command: ../../i386-softmmu/qemu -L ../../pc-bios -m 128 -net tap -net nic,model=e1000 -net nic,model=rtl8139 -snapshot -vnc none -drive file=/home/rharper/work/images/ubuntu_6.06_i386_10G.qcow2,if=ide -boot c
[42949372.960000] Linux version 2.6.15-51-server (buildd@rothera) (gcc version 4.0.3 (Ubuntu 4.0.3-1ubuntu5)) #1 SMP Thu Dec 6 21:37:18 UTC 2007 [42949372.960000] BIOS-provided physical RAM map: [42949372.960000] BIOS-e820: 0000000000000000 - 000000000009fc00 (usable) [42949372.960000] BIOS-e820: 000000000009fc00 - 00000000000a0000 (reserved) [42949372.960000] BIOS-e820: 00000000000e8000 - 0000000000100000 (reserved) [42949372.960000] BIOS-e820: 0000000000100000 - 0000000007ff0000 (usable) [42949372.960000] BIOS-e820: 0000000007ff0000 - 0000000008000000 (ACPI data) [42949372.960000] BIOS-e820: 00000000fffc0000 - 0000000100000000 (reserved)
% tail -n 7 i386-softmmu_test_results.out
0
root@vm1:~#
************************************************************
Results: 2 passed, 0 FAILED
passed: migrate.py:ubuntu-6.06
passed: migrate_networking.py:ubuntu-6.06
************************************************************
PATCH 1/2 Add qemu-test for automated testing
This patch places the qemu-test framework and tests into the qemu source tree. There are a number of components to this patch:
- Python-based framework for interacting with the qemu process and the guest via serial console and qemu monitor.
- Several intial tests cases for exercising various qemu features/functions
- Bash script (run.sh) for running a set of tests on a set of images and collecting results.
This is a self-contained patch, the framework, tests and script are self-reliant, no further qemu integration is needed to realize the value of automatically testing qemu features against a set of images.
Patch 2/2 provides Makefile integration into qemu to execute qemu-test against the current build of the tree. This can be done without the Makefile integration, but simplifies the execution.
tests/qemu-test/CONFIG new file +58 -0
@@ -0,0 +1,58 @@ +############################################################################### +# QEMU-TEST options and defaults +# +############################################################################### +[options] +debug=1 +logfile=qemu-test.log +# Uncomment if you want to redirect guest serial output to a file instead +# of stdout +#serialfile=console.log + +############################################################################### +# !!!!WARNING!!!!: don't change the defaults, instead add an override for your +# distro, see below +############################################################################### +[defaults] +username=root +password= +login_prompt=^(\S+) login: +shell_prompt=(%(username)s@)*%(hostname)s.*#\ $ + +############################################################################### +# OVERRIDES +# +# Distro overrides section, to override the default values as specified in the +# [defaults] section, add the same option name and a new value, e.g, overriding +# the default username: +# +# [rhel] +# username=foobar +# +# +# Fields: +# username: +# password: +# login_prompt: +# shell_prompt: +# banner: +# add a regular expression to match the output from your distro's welcome banner +# (/etc/issue) the option name will be used for overriding the default section. +# For example, if you add the following option: +# +############################################################################### + +[rhel] +banner=^Red Hat Enterprise Linux +shell_prompt=^\[%(username)s@%(hostname)s.*\]#\ $ + +[opensuse] +banner=^Welcome to openSUSE +shell_prompt=%(hostname)s:.*#\ $ + +[ubuntu] +banner=^Ubuntu +shell_prompt=^%(username)s@%(hostname)s:.*#\ $ + +[fedora] +banner=^Fedora
tests/qemu-test/HOWTO new file +30 -0
@@ -0,0 +1,30 @@ +Configure your Guest +-------------------- +1. Configure guest to support serial login + + +2. Create an image file in qemu-test/images: + +For example: + +% cat images/rhel5.2 +DISK="/home/rharper/work/images/rhel5.2_x86_64_10G.qcow2" +COMMAND="qemu-system-x86_64 -m 512 -smp 2 -net tap -net nic,model=e1000 -net nic,model=rtl8139 -drive file=${DISK},if=ide,boot=on -vnc none" + +You can omit the COMMAND variable and a default qemu command will be run instead +(see run.sh). For each guest image or config add additional files in +qemu-test/images. + +3. Run the test and observe the results: + +% make && sudo make test +<snip massive amount of output> +************************************************************ +Results: 5 passed, 4 FAILED +passed: e820_memory.py:fedora-9-x86_64 +passed: host_shutdown.py:fedora-9-x86_64 +passed: networking.py:fedora-9-x86_64 +passed: reboot.py:fedora-9-x86_64 +FAILED: Test:host_reset.py,Image:fedora-9-x86_64 +FAILED: Test:timedrift.py,Image:fedora-9-x86_64 +************************************************************
tests/qemu-test/Makefile new file +24 -0
@@ -0,0 +1,24 @@ +-include ../../config-host.mak + +TARGET_ARCH := $(shell grep TARGET_ARCH $(QEMU)/config.mak | sed -e s/TARGET_ARCH=//) +ifeq ($(TARGET_ARCH), i386) +QEMU_PROG=qemu$(EXESUF) +else +QEMU_PROG=qemu-system-$(TARGET_ARCH)$(EXESUF) +endif + +setup: + cd ../../pc-bios && ln -sf ../keymaps + chmod a+x ./run.sh + +clean: + rm -f ../../pc-bios/keymaps + +test: all + +.PHONY: all test clean setup +all: setup + ./run.sh QEMU="$(QEMU)/$(QEMU_PROG) -L ../../pc-bios" \ + TESTS="$(TESTS)" ARGS="$(ARGS)" IMAGEDIR="$(IMAGEDIR)" |\ + tee $(QEMU)_test_results.out +
tests/qemu-test/THEORY new file +4 -0
@@ -0,0 +1,4 @@ +Each test should work with as many guests as possible with the least number +of parameters required. + +Minimum guest requirements (only configuration)
tests/qemu-test/TODO new file +33 -0
@@ -0,0 +1,33 @@ +* check guest image for commands/utilities needed for each benchmark +* improve failure detection + o oops/soft lockup detection + o freeze detection + - hard lockup detection (100% cpu usage, min timeout expired) + - soft lockup detection (0% cpu usage, min timeout expired) + - qemu freeze detection (timeout in monitor command) +* lots more tests + o device validation + o disk emu/paravirt verification + o pause/resume + o savevm/loadvm +* randomize sockets +* rewrite networking.py to parse info out of sysfs +* pass test name to launch for logging + + +#### Completed ##### +2008-08-01 +* write up on how to configure various distros to be ready to run any test +* redirect serial output to file, print to screen as option +* detect guest type + o automagically select appropriate defaults for prompt +2008-07-23 +* make check|test integration into kvm-userspace tree +* fedora guest support + +2008-07-16 +* integrate config file + o support per-distro overrides +* ubuntu guest support +* rhel5 guest support +* opensuse geust support
tests/qemu-test/boottime.py new file +38 -0
@@ -0,0 +1,38 @@ +# Copyright IBM Corp. 2008 +# Authors: Ryan Harper <[email protected] + +from qemu.test import launch, TimeoutException +import sys, time + +def run_test(vm): + start = time.time() + vm.wait_for_boot() + end = time.time() + vm.login() + vm.shutdown() + vm.wait_for_shutdown() + print '\n************' + print 'Time to boot: %s seconds'%(end-start) + print '************' + + return 0 + + +def main(args): + err = 1 + vm = launch(*args) + + try: + err = run_test(vm) + finally: + vm.quit() + + return err + + +if __name__ == '__main__': + try: + sys.exit(main(sys.argv[1:])) + except TimeoutException, e: + print 'Timeout occurred waiting for %s' % e.message + sys.exit(1)
tests/qemu-test/e820_memory.py new file +117 -0
117 lines not on this page · raw message
tests/qemu-test/host_reset.py new file +39 -0
@@ -0,0 +1,39 @@ +# Copyright IBM Corp. 2008 +# Authors: Ryan Harper <[email protected] +# + +from qemu.test import launch, TimeoutException +import sys + +def run_test(vm): + vm.wait_for_boot() + vm.login() + vm.guest_command("echo pressing reset button") + output = vm.monitor_command('system_reset') + vm.wait_for_restart() + vm.wait_for_boot() + vm.login() + + return 0 + + +def main(args): + err = 1 + vm = launch(*args) + + try: + err = run_test(vm) + vm.shutdown() + vm.wait_for_shutdown() + finally: + vm.quit() + + return err + + +if __name__ == '__main__': + try: + sys.exit(main(sys.argv[1:])) + except TimeoutException, e: + print 'Timeout occurred waiting for %s' % e.message + sys.exit(1)
tests/qemu-test/host_shutdown.py new file +34 -0
@@ -0,0 +1,34 @@ +# Copyright IBM Corp. 2008 +# Authors: Ryan Harper <[email protected] + +from qemu.test import launch, TimeoutException +import sys + +def run_test(vm): + vm.wait_for_boot() + vm.login() + vm.guest_command("echo pressing power button") + output = vm.monitor_command('system_powerdown') + if vm.wait_for_shutdown(): return 1 + + return 0 + + +def main(args): + err = 1 + vm = launch(*args) + + try: + err = run_test(vm) + finally: + vm.quit() + + return err + + +if __name__ == '__main__': + try: + sys.exit(main(sys.argv[1:])) + except TimeoutException, e: + print 'Timeout occurred waiting for %s' % e.message + sys.exit(1)
tests/qemu-test/iperf.py new file +75 -0
75 lines not on this page · raw message
tests/qemu-test/migrate.py new file +67 -0
67 lines not on this page · raw message
tests/qemu-test/migrate_networking.py new file +73 -0
73 lines not on this page · raw message
tests/qemu-test/networking.py new file +80 -0
80 lines not on this page · raw message
tests/qemu-test/qemu/__init__.py new file +0 -0
tests/qemu-test/qemu/test.py new file +433 -0
433 lines not on this page · raw message
tests/qemu-test/reboot.py new file +42 -0
42 lines not on this page · raw message
tests/qemu-test/run.sh new file +69 -0
69 lines not on this page · raw message
tests/qemu-test/timedrift.py new file +67 -0
67 lines not on this page · raw message
PATCH 2/2 Integrate qemu-test into make system
In reply to Ryan HarperThis patch integrates qemu-test into the Make system for qemu. Providing a new target at the toplevel and invoking the included Makefile in qemu-test to execute testing. Invoking make qemu-test from the toplevel will run qemu-test across each configured target, for example, if qemu was configured with:
./configure --target-list="i386-softmmu x86_64-softmmu"
then qemu-test will execute the tests against the above targets.
Makefile +3 -0
@@ -252,6 +252,9 @@ endif test speed: all $(MAKE) -C tests $@ +qemu-test: all + $(MAKE) -C tests $@ + TAGS: etags *.[ch] tests/*.[ch]
tests/Makefile +7 -0
@@ -103,6 +103,13 @@ hello-mipsel: hello-mips.c test-cris: $(MAKE) -C cris check +SUBDIR_RULES=$(patsubst %,qemu-%, $(TARGET_DIRS)) +qemu-%: + $(MAKE) -C qemu-test QEMU=../../$(subst qemu-,,$@) all +recurse-all: $(SUBDIR_RULES) +.PHONY: qemu-test +qemu-test: recurse-all + clean: rm -f *~ *.o test-i386.out test-i386.ref \ test-x86_64.log test-x86_64.ref qruncom $(TESTS)
Quoted 2 lines · Ryan Harper
This patch places the qemu-test framework and tests into the qemu source tree. There are a number of components to this patch:
Is there any point having this in the qemu repository?
AFAICS it gains nothing from being "integrated" with qemu. It should work equally well with other hypervisors, and even real hardware.
I'm not saying this is a bad thing, just that is seems like it should be a separate project, and I'd be surprised if such projects don't already exist.
Paul
Quoted 8 lines · Paul Brook
Quoted 3 lines · Ryan Harper
This patch places the qemu-test framework and tests into the qemu source tree. There are a number of components to this patch:
Is there any point having this in the qemu repository?
In tree unit testing. The ideal model would be to have something that anyone could run via a "make check" that could confirm whether something you've done introduces regressions in things you don't normally test.
Quoted 2 lines
AFAICS it gains nothing from being "integrated" with qemu. It should work equally well with other hypervisors, and even real hardware.
If we're just talking about booting a guest, yeah, I agree. But even the tests introduced here are validating specific QEMU features (like migration). Ideally, this is the type of test that would be added. Things like verifying that an emulated USB disk still works, that USB hotplug works, that SCSI disks can be mounted in the guest, etc. If we can find a place to host images, it could be automated in such a way that images could be easily downloaded. This would be extremely good for doing quick sniff tests of whether or not a change breaks SPARC emulation (not that any of us ever do that :-)).
Basically, I think we all end up building this sort of infrastructure on our own to be able to do testing so it's a good idea if we all work on the same set of tests.
Quoted 2 lines
I'm not saying this is a bad thing, just that is seems like it should be a separate project, and I'd be surprised if such projects don't already exist.
There are separate, more generic test programs like autotest that do support QEMU (at least, KVM). The focus here is more QEMU specific unit/regression testing.
Regards,
Anthony Liguori
Quoted 6 lines
Paul
--
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