Re: [Autotest] [PATCH] KVM-Test: Add kvm userspace unit test

2010-03-21 Thread Shuxi Shang
OK, I approve of your suggestion.

- "Lucas Meneghel Rodrigues"  写道:

> 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?
> 
> On Thu, Mar 18, 2010 at 12:16 AM, Lucas Meneghel Rodrigues
>  wrote:
> > 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:
> >
> > On Fri, Mar 5, 2010 at 3:22 AM, sshang  wrote:
> >>  The test use kvm test harness kvmctl load binary test case file to
> test various function of kvm kernel module.
> >>
> >> Signed-off-by: sshang 
> >> ---
> >>  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
> >>
> >> diff --git a/client/tests/kvm/tests/unit_test.py
> b/client/tests/kvm/tests/unit_test.py
> >> new file mode 100644
> >> index 000..9bc7441
> >> --- /dev/null
> >> +++ b/client/tests/kvm/tests/unit_test.py
> >> @@ -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)
> >
> > 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.
> >
> >> +        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.
> >
> >> diff --git a/client/tests/kvm/tests_base.cfg.sample
> b/client/tests/kvm/tests_base.cfg.sample
> >> index 040d0c3..0918c26 100644
> >> --- a/client/tests/kvm/tests_base.cfg.sample
> >> +++ b/client/tests/kvm/tests_base.cfg.sample
> >> @@ -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
>

Re: [PATCH] KVM-Test: Add private bridge to use for communication

2010-02-24 Thread Shuxi Shang
Hello, Lucas, I think there are two advantages of such a private bridge:
1). With private bridge, not paying attention to the conflict of guest's mac 
address.
2). segregating from public network which host locates.



- "Lucas Meneghel Rodrigues"  写道:

> On Tue, 2010-02-23 at 16:56 +0800, sshang wrote:
> > Add private bridge to use for communication between host and guest.
> >Config of parameter:
> >bridge = private
> >private_bridge_name = private(default)
> >private_bridge_addr = 192.168.0.1(default)
> >private_bridge_mask = 255.255.255.0(default)
> >pre_command = scripts/private_bridge_setup.py
> 
> Hi, I've checked your patch, seems fair enough. But can you elaborate
> more on the advantages of having such a private bridge for
> communication
> between hosts and guests? We have mechanisms of doing so in both tap
> and
> user mode networking...
> 
> > Signed-off-by: sshang 
> > ---
> >  client/tests/kvm/scripts/private_bridge_setup.py |   90
> ++
> >  1 files changed, 90 insertions(+), 0 deletions(-)
> >  create mode 100755
> client/tests/kvm/scripts/private_bridge_setup.py
> > 
> > diff --git a/client/tests/kvm/scripts/private_bridge_setup.py
> b/client/tests/kvm/scripts/private_bridge_setup.py
> > new file mode 100755
> > index 000..fe1b653
> > --- /dev/null
> > +++ b/client/tests/kvm/scripts/private_bridge_setup.py
> > @@ -0,0 +1,90 @@
> > +#!/usr/bin/python
> > +import os, sys, commands
> > +
> > +class SetupError(Exception):
> > +"""
> > +Simple wrapper for the builtin Exception class.
> > +"""
> > +pass
> > +
> > +
> > +class SetupPrivateBridge(object):
> > +"""
> > +Setup private bridge and running dnsmasq for communication
> > +between host and guest.
> > +"""
> > +def __init__(self):
> > +script_dir =
> os.path.dirname(sys.modules[__name__].__file__)
> > +kvm_test_dir = os.path.abspath(os.path.join(script_dir,
> ".."))
> > +self.private_bridge_name = os.environ.get(\
> > + 
> 'KVM_TEST_private_bridge_name','private')
> > +self.private_bridge_addr = os.environ.get(\
> > + 
> 'KVM_TEST_private_bridge_addr','192.168.0.1')
> > +self.private_bridge_mask = os.environ.get(\
> > + 
> 'KVM_TEST_private_bridge_mask','255.255.255.0')
> > +self.dhcp_boot = os.environ.get(\
> > +  'KVM_TEST_dhcp_boot','/pxelinux.0')
> > +self.tftp_root = os.environ.get('KVM_TEST_tftp')
> > +if self.tftp_root:
> > +self.tftp_root = os.path.join(kvm_test_dir,
> self.tftp_root)
> > +self.qemu_ifup_file = os.path.join(script_dir,
> "qemu-ifup-private")
> > +
> > +
> > +def setup_private_bridge(self):
> > +"""
> > +Setup private bridge.
> > +"""
> > +
> > +text = """#!/bin/sh
> > +switch=%s
> > +/sbin/ifconfig $1 0.0.0.0 up
> > +/usr/sbin/brctl addif ${switch} $1
> > +"""
> > +text = text % (self.private_bridge_name)
> > +f = open(self.qemu_ifup_file,"w")
> > +f.write(text)
> > +f.close()
> > +commands.getoutput('chmod a+x %s' % self.qemu_ifup_file)
> > +
> > +check_br_cmd = "brctl show | grep %s" %
> self.private_bridge_name
> > +s,o = commands.getstatusoutput(check_br_cmd)
> > +if s:
> > +add_br_cmd = "brctl addbr %s" %
> self.private_bridge_name
> > +s,o = commands.getstatusoutput(add_br_cmd)
> > +if s:
> > +raise SetupError('Add bridge error: %s' % o)
> > +else:
> > +ifdown_cmd = "ifconfig %s down" %
> self.private_bridge_name
> > +s,o = commands.getstatusoutput(ifdown_cmd)
> > +if s:
> > +raise SetupError('Down bridge error: %s' % o)
> > +
> > +ifconfig_cmd = "ifconfig %s %s netmask %s up" % \
> > + 
> (self.private_bridge_name,self.private_bridge_addr,\
> > +  self.private_bridge_mask)
> > +s,o = commands.getstatusoutput(ifconfig_cmd)
> > +if s:
> > +raise SetupError('Config bridge error: %s' % o)
> > +
> > +commands.getoutput("pkill dnsmasq")
> > +
> > +addr_list = self.private_bridge_addr.split('.')
> > +addr_list[3] = str(int(addr_list[3]) + 1)
> > +dhcp_addr_begin = '.'.join(addr_list)
> > +addr_list[3] = '254'
> > +dhcp_addr_end = '.'.join(addr_list)
> > +
> > +dnsmasq_argument = " -u root --listen-address %s
> --dhcp-range %s,%s" %\
> > +   
> (self.private_bridge_addr,dhcp_addr_begin,dhcp_addr_end)
> > +if self.tftp_root:
> > +dnsmasq_argument += " --dhcp-boot %s --enable-tftp
> --tftp-root %s"\
> > +   % (self.dhcp_boot,self.tftp_root)
> > +dnsmasq_cmd = "dnsmasq" + dnsmasq_argument
> > +s,o = commands.getstatusoutput(dnsma