Skip to contentSkip to conversation

tools/tests: More cleanup for automation improvements

PATCH In review Andrew Cooper 2 participants 9 messages Jun 22, 2021 – Jun 28, 2021

lore
Share & tools
lore
#0 lore raw

v2 cover tools/tests: More cleanup for automation improvements

v2:
* Fix CI failures from newly-exposed logic
* Drop -f's from $(RM)
* Drop the 'run' rune patch. Its clearly controvertial, but ignoring the problems isn't an available option in the longterm.

All other RFC questions still outstanding.

Andrew Cooper (4):
tools/tests: Drop obsolete mce-test infrastructure tests/resource: Rework Makefile tests/cpu-policy: Rework Makefile tests/xenstore: Rework Makefile

 .gitignore                                         |   2 -
 tools/misc/.gitignore                              |   1 +
 tools/misc/Makefile                                |   4 +
 tools/{tests/mce-test/tools => misc}/xen-mceinj.c  |  32 +--
 tools/tests/Makefile                               |   1 -
 tools/tests/cpu-policy/Makefile                    |  31 ++-
 tools/tests/mce-test/Makefile                      |  12 -
 tools/tests/mce-test/README                        |  75 ------
 tools/tests/mce-test/cases/srao_llc/dom0/cases.sh  |  73 ------
 tools/tests/mce-test/cases/srao_llc/guest/cases.sh |  94 --------
 tools/tests/mce-test/cases/srao_llc/xen/cases.sh   |  69 ------
 tools/tests/mce-test/cases/srao_mem/dom0/cases.sh  |  73 ------
 tools/tests/mce-test/cases/srao_mem/guest/cases.sh |  94 --------
 tools/tests/mce-test/cases/srao_mem/xen/cases.sh   |  69 ------
 tools/tests/mce-test/cases/ucna_llc/dom0/cases.sh  |  72 ------
 tools/tests/mce-test/cases/ucna_llc/guest/cases.sh |  92 --------
 tools/tests/mce-test/cases/ucna_llc/xen/cases.sh   |  68 ------
 tools/tests/mce-test/config/setup.conf             |  24 --
 tools/tests/mce-test/lib/xen-mceinj-tool.sh        | 260 ---------------------
 tools/tests/mce-test/tools/Makefile                |  24 --
 tools/tests/mce-test/tools/README                  |  24 --
 tools/tests/resource/Makefile                      |  11 +-
 tools/tests/xenstore/.gitignore                    |   1 +
 tools/tests/xenstore/Makefile                      |  31 ++-
 .../tests/xenstore/{xs-test.c => test-xenstore.c}  |   8 +-
 25 files changed, 80 insertions(+), 1165 deletions(-)
 rename tools/{tests/mce-test/tools => misc}/xen-mceinj.c (97%)
 delete mode 100644 tools/tests/mce-test/Makefile
 delete mode 100644 tools/tests/mce-test/README
 delete mode 100644 tools/tests/mce-test/cases/srao_llc/dom0/cases.sh
 delete mode 100644 tools/tests/mce-test/cases/srao_llc/guest/cases.sh
 delete mode 100644 tools/tests/mce-test/cases/srao_llc/xen/cases.sh
 delete mode 100644 tools/tests/mce-test/cases/srao_mem/dom0/cases.sh
 delete mode 100644 tools/tests/mce-test/cases/srao_mem/guest/cases.sh
 delete mode 100644 tools/tests/mce-test/cases/srao_mem/xen/cases.sh
 delete mode 100644 tools/tests/mce-test/cases/ucna_llc/dom0/cases.sh
 delete mode 100644 tools/tests/mce-test/cases/ucna_llc/guest/cases.sh
 delete mode 100644 tools/tests/mce-test/cases/ucna_llc/xen/cases.sh
 delete mode 100644 tools/tests/mce-test/config/setup.conf
 delete mode 100644 tools/tests/mce-test/lib/xen-mceinj-tool.sh
 delete mode 100644 tools/tests/mce-test/tools/Makefile
 delete mode 100644 tools/tests/mce-test/tools/README
 create mode 100644 tools/tests/xenstore/.gitignore
 rename tools/tests/xenstore/{xs-test.c => test-xenstore.c} (98%)
Signature · 1 line
2.11.0
#1 lore raw

PATCH v2 1/4 tools/tests: Drop obsolete mce-test infrastructure

mce-test has a test suite, but it depends on xend, needs to run in-tree, and requires manual setup of at least one guest, and manual parameters to pass into cases. Drop the test infrasturcture.

Move the one useful remaining item, xen-mceinj, into misc/, fixing some minor style issues as it goes.

---
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Juergen Gross <[email protected]>

---
 .gitignore                                         |   1 -
 tools/misc/.gitignore                              |   1 +
 tools/misc/Makefile                                |   4 +
 tools/{tests/mce-test/tools => misc}/xen-mceinj.c  |  32 +--
 tools/tests/Makefile                               |   1 -
 tools/tests/mce-test/Makefile                      |  12 -
 tools/tests/mce-test/README                        |  75 ------
 tools/tests/mce-test/cases/srao_llc/dom0/cases.sh  |  73 ------
 tools/tests/mce-test/cases/srao_llc/guest/cases.sh |  94 --------
 tools/tests/mce-test/cases/srao_llc/xen/cases.sh   |  69 ------
 tools/tests/mce-test/cases/srao_mem/dom0/cases.sh  |  73 ------
 tools/tests/mce-test/cases/srao_mem/guest/cases.sh |  94 --------
 tools/tests/mce-test/cases/srao_mem/xen/cases.sh   |  69 ------
 tools/tests/mce-test/cases/ucna_llc/dom0/cases.sh  |  72 ------
 tools/tests/mce-test/cases/ucna_llc/guest/cases.sh |  92 --------
 tools/tests/mce-test/cases/ucna_llc/xen/cases.sh   |  68 ------
 tools/tests/mce-test/config/setup.conf             |  24 --
 tools/tests/mce-test/lib/xen-mceinj-tool.sh        | 260 ---------------------
 tools/tests/mce-test/tools/Makefile                |  24 --
 tools/tests/mce-test/tools/README                  |  24 --
 20 files changed, 24 insertions(+), 1138 deletions(-)
 rename tools/{tests/mce-test/tools => misc}/xen-mceinj.c (97%)
 delete mode 100644 tools/tests/mce-test/Makefile
 delete mode 100644 tools/tests/mce-test/README
 delete mode 100644 tools/tests/mce-test/cases/srao_llc/dom0/cases.sh
 delete mode 100644 tools/tests/mce-test/cases/srao_llc/guest/cases.sh
 delete mode 100644 tools/tests/mce-test/cases/srao_llc/xen/cases.sh
 delete mode 100644 tools/tests/mce-test/cases/srao_mem/dom0/cases.sh
 delete mode 100644 tools/tests/mce-test/cases/srao_mem/guest/cases.sh
 delete mode 100644 tools/tests/mce-test/cases/srao_mem/xen/cases.sh
 delete mode 100644 tools/tests/mce-test/cases/ucna_llc/dom0/cases.sh
 delete mode 100644 tools/tests/mce-test/cases/ucna_llc/guest/cases.sh
 delete mode 100644 tools/tests/mce-test/cases/ucna_llc/xen/cases.sh
 delete mode 100644 tools/tests/mce-test/config/setup.conf
 delete mode 100644 tools/tests/mce-test/lib/xen-mceinj-tool.sh
 delete mode 100644 tools/tests/mce-test/tools/Makefile
 delete mode 100644 tools/tests/mce-test/tools/README
.gitignore +0 -1
index 38a085e398..d4b90303b2 100644
@@ -276,7 +276,6 @@ 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/mce-test/tools/xen-mceinj
 tools/tests/vpci/list.h
 tools/tests/vpci/vpci.[hc]
 tools/tests/vpci/test_vpci
tools/misc/.gitignore +1 -0
index ce6f937d0c..73ce95e6d7 100644
@@ -1,4 +1,5 @@
 xen-access
+xen-mceinj
 xen-memshare
 xen-ucode
 xen-vmtrace
tools/misc/Makefile +4 -0
index 2b683819d4..1a07191d83 100644
@@ -22,6 +22,7 @@ INSTALL_SBIN-$(CONFIG_MIGRATE) += xen-hptool
 INSTALL_SBIN-$(CONFIG_X86)     += xen-hvmcrash
 INSTALL_SBIN-$(CONFIG_X86)     += xen-hvmctx
 INSTALL_SBIN-$(CONFIG_X86)     += xen-lowmemd
+INSTALL_SBIN-$(CONFIG_X86)     += xen-mceinj
 INSTALL_SBIN-$(CONFIG_X86)     += xen-memshare
 INSTALL_SBIN-$(CONFIG_X86)     += xen-mfndump
 INSTALL_SBIN-$(CONFIG_X86)     += xen-ucode
@@ -97,6 +98,9 @@ xen-memshare: xen-memshare.o
 xen-vmtrace: xen-vmtrace.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(LDLIBS_libxenforeignmemory) $(APPEND_LDFLAGS)
 
+xen-mceinj: xen-mceinj.o
+	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS)
+
 xenperf: xenperf.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
 
tools/misc/xen-mceinj.c renamed from tools/tests/mce-test/tools/xen-mceinj.c +19 -13
similarity index 97%
rename from tools/tests/mce-test/tools/xen-mceinj.c
rename to tools/misc/xen-mceinj.c
index 1187d01e5f..df55eefbac 100644
@@ -137,7 +137,7 @@ static void err(xc_interface *xc_handle, const char *fmt, ...)
     va_list args;
 
     va_start(args, fmt);
-    if (vasprintf(&buf, fmt, args) < 0)
+    if ( vasprintf(&buf, fmt, args) < 0 )
         abort();
     perror(buf);
     va_end(args);
@@ -173,7 +173,7 @@ static unsigned int mca_cpuinfo(xc_interface *xc_handle)
     mc.cmd = XEN_MC_physcpuinfo;
     mc.interface_version = XEN_MCA_INTERFACE_VERSION;
 
-    if (!xc_mca_op(xc_handle, &mc))
+    if ( !xc_mca_op(xc_handle, &mc) )
         return mc.u.mc_physcpuinfo.ncpus;
     else
         return 0;
@@ -187,9 +187,9 @@ static int inject_cmci(xc_interface *xc_handle, unsigned int cpu_nr)
     memset(&mc, 0, sizeof(struct xen_mc));
 
     nr_cpus = mca_cpuinfo(xc_handle);
-    if (!nr_cpus)
+    if ( !nr_cpus )
         err(xc_handle, "Failed to get mca_cpuinfo");
-    if (cpu_nr >= nr_cpus)
+    if ( cpu_nr >= nr_cpus )
         err(xc_handle, "-c %u is larger than %u", cpu_nr, nr_cpus - 1);
 
     mc.cmd = XEN_MC_inject_v2;
@@ -284,7 +284,7 @@ static int add_msr_intpose(xc_interface *xc_handle,
         flush_msr_inj(xc_handle);
         init_msr_inj();
     }
-    count= msr_inj.mcinj_count;
+    count = msr_inj.mcinj_count;
 
     if ( !count )
     {
@@ -422,7 +422,7 @@ static long xs_get_dom_mem(int domid)
     if (!memstr || !plen)
         return -1;
 
-    mem = atoll(memstr)*1024;
+    mem = atoll(memstr) * 1024;
     free(memstr);
 
     return mem;
@@ -474,17 +474,20 @@ int main(int argc, char *argv[])
     cpu_nr = 0;
 
     init_msr_inj();
-    xc_handle = xc_interface_open(0, 0, 0);
-    if ( !xc_handle ) {
+    xc_handle = xc_interface_open(NULL, NULL, 0);
+    if ( !xc_handle )
+    {
         Lprintf("Failed to get xc interface");
         exit(EXIT_FAILURE);
     }
 
-    while ( 1 ) {
+    while ( 1 )
+    {
         c = getopt_long(argc, argv, "c:Dd:t:hp:l", opts, &opt_index);
         if ( c == -1 )
             break;
-        switch ( c ) {
+        switch ( c )
+        {
         case 'D':
             dump=1;
             break;
@@ -516,7 +519,8 @@ int main(int argc, char *argv[])
         }
     }
 
-    if ( domid != DOMID_XEN ) {
+    if ( domid != DOMID_XEN )
+    {
         max_gpa = xs_get_dom_mem(domid);
         Lprintf("get domain %d max gpa is: 0x%lx", domid, max_gpa);
         if ( gaddr >= max_gpa )
@@ -524,7 +528,8 @@ int main(int argc, char *argv[])
     }
     Lprintf("get gaddr of error inject is: 0x%lx", gaddr);
 
-    if ( dump ) {
+    if ( dump )
+    {
         if ( domid == DOMID_XEN )
             Lprintf("Xen: gaddr=0x%lx", gaddr);
         else
@@ -532,7 +537,8 @@ int main(int argc, char *argv[])
         goto out;
     }
 
-    if ( type < 0 || type >= MCE_TABLE_SIZE ) {
+    if ( type < 0 || type >= MCE_TABLE_SIZE )
+    {
         err(xc_handle, "Unsupported error type");
         goto out;
     }
tools/tests/Makefile +0 -1
index 25531a984a..33e32730c4 100644
@@ -4,7 +4,6 @@ include $(XEN_ROOT)/tools/Rules.mk
 SUBDIRS-y :=
 SUBDIRS-y += resource
 SUBDIRS-$(CONFIG_X86) += cpu-policy
-SUBDIRS-$(CONFIG_X86) += mce-test
 SUBDIRS-$(CONFIG_X86) += tsx
 ifneq ($(clang),y)
 SUBDIRS-$(CONFIG_X86) += x86_emulator
tools/tests/mce-test/Makefile deleted +0 -12
deleted file mode 100644
index 1395df38ac..0000000000
@@ -1,12 +0,0 @@
-.PHONY: all clean distclean
-
-all: 
-	$(MAKE) -C tools
-
-clean:
-	$(MAKE) -C tools clean
-
-distclean:
-	$(MAKE) -C tools distclean
-
-install uninstall:
tools/tests/mce-test/README deleted +0 -75

75 lines not on this page · raw message

tools/tests/mce-test/cases/srao_llc/dom0/cases.sh deleted +0 -73

73 lines not on this page · raw message

tools/tests/mce-test/cases/srao_llc/guest/cases.sh deleted +0 -94

94 lines not on this page · raw message

tools/tests/mce-test/cases/srao_llc/xen/cases.sh deleted +0 -69

69 lines not on this page · raw message

tools/tests/mce-test/cases/srao_mem/dom0/cases.sh deleted +0 -73

73 lines not on this page · raw message

tools/tests/mce-test/cases/srao_mem/guest/cases.sh deleted +0 -94

94 lines not on this page · raw message

tools/tests/mce-test/cases/srao_mem/xen/cases.sh deleted +0 -69

69 lines not on this page · raw message

tools/tests/mce-test/cases/ucna_llc/dom0/cases.sh deleted +0 -72

72 lines not on this page · raw message

tools/tests/mce-test/cases/ucna_llc/guest/cases.sh deleted +0 -92

92 lines not on this page · raw message

tools/tests/mce-test/cases/ucna_llc/xen/cases.sh deleted +0 -68

68 lines not on this page · raw message

tools/tests/mce-test/config/setup.conf deleted +0 -24
deleted file mode 100644
index 05f754dfd6..0000000000
@@ -1,24 +0,0 @@
-#!/bin/bash
-#
-# Software injection based test cases: test cases are triggered via
-# mce-inject tool.
-# Copyright (c) 2010, Intel Corporation
-# 
-# This program is free software; you can redistribute it and/or
-# modify it under the terms 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 <http://www.gnu.org/licenses/>.
-#
-# Author: Xudong Hao <[email protected]>
-#
-
-export MCE_SRAO_MEM=0
-export MCE_SRAO_LLC=1
-export CMCI_UCNA_LLC=2
tools/tests/mce-test/lib/xen-mceinj-tool.sh deleted +0 -260

260 lines not on this page · raw message

tools/tests/mce-test/tools/Makefile deleted +0 -24
deleted file mode 100644
index 0e92ac2977..0000000000
@@ -1,24 +0,0 @@
-XEN_ROOT=$(CURDIR)/../../../..
-include $(XEN_ROOT)/tools/Rules.mk
-
-CFLAGS += -Werror
-CFLAGS += $(CFLAGS_libxenctrl)
-CFLAGS += $(CFLAGS_libxenguest)
-CFLAGS += $(CFLAGS_libxenstore)
-CFLAGS += $(CFLAGS_xeninclude)
-
-.PHONY: all
-all: xen-mceinj
-
-install: xen-mceinj
-	$(INSTALL_PROG) xen-mceinj $(DESTDIR)$(sbindir)
-
-.PHONY: clean
-clean:
-	$(RM) *.o xen-mceinj
-
-.PHONY: distclean
-distclean: clean
-
-xen-mceinj: xen-mceinj.o Makefile
-	$(CC) -o $@ $< $(LDFLAGS) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore)
tools/tests/mce-test/tools/README deleted +0 -24
deleted file mode 100644
index bd0d442bae..0000000000
@@ -1,24 +0,0 @@
-Xen Machine Check Exception(MCE) error inject tool
-----------------------------------------------
-
-xen-mceinj is a software MCE injection tool, which is based on Xen 
-MCE injection mechanism. It allows to inject machine check errors on the
-software level into a running Xen/dom0/VM. This is intended for
-validation of the Xen machine check handler.
-
-With the help of the Makefile, it is possible to compile a binary file 
-named "xen-mceinj".
-
-Usage
------
-$make (make install) --Note: make sure compile xen/tools before do this step
-$./xen-mceinj [OPTION]...
-
-OPTION arguments can be:
-  -D, --dump           dump addr info without error injection
-  -c, --cpu=CPU_ID     target CPU, the default is CPU0
-  -d, --domain=DomID   target domain, the default is Xen itself
-  -p, --page           physical page address, the default is 0x180020
-  -t, --type=error     error type
-
-For detail help, please refer to "./xen-mceinj -h"
Signature · 1 line
2.11.0
#2 lore raw

PATCH v2 2/4 tests/resource: Rework Makefile

In reply to Andrew Cooper

In particular, fill in the install/uninstall rules so this test can be packaged to be automated sensibly.

Make all object files depend on the Makefile, drop redundant -f's for $(RM), and use $(TARGET) when appropriate.

---
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Juergen Gross <[email protected]>

v2:
* Fix typo in commit message
* Drop -f's
* Use %.o rather than *.o for Make level wildcards

---
 tools/tests/resource/Makefile | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
tools/tests/resource/Makefile +8 -3
index 4bef482966..1c3aee4ff7 100644
@@ -12,17 +12,20 @@ run: $(TARGET)
 
 .PHONY: clean
 clean:
-	$(RM) -f -- *.o $(TARGET) $(DEPS_RM)
+	$(RM) -- *.o $(TARGET) $(DEPS_RM)
 
 .PHONY: distclean
 distclean: clean
-	$(RM) -f -- *~
+	$(RM) -- *~
 
 .PHONY: install
 install: all
+	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC_BIN)
+	$(INSTALL_PROG) $(TARGET) $(DESTDIR)$(LIBEXEC_BIN)
 
 .PHONY: uninstall
 uninstall:
+	$(RM) -- $(DESTDIR)$(LIBEXEC_BIN)/$(TARGET)
 
 CFLAGS += -Werror
 CFLAGS += $(CFLAGS_xeninclude)
@@ -34,7 +37,9 @@ LDFLAGS += $(LDLIBS_libxenctrl)
 LDFLAGS += $(LDLIBS_libxenforeignmemory)
 LDFLAGS += $(APPEND_LDFLAGS)
 
-test-resource: test-resource.o
+%.o: Makefile
+
+$(TARGET): test-resource.o
 	$(CC) -o $@ $< $(LDFLAGS)
 
 -include $(DEPS_INCLUDE)
Signature · 1 line
2.11.0
Reviewed-by on v2 2/4
#3 lore raw

Re: [PATCH 2/4] tests/resource: Rework Makefile

Quoted 7 lines · Andrew Cooper

In particular, fill in the install/uninstall rules so this test can be packaged to be automated sensibly.

Make all object files depend on the Makefile, drop redundant -f's for $(RM), and use $(TARGET) when appropriate.

tools/tests/resource/Makefile run: $(TARGET) · line 19

Quoted 13 lines
tools/tests/resource/Makefile +2 -2
@@ -12,17 +12,20 @@ run: $(TARGET)
 
 .PHONY: clean
 clean:
-	$(RM) -f -- *.o $(TARGET) $(DEPS_RM)
+	$(RM) -- *.o $(TARGET) $(DEPS_RM)
 
 .PHONY: distclean
 distclean: clean
-	$(RM) -f -- *~
+	$(RM) -- *~

While needing to repeat very similar clean: rules in every Makefile is already looking odd to me, having to repeat this distclean: rule everywhere leaves me with even more question marks. But of course this is nothing you introduce here, so merely a remark.

Jan

#4 lore raw

PATCH v2 3/4 tests/cpu-policy: Rework Makefile

In reply to Andrew Cooper

In particular, fill in the install/uninstall rules so this test can be packaged to be automated sensibly.

Rework TARGET-y to be TARGETS, drop redundant -f's for $(RM), drop the unconditional -O3 and use the default instead, and drop CFLAGS from the link line but honour APPEND_LDFLAGS.

---
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Juergen Gross <[email protected]>

v2:
* Drop -f's
* Use %.o rather than *.o for Make level wildcards

---
 tools/tests/cpu-policy/Makefile | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)
tools/tests/cpu-policy/Makefile +19 -12
index 70ff154da6..161732ad16 100644
@@ -1,21 +1,19 @@
 XEN_ROOT = $(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
-TARGET-y := test-cpu-policy
+TARGETS :=
 
 # For brevity, these tests make extensive use of designated initialisers in
 # anonymous unions, but GCCs older than 4.6 can't cope.  Ignore the test in
 # this case.
-ifneq ($(clang),y)
-TARGET-$(call cc-ver,$(CC),lt,0x040600) :=
-endif
-
-ifeq ($(TARGET-y),)
+ifneq ($(gcc)$(call cc-ver,$(CC),lt,0x040600),yy)
+TARGETS += test-cpu-policy
+else
 $(warning Test harness not built, use newer compiler than "$(CC)" (version $(shell $(CC) -dumpversion)))
 endif
 
 .PHONY: all
-all: $(TARGET-y)
+all: $(TARGETS)
 
 .PHONY: run
 run: $(TARGET-y)
@@ -23,23 +21,32 @@ run: $(TARGET-y)
 
 .PHONY: clean
 clean:
-	$(RM) -f -- *.o .*.d .*.d2 test-cpu-policy
+	$(RM) -- *.o $(TARGETS) $(DEPS_RM)
 
 .PHONY: distclean
 distclean: clean
-	$(RM) -f -- *~
+	$(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_xeninclude) -D__XEN_TOOLS__ -O3
+CFLAGS += -Werror -D__XEN_TOOLS__
+CFLAGS += $(CFLAGS_xeninclude)
 CFLAGS += $(APPEND_CFLAGS)
 
-vpath %.c ../../../xen/lib/x86
+LDFLAGS += $(APPEND_LDFLAGS)
+
+vpath %.c $(XEN_ROOT)/xen/lib/x86
+
+%.o: Makefile
 
 test-cpu-policy: test-cpu-policy.o msr.o cpuid.o policy.o
-	$(CC) $(CFLAGS) $^ -o $@
+	$(CC) $^ -o $@ $(LDFLAGS)
 
 -include $(DEPS_INCLUDE)
Signature · 1 line
2.11.0
Reviewed-by on v2 3/4
#5 lore raw

Re: [PATCH 3/4] tests/cpu-policy: Rework Makefile

Quoted 20 lines · Andrew Cooper
tools/tests/cpu-policy/Makefile +6 -2
@@ -23,23 +21,32 @@ run: $(TARGET-y)
 
 .PHONY: clean
 clean:
-	$(RM) -f -- *.o .*.d .*.d2 test-cpu-policy
+	$(RM) -- *.o $(TARGETS) $(DEPS_RM)
 
 .PHONY: distclean
 distclean: clean
-	$(RM) -f -- *~
+	$(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))

tools/tests/cpu-policy/Makefile run: $(TARGET-y) · line 45

Quoted 10 lines
tools/tests/cpu-policy/Makefile +5 -2
 
-CFLAGS += -Werror $(CFLAGS_xeninclude) -D__XEN_TOOLS__ -O3
+CFLAGS += -Werror -D__XEN_TOOLS__
+CFLAGS += $(CFLAGS_xeninclude)
 CFLAGS += $(APPEND_CFLAGS)
 
-vpath %.c ../../../xen/lib/x86
+LDFLAGS += $(APPEND_LDFLAGS)
+
+vpath %.c $(XEN_ROOT)/xen/lib/x86

Is this a good move? In general I think relative references are better, because it is then possible to move the tree as a whole (or access it from multiple locations, where each one has it appearing in a different place in the file system). I do realize though that we have many such absolute references, so this one more isn't making things much worse. Still

preferably with it left relative (or a strong reason for making it absolute spelled out in the description).

Jan

#6 lore raw

PATCH v2 4/4 tests/xenstore: Rework Makefile

In reply to Andrew Cooper

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.

---
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Juergen Gross <[email protected]>

v2:
* Drop -f's
* Fix CI breakage, now that CI can build the test.

---
 .gitignore                                         |  1 -
 tools/tests/xenstore/.gitignore                    |  1 +
 tools/tests/xenstore/Makefile                      | 31 +++++++++++++++-------
 .../tests/xenstore/{xs-test.c => test-xenstore.c}  |  8 ++++--
 4 files changed, 29 insertions(+), 12 deletions(-)
 create mode 100644 tools/tests/xenstore/.gitignore
 rename tools/tests/xenstore/{xs-test.c => test-xenstore.c} (98%)
.gitignore +0 -1
index d4b90303b2..8ebb51b6c5 100644
@@ -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
tools/tests/xenstore/.gitignore new file +1 -0
new file mode 100644
index 0000000000..4b44f5dd60
@@ -0,0 +1 @@
+test-xenstore
tools/tests/xenstore/Makefile +22 -9
index a367d88803..b9969dd090 100644
@@ -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)
tools/tests/xenstore/test-xenstore.c renamed from tools/tests/xenstore/xs-test.c +6 -2
similarity index 98%
rename from tools/tests/xenstore/xs-test.c
rename to tools/tests/xenstore/test-xenstore.c
index c4c99c0661..d3574b3fa2 100644
@@ -20,6 +20,7 @@
  */
 
 #define _GNU_SOURCE
+#include <err.h>
 #include <getopt.h>
 #include <inttypes.h>
 #include <stdbool.h>
@@ -483,11 +484,14 @@ int main(int argc, char *argv[])
         return 0;
     }
 
-    asprintf(&path, "%s/%u", TEST_PATH, getpid());
+    if ( asprintf(&path, "%s/%u", TEST_PATH, getpid()) < 0 )
+        err(2, "asprintf() malloc failure\n");
+
     for ( t = 0; t < WRITE_BUFFERS_N; t++ )
     {
         memset(write_buffers[t], 'a' + t, WRITE_BUFFERS_SIZE);
-        asprintf(&paths[t], "%s/%c", path, 'a' + t);
+        if ( asprintf(&paths[t], "%s/%c", path, 'a' + t) < 0 )
+            err(2, "asprintf() malloc failure\n");
     }
 
     xsh = xs_open(0);
Signature · 1 line
2.11.0
Reviewed-by on v2 4/4
#7 lore raw

Re: [PATCH 4/4] tests/xenstore: Rework Makefile

Quoted 11 lines · Andrew Cooper

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());
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 6 lines

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.

#8 lore raw
In reply to Andrew Cooper
Quoted 5 lines · Andrew Cooper

v2:
* Fix CI failures from newly-exposed logic
* Drop -f's from $(RM)
* Drop the 'run' rune patch. Its clearly controvertial, but ignoring the problems isn't an available option in the longterm.

What is "the problem" here? The presence of the run targets in the first place (and their wiring up from the top level Makefile, allowing direct invocation)? If so, I'm afraid so far I haven't seen replacement proposals by you (nor why exactly this would be a problem).

Quoted 1 line

All other RFC questions still outstanding.

I didn't find any here or in the individual patches.

Also a remark on patches 2 ... 4 each saying "fill in the install/uninstall rules so this test can be packaged to be automated sensibly": Why is running (or at least picking) tests from the build area not an option in an automated environment? And why is installing tests unconditionally a generally good idea? I'd view this as unnecessary bloat for the majority of downstreams.

Jan