chiark / gitweb /
test: Make testing work on systems without or old systemd
[elogind.git] / src / test / test-util.c
index 315bc419c29391ad0f8fbb1b7ca20bd5479e473e..dd7768d36c5652720fb64c9590683c7411628da0 100644 (file)
@@ -192,41 +192,40 @@ static void test_safe_atod(void) {
 }
 
 static void test_strappend(void) {
-       _cleanup_free_ char *t1, *t2, *t3, *t4;
+        _cleanup_free_ char *t1, *t2, *t3, *t4;
 
-       t1 = strappend(NULL, NULL);
-       assert_se(streq(t1, ""));
+        t1 = strappend(NULL, NULL);
+        assert_se(streq(t1, ""));
 
-       t2 = strappend(NULL, "suf");
-       assert_se(streq(t2, "suf"));
+        t2 = strappend(NULL, "suf");
+        assert_se(streq(t2, "suf"));
 
-       t3 = strappend("pre", NULL);
-       assert_se(streq(t3, "pre"));
+        t3 = strappend("pre", NULL);
+        assert_se(streq(t3, "pre"));
 
-       t4 = strappend("pre", "suf");
-       assert_se(streq(t4, "presuf"));
+        t4 = strappend("pre", "suf");
+        assert_se(streq(t4, "presuf"));
 }
 
 static void test_strstrip(void) {
-       char *r;
-       char input[] = "   hello, waldo.   ";
-
-       r = strstrip(input);
-       assert_se(streq(r, "hello, waldo."));
+        char *r;
+        char input[] = "   hello, waldo.   ";
 
+        r = strstrip(input);
+        assert_se(streq(r, "hello, waldo."));
 }
 
 static void test_delete_chars(void) {
-       char *r;
-       char input[] = "   hello, waldo.   abc";
+        char *r;
+        char input[] = "   hello, waldo.   abc";
 
-       r = delete_chars(input, WHITESPACE);
-       assert_se(streq(r, "hello,waldo.abc"));
+        r = delete_chars(input, WHITESPACE);
+        assert_se(streq(r, "hello,waldo.abc"));
 }
 
 static void test_in_charset(void) {
-      assert_se(in_charset("dddaaabbbcccc", "abcd"));
-      assert_se(!in_charset("dddaaabbbcccc", "abc f"));
+        assert_se(in_charset("dddaaabbbcccc", "abcd"));
+        assert_se(!in_charset("dddaaabbbcccc", "abc f"));
 }
 
 static void test_hexchar(void) {
@@ -398,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;
@@ -406,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);