summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-07-18 08:30:06 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-08-22 00:52:14 -0400
commit143bfdaf0b890fa7acadf02d1eafacaef1b696bd (patch)
tree5a640d40bc7489c5933aac824f2bf23ecd2818ff /src/test
parent67ccd1c4b821b142ccd7b4bb292d9947aea8c581 (diff)
test: Make testing work on systems without or old systemd
* 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.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-cgroup-util.c5
-rw-r--r--src/test/test-helper.h31
-rw-r--r--src/test/test-id128.c11
-rw-r--r--src/test/test-unit-file.c3
-rw-r--r--src/test/test-unit-name.c5
-rw-r--r--src/test/test-util.c9
6 files changed, 54 insertions, 10 deletions
diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c
index 295bb02e3b..16bf968340 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 0000000000..92864edb54
--- /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 2ed8e292e6..7b92758174 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 2075e86115..dc6bc55244 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 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;
}
diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c
index 6776ef0857..c17692b845 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 875aeab3d5..dd7768d36c 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -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);