From: Juergen Gross Date: Thu, 19 Jan 2017 07:18:53 +0000 (+0100) Subject: tools/tests: add xenstore testing framework X-Git-Tag: archive/raspbian/4.11.1-1+rpi1~1^2~66^2~2948 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=3afc5e4a5b750384a469c2b9ba27eb6bdd55b3b8;p=xen.git tools/tests: add xenstore testing framework Add tools/tests/xenstore for a framework to do tests of xenstore. The aim is to test for correctness and performance. Add a test program containing some tests meant to be run against any xenstore implementation (xenstored, oxenstored, xenstore-stubdom). It is using libxenstore for access to xenstore and supports multiple tests to be either selected all or individually. All tests are using /local/domain//xenstore-test/ as base for doing the tests. This allows multiple instances of the program to run in parallel. Signed-off-by: Juergen Gross Acked-by: Wei Liu --- diff --git a/.gitignore b/.gitignore index 76895966f2..d9982f6bea 100644 --- a/.gitignore +++ b/.gitignore @@ -212,6 +212,7 @@ tools/tests/x86_emulator/blowfish.h tools/tests/x86_emulator/test_x86_emulator tools/tests/x86_emulator/x86_emulate tools/tests/xen-access/xen-access +tools/tests/xenstore/xs-test tools/tests/regression/installed/* tools/tests/regression/build/* tools/tests/regression/downloads/* diff --git a/tools/tests/Makefile b/tools/tests/Makefile index adeb120abc..639776130b 100644 --- a/tools/tests/Makefile +++ b/tools/tests/Makefile @@ -12,6 +12,7 @@ SUBDIRS-y += regression endif SUBDIRS-$(CONFIG_X86) += x86_emulator SUBDIRS-y += xen-access +SUBDIRS-y += xenstore .PHONY: all clean install distclean all clean distclean: %: subdirs-% diff --git a/tools/tests/xenstore/Makefile b/tools/tests/xenstore/Makefile new file mode 100644 index 0000000000..6c85f982ed --- /dev/null +++ b/tools/tests/xenstore/Makefile @@ -0,0 +1,27 @@ +XEN_ROOT=$(CURDIR)/../../.. +include $(XEN_ROOT)/tools/Rules.mk + +CFLAGS += -Werror + +CFLAGS += $(CFLAGS_libxenstore) + +TARGETS-y := xs-test +TARGETS := $(TARGETS-y) + +.PHONY: all +all: build + +.PHONY: build +build: $(TARGETS) + +.PHONY: clean +clean: + $(RM) *.o $(TARGETS) *~ $(DEPS) + +.PHONY: distclean +distclean: clean + +xs-test: xs-test.o Makefile + $(CC) -o $@ $< $(LDFLAGS) $(LDLIBS_libxenstore) + +-include $(DEPS) diff --git a/tools/tests/xenstore/xs-test.c b/tools/tests/xenstore/xs-test.c new file mode 100644 index 0000000000..eb5fe55722 --- /dev/null +++ b/tools/tests/xenstore/xs-test.c @@ -0,0 +1,536 @@ +/* + * xs-test.c + * + * Do Xenstore tests. + * + * Copyright (C) 2016 Juergen Gross , + * SUSE Linux GmbH + * + * This program is free software; you can redistribute it and/or + * modify it under the terms and conditions of the GNU General Public + * License, version 2, as published by the Free Software Foundation. + * + * 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 . + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TEST_PATH "xenstore-test" +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) +#define WRITE_BUFFERS_N 10 +#define WRITE_BUFFERS_SIZE 4000 +#define MAX_TA_LOOPS 100 + +struct test { + char *name; + int (*func_init)(uintptr_t par); + int (*func)(uintptr_t par); + int (*func_deinit)(uintptr_t par); + uintptr_t par; + char *descr; +}; + +static struct xs_handle *xsh; +static char *path; +static char *paths[WRITE_BUFFERS_N]; +static char write_buffers[WRITE_BUFFERS_N][WRITE_BUFFERS_SIZE]; +static int ta_loops; + +static struct option options[] = { + { "list-tests", 0, NULL, 'l' }, + { "test", 1, NULL, 't' }, + { "random", 1, NULL, 'r' }, + { "help", 0, NULL, 'h' }, + { "iterations", 1, NULL, 'i' }, + { NULL, 0, NULL, 0 } +}; + +static int call_test(struct test *tst, int iters, bool no_clock) +{ + char *stage = "?"; + struct timespec tp1, tp2; + uint64_t nsec, nsec_min, nsec_max, nsec_sum; + int i, ret; + + nsec_min = -1; + nsec_max = 0; + nsec_sum = 0; + + for ( i = 0; i < iters; i++ ) + { + stage = "pre-init"; + xs_rm(xsh, XBT_NULL, path); + if ( !xs_write(xsh, XBT_NULL, path, "", 0) ) + { + ret = errno; + break; + } + stage = "init"; + ret = tst->func_init(tst->par); + if ( ret ) + break; + if ( clock_gettime(CLOCK_REALTIME, &tp1) ) + no_clock = true; + stage = "run"; + ret = tst->func(tst->par); + if ( ret ) + break; + if ( clock_gettime(CLOCK_REALTIME, &tp2) ) + no_clock = true; + if ( !no_clock ) + { + nsec = tp2.tv_sec * 1000000000 + tp2.tv_nsec - + tp1.tv_sec * 1000000000 - tp1.tv_nsec; + if ( nsec < nsec_min ) + nsec_min = nsec; + if ( nsec > nsec_max ) + nsec_max = nsec; + nsec_sum += nsec; + } + stage = "deinit"; + ret = tst->func_deinit(tst->par); + if ( ret ) + break; + } + + if ( ret ) + printf("%-10s: failed (ret = %d, stage %s)\n", tst->name, ret, stage); + else if ( !no_clock ) + { + printf("%-10s:", tst->name); + if ( iters > 1 ) + printf(" avg: %"PRIu64" ns (%"PRIu64" ns .. %"PRIu64" ns)", + nsec_sum / iters, nsec_min, nsec_max); + else + printf(" %"PRIu64" ns", nsec_sum); + printf("\n"); + } + + return ret; +} + +static void usage(int ret) +{ + FILE *out; + + out = ret ? stderr : stdout; + + fprintf(out, "usage: xs-test []\n"); + fprintf(out, " are:\n"); + fprintf(out, " -i|--iterations perform each test times (default 1)\n"); + fprintf(out, " -l|--list-tests list available tests\n"); + fprintf(out, " -r|--random