From: Andrew Cooper Date: Tue, 15 Jun 2021 15:02:29 +0000 (+0100) Subject: tests/xenstore: Rework Makefile X-Git-Tag: archive/raspbian/4.16.0+51-g0941d6cb-1+rpi1~2^2~42^2~319 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=93c9edbef51b31056f93a37a778326c90a83158c;p=xen.git tests/xenstore: Rework Makefile In particular, fill in the install/uninstall rules so this test can be packaged to be automated sensibly. This causes the code to be noticed by CI, which objects as follows: test-xenstore.c: In function 'main': test-xenstore.c:486:5: error: ignoring return value of 'asprintf', declared with attribute warn_unused_result [-Werror=unused-result] asprintf(&path, "%s/%u", TEST_PATH, getpid()); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Address the CI failure by checking the asprintf() return value and exiting. Rename xs-test to test-xenstore to be consistent with other tests. Honour APPEND_FLAGS too. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- diff --git a/.gitignore b/.gitignore index d4b90303b2..8ebb51b6c5 100644 --- a/.gitignore +++ b/.gitignore @@ -275,7 +275,6 @@ tools/tests/x86_emulator/*sse*.[ch] tools/tests/x86_emulator/test_x86_emulator tools/tests/x86_emulator/x86_emulate tools/tests/x86_emulator/xop*.[ch] -tools/tests/xenstore/xs-test tools/tests/vpci/list.h tools/tests/vpci/vpci.[hc] tools/tests/vpci/test_vpci diff --git a/tools/tests/xenstore/.gitignore b/tools/tests/xenstore/.gitignore new file mode 100644 index 0000000000..4b44f5dd60 --- /dev/null +++ b/tools/tests/xenstore/.gitignore @@ -0,0 +1 @@ +test-xenstore diff --git a/tools/tests/xenstore/Makefile b/tools/tests/xenstore/Makefile index a367d88803..b9969dd090 100644 --- a/tools/tests/xenstore/Makefile +++ b/tools/tests/xenstore/Makefile @@ -1,11 +1,7 @@ XEN_ROOT=$(CURDIR)/../../.. include $(XEN_ROOT)/tools/Rules.mk -CFLAGS += -Werror - -CFLAGS += $(CFLAGS_libxenstore) - -TARGETS-y := xs-test +TARGETS-y := test-xenstore TARGETS := $(TARGETS-y) .PHONY: all @@ -16,14 +12,31 @@ build: $(TARGETS) .PHONY: clean clean: - $(RM) *.o $(TARGETS) *~ $(DEPS_RM) + $(RM) -- *.o $(TARGETS) $(DEPS_RM) .PHONY: distclean distclean: clean + $(RM) -- *~ + +.PHONY: install +install: all + $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC_BIN) + $(if $(TARGETS),$(INSTALL_PROG) $(TARGETS) $(DESTDIR)$(LIBEXEC_BIN)) + +.PHONY: uninstall +uninstall: + $(RM) -- $(addprefix $(DESTDIR)$(LIBEXEC_BIN)/,$(TARGETS)) + +CFLAGS += -Werror +CFLAGS += $(CFLAGS_libxenstore) +CFLAGS += $(APPEND_CFLAGS) + +LDFLAGS += $(LDLIBS_libxenstore) +LDFLAGS += $(APPEND_LDFLAGS) -xs-test: xs-test.o Makefile - $(CC) -o $@ $< $(LDFLAGS) $(LDLIBS_libxenstore) +%.o: Makefile -install uninstall: +test-xenstore: test-xenstore.o + $(CC) -o $@ $< $(LDFLAGS) -include $(DEPS_INCLUDE) diff --git a/tools/tests/xenstore/test-xenstore.c b/tools/tests/xenstore/test-xenstore.c new file mode 100644 index 0000000000..d3574b3fa2 --- /dev/null +++ b/tools/tests/xenstore/test-xenstore.c @@ -0,0 +1,541 @@ +/* + * 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 +#include + +#include + +#define TEST_PATH "xenstore-test" +#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 = 0; + + 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