KVM-Test: Add kvm userspace unit test
PATCH 1/1 KVM-Test: Add kvm userspace unit test
The test use kvm test harness kvmctl load binary test case file to test various function of kvm kernel module.
--- client/tests/kvm/tests/unit_test.py | 29 +++++++++++++++++++++++++++++ client/tests/kvm/tests_base.cfg.sample | 7 +++++++ 2 files changed, 36 insertions(+), 0 deletions(-) create mode 100644 client/tests/kvm/tests/unit_test.py
client/tests/kvm/tests/unit_test.py new file +29 -0
@@ -0,0 +1,29 @@ +import os +from autotest_lib.client.bin import utils +from autotest_lib.client.common_lib import error + +def run_unit_test(test, params, env): + """ + This is kvm userspace unit test, use kvm test harness kvmctl load binary + test case file to test various function of kvm kernel module. + The output of all unit test can be found in the test result dir. + """ + + case_list = params.get("case_list","access apic emulator hypercall irq"\ + " port80 realmode sieve smptest tsc stringio vmexit").split() + srcdir = params.get("srcdir",test.srcdir) + user_dir = os.path.join(srcdir,"kvm_userspace/kvm/user") + os.chdir(user_dir) + test_fail_list = [] + + for i in case_list: + result_file = test.outputdir + "/" + i + testfile = i + ".flat" + results = utils.system("./kvmctl test/x86/bootstrap test/x86/" + \ + testfile + " > " + result_file,ignore_status=True) + if results != 0: + test_fail_list.append(i) + + if test_fail_list: + raise error.TestFail("< " + " ".join(test_fail_list) + \ + " >")
client/tests/kvm/tests_base.cfg.sample +7 -0
@@ -300,6 +300,13 @@ variants: shutdown_method = shell kill_vm = yes kill_vm_gracefully = no + + - unit_test: + type = unit_test + case_list = access apic emulator hypercall msr port80 realmode sieve smptest tsc stringio vmexit + #srcdir should be same as build.cfg + srcdir = + vms = '' # Do not define test variants below shutdown
Signature · 1 line
1.5.5.6
Hi Shuxi, sorry that it took so long before I could give you return on this one.
The general idea is just fine, but there is one gotcha that will need more thought: This is dependent of having the KVM source code for testing (ie, it depends on the build test *and* the build mode has to involve source code, such as git builds, things like koji install will also not work). Since by default we are not making the tests depending directly on build, so we have to figure out a way to have this integrated without breaking things for users who are not interested to run the build test.
Today I was reviewing the qemu-img functional test, so it occurred to me that all those tests that do not depend on guests and different qemu command line options, we can make them all dependent on the build test. This way we'd have the separation that we need, still not breaking anything for users that do not care about build and other types of test.
Michael, what do you think? Should we put the config of tests like this one and qemu_img on build.cfg, making them depend on build?
Oh Shuxi, on the code below I have some small comments to make:
Quoted 28 lines · sshang
The test use kvm test harness kvmctl load binary test case file to test various function of kvm kernel module.
Signed-off-by sshang <[email protected]>---
client/tests/kvm/tests/unit_test.py | 29 +++++++++++++++++++++++++++++ client/tests/kvm/tests_base.cfg.sample | 7 +++++++2 files changed, 36 insertions(+), 0 deletions(-)create mode 100644
client/tests/kvm/tests/unit_test.pyclient/tests/kvm/tests/unit_test.py new file +13
-0@@ -0,0 +1,29 @@ +import os +from autotest_lib.client.bin import utils +from autotest_lib.client.common_lib import error + +def run_unit_test(test, params, env): + """ + This is kvm userspace unit test, use kvm test harness kvmctl load binary + test case file to test various function of kvm kernel module. + The output of all unit test can be found in the test result dir. + """ + + case_list = params.get("case_list","access apic emulator hypercall irq"\ + " port80 realmode sieve smptest tsc stringio vmexit").split()
client/tests/kvm/tests/unit_test.py line 23
Quoted 10 lines
client/tests/kvm/tests/unit_test.py new file +10
-0+ srcdir = params.get("srcdir",test.srcdir) + user_dir = os.path.join(srcdir,"kvm_userspace/kvm/user") + os.chdir(user_dir) + test_fail_list = [] + + for i in case_list: + result_file = test.outputdir + "/" + i + testfile = i + ".flat" + results = utils.system("./kvmctl test/x86/bootstrap test/x86/" + \ + testfile + " > " + result_file,ignore_status=True)
About the above statement: In general you should not use shell redirection to write the output of your program to the log files. Please take advantage of the fact utils.run allow you to connect stdout and stderr pipes to the result file. Also, utils.run return a CmdResult object, hat has a list of useful properties out of it.
client/tests/kvm/tests/unit_test.py line 29
Quoted 6 lines
client/tests/kvm/tests/unit_test.py new file +6
-0+ if results != 0: + test_fail_list.append(i) + + if test_fail_list: + raise error.TestFail("< " + " ".join(test_fail_list) + \ + " >")
In the above, you could just have used
raise error.TestFail("KVM module unit test failed. Test cases
failed: %s" % test_fail_list)
IMHO it's easier to understand.
Quoted 26 lines
client/tests/kvm/tests_base.cfg.sample +0
-0@@ -300,6 +300,13 @@ variants:
shutdown_method= shell
kill_vm= yes
kill_vm_gracefully= no
+
+ -unit_test:
+ type =unit_test
+ case_list = access apic emulator hypercall msr port80 realmode sieve smptest tsc stringio vmexit
+ #srcdir should be same as build.cfg
+ srcdir =
+ vms = ''
# Do not define test variants below shutdown--
1.5.5.6_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
Signature · 1 line
Lucas
I have an update about this test after talking to Naphtali Sprei:
This patch does the unit testing using the old way of invoking it, and Avi superseded it with a new -kernel option. Naphtali is working in making the new way of doing the test work, so I will wait until we can merge both ways of doing this test, OK?
Quoted 115 lines · Lucas Meneghel Rodrigues
Hi Shuxi, sorry that it took so long before I could give you return on this one.
The general idea is just fine, but there is one gotcha that will need more thought: This is dependent of having the KVM source code for testing (ie, it depends on the build test *and* the build mode has to involve source code, such as git builds, things like koji install will also not work). Since by default we are not making the tests depending directly on build, so we have to figure out a way to have this integrated without breaking things for users who are not interested to run the build test.
Today I was reviewing the qemu-img functional test, so it occurred to me that all those tests that do not depend on guests and different qemu command line options, we can make them all dependent on the build test. This way we'd have the separation that we need, still not breaking anything for users that do not care about build and other types of test.
Michael, what do you think? Should we put the config of tests like this one and
qemu_imgon build.cfg, making them depend on build?Oh Shuxi, on the code below I have some small comments to make:
Quoted 28 lines · sshang
The test use kvm test harness kvmctl load binary test case file to test various function of kvm kernel module.
Signed-off-by sshang <[email protected]>---
client/tests/kvm/tests/unit_test.py | 29 +++++++++++++++++++++++++++++ client/tests/kvm/tests_base.cfg.sample | 7 +++++++2 files changed, 36 insertions(+), 0 deletions(-)create mode 100644
client/tests/kvm/tests/unit_test.pyclient/tests/kvm/tests/unit_test.py new file +13
-0@@ -0,0 +1,29 @@ +import os +from autotest_lib.client.bin import utils +from autotest_lib.client.common_lib import error + +def run_unit_test(test, params, env): + """ + This is kvm userspace unit test, use kvm test harness kvmctl load binary + test case file to test various function of kvm kernel module. + The output of all unit test can be found in the test result dir. + """ + + case_list = params.get("case_list","access apic emulator hypercall irq"\ + " port80 realmode sieve smptest tsc stringio vmexit").split()client/tests/kvm/tests/unit_test.py line 23
Quoted 10 lines
client/tests/kvm/tests/unit_test.py new file +10
-0+ srcdir = params.get("srcdir",test.srcdir) + user_dir = os.path.join(srcdir,"kvm_userspace/kvm/user") + os.chdir(user_dir) + test_fail_list = [] + + for i in case_list: + result_file = test.outputdir + "/" + i + testfile = i + ".flat" + results = utils.system("./kvmctl test/x86/bootstrap test/x86/" + \ + testfile + " > " + result_file,ignore_status=True)About the above statement: In general you should not use shell redirection to write the output of your program to the log files. Please take advantage of the fact utils.run allow you to connect stdout and stderr pipes to the result file. Also, utils.run return a CmdResult object, hat has a list of useful properties out of it.
client/tests/kvm/tests/unit_test.py line 29
Quoted 6 lines
client/tests/kvm/tests/unit_test.py new file +6
-0+ if results != 0: + test_fail_list.append(i) + + if test_fail_list: + raise error.TestFail("< " + " ".join(test_fail_list) + \ + " >")In the above, you could just have used
raise error.TestFail("KVM module unit test failed. Test cases
failed: %s" %test_fail_list)IMHO it's easier to understand.
Quoted 18 lines
client/tests/kvm/tests_base.cfg.sample +0
-0@@ -300,6 +300,13 @@ variants:
shutdown_method= shell
kill_vm= yes
kill_vm_gracefully= no
+
+ -unit_test:
+ type =unit_test
+ case_list = access apic emulator hypercall msr port80 realmode sieve smptest tsc stringio vmexit
+ #srcdir should be same as build.cfg
+ srcdir =
+ vms = ''
# Do not define test variants below shutdownQuoted 8 lines
--
1.5.5.6_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest--
Lucas
Signature · 1 line
Lucas