From patchwork Thu Jun 24 23:33:04 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 107956 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o5ONXNhq030431 for ; Thu, 24 Jun 2010 23:33:23 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754439Ab0FXXdU (ORCPT ); Thu, 24 Jun 2010 19:33:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60938 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753033Ab0FXXdT (ORCPT ); Thu, 24 Jun 2010 19:33:19 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5ONXI6j015269 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 24 Jun 2010 19:33:19 -0400 Received: from localhost.localdomain (vpn-9-214.rdu.redhat.com [10.11.9.214]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5ONX8oA020871; Thu, 24 Jun 2010 19:33:17 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org, mgoldish@redhat.com Cc: kvm@vger.kernel.org, Lucas Meneghel Rodrigues Subject: [PATCH 3/5] KVM test: add wrapper for RHEL-6 style unittests Date: Thu, 24 Jun 2010 20:33:04 -0300 Message-Id: <1277422386-13516-3-git-send-email-lmr@redhat.com> In-Reply-To: <1277422386-13516-1-git-send-email-lmr@redhat.com> References: <1277422386-13516-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 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.3 (demeter.kernel.org [140.211.167.41]); Thu, 24 Jun 2010 23:33:24 +0000 (UTC) diff --git a/client/tests/kvm/tests/unittest.py b/client/tests/kvm/tests/unittest.py new file mode 100644 index 0000000..84e778c --- /dev/null +++ b/client/tests/kvm/tests/unittest.py @@ -0,0 +1,114 @@ +import logging, time, os, shutil, glob, ConfigParser +from autotest_lib.client.common_lib import error +import kvm_subprocess, kvm_test_utils, kvm_utils, kvm_preprocessing + + +def run_unittest(test, params, env): + """ + KVM RHEL-6 style unit test: + 1) Resume a stopped VM + 2) Wait for VM to terminate + 3) If qemu exited with code = 0, the unittest passed. Otherwise, it failed + 4) Collect all logs generated + + @param test: kvm test object + @param params: Dictionary with the test parameters + @param env: Dictionary with test environment + """ + unittest_dir = os.path.join(test.bindir, 'unittests') + if not os.path.isdir(unittest_dir): + raise error.TestError("No unittest dir %s available (did you run the " + "build test first?)" % unittest_dir) + os.chdir(unittest_dir) + unittest_list = glob.glob('*.flat') + if not unittest_list: + raise error.TestError("No unittest files available (did you run the " + "build test first?)") + logging.debug('Flat file list: %s', unittest_list) + + unittest_cfg = os.path.join(unittest_dir, 'unittests.cfg') + parser = ConfigParser.ConfigParser() + parser.read(unittest_cfg) + test_list = parser.sections() + + if not test_list: + raise error.TestError("No tests listed on config file %s" % + unittest_cfg) + logging.debug('Unit test list: %s' % test_list) + + if params.get('test_list', None): + test_list = eval(params.get('test_list')) + logging.info('Original test list overriden by user') + logging.info('User defined unit test list: %s' % test_list) + + nfail = 0 + tests_failed = [] + + timeout = int(params.get('unittest_timeout', 600)) + + for t in test_list: + file = None + if parser.has_option(t, 'file'): + file = parser.get(t, 'file') + + if file is None: + raise error.TestError('Unittest config file %s has section %s but ' + 'no mandatory option file.' % + (unittest_cfg, t)) + + if file not in unittest_list: + raise error.TestError('Unittest file %s referenced in config file ' + '%s but was not find under the unittest dir' % + (file, unittest_cfg)) + + smp = None + if parser.has_option(t, 'smp'): + smp = int(parser.get(t, 'smp')) + + extra_params = None + if parser.has_option(t, 'extra_params'): + extra_params = parser.get(t, 'extra_params') + + vm_name = params.get("main_vm") + testlog_path = os.path.join(test.debugdir, "%s.log" % t) + + params['kernel'] = os.path.join(unittest_dir, file) + logging.info('Running %s', t) + + if smp is not None: + params['smp'] = smp + logging.info('SMP: %s', smp) + + if extra_params is not None: + params['extra_params'] = extra_params + logging.info('Extra params: %s', extra_params) + + try: + try: + kvm_preprocessing.preprocess_vm(test, params, env, vm_name) + vm = kvm_utils.env_get_vm(env, vm_name) + vm.monitor.cmd("cont") + logging.info("Waiting for unittest %s to complete, timeout %s, " + "output in %s", t, timeout, + vm.get_testlog_filename()) + if not kvm_utils.wait_for(vm.is_dead, timeout): + raise error.TestFail("Timeout elapsed (%ss)" % timeout) + # Check qemu's exit status + status = vm.process.get_status() + if status != 0: + nfail += 1 + tests_failed.append(t) + logging.error("Unit test %s failed", t) + except Exception, e: + nfail += 1 + logging.error('Exception happened during %s: %s', t, str(e)) + finally: + try: + shutil.copy(vm.get_testlog_filename(), testlog_path) + logging.info("Unit test log collected and available under %s", + testlog_path) + except NameError, IOError: + logging.error("Not possible to collect logs") + + if nfail != 0: + raise error.TestFail("Unit tests failed: %s" % " ".join(tests_failed))