chiark / gitweb /
test: Make testing work on systems without or old systemd
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>
Thu, 18 Jul 2013 06:30:06 +0000 (08:30 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 22 Aug 2013 04:52:14 +0000 (00:52 -0400)
* 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
* Use -D"CATALOG_DIR=STR($(abs_top_srcdir)/catalog)" as a STRINGIY
  would result in the path '/home/ich/source/linux' to be expanded
  to '/home/ich/source/1' as linux is defined to 1.

13 files changed:
.travis.yml
Makefile.am
src/journal/test-catalog.c
src/journal/test-journal-interleaving.c
src/journal/test-journal-stream.c
src/journal/test-journal-verify.c
src/journal/test-journal.c
src/test/test-cgroup-util.c
src/test/test-helper.h [new file with mode: 0644]
src/test/test-id128.c
src/test/test-unit-file.c
src/test/test-unit-name.c
src/test/test-util.c

index 42433fd4d0088cf070f280afd5bcac14eef61c41..7e5251cfb02c28ac3b7c22aefb0a4fe7f452abdf 100644 (file)
@@ -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:
index fdfdd6515e4c7deda55e5e3ef725f8cbc8d15881..fd38e8201f325e9be1c70215f6c545b31a15f4e1 100644 (file)
@@ -1143,6 +1143,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
 
@@ -1341,7 +1344,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
@@ -2680,7 +2684,8 @@ test_id128_SOURCES = \
 
 test_id128_LDADD = \
        libsystemd-shared.la \
-       libsystemd-id128-internal.la
+       libsystemd-id128-internal.la \
+       libsystemd-daemon.la
 
 tests += \
        test-id128
@@ -2852,6 +2857,10 @@ test_mmap_cache_LDADD = \
 test_catalog_SOURCES = \
        src/journal/test-catalog.c
 
+test_catalog_CFLAGS = \
+       $(AM_CFLAGS) \
+       -DCATALOG_DIR=\"$(abs_top_srcdir)/catalog\"
+
 test_catalog_LDADD = \
        libsystemd-shared.la \
        libsystemd-label.la \
index 987867f0c8b3dfd0dd907c8dc87b1d59e68dca41..5db5bed8de0135826130133ed5c0b45c7cc2ac7c 100644 (file)
 #include "sd-messages.h"
 #include "catalog.h"
 
+static const char *catalog_dirs[] = {
+        CATALOG_DIR,
+        NULL,
+};
+
+static const char *no_catalog_dirs[] = {
+        "/bin/hopefully/with/no/catalog",
+        NULL
+};
+
 static void test_import(Hashmap *h, struct strbuf *sb,
                         const char* contents, ssize_t size, int code) {
         int r;
@@ -100,9 +110,13 @@ static void test_catalog_update(void) {
         r = catalog_update(database, NULL, NULL);
         assert(r >= 0);
 
-        /* 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);
+        /* Test what happens if there are no files in the directory. */
+        r = catalog_update(database, NULL, no_catalog_dirs);
+        assert(r >= 0);
+
+        /* Make sure that we at least have some files loaded or the
+           catalog_list below will fail. */
+        r = catalog_update(database, NULL, catalog_dirs);
         assert(r >= 0);
 }
 
index 069d297a9f77d7106218ad4d92b4b945fe5c609d..2b21523f57d7c904ce8ea90c4f653aee87e77a8c 100644 (file)
@@ -288,6 +288,10 @@ static void test_sequence_numbers(void) {
 int main(int argc, char *argv[]) {
         log_set_max_level(LOG_DEBUG);
 
+        /* journal_file_open requires a valid machine id */
+        if (access("/etc/machine-id", F_OK) != 0)
+                return EXIT_TEST_SKIP;
+
         arg_keep = argc > 1;
 
         test_skip(setup_sequential);
index 6b32b252e8d6efe848c8af85bb2c85b9ab4a62f8..8e1d08d59608e41c8721962974c7331206ca465a 100644 (file)
@@ -80,6 +80,10 @@ int main(int argc, char *argv[]) {
         const void *data;
         size_t l;
 
+        /* journal_file_open requires a valid machine id */
+        if (access("/etc/machine-id", F_OK) != 0)
+                return EXIT_TEST_SKIP;
+
         log_set_max_level(LOG_DEBUG);
 
         assert_se(mkdtemp(t));
index 6b7414a4b1bff8ba0a10e6f580492a1010a694bb..05400742074e1e1ac122617267892bb2ee9a30fd 100644 (file)
@@ -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 (access("/etc/machine-id", F_OK) != 0)
+                return EXIT_TEST_SKIP;
+
         log_set_max_level(LOG_DEBUG);
 
         assert_se(mkdtemp(t));
index 534fd28fa69a54e5c3472512667069af74a773a8..190c426ebad52dc4916dd3809401607ba0e57978 100644 (file)
@@ -174,6 +174,10 @@ static void test_empty(void) {
 int main(int argc, char *argv[]) {
         arg_keep = argc > 1;
 
+        /* journal_file_open requires a valid machine id */
+        if (access("/etc/machine-id", F_OK) != 0)
+                return EXIT_TEST_SKIP;
+
         test_non_empty();
         test_empty();
 
index 295bb02e3be788952fabd8a81787fe24e0abf3e7..16bf96834022f75ca4d03ba88e46bbeb4da6ac4d 100644 (file)
@@ -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 (file)
index 0000000..92864ed
--- /dev/null
@@ -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);   \
+        }
index 2ed8e292e6af1af1e2030690473ffeded38aa2f0..7b92758174b978e7aad651a4e6aad0feb6fb7ab9 100644 (file)
@@ -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));
index 2075e8611551766ed45a137c76a89cb1c3041741..dc6bc55244dc65ecec4fa571ce29b69d18c60fc7 100644 (file)
@@ -35,6 +35,7 @@
 #include "load-fragment.h"
 #include "strv.h"
 #include "fileio.h"
+#include "test-helper.h"
 
 static int test_unit_file_get_set(void) {
         int r;
@@ -366,7 +367,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 r;
 }
index 6776ef0857716b4e70418e9b8b0b9c9444913ec5..c17692b845e5af80f469954acaf0baaec39b4ed5 100644 (file)
@@ -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;
 }
index 875aeab3d582b20785d1bb8acfed4c090ed597eb..dd7768d36c5652720fb64c9590683c7411628da0 100644 (file)
@@ -397,6 +397,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;
@@ -405,8 +406,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_warning("/proc/1/comm does not exist.");
+        }
 
         assert_se(get_starttime_of_pid(1, &b) >= 0);
         log_info("pid1 starttime: '%llu'", b);