From patchwork Wed Nov 25 06:05:02 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sudhir kumar X-Patchwork-Id: 62690 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nAP658Tk024218 for ; Wed, 25 Nov 2009 06:05:08 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751030AbZKYGE5 (ORCPT ); Wed, 25 Nov 2009 01:04:57 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751141AbZKYGE5 (ORCPT ); Wed, 25 Nov 2009 01:04:57 -0500 Received: from mail-px0-f180.google.com ([209.85.216.180]:33023 "EHLO mail-px0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750972AbZKYGE4 (ORCPT ); Wed, 25 Nov 2009 01:04:56 -0500 Received: by pxi10 with SMTP id 10so5508299pxi.33 for ; Tue, 24 Nov 2009 22:05:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:cc:content-type; bh=qXmcSiuh5iuCPpSzeehtTsZRlBE2F7pbDnVWbmXKez4=; b=Gg5gYlq3PkpX/r33HXarR4oQFBdFSTctGpuAPqRL99OAuH1pn5PXzxkH0GtukvvCXu 3Xktti8UG4ILXvBIRHrXLGsL83PeEyd+f1cMPfnKixLFwqMmqs8UtdvBJEFBw1JVglLw 9wjAOBR/L17yH0VNegwMiOxgcJtQLSmSjSE8I= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:cc:content-type; b=dEo1Lvn+Fo2aGJFG0GlTCBl1UcZqXPBfbMk+u62ft61yJQktgGLT5XmCVijMYMM8pR 6JbSCDbfD5KcojWwsWtcBwwZSrHtgx2X8ITNUagpaj/AJeegrXefG+TNo7sPG9KEBY8T y1o6vZaxNV0lMnaEPENs0oJBvNTDv7XpG9Rmc= MIME-Version: 1.0 Received: by 10.143.138.7 with SMTP id q7mr854700wfn.314.1259129102635; Tue, 24 Nov 2009 22:05:02 -0800 (PST) Date: Wed, 25 Nov 2009 11:35:02 +0530 Message-ID: Subject: [PATCH 1/2] Adds a test to verify resources inside a VM From: sudhir kumar To: kvm-devel Cc: Autotest mailing list , Lucas Meneghel Rodrigues , Michael Goldish , smalikphy@gmail.com Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This patch adds a test for verifying whether the number of cpus and amount of memory as seen inside a guest is same as allocated to it on the qemu command line. Signed-off-by: Sudhir Kumar Index: kvm/tests/verify_resources.py =================================================================== --- /dev/null +++ kvm/tests/verify_resources.py @@ -0,0 +1,74 @@ +import logging, time +from autotest_lib.client.common_lib import error +import kvm_subprocess, kvm_test_utils, kvm_utils + +""" +Test to verify if the guest has the equal amount of resources +as allocated through the qemu command line + +@Copyright: 2009 IBM Corporation +@author: Sudhir Kumar + +""" + +def run_verify_resources(test, params, env): + """ + KVM test for verifying VM resources(#vcpu, memory): + 1) Get resources from the VM parameters + 2) Log into the guest + 3) Get actual resources, compare and report the pass/failure + + @param test: kvm test object + @param params: Dictionary with the test parameters + @param env: Dictionary with test environment. + """ + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + + # Get info about vcpu and memory from dictionary + exp_vcpus = int(params.get("smp")) + exp_mem_mb = long(params.get("mem")) + real_vcpus = 0 + real_mem_kb = 0 + real_mem_mb = 0 + # Some memory is used by bios and all, so lower the expected value say by 5% + exp_mem_mb = long(exp_mem_mb * 0.95) + logging.info("The guest should have vcpus: %s" % exp_vcpus) + logging.info("The guest should have min mem: %s MB" % exp_mem_mb) + + session = kvm_test_utils.wait_for_login(vm) + + # Get info about vcpu and memory from within guest + if params.get("guest_os_type") == "Linux": + output = session.get_command_output("cat /proc/cpuinfo|grep processor") + for line in output.split('\n'): + if 'processor' in line: + real_vcpus = real_vcpus + 1 + + output = session.get_command_output("cat /proc/meminfo") + for line in output.split('\n'): + if 'MemTotal' in line: + real_mem_kb = long(line.split()[1]) + real_mem_mb = real_mem_kb / 1024 + + elif params.get("guest_os_type") == "Windows": + # Windows takes long time to display output for systeminfo + output = session.get_command_output("systeminfo", timeout = 150, internal_timeout = 50) + for line in output.split('\n'): + if 'Processor' in line: + real_vcpus = int(line.split()[1]) + + for line in output.split('\n'): + if 'Total Physical Memory' in line: + real_mem_mb = long("".join("%s" % k for k in line.split()[3].split(','))) + + else: + raise error.TestFail("Till date this test is supported only for Linux and Windows") + + logging.info("The guest has cpus: %s" % real_vcpus) + logging.info("The guest has mem: %s MB" % real_mem_mb) + if exp_vcpus != real_vcpus or real_mem_mb < exp_mem_mb: + raise error.TestFail("Actual resources(cpu ='%s' memory ='%s' MB) " + "differ from Allocated resources(cpu = '%s' memory ='%s' MB" + % (real_vcpus, real_mem_mb, exp_vcpus, exp_mem_mb)) + + session.close()