summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-02-13 21:13:50 -0500
committerGitHub <noreply@github.com>2017-02-13 21:13:50 -0500
commitf34182f00e5517c22cba81a8886481e804f4cc78 (patch)
tree9ed878e2ae674614a7e5b1798fdb44877fb0e83a
parent4a027e1935c630e71efdc829c4b72492ad25cbde (diff)
parent4f8425b8d5a3fb2e5ec24b77f1a7a95db55f532c (diff)
Merge pull request #5298 from martinpitt/relocatable-tests
test: make unit tests relocatable and add an "install-tests" make target
-rw-r--r--Makefile.am48
-rw-r--r--src/resolve/test-dns-packet.c4
-rw-r--r--src/shared/tests.c13
-rw-r--r--src/shared/tests.h1
-rw-r--r--src/test/test-cgroup-mask.c2
-rw-r--r--src/test/test-engine.c2
-rw-r--r--src/test/test-execute.c2
-rw-r--r--src/test/test-helper.h5
-rw-r--r--src/test/test-path.c2
-rw-r--r--src/test/test-sched-prio.c2
-rw-r--r--test/test-resolve/_443._tcp.fedoraproject.org.pkts (renamed from src/resolve/test-data/_443._tcp.fedoraproject.org.pkts)bin169 -> 169 bytes
-rw-r--r--test/test-resolve/_openpgpkey.fedoraproject.org.pkts (renamed from src/resolve/test-data/_openpgpkey.fedoraproject.org.pkts)bin986 -> 986 bytes
-rw-r--r--test/test-resolve/fake-caa.pkts (renamed from src/resolve/test-data/fake-caa.pkts)bin196 -> 196 bytes
-rw-r--r--test/test-resolve/fedoraproject.org.pkts (renamed from src/resolve/test-data/fedoraproject.org.pkts)bin1483 -> 1483 bytes
-rw-r--r--test/test-resolve/gandi.net.pkts (renamed from src/resolve/test-data/gandi.net.pkts)bin1010 -> 1010 bytes
-rw-r--r--test/test-resolve/google.com.pkts (renamed from src/resolve/test-data/google.com.pkts)bin747 -> 747 bytes
-rw-r--r--test/test-resolve/kyhwana.org.pkts (renamed from src/resolve/test-data/kyhwana.org.pkts)bin1803 -> 1803 bytes
-rw-r--r--test/test-resolve/root.pkts (renamed from src/resolve/test-data/root.pkts)bin1061 -> 1061 bytes
-rw-r--r--test/test-resolve/sw1a1aa-sw1a2aa-sw1a2ab-sw1a2ac.find.me.uk.pkts (renamed from src/resolve/test-data/sw1a1aa-sw1a2aa-sw1a2ab-sw1a2ac.find.me.uk.pkts)bin330 -> 330 bytes
-rw-r--r--test/test-resolve/teamits.com.pkts (renamed from src/resolve/test-data/teamits.com.pkts)bin1021 -> 1021 bytes
-rw-r--r--test/test-resolve/zbyszek@fedoraproject.org.pkts (renamed from src/resolve/test-data/zbyszek@fedoraproject.org.pkts)bin2533 -> 2533 bytes
21 files changed, 60 insertions, 21 deletions
diff --git a/Makefile.am b/Makefile.am
index 77e5aa7402..c45755f36e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -93,6 +93,7 @@ kernelinstalldir = $(prefix)/lib/kernel/install.d
factory_etcdir = $(datadir)/factory/etc
factory_pamdir = $(datadir)/factory/etc/pam.d
bootlibdir = $(prefix)/lib/systemd/boot/efi
+testsdir = $(prefix)/lib/systemd/tests
# And these are the special ones for /
rootprefix=@rootprefix@
@@ -133,6 +134,7 @@ check_DATA =
dist_rootlibexec_DATA =
tests=
manual_tests =
+TEST_DATA_FILES =
TEST_EXTENSIONS = .py
PY_LOG_COMPILER = $(PYTHON)
DISABLE_HARD_ERRORS = yes
@@ -150,6 +152,7 @@ endif
AM_TESTS_ENVIRONMENT = \
export SYSTEMD_KBD_MODEL_MAP=$(abs_top_srcdir)/src/locale/kbd-model-map; \
export SYSTEMD_LANGUAGE_FALLBACK_MAP=$(abs_top_srcdir)/src/locale/language-fallback-map; \
+ export TEST_DIR=$(abs_top_srcdir)/test; \
export PATH=$(abs_top_builddir):$$PATH;
if ENABLE_BASH_COMPLETION
@@ -218,7 +221,6 @@ AM_CPPFLAGS = \
-DLIBDIR=\"$(libdir)\" \
-DROOTLIBDIR=\"$(rootlibdir)\" \
-DROOTLIBEXECDIR=\"$(rootlibexecdir)\" \
- -DTEST_DIR=\"$(abs_top_srcdir)/test\" \
-I $(top_srcdir)/src \
-I $(top_builddir)/src/basic \
-I $(top_srcdir)/src/basic \
@@ -1606,7 +1608,7 @@ tests += \
test-seccomp
endif
-EXTRA_DIST += \
+TEST_DATA_FILES += \
test/a.service \
test/basic.target \
test/b.service \
@@ -5638,7 +5640,7 @@ test_dns_packet_SOURCES = \
test_dns_packet_CPPFLAGS = \
$(AM_CPPFLAGS) \
- -DRESOLVE_TEST_DIR=\"$(abs_top_srcdir)/src/resolve/test-data\"
+ -I $(top_srcdir)/src/test
test_dns_packet_CFLAGS = \
$(AM_CFLAGS) \
@@ -5649,18 +5651,20 @@ test_dns_packet_LDADD = \
$(GCRYPT_LIBS) \
-lm
-EXTRA_DIST += \
- src/resolve/test-data/_openpgpkey.fedoraproject.org.pkts \
- src/resolve/test-data/fedoraproject.org.pkts \
- src/resolve/test-data/gandi.net.pkts \
- src/resolve/test-data/google.com.pkts \
- src/resolve/test-data/root.pkts \
- src/resolve/test-data/sw1a1aa-sw1a2aa-sw1a2ab-sw1a2ac.find.me.uk.pkts \
- src/resolve/test-data/teamits.com.pkts \
- src/resolve/test-data/zbyszek@fedoraproject.org.pkts \
- src/resolve/test-data/_443._tcp.fedoraproject.org.pkts \
- src/resolve/test-data/kyhwana.org.pkts \
- src/resolve/test-data/fake-caa.pkts
+TEST_DATA_FILES += \
+ test/test-resolve/_openpgpkey.fedoraproject.org.pkts \
+ test/test-resolve/fedoraproject.org.pkts \
+ test/test-resolve/gandi.net.pkts \
+ test/test-resolve/google.com.pkts \
+ test/test-resolve/root.pkts \
+ test/test-resolve/sw1a1aa-sw1a2aa-sw1a2ab-sw1a2ac.find.me.uk.pkts \
+ test/test-resolve/teamits.com.pkts \
+ test/test-resolve/zbyszek@fedoraproject.org.pkts \
+ test/test-resolve/_443._tcp.fedoraproject.org.pkts \
+ test/test-resolve/kyhwana.org.pkts \
+ test/test-resolve/fake-caa.pkts
+
+EXTRA_DIST += $(TEST_DATA_FILES)
test_dnssec_SOURCES = \
src/resolve/test-dnssec.c \
@@ -6694,6 +6698,20 @@ tests += \
test-libsystemd-sym \
test-libudev-sym
+.PHONY: install-tests
+install-tests: $(tests) $(TEST_DATA_FILES)
+ for f in $(tests); do \
+ if [ -x .libs/$$f ]; then \
+ install -D -m 755 .libs/$$f $(DESTDIR)/$(testsdir)/$$f; \
+ else \
+ install -D -m 755 $$f $(DESTDIR)/$(testsdir)/$$f; \
+ fi; \
+ done
+ for f in $(TEST_DATA_FILES); do \
+ install -D -m 644 $$f $(DESTDIR)/$(testsdir)/testdata/$${f#test/}; \
+ done
+
+
.PHONY: cppcheck
cppcheck:
cppcheck --enable=all -q $(top_srcdir)
diff --git a/src/resolve/test-dns-packet.c b/src/resolve/test-dns-packet.c
index 956b155872..3ca7e78495 100644
--- a/src/resolve/test-dns-packet.c
+++ b/src/resolve/test-dns-packet.c
@@ -31,6 +31,8 @@
#include "strv.h"
#include "unaligned.h"
+#include "test-helper.h"
+
#define HASH_KEY SD_ID128_MAKE(d3,1e,48,90,4b,fa,4c,fe,af,9d,d5,a1,d7,2e,8a,b1)
static void verify_rr_copy(DnsResourceRecord *rr) {
@@ -115,7 +117,7 @@ int main(int argc, char **argv) {
N = argc - 1;
fnames = argv + 1;
} else {
- assert_se(glob(RESOLVE_TEST_DIR "/*.pkts", GLOB_NOSORT, NULL, &g) == 0);
+ assert_se(glob(TEST_DATA_DIR("/test-resolve/*.pkts"), GLOB_NOSORT, NULL, &g) == 0);
N = g.gl_pathc;
fnames = g.gl_pathv;
}
diff --git a/src/shared/tests.c b/src/shared/tests.c
index 409116290d..7034687725 100644
--- a/src/shared/tests.c
+++ b/src/shared/tests.c
@@ -17,6 +17,9 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include <alloc-util.h>
+#include <fs-util.h>
+#include <libgen.h>
#include <stdlib.h>
#include <util.h>
@@ -31,3 +34,13 @@ char* setup_fake_runtime_dir(void) {
return p;
}
+
+const char* get_exe_relative_testdata_dir(void) {
+ _cleanup_free_ char *exedir = NULL;
+ /* convenience: caller does not need to free result */
+ static char testdir[PATH_MAX];
+
+ assert_se(readlink_and_make_absolute("/proc/self/exe", &exedir) >= 0);
+ assert_se(snprintf(testdir, sizeof(testdir), "%s/testdata", dirname(exedir)) > 0);
+ return testdir;
+}
diff --git a/src/shared/tests.h b/src/shared/tests.h
index 93f09013a1..0100b48937 100644
--- a/src/shared/tests.h
+++ b/src/shared/tests.h
@@ -20,3 +20,4 @@
***/
char* setup_fake_runtime_dir(void);
+const char* get_exe_relative_testdata_dir(void);
diff --git a/src/test/test-cgroup-mask.c b/src/test/test-cgroup-mask.c
index a027eb0fd2..630587aaf1 100644
--- a/src/test/test-cgroup-mask.c
+++ b/src/test/test-cgroup-mask.c
@@ -34,7 +34,7 @@ static int test_cgroup_mask(void) {
int r;
/* Prepare the manager. */
- assert_se(set_unit_path(TEST_DIR) >= 0);
+ assert_se(set_unit_path(TEST_DATA_DIR("")) >= 0);
r = manager_new(UNIT_FILE_USER, true, &m);
if (r == -EPERM || r == -EACCES) {
puts("manager_new: Permission denied. Skipping test.");
diff --git a/src/test/test-engine.c b/src/test/test-engine.c
index a651f6b683..3ec2dfe10e 100644
--- a/src/test/test-engine.c
+++ b/src/test/test-engine.c
@@ -40,7 +40,7 @@ int main(int argc, char *argv[]) {
assert_se(runtime_dir = setup_fake_runtime_dir());
/* prepare the test */
- assert_se(set_unit_path(TEST_DIR) >= 0);
+ assert_se(set_unit_path(TEST_DATA_DIR("")) >= 0);
r = manager_new(UNIT_FILE_USER, true, &m);
if (MANAGER_SKIP_TEST(r)) {
log_notice_errno(r, "Skipping test: manager_new: %m");
diff --git a/src/test/test-execute.c b/src/test/test-execute.c
index 3a3ab3eb94..145aa37a66 100644
--- a/src/test/test-execute.c
+++ b/src/test/test-execute.c
@@ -516,7 +516,7 @@ int main(int argc, char *argv[]) {
}
assert_se(setenv("XDG_RUNTIME_DIR", "/tmp/", 1) == 0);
- assert_se(set_unit_path(TEST_DIR "/test-execute/") >= 0);
+ assert_se(set_unit_path(TEST_DATA_DIR("/test-execute/")) >= 0);
/* Unset VAR1, VAR2 and VAR3 which are used in the PassEnvironment test
* cases, otherwise (and if they are present in the environment),
diff --git a/src/test/test-helper.h b/src/test/test-helper.h
index ddb10f88fd..4e633ae6d8 100644
--- a/src/test/test-helper.h
+++ b/src/test/test-helper.h
@@ -20,6 +20,8 @@
***/
#include "sd-daemon.h"
+#include "string-util.h"
+#include "tests.h"
#include "macro.h"
@@ -39,3 +41,6 @@
-ENOENT, \
-ENOMEDIUM /* cannot determine cgroup */ \
)
+
+#define TEST_DATA_DIR(subdir) \
+ strjoina(getenv("TEST_DIR") ?: get_exe_relative_testdata_dir(), subdir)
diff --git a/src/test/test-path.c b/src/test/test-path.c
index 5e99d478ee..d09df3e8a5 100644
--- a/src/test/test-path.c
+++ b/src/test/test-path.c
@@ -263,7 +263,7 @@ int main(int argc, char *argv[]) {
log_open();
assert_se(runtime_dir = setup_fake_runtime_dir());
- assert_se(set_unit_path(TEST_DIR "/test-path/") >= 0);
+ assert_se(set_unit_path(TEST_DATA_DIR("/test-path/")) >= 0);
for (test = tests; test && *test; test++) {
int r;
diff --git a/src/test/test-sched-prio.c b/src/test/test-sched-prio.c
index 7b37910c33..dab64fea57 100644
--- a/src/test/test-sched-prio.c
+++ b/src/test/test-sched-prio.c
@@ -37,7 +37,7 @@ int main(int argc, char *argv[]) {
assert_se(runtime_dir = setup_fake_runtime_dir());
/* prepare the test */
- assert_se(set_unit_path(TEST_DIR) >= 0);
+ assert_se(set_unit_path(TEST_DATA_DIR("")) >= 0);
r = manager_new(UNIT_FILE_USER, true, &m);
if (MANAGER_SKIP_TEST(r)) {
log_notice_errno(r, "Skipping test: manager_new: %m");
diff --git a/src/resolve/test-data/_443._tcp.fedoraproject.org.pkts b/test/test-resolve/_443._tcp.fedoraproject.org.pkts
index a383c6286d..a383c6286d 100644
--- a/src/resolve/test-data/_443._tcp.fedoraproject.org.pkts
+++ b/test/test-resolve/_443._tcp.fedoraproject.org.pkts
Binary files differ
diff --git a/src/resolve/test-data/_openpgpkey.fedoraproject.org.pkts b/test/test-resolve/_openpgpkey.fedoraproject.org.pkts
index 15de02e997..15de02e997 100644
--- a/src/resolve/test-data/_openpgpkey.fedoraproject.org.pkts
+++ b/test/test-resolve/_openpgpkey.fedoraproject.org.pkts
Binary files differ
diff --git a/src/resolve/test-data/fake-caa.pkts b/test/test-resolve/fake-caa.pkts
index 1c3ecc5491..1c3ecc5491 100644
--- a/src/resolve/test-data/fake-caa.pkts
+++ b/test/test-resolve/fake-caa.pkts
Binary files differ
diff --git a/src/resolve/test-data/fedoraproject.org.pkts b/test/test-resolve/fedoraproject.org.pkts
index 17874844d9..17874844d9 100644
--- a/src/resolve/test-data/fedoraproject.org.pkts
+++ b/test/test-resolve/fedoraproject.org.pkts
Binary files differ
diff --git a/src/resolve/test-data/gandi.net.pkts b/test/test-resolve/gandi.net.pkts
index 5ef51e0c8e..5ef51e0c8e 100644
--- a/src/resolve/test-data/gandi.net.pkts
+++ b/test/test-resolve/gandi.net.pkts
Binary files differ
diff --git a/src/resolve/test-data/google.com.pkts b/test/test-resolve/google.com.pkts
index f98c4cd855..f98c4cd855 100644
--- a/src/resolve/test-data/google.com.pkts
+++ b/test/test-resolve/google.com.pkts
Binary files differ
diff --git a/src/resolve/test-data/kyhwana.org.pkts b/test/test-resolve/kyhwana.org.pkts
index e28a725c9a..e28a725c9a 100644
--- a/src/resolve/test-data/kyhwana.org.pkts
+++ b/test/test-resolve/kyhwana.org.pkts
Binary files differ
diff --git a/src/resolve/test-data/root.pkts b/test/test-resolve/root.pkts
index 54ba668c75..54ba668c75 100644
--- a/src/resolve/test-data/root.pkts
+++ b/test/test-resolve/root.pkts
Binary files differ
diff --git a/src/resolve/test-data/sw1a1aa-sw1a2aa-sw1a2ab-sw1a2ac.find.me.uk.pkts b/test/test-resolve/sw1a1aa-sw1a2aa-sw1a2ab-sw1a2ac.find.me.uk.pkts
index a854249532..a854249532 100644
--- a/src/resolve/test-data/sw1a1aa-sw1a2aa-sw1a2ab-sw1a2ac.find.me.uk.pkts
+++ b/test/test-resolve/sw1a1aa-sw1a2aa-sw1a2ab-sw1a2ac.find.me.uk.pkts
Binary files differ
diff --git a/src/resolve/test-data/teamits.com.pkts b/test/test-resolve/teamits.com.pkts
index 11deb39677..11deb39677 100644
--- a/src/resolve/test-data/teamits.com.pkts
+++ b/test/test-resolve/teamits.com.pkts
Binary files differ
diff --git a/src/resolve/test-data/zbyszek@fedoraproject.org.pkts b/test/test-resolve/zbyszek@fedoraproject.org.pkts
index f0a6f982df..f0a6f982df 100644
--- a/src/resolve/test-data/zbyszek@fedoraproject.org.pkts
+++ b/test/test-resolve/zbyszek@fedoraproject.org.pkts
Binary files differ