From patchwork Thu Nov 11 12:04:47 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: 317222 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oABC4tcI027163 for ; Thu, 11 Nov 2010 12:04:56 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756032Ab0KKMEw (ORCPT ); Thu, 11 Nov 2010 07:04:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:29574 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755623Ab0KKMEv (ORCPT ); Thu, 11 Nov 2010 07:04:51 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oABC4oS7026306 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 11 Nov 2010 07:04:50 -0500 Received: from freedom.redhat.com (vpn-10-206.rdu.redhat.com [10.11.10.206]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oABC4mkC029707; Thu, 11 Nov 2010 07:04:49 -0500 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Lucas Meneghel Rodrigues Subject: [PATCH] KVM test: Add subtest clock_getres Date: Thu, 11 Nov 2010 10:04:47 -0200 Message-Id: <1289477087-4460-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 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 (demeter1.kernel.org [140.211.167.41]); Thu, 11 Nov 2010 12:04:56 +0000 (UTC) diff --git a/client/tests/kvm/deps/test_clock_getres/Makefile b/client/tests/kvm/deps/test_clock_getres/Makefile new file mode 100644 index 0000000..b4f73c7 --- /dev/null +++ b/client/tests/kvm/deps/test_clock_getres/Makefile @@ -0,0 +1,11 @@ +CC = gcc +PROG = test_clock_getres +SRC = test_clock_getres.c +LIBS = -lrt + +all: $(PROG) + +$(PROG): + $(CC) $(LIBS) -o $(PROG) $(SRC) +clean: + rm -f $(PROG) diff --git a/client/tests/kvm/deps/test_clock_getres/test_clock_getres.c b/client/tests/kvm/deps/test_clock_getres/test_clock_getres.c new file mode 100644 index 0000000..81d3b9c --- /dev/null +++ b/client/tests/kvm/deps/test_clock_getres/test_clock_getres.c @@ -0,0 +1,58 @@ +/* + * Test clock resolution for KVM guests that have kvm-clock as clock source + * + * Copyright (c) 2010 Red Hat, Inc + * Author: Lucas Meneghel Rodrigues + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#include +#include +#include +#include + +int main(void) { + struct timespec res; + int clock_return = clock_getres(CLOCK_MONOTONIC, &res); + char clocksource[50]; + char line[80]; + FILE *fr; + if ((fr = fopen( + "/sys/devices/system/clocksource/clocksource0/current_clocksource", + "rt")) == NULL) { + perror("fopen"); + return EXIT_FAILURE; + } + while (fgets(line, 80, fr) != NULL) { + sscanf(line, "%s", &clocksource); + } + fclose(fr); + if (!strncmp(clocksource, "kvm-clock", strlen("kvm-clock"))) { + if (clock_return == 0) { + if (res.tv_sec > 1 || res.tv_nsec > 100) { + printf("FAIL: clock_getres returned bad clock resolution\n"); + return EXIT_FAILURE; + } else { + printf("PASS: check successful\n"); + return EXIT_SUCCESS; + } + } else { + printf("FAIL: clock_getres failed\n"); + return EXIT_FAILURE; + } + } else { + printf("FAIL: invalid clock source: %s\n", clocksource); + return EXIT_FAILURE; + } +} diff --git a/client/tests/kvm/tests/clock_getres.py b/client/tests/kvm/tests/clock_getres.py new file mode 100644 index 0000000..7cadae8 --- /dev/null +++ b/client/tests/kvm/tests/clock_getres.py @@ -0,0 +1,44 @@ +import logging, time, os +from autotest_lib.client.common_lib import error +from autotest_lib.client.common_lib import utils +import kvm_test_utils, kvm_utils + + +def run_clock_getres(test, params, env): + """ + Verify if guests using kvm-clock as the time source have a sane clock + resolution. + + @param test: kvm test object. + @param params: Dictionary with test parameters. + @param env: Dictionary with the test environment. + """ + t_name = "test_clock_getres" + base_dir = "/tmp" + + deps_dir = os.path.join(test.bindir, "deps", t_name) + os.chdir(deps_dir) + try: + utils.system("make clean") + utils.system("make") + except: + raise error.TestError("Failed to compile %s" % t_name) + + test_clock = os.path.join(deps_dir, t_name) + if not os.path.isfile(test_clock): + raise error.TestError("Could not find %s" % t_name) + + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + timeout = int(params.get("login_timeout", 360)) + session = kvm_test_utils.wait_for_login(vm, timeout=timeout) + if not vm.copy_files_to(test_clock, base_dir): + raise error.TestError("Failed to copy %s to VM" % t_name) + s, o = session.get_command_status_output(os.path.join(base_dir, t_name)) + if s: + raise error.TestError("Execution of %s failed: %s" % (t_name, o)) + else: + logging.info("PASS: Guest reported an appropriate clock source " + "resolution") + s, o = session.get_command_status_output("dmesg") + logging.info("guest's dmesg:") + logging.info(o) diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample index 40ecf4a..7e36841 100644 --- a/client/tests/kvm/tests_base.cfg.sample +++ b/client/tests/kvm/tests_base.cfg.sample @@ -663,6 +663,9 @@ variants: image_name_snapshot1 = sn1 image_name_snapshot2 = sn2 + - clock_getres: install setup unattended_install.cdrom + type = clock_getres + # system_powerdown, system_reset and shutdown *must* be the last ones # defined (in this order), since the effect of such tests can leave # the VM on a bad state.