From: Alan T. DeKok Date: Mon, 22 Dec 2014 16:40:20 +0000 (-0500) Subject: Framework to do module-specific tests X-Git-Tag: release_3_0_7~422 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3007ea11e801b710a48cffb42a801cccbf6a355d;p=thirdparty%2Ffreeradius-server.git Framework to do module-specific tests With examples and documentation --- diff --git a/Makefile b/Makefile index 89a84ad81ce..548b768bdb9 100644 --- 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 diff --git a/src/all.mk b/src/all.mk index 16ea457c9c7..b3dfdbd71c4 100644 --- a/src/all.mk +++ b/src/all.mk @@ -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 diff --git a/src/tests/all.mk b/src/tests/all.mk index 77ca1cc84fd..fd7ee97af4d 100644 --- a/src/tests/all.mk +++ b/src/tests/all.mk @@ -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 index 00000000000..bcad79b3b13 --- /dev/null +++ b/src/tests/modules/README.rst @@ -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 index 00000000000..56bcef8dee4 --- /dev/null +++ b/src/tests/modules/all.mk @@ -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 index 00000000000..74619dbd894 --- /dev/null +++ b/src/tests/modules/files/all.mk @@ -0,0 +1,7 @@ +# +# Test the "files" module +# + +# MODULE.test is the main target for this module. +files.test: + @echo OK: files.test