From: Holger Hans Peter Freyther <hol...@moiji-mobile.com> * Introduce a macro to conditionally execute tests. This avoids skipping the entire test if some parts require systemd * Skip the journal tests when no /etc/machine-id is present * Change test-catalog to load the catalog from the source directory of systemd. * /proc/PID/comm got introduced in v2.6.33 but travis is still using v2.6.32. * Enable make check and make distcheck on the travis build --- .travis.yml | 5 +++-- Makefile.am | 13 +++++++++++-- src/journal/test-catalog.c | 7 ++++++- src/journal/test-journal-interleaving.c | 5 +++++ src/journal/test-journal-stream.c | 5 +++++ src/journal/test-journal-verify.c | 4 ++++ src/journal/test-journal.c | 5 +++++ src/test/test-cgroup-util.c | 5 +++-- src/test/test-helper.h | 31 +++++++++++++++++++++++++++++++ src/test/test-id128.c | 11 +++++++---- src/test/test-unit-file.c | 3 ++- src/test/test-unit-name.c | 5 ++++- src/test/test-util.c | 9 +++++++-- 13 files changed, 93 insertions(+), 15 deletions(-) create mode 100644 src/test/test-helper.h
diff --git a/.travis.yml b/.travis.yml index 42433fd..7e5251c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,9 @@ compiler: - gcc before_install: - sudo apt-get update -qq - - sudo apt-get install autotools-dev automake autoconf libtool libdbus-1-dev libcap-dev libblkid-dev libpam-dev libcryptsetup-dev libaudit-dev libacl1-dev libattr1-dev libselinux-dev liblzma-dev libgcrypt-dev libqrencode-dev libmicrohttpd-dev gtk-doc-tools gperf -script: ./autogen.sh && ./configure --enable-gtk-doc --enable-gtk-doc-pdf && make V=1 && make dist V=1 + - sudo apt-get install autotools-dev automake autoconf libtool libdbus-1-dev libcap-dev libblkid-dev libpam-dev libcryptsetup-dev libaudit-dev libacl1-dev libattr1-dev libselinux-dev liblzma-dev libgcrypt-dev libqrencode-dev libmicrohttpd-dev gtk-doc-tools gperf python2.7-dev +script: ./autogen.sh && ./configure --enable-gtk-doc --enable-gtk-doc-pdf && make V=1 && sudo ./systemd-machine-id-setup && make check && make distcheck +after_failure: cat test-suite.log notifications: irc: channels: diff --git a/Makefile.am b/Makefile.am index c4b9b1a..e598585 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1130,6 +1130,9 @@ EXTRA_DIST += \ test/sched_rr_ok.service \ test/sched_rr_change.service +EXTRA_DIST += \ + src/test/test-helper.h + test_engine_SOURCES = \ src/test/test-engine.c @@ -1328,7 +1331,8 @@ test_cgroup_util_SOURCES = \ test_cgroup_util_LDADD = \ libsystemd-label.la \ - libsystemd-shared.la + libsystemd-shared.la \ + libsystemd-daemon.la test_env_replace_SOURCES = \ src/test/test-env-replace.c @@ -2647,7 +2651,8 @@ test_id128_SOURCES = \ test_id128_LDADD = \ libsystemd-shared.la \ - libsystemd-id128-internal.la + libsystemd-id128-internal.la \ + libsystemd-daemon.la tests += \ test-id128 @@ -2810,6 +2815,10 @@ test_mmap_cache_LDADD = \ test_catalog_SOURCES = \ src/journal/test-catalog.c +test_catalog_CFLAGS = \ + $(AM_CFLAGS) \ + -D"STR(s)=\#s" -D"CATALOG_DIR=STR($(abs_top_srcdir)/catalog)" + test_catalog_LDADD = \ libsystemd-shared.la \ libsystemd-label.la \ diff --git a/src/journal/test-catalog.c b/src/journal/test-catalog.c index 987867f..9620301 100644 --- a/src/journal/test-catalog.c +++ b/src/journal/test-catalog.c @@ -31,6 +31,11 @@ #include "sd-messages.h" #include "catalog.h" +static const char *catalog_dirs[] = { + CATALOG_DIR, + NULL, +}; + static void test_import(Hashmap *h, struct strbuf *sb, const char* contents, ssize_t size, int code) { int r; @@ -102,7 +107,7 @@ static void test_catalog_update(void) { /* Note: this might actually not find anything, if systemd was * not installed before. That should be fine too. */ - r = catalog_update(database, NULL, catalog_file_dirs); + r = catalog_update(database, NULL, catalog_dirs); assert(r >= 0); } diff --git a/src/journal/test-journal-interleaving.c b/src/journal/test-journal-interleaving.c index 069d297..bd3cb7f 100644 --- a/src/journal/test-journal-interleaving.c +++ b/src/journal/test-journal-interleaving.c @@ -286,8 +286,13 @@ static void test_sequence_numbers(void) { } int main(int argc, char *argv[]) { + struct stat st; log_set_max_level(LOG_DEBUG); + /* journal_file_open requires a valid machine id */ + if (stat("/etc/machine-id", &st) != 0) + return EXIT_TEST_SKIP; + arg_keep = argc > 1; test_skip(setup_sequential); diff --git a/src/journal/test-journal-stream.c b/src/journal/test-journal-stream.c index 4aba7fe..34f44f6 100644 --- a/src/journal/test-journal-stream.c +++ b/src/journal/test-journal-stream.c @@ -72,6 +72,7 @@ static void verify_contents(sd_journal *j, unsigned skip) { } int main(int argc, char *argv[]) { + struct stat st; JournalFile *one, *two, *three; char t[] = "/tmp/journal-stream-XXXXXX"; unsigned i; @@ -80,6 +81,10 @@ int main(int argc, char *argv[]) { const void *data; size_t l; + /* journal_file_open requires a valid machine id */ + if (stat("/etc/machine-id", &st) != 0) + return EXIT_TEST_SKIP; + log_set_max_level(LOG_DEBUG); assert_se(mkdtemp(t)); diff --git a/src/journal/test-journal-verify.c b/src/journal/test-journal-verify.c index 6b7414a..52bd902 100644 --- a/src/journal/test-journal-verify.c +++ b/src/journal/test-journal-verify.c @@ -77,6 +77,10 @@ int main(int argc, char *argv[]) { struct stat st; uint64_t p; + /* journal_file_open requires a valid machine id */ + if (stat("/etc/machine-id", &st) != 0) + return EXIT_TEST_SKIP; + log_set_max_level(LOG_DEBUG); assert_se(mkdtemp(t)); diff --git a/src/journal/test-journal.c b/src/journal/test-journal.c index 534fd28..abf55b5 100644 --- a/src/journal/test-journal.c +++ b/src/journal/test-journal.c @@ -172,8 +172,13 @@ static void test_empty(void) { } int main(int argc, char *argv[]) { + struct stat st; arg_keep = argc > 1; + /* journal_file_open requires a valid machine id */ + if (stat("/etc/machine-id", &st) != 0) + return EXIT_TEST_SKIP; + test_non_empty(); test_empty(); diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c index 295bb02..16bf968 100644 --- a/src/test/test-cgroup-util.c +++ b/src/test/test-cgroup-util.c @@ -23,6 +23,7 @@ #include "util.h" #include "cgroup-util.h" +#include "test-helper.h" static void check_p_d_u(const char *path, int code, const char *result) { _cleanup_free_ char *unit = NULL; @@ -239,9 +240,9 @@ int main(void) { test_path_get_session(); test_path_get_owner_uid(); test_path_get_machine_name(); - test_get_paths(); + TEST_REQ_RUNNING_SYSTEMD(test_get_paths()); test_proc(); - test_escape(); + TEST_REQ_RUNNING_SYSTEMD(test_escape()); test_controller_is_valid(); test_slice_to_path(); diff --git a/src/test/test-helper.h b/src/test/test-helper.h new file mode 100644 index 0000000..92864ed --- /dev/null +++ b/src/test/test-helper.h @@ -0,0 +1,31 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2013 Holger Hans Peter Freyther + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ + +#include "sd-daemon.h" + +#define TEST_REQ_RUNNING_SYSTEMD(x) \ + if (sd_booted() > 0) { \ + x; \ + } else { \ + printf("systemd not booted skipping '%s'\n", #x); \ + } diff --git a/src/test/test-id128.c b/src/test/test-id128.c index 2ed8e29..7b92758 100644 --- a/src/test/test-id128.c +++ b/src/test/test-id128.c @@ -25,6 +25,7 @@ #include "util.h" #include "macro.h" +#include "sd-daemon.h" #define ID128_WALDI SD_ID128_MAKE(01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 10) #define STR_WALDI "0102030405060708090a0b0c0d0e0f10" @@ -41,11 +42,13 @@ int main(int argc, char *argv[]) { assert_se(sd_id128_from_string(t, &id2) == 0); assert_se(sd_id128_equal(id, id2)); - assert_se(sd_id128_get_machine(&id) == 0); - printf("machine: %s\n", sd_id128_to_string(id, t)); + if (sd_booted() > 0) { + assert_se(sd_id128_get_machine(&id) == 0); + printf("machine: %s\n", sd_id128_to_string(id, t)); - assert_se(sd_id128_get_boot(&id) == 0); - printf("boot: %s\n", sd_id128_to_string(id, t)); + assert_se(sd_id128_get_boot(&id) == 0); + printf("boot: %s\n", sd_id128_to_string(id, t)); + } printf("waldi: %s\n", sd_id128_to_string(ID128_WALDI, t)); assert_se(streq(t, STR_WALDI)); diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c index a7fe77a..8491153 100644 --- a/src/test/test-unit-file.c +++ b/src/test/test-unit-file.c @@ -35,6 +35,7 @@ #include "load-fragment.h" #include "strv.h" #include "fileio.h" +#include "test-helper.h" static void test_unit_file_get_set(void) { int r; @@ -361,7 +362,7 @@ int main(int argc, char *argv[]) { test_load_env_file_2(); test_load_env_file_3(); test_load_env_file_4(); - test_install_printf(); + TEST_REQ_RUNNING_SYSTEMD(test_install_printf()); return 0; } diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c index 2fa0294..fc6fd98 100644 --- a/src/test/test-unit-name.c +++ b/src/test/test-unit-name.c @@ -34,6 +34,7 @@ #include "specifier.h" #include "util.h" #include "macro.h" +#include "test-helper.h" static void test_replacements(void) { #define expect(pattern, repl, expected) \ @@ -196,6 +197,8 @@ static int test_unit_printf(void) { } int main(int argc, char* argv[]) { + int rc = 0; test_replacements(); - return test_unit_printf(); + TEST_REQ_RUNNING_SYSTEMD(rc = test_unit_printf()); + return rc; } diff --git a/src/test/test-util.c b/src/test/test-util.c index 4768310..231ffc4 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -398,6 +398,7 @@ static void test_u64log2(void) { } static void test_get_process_comm(void) { + struct stat st; _cleanup_free_ char *a = NULL, *c = NULL, *d = NULL, *f = NULL, *i = NULL; unsigned long long b; pid_t e; @@ -406,8 +407,12 @@ static void test_get_process_comm(void) { dev_t h; int r; - assert_se(get_process_comm(1, &a) >= 0); - log_info("pid1 comm: '%s'", a); + if (stat("/proc/1/comm", &st) == 0) { + assert_se(get_process_comm(1, &a) >= 0); + log_info("pid1 comm: '%s'", a); + } else { + log_info("/proc/1/comm does not exist."); + } assert_se(get_starttime_of_pid(1, &b) >= 0); log_info("pid1 starttime: '%llu'", b); -- 1.8.3.2 _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel