]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Framework to do module-specific tests
authorAlan T. DeKok <aland@freeradius.org>
Mon, 22 Dec 2014 16:40:20 +0000 (11:40 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 22 Dec 2014 16:54:00 +0000 (11:54 -0500)
With examples and documentation

Makefile
src/all.mk
src/tests/all.mk
src/tests/modules/README.rst [new file with mode: 0644]
src/tests/modules/all.mk [new file with mode: 0644]
src/tests/modules/files/all.mk [new file with mode: 0644]

index 89a84ad81ce6e4c134a65aac6523d8c1daf9a60c..548b768bdb97a38fc7b120323abbbef5ab2ccd56 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -52,7 +52,7 @@ $(BUILD_DIR)/tests/radiusd-c: raddb/test.conf ${BUILD_DIR}/bin/radiusd | build.r
        @echo "ok"
        @touch $@
 
-test: ${BUILD_DIR}/bin/radiusd ${BUILD_DIR}/bin/radclient tests.unit tests.keywords tests.auth $(BUILD_DIR)/tests/radiusd-c | build.raddb
+test: ${BUILD_DIR}/bin/radiusd ${BUILD_DIR}/bin/radclient tests.unit tests.keywords tests.auth tests.modules $(BUILD_DIR)/tests/radiusd-c | build.raddb
        @$(MAKE) -C src/tests tests
 
 #  Tests specifically for Travis.  We do a LOT more than just
index 16ea457c9c785e4b6bea5e502bb9348fb088f594..b3dfdbd71c451b441082a4a17b06c956a5fc86fe 100644 (file)
@@ -12,4 +12,4 @@ ifeq "$(shell [ -e src/freeradius-devel ] || ln -s include src/freeradius-devel)
 # do nothing
 endif
 
-SUBMAKEFILES := include/all.mk lib/all.mk tests/all.mk modules/all.mk main/all.mk
+SUBMAKEFILES := include/all.mk lib/all.mk modules/all.mk main/all.mk tests/all.mk
index 77ca1cc84fded89409516c9b020cbee1c0772f49..fd7ee97af4db266f9506b98080a77434cef9e575 100644 (file)
@@ -1,4 +1,4 @@
-SUBMAKEFILES := rbmonkey.mk unit/all.mk keywords/all.mk auth/all.mk
+SUBMAKEFILES := rbmonkey.mk unit/all.mk keywords/all.mk auth/all.mk modules/all.mk
 
 #
 #  Include all of the autoconf definitions into the Make variable space
diff --git a/src/tests/modules/README.rst b/src/tests/modules/README.rst
new file mode 100644 (file)
index 0000000..bcad79b
--- /dev/null
@@ -0,0 +1,15 @@
+Module Tests
+------------
+
+To test module `foo`, create a directory `foo`, and put a file `all.mk` into it, e.g.
+
+    foo/all.mk
+
+All of the tests for the module should go here.  The tests will be run
+*only* if the module is available, and has been built correctly on the system.
+
+The file should contain a target "MODULE.test".  This is the main
+target used to test the module.  The framework automatically makes the
+tests depend on the module (i.e. library).  So if the module source
+changes, you can just do `make MODULE.test`.  The module will be
+re-built, and the tests will be run.
diff --git a/src/tests/modules/all.mk b/src/tests/modules/all.mk
new file mode 100644 (file)
index 0000000..56bcef8
--- /dev/null
@@ -0,0 +1,27 @@
+#
+#  Find the subdirs which have "all.mk"
+#
+TEST_SUBDIRS := $(patsubst src/tests/modules/%/all.mk,%,$(wildcard src/tests/modules/*/all.mk))
+
+#
+#  Find out which of those have a similar target.  i.e. modules/foo -> rlm_foo.la
+#
+TEST_TARGETS := $(foreach x,$(TEST_SUBDIRS),$(findstring rlm_$x.la,$(ALL_TGTS)))
+
+TEST_BUILT := $(patsubst rlm_%.la,%,$(TEST_TARGETS))
+
+#
+#  For the remaining ones, add on the directory to include.
+#
+SUBMAKEFILES := $(addsuffix /all.mk,$(TEST_BUILT))
+
+#
+#  Ensure that the tests depend on the module, so that changes to the
+#  module will re-run the test
+#
+$(foreach x,$(TEST_BUILT),$(eval $x.test: rlm_$x.la))
+
+#
+#  Add the module tests to the overall dependencies
+#
+tests.modules: tests.unit tests.keywords tests.auth $(patsubst %,%.test,$(TEST_BUILT))
diff --git a/src/tests/modules/files/all.mk b/src/tests/modules/files/all.mk
new file mode 100644 (file)
index 0000000..74619db
--- /dev/null
@@ -0,0 +1,7 @@
+#
+#  Test the "files" module
+#
+
+#  MODULE.test is the main target for this module.
+files.test:
+       @echo OK: files.test