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

[PATCH 1/7] tools/tests/*/Makefile: factor out common PHONY rules into Rules.mk



Introduce a new tools/tests/Rules.mk that must be included *last* in a
Makefile, after TARGETS is defined.
This reduces the boilerplate that must be copy pasted when new tests are
written.

Renamed TESTS to TARGETS in tools/tests/domid/Makefile
Extend DEPS_RM, so that most tests don't need custom clean rules,
except in tools/tests/domid which needs to remove a directory too.

Make the run rules consistent: do not attempt to run the tests if HOSTCC != CC.

The common rules use the rule forms which allow multiple TARGETS.

tools/tests/x86_emulator/Makefile is unchanged, since this has a lot of
conditional rules that are very different from the other tests.

Signed-off-by: Edwin Török <edwin.torok@xxxxxxxxxx>
---
 tools/tests/Rules.mk                | 48 +++++++++++++++++++++++++++++
 tools/tests/cpu-policy/Makefile     | 26 +---------------
 tools/tests/domid/Makefile          | 28 ++---------------
 tools/tests/mem-claim/Makefile      | 23 ++------------
 tools/tests/paging-mempool/Makefile | 23 ++------------
 tools/tests/pdx/Makefile            | 33 ++------------------
 tools/tests/rangeset/Makefile       | 27 ++--------------
 tools/tests/resource/Makefile       | 27 ++--------------
 tools/tests/tsx/Makefile            | 26 ++--------------
 tools/tests/vpci/Makefile           | 30 +++---------------
 tools/tests/xenstore/Makefile       | 29 ++---------------
 11 files changed, 72 insertions(+), 248 deletions(-)
 create mode 100644 tools/tests/Rules.mk

diff --git a/tools/tests/Rules.mk b/tools/tests/Rules.mk
new file mode 100644
index 0000000000..f7ef76bf4f
--- /dev/null
+++ b/tools/tests/Rules.mk
@@ -0,0 +1,48 @@
+# Usage: include this last in your Makefile.
+#
+# For example:
+#
+# XEN_ROOT = $(CURDIR)/../../..
+# include $(XEN_ROOT)/tools/Rules.mk
+#
+# TARGETS := ...
+# ...
+# include $(XEN_ROOT)/tools/tests/Rules.mk
+
+ifndef XEN_ROOT
+$(error XEN_ROOT is not defined)
+endif
+
+.PHONY: all
+all: $(TARGETS)
+.DEFAULT_GOAL: all
+
+.PHONY: run
+run: $(TARGETS)
+ifeq ($(CC),$(HOSTCC))
+       set -e;             \
+       for test in $? ; do \
+               ./$$test ;  \
+       done
+else
+       $(warning HOSTCC != CC, will not run test)
+endif
+
+.PHONY: clean
+clean::
+       $(RM) -- *.o $(TARGETS) $(DEPS_RM)
+
+.PHONY: distclean
+distclean: clean
+       $(RM) -- *~
+
+.PHONY: install
+install: all
+       $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
+       $(if $(TARGETS),$(INSTALL_PROG) $(TARGETS) $(DESTDIR)$(LIBEXEC)/tests)
+
+.PHONY: uninstall
+uninstall:
+       $(RM) -- $(addprefix $(DESTDIR)$(LIBEXEC)/tests/,$(TARGETS))
+
+-include $(DEPS_INCLUDE)
diff --git a/tools/tests/cpu-policy/Makefile b/tools/tests/cpu-policy/Makefile
index 24f87e2eca..700e325215 100644
--- a/tools/tests/cpu-policy/Makefile
+++ b/tools/tests/cpu-policy/Makefile
@@ -12,30 +12,6 @@ else
 $(warning Test harness not built, use newer compiler than "$(CC)" (version 
$(shell $(CC) -dumpversion)))
 endif
 
-.PHONY: all
-all: $(TARGETS)
-
-.PHONY: run
-run: $(TARGETS)
-       ./$<
-
-.PHONY: clean
-clean:
-       $(RM) -- *.o $(TARGETS) $(DEPS_RM)
-
-.PHONY: distclean
-distclean: clean
-       $(RM) -- *~
-
-.PHONY: install
-install: all
-       $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-       $(if $(TARGETS),$(INSTALL_PROG) $(TARGETS) $(DESTDIR)$(LIBEXEC)/tests)
-
-.PHONY: uninstall
-uninstall:
-       $(RM) -- $(addprefix $(DESTDIR)$(LIBEXEC)/tests/,$(TARGETS))
-
 CFLAGS += -D__XEN_TOOLS__
 CFLAGS += $(CFLAGS_xeninclude)
 CFLAGS += $(APPEND_CFLAGS)
@@ -49,4 +25,4 @@ vpath %.c ../../../xen/lib/x86
 test-cpu-policy: test-cpu-policy.o msr.o cpuid.o policy.o
        $(CC) $^ -o $@ $(LDFLAGS)
 
--include $(DEPS_INCLUDE)
+include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/domid/Makefile b/tools/tests/domid/Makefile
index 753129029e..92f11777f2 100644
--- a/tools/tests/domid/Makefile
+++ b/tools/tests/domid/Makefile
@@ -7,7 +7,7 @@
 XEN_ROOT=$(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
-TESTS := test-domid
+TARGETS += test-domid
 
 define list-c-headers
 $(shell sed -n \
@@ -36,30 +36,8 @@ vpath $(1) $(2)
 $(call emit-harness-deps,$(1),$(call list-c-headers,$(2)$(1)))
 endef
 
-.PHONY: all
-all: $(TESTS)
-
-.PHONY: run
-run: $(TESTS)
-       set -e; $(foreach t,$(TESTS),./$(t);)
-
-.PHONY: clean
-clean:
+clean::
        $(RM) -r generated
-       $(RM) -- *.o $(TESTS) $(DEPS_RM)
-
-.PHONY: distclean
-distclean: clean
-       $(RM) -- *~
-
-.PHONY: install
-install: all
-       $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-       $(INSTALL_PROG) test-domid $(DESTDIR)$(LIBEXEC)/tests
-
-.PHONY: uninstall
-uninstall:
-       $(RM) -- $(DESTDIR)$(LIBEXEC)/tests/test-domid
 
 CFLAGS += -D__XEN_TOOLS__
 # find-next-bit.c
@@ -85,4 +63,4 @@ $(eval $(call 
vpath-with-harness-deps,domid.c,$(XEN_ROOT)/xen/common/))
 test-domid: domid.o find-next-bit.o test-domid.o
        $(CC) $^ -o $@ $(LDFLAGS)
 
--include $(DEPS_INCLUDE)
+include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/mem-claim/Makefile b/tools/tests/mem-claim/Makefile
index 76ba3e3c8b..6790e48417 100644
--- a/tools/tests/mem-claim/Makefile
+++ b/tools/tests/mem-claim/Makefile
@@ -2,26 +2,7 @@ XEN_ROOT = $(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
 TARGET := test-mem-claim
-
-.PHONY: all
-all: $(TARGET)
-
-.PHONY: clean
-clean:
-       $(RM) -- *.o $(TARGET) $(DEPS_RM)
-
-.PHONY: distclean
-distclean: clean
-       $(RM) -- *~
-
-.PHONY: install
-install: all
-       $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-       $(INSTALL_PROG) $(TARGET) $(DESTDIR)$(LIBEXEC)/tests
-
-.PHONY: uninstall
-uninstall:
-       $(RM) -- $(DESTDIR)$(LIBEXEC)/tests/$(TARGET)
+TARGETS := $(TARGET)
 
 CFLAGS += $(CFLAGS_xeninclude)
 CFLAGS += $(CFLAGS_libxenctrl)
@@ -35,4 +16,4 @@ LDFLAGS += $(APPEND_LDFLAGS)
 $(TARGET): test-mem-claim.o
        $(CC) -o $@ $< $(LDFLAGS)
 
--include $(DEPS_INCLUDE)
+include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/paging-mempool/Makefile 
b/tools/tests/paging-mempool/Makefile
index a1e12584ce..9ebeb24ab6 100644
--- a/tools/tests/paging-mempool/Makefile
+++ b/tools/tests/paging-mempool/Makefile
@@ -2,26 +2,7 @@ XEN_ROOT = $(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
 TARGET := test-paging-mempool
-
-.PHONY: all
-all: $(TARGET)
-
-.PHONY: clean
-clean:
-       $(RM) -- *.o $(TARGET) $(DEPS_RM)
-
-.PHONY: distclean
-distclean: clean
-       $(RM) -- *~
-
-.PHONY: install
-install: all
-       $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-       $(INSTALL_PROG) $(TARGET) $(DESTDIR)$(LIBEXEC)/tests
-
-.PHONY: uninstall
-uninstall:
-       $(RM) -- $(DESTDIR)$(LIBEXEC)/tests/$(TARGET)
+TARGETS := $(TARGET)
 
 CFLAGS += $(CFLAGS_xeninclude)
 CFLAGS += $(CFLAGS_libxenctrl)
@@ -35,4 +16,4 @@ LDFLAGS += $(APPEND_LDFLAGS)
 $(TARGET): test-paging-mempool.o
        $(CC) -o $@ $< $(LDFLAGS)
 
--include $(DEPS_INCLUDE)
+include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/pdx/Makefile b/tools/tests/pdx/Makefile
index 3c431d7c78..a5129a8282 100644
--- a/tools/tests/pdx/Makefile
+++ b/tools/tests/pdx/Makefile
@@ -3,36 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 TARGETS := test-pdx-mask test-pdx-offset
 
-.PHONY: all
-all: $(TARGETS)
-
-.PHONY: run
-run: $(TARGETS)
-ifeq ($(CC),$(HOSTCC))
-       set -e;             \
-       for test in $? ; do \
-               ./$$test ;  \
-       done
-else
-       $(warning HOSTCC != CC, will not run test)
-endif
-
-.PHONY: clean
-clean:
-       $(RM) -- *.o $(TARGETS) $(DEPS_RM) pdx.h
-
-.PHONY: distclean
-distclean: clean
-       $(RM) -- *~
-
-.PHONY: install
-install: all
-       $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-       $(INSTALL_PROG) $(TARGETS) $(DESTDIR)$(LIBEXEC)/tests
-
-.PHONY: uninstall
-uninstall:
-       $(RM) -- $(patsubst %,$(DESTDIR)$(LIBEXEC)/tests/%,$(TARGETS))
+DEPS_RM += pdx.h
 
 pdx.h: $(XEN_ROOT)/xen/include/xen/pdx.h
        sed -e '/^#[[:space:]]*include/d' <$< >$@
@@ -47,4 +18,4 @@ test-pdx-offset: CFLAGS += -DCONFIG_PDX_OFFSET_COMPRESSION
 test-pdx-%: test-pdx.c pdx.h
        $(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_$*.o) -o $@ $< $(APPEND_CFLAGS)
 
--include $(DEPS_INCLUDE)
+include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/rangeset/Makefile b/tools/tests/rangeset/Makefile
index e3bfce471c..c76746ce7a 100644
--- a/tools/tests/rangeset/Makefile
+++ b/tools/tests/rangeset/Makefile
@@ -2,30 +2,9 @@ XEN_ROOT=$(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
 TARGET := test-rangeset
+TARGETS := $(TARGET)
 
-.PHONY: all
-all: $(TARGET)
-
-.PHONY: run
-run: $(TARGET)
-       ./$<
-
-.PHONY: clean
-clean:
-       $(RM) -- *.o $(TARGET) $(DEPS_RM) list.h rangeset.h rangeset.c
-
-.PHONY: distclean
-distclean: clean
-       $(RM) -- *~
-
-.PHONY: install
-install: all
-       $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-       $(INSTALL_PROG) $(TARGET) $(DESTDIR)$(LIBEXEC)/tests
-
-.PHONY: uninstall
-uninstall:
-       $(RM) -- $(addprefix $(DESTDIR)$(LIBEXEC)/tests/,$(TARGET))
+DEPS_RM += list.h rangeset.h rangeset.c
 
 list.h: $(XEN_ROOT)/xen/include/xen/list.h
 rangeset.h: $(XEN_ROOT)/xen/include/xen/rangeset.h
@@ -47,4 +26,4 @@ test-rangeset.o rangeset.o: list.h rangeset.h
 test-rangeset: rangeset.o test-rangeset.o
        $(CC) $^ -o $@ $(LDFLAGS)
 
--include $(DEPS_INCLUDE)
+include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/resource/Makefile b/tools/tests/resource/Makefile
index 09d678fffe..764e34f3fa 100644
--- a/tools/tests/resource/Makefile
+++ b/tools/tests/resource/Makefile
@@ -2,30 +2,7 @@ XEN_ROOT = $(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
 TARGET := test-resource
-
-.PHONY: all
-all: $(TARGET)
-
-.PHONY: run
-run: $(TARGET)
-       ./$(TARGET)
-
-.PHONY: clean
-clean:
-       $(RM) -- *.o $(TARGET) $(DEPS_RM)
-
-.PHONY: distclean
-distclean: clean
-       $(RM) -- *~
-
-.PHONY: install
-install: all
-       $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-       $(INSTALL_PROG) $(TARGET) $(DESTDIR)$(LIBEXEC)/tests
-
-.PHONY: uninstall
-uninstall:
-       $(RM) -- $(DESTDIR)$(LIBEXEC)/tests/$(TARGET)
+TARGETS := $(TARGET)
 
 CFLAGS += $(CFLAGS_xeninclude)
 CFLAGS += $(CFLAGS_libxenctrl)
@@ -43,4 +20,4 @@ LDFLAGS += $(APPEND_LDFLAGS)
 $(TARGET): test-resource.o
        $(CC) -o $@ $< $(LDFLAGS)
 
--include $(DEPS_INCLUDE)
+include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/tsx/Makefile b/tools/tests/tsx/Makefile
index 0bb7e70103..817a63b085 100644
--- a/tools/tests/tsx/Makefile
+++ b/tools/tests/tsx/Makefile
@@ -2,29 +2,7 @@ XEN_ROOT = $(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
 TARGET := test-tsx
-
-.PHONY: all
-all: $(TARGET)
-
-.PHONY: clean
-clean:
-       $(RM) -- *.o $(TARGET) $(DEPS_RM)
-
-.PHONY: distclean
-distclean: clean
-       $(RM) -- *~
-
-.PHONY: install
-install: all
-       $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-       $(INSTALL_PROG) $(TARGET) $(DESTDIR)$(LIBEXEC)/tests
-
-.PHONY: uninstall
-uninstall:
-       $(RM) -- $(DESTDIR)$(LIBEXEC)/tests/$(TARGET)
-
-.PHONY: uninstall
-uninstall:
+TARGETS := $(TARGET)
 
 CFLAGS += -I$(XEN_ROOT)/tools/libs/ctrl -I$(XEN_ROOT)/tools/libs/guest
 CFLAGS += $(CFLAGS_xeninclude)
@@ -41,4 +19,4 @@ LDFLAGS += $(APPEND_LDFLAGS)
 $(TARGET): test-tsx.o
        $(CC) -o $@ $< $(LDFLAGS)
 
--include $(DEPS_INCLUDE)
+include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/vpci/Makefile b/tools/tests/vpci/Makefile
index 97359ff67f..597303e31d 100644
--- a/tools/tests/vpci/Makefile
+++ b/tools/tests/vpci/Makefile
@@ -2,36 +2,12 @@ XEN_ROOT=$(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
 TARGET := test_vpci
-
-.PHONY: all
-all: $(TARGET)
-
-.PHONY: run
-run: $(TARGET)
-ifeq ($(CC),$(HOSTCC))
-       ./$(TARGET)
-else
-       $(warning HOSTCC != CC, will not run test)
-endif
+TARGETS := $(TARGET)
 
 $(TARGET): vpci.c vpci.h list.h main.c emul.h
        $(CC) $(CFLAGS_xeninclude) -g -o $@ vpci.c main.c
 
-.PHONY: clean
-clean:
-       rm -rf $(TARGET) *.o *~ vpci.h vpci.c list.h
-
-.PHONY: distclean
-distclean: clean
-
-.PHONY: install
-install: all
-       $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-       $(INSTALL_PROG) $(TARGET) $(DESTDIR)$(LIBEXEC)/tests
-
-.PHONY: uninstall
-uninstall:
-       $(RM) -- $(DESTDIR)$(LIBEXEC)/tests/$(TARGET)
+DEPS_RM += vpci.h vpci.c list.h
 
 vpci.c: $(XEN_ROOT)/xen/drivers/vpci/vpci.c
        # Remove includes and add the test harness header
@@ -41,3 +17,5 @@ list.h: $(XEN_ROOT)/xen/include/xen/list.h
 vpci.h: $(XEN_ROOT)/xen/include/xen/vpci.h
 list.h vpci.h:
        sed -e '/#include/d' <$< >$@
+
+include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/xenstore/Makefile b/tools/tests/xenstore/Makefile
index 2ee4a1327e..56cfe07f25 100644
--- a/tools/tests/xenstore/Makefile
+++ b/tools/tests/xenstore/Makefile
@@ -1,31 +1,8 @@
 XEN_ROOT=$(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
-TARGETS-y := test-xenstore
-TARGETS := $(TARGETS-y)
-
-.PHONY: all
-all: build
-
-.PHONY: build
-build: $(TARGETS)
-
-.PHONY: clean
-clean:
-       $(RM) -- *.o $(TARGETS) $(DEPS_RM)
-
-.PHONY: distclean
-distclean: clean
-       $(RM) -- *~
-
-.PHONY: install
-install: all
-       $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-       $(if $(TARGETS),$(INSTALL_PROG) $(TARGETS) $(DESTDIR)$(LIBEXEC)/tests)
-
-.PHONY: uninstall
-uninstall:
-       $(RM) -- $(addprefix $(DESTDIR)$(LIBEXEC)/tests/,$(TARGETS))
+TARGET := test-xenstore
+TARGETS := $(TARGET)
 
 CFLAGS += $(CFLAGS_libxenstore)
 CFLAGS += $(APPEND_CFLAGS)
@@ -41,4 +18,4 @@ endif
 test-xenstore: test-xenstore.o
        $(CC) -o $@ $< $(LDFLAGS)
 
--include $(DEPS_INCLUDE)
+include $(XEN_ROOT)/tools/tests/Rules.mk
-- 
2.47.3




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.