Merge pull request #5338 from mbiebl/fix-install-tests-target

Fix "make install-tests" when srcdir != builddir, fix valgrind-tests
This commit is contained in:
Evgeny Vereshchagin 2017-02-17 11:38:23 +03:00 committed by GitHub
commit f73e6ee687
12 changed files with 59 additions and 33 deletions

View file

@ -59,3 +59,8 @@ systemd-logind:
* `$SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK=1` — if set, report that
hibernation is available even if the swap devices do not provide enough room
for it.
installed systemd tests:
* `$SYSTEMD_TEST_DATA` — override the location of test data. This is useful if
a test executable is moved to an arbitrary location.

View file

@ -152,7 +152,6 @@ 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
@ -252,6 +251,8 @@ AM_CPPFLAGS = \
-I $(top_srcdir)/src/libsystemd/sd-device \
-I $(top_srcdir)/src/libsystemd/sd-id128 \
-I $(top_srcdir)/src/libsystemd-network \
-DABS_SRC_DIR=\"$(abs_top_srcdir)\" \
-DABS_BUILD_DIR=\"$(abs_top_builddir)\" \
$(OUR_CPPFLAGS)
AM_CFLAGS = $(OUR_CFLAGS)
@ -6615,7 +6616,7 @@ valgrind-tests: $(TESTS)
if $(LIBTOOL) --mode=execute file $$f | grep -q shell; then \
echo -e "$${x}Skipping non-binary $$f"; else \
echo -e "$${x}Running $$f"; \
$(LIBTOOL) --mode=execute valgrind -q --leak-check=full --max-stackframe=5242880 --error-exitcode=55 $(builddir)/$$f ; fi; \
$(AM_TESTS_ENVIRONMENT) $(LIBTOOL) --mode=execute valgrind -q --leak-check=full --max-stackframe=5242880 --error-exitcode=55 $(builddir)/$$f ; fi; \
x="\n\n"; \
done
@ -6716,14 +6717,14 @@ tests += \
.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; \
if [ -x $(top_builddir)/.libs/$$f ]; then \
install -D -m 755 $(top_builddir)/.libs/$$f $(DESTDIR)/$(testsdir)/$$f; \
else \
install -D -m 755 $$f $(DESTDIR)/$(testsdir)/$$f; \
install -D -m 755 $(top_builddir)/$$f $(DESTDIR)/$(testsdir)/$$f; \
fi; \
done
for f in $(TEST_DATA_FILES); do \
install -D -m 644 $$f $(DESTDIR)/$(testsdir)/testdata/$${f#test/}; \
install -D -m 644 $(top_srcdir)/$$f $(DESTDIR)/$(testsdir)/testdata/$${f#test/}; \
done

View file

@ -29,10 +29,9 @@
#include "resolved-dns-rr.h"
#include "string-util.h"
#include "strv.h"
#include "tests.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) {
@ -117,7 +116,7 @@ int main(int argc, char **argv) {
N = argc - 1;
fnames = argv + 1;
} else {
assert_se(glob(TEST_DATA_DIR("/test-resolve/*.pkts"), GLOB_NOSORT, NULL, &g) == 0);
assert_se(glob(get_testdata_dir("/test-resolve/*.pkts"), GLOB_NOSORT, NULL, &g) == 0);
N = g.gl_pathc;
fnames = g.gl_pathv;
}

View file

@ -24,6 +24,7 @@
#include <util.h>
#include "tests.h"
#include "path-util.h"
char* setup_fake_runtime_dir(void) {
char t[] = "/tmp/fake-xdg-runtime-XXXXXX", *p;
@ -35,12 +36,38 @@ char* setup_fake_runtime_dir(void) {
return p;
}
const char* get_exe_relative_testdata_dir(void) {
_cleanup_free_ char *exedir = NULL;
const char* get_testdata_dir(const char *suffix) {
const char *env;
/* 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);
/* if the env var is set, use that */
env = getenv("SYSTEMD_TEST_DATA");
testdir[sizeof(testdir) - 1] = '\0';
if (env) {
if (access(env, F_OK) < 0) {
fputs("ERROR: $SYSTEMD_TEST_DATA directory does not exist\n", stderr);
exit(1);
}
strncpy(testdir, env, sizeof(testdir) - 1);
} else {
_cleanup_free_ char *exedir = NULL;
assert_se(readlink_and_make_absolute("/proc/self/exe", &exedir) >= 0);
/* Check if we're running from the builddir. If so, use the compiled in path. */
if (path_startswith(exedir, ABS_BUILD_DIR))
assert_se(snprintf(testdir, sizeof(testdir), "%s/test", ABS_SRC_DIR) > 0);
else
/* Try relative path, according to the install-test layout */
assert_se(snprintf(testdir, sizeof(testdir), "%s/testdata", dirname(exedir)) > 0);
/* test this without the suffix, as it may contain a glob */
if (access(testdir, F_OK) < 0) {
fputs("ERROR: Cannot find testdata directory, set $SYSTEMD_TEST_DATA\n", stderr);
exit(1);
}
}
strncpy(testdir + strlen(testdir), suffix, sizeof(testdir) - strlen(testdir) - 1);
return testdir;
}

View file

@ -20,4 +20,4 @@
***/
char* setup_fake_runtime_dir(void);
const char* get_exe_relative_testdata_dir(void);
const char* get_testdata_dir(const char *suffix);

View file

@ -27,6 +27,7 @@
#include "unit.h"
static int test_cgroup_mask(void) {
_cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
Manager *m = NULL;
Unit *son, *daughter, *parent, *root, *grandchild, *parent_deep;
FILE *serial = NULL;
@ -34,7 +35,8 @@ static int test_cgroup_mask(void) {
int r;
/* Prepare the manager. */
assert_se(set_unit_path(TEST_DATA_DIR("")) >= 0);
assert_se(set_unit_path(get_testdata_dir("")) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
r = manager_new(UNIT_FILE_USER, true, &m);
if (r == -EPERM || r == -EACCES) {
puts("manager_new: Permission denied. Skipping test.");
@ -110,10 +112,8 @@ static int test_cgroup_mask(void) {
}
int main(int argc, char* argv[]) {
_cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
int rc = 0;
assert_se(runtime_dir = setup_fake_runtime_dir());
TEST_REQ_RUNNING_SYSTEMD(rc = test_cgroup_mask());
return rc;

View file

@ -37,10 +37,9 @@ int main(int argc, char *argv[]) {
Job *j;
int r;
assert_se(runtime_dir = setup_fake_runtime_dir());
/* prepare the test */
assert_se(set_unit_path(TEST_DATA_DIR("")) >= 0);
assert_se(set_unit_path(get_testdata_dir("")) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
r = manager_new(UNIT_FILE_USER, true, &m);
if (MANAGER_SKIP_TEST(r)) {
log_notice_errno(r, "Skipping test: manager_new: %m");

View file

@ -35,6 +35,7 @@
#endif
#include "stat-util.h"
#include "test-helper.h"
#include "tests.h"
#include "unit.h"
#include "util.h"
#include "virt.h"
@ -516,7 +517,7 @@ int main(int argc, char *argv[]) {
}
assert_se(setenv("XDG_RUNTIME_DIR", "/tmp/", 1) == 0);
assert_se(set_unit_path(TEST_DATA_DIR("/test-execute/")) >= 0);
assert_se(set_unit_path(get_testdata_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),

View file

@ -20,8 +20,6 @@
***/
#include "sd-daemon.h"
#include "string-util.h"
#include "tests.h"
#include "macro.h"
@ -41,6 +39,3 @@
-ENOENT, \
-ENOMEDIUM /* cannot determine cgroup */ \
)
#define TEST_DATA_DIR(subdir) \
strjoina(getenv("TEST_DIR") ?: get_exe_relative_testdata_dir(), subdir)

View file

@ -24,7 +24,7 @@
#include "log.h"
#include "journal-importer.h"
#include "string-util.h"
#include "test-helper.h"
#include "tests.h"
static void assert_iovec_entry(const struct iovec *iovec, const char* content) {
assert_se(strlen(content) == iovec->iov_len);
@ -39,7 +39,7 @@ static void test_basic_parsing(void) {
_cleanup_(journal_importer_cleanup) JournalImporter imp = {};
int r;
imp.fd = open(TEST_DATA_DIR("/journal-data/journal-1.txt"), O_RDONLY|O_CLOEXEC);
imp.fd = open(get_testdata_dir("/journal-data/journal-1.txt"), O_RDONLY|O_CLOEXEC);
assert_se(imp.fd >= 0);
do
@ -68,7 +68,7 @@ static void test_bad_input(void) {
_cleanup_(journal_importer_cleanup) JournalImporter imp = {};
int r;
imp.fd = open(TEST_DATA_DIR("/journal-data/journal-2.txt"), O_RDONLY|O_CLOEXEC);
imp.fd = open(get_testdata_dir("/journal-data/journal-2.txt"), O_RDONLY|O_CLOEXEC);
assert_se(imp.fd >= 0);
do

View file

@ -262,8 +262,8 @@ int main(int argc, char *argv[]) {
log_parse_environment();
log_open();
assert_se(set_unit_path(get_testdata_dir("/test-path")) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
assert_se(set_unit_path(TEST_DATA_DIR("/test-path/")) >= 0);
for (test = tests; test && *test; test++) {
int r;

View file

@ -34,10 +34,9 @@ int main(int argc, char *argv[]) {
FDSet *fdset = NULL;
int r;
assert_se(runtime_dir = setup_fake_runtime_dir());
/* prepare the test */
assert_se(set_unit_path(TEST_DATA_DIR("")) >= 0);
assert_se(set_unit_path(get_testdata_dir("")) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
r = manager_new(UNIT_FILE_USER, true, &m);
if (MANAGER_SKIP_TEST(r)) {
log_notice_errno(r, "Skipping test: manager_new: %m");