[PATCH] KVM test: Add subtest clock_getres

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In order to track a regression that happens using kvmclock
in guests, add test of the clock_getres() syscall, to see
what is the clocksource resolution reported by the guest.
This, combined with variants that set different -cpu params
for the qemu command line, will give us the desired outcome.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@xxxxxxxxxx>
---
 client/tests/kvm/deps/test_clock_getres/Makefile   |   11 ++++
 .../kvm/deps/test_clock_getres/test_clock_getres.c |   58 ++++++++++++++++++++
 client/tests/kvm/tests/clock_getres.py             |   44 +++++++++++++++
 client/tests/kvm/tests_base.cfg.sample             |    3 +
 4 files changed, 116 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/deps/test_clock_getres/Makefile
 create mode 100644 client/tests/kvm/deps/test_clock_getres/test_clock_getres.c
 create mode 100644 client/tests/kvm/tests/clock_getres.py

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 <lmr@xxxxxxxxxx>
+ *
+ *  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 <http://www.gnu.org/licenses/>.
+ */
+#include <stdio.h>
+#include <time.h>
+#include <stdlib.h>
+#include <string.h>
+
+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.
-- 
1.7.2.3

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux