summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2015-04-19 13:28:47 +0200
committerAndy Wingo <wingo@pobox.com>2015-04-19 13:32:26 +0200
commit94ca573005daeb5c2d0f141b688175d493617cf1 (patch)
tree412d64d6559efa223fd3ab8a1b42876d80d148a3
parent203b112fe8f3204a9130047dd8bb91549211660b (diff)
Remove src/test
-rw-r--r--src/test/.gitignore1
l---------src/test/Makefile1
-rw-r--r--src/test/test-architecture.c54
-rw-r--r--src/test/test-async.c54
-rw-r--r--src/test/test-barrier.c462
-rw-r--r--src/test/test-boot-timestamps.c98
-rw-r--r--src/test/test-btrfs.c105
-rw-r--r--src/test/test-calendarspec.c92
-rw-r--r--src/test/test-cap-list.c110
-rw-r--r--src/test/test-capability.c160
-rw-r--r--src/test/test-cgroup-mask.c104
-rw-r--r--src/test/test-cgroup-util.c264
-rw-r--r--src/test/test-cgroup.c104
-rw-r--r--src/test/test-condition.c237
-rw-r--r--src/test/test-conf-files.c84
-rw-r--r--src/test/test-copy.c141
-rw-r--r--src/test/test-daemon.c53
-rw-r--r--src/test/test-date.c64
-rw-r--r--src/test/test-device-nodes.c57
-rw-r--r--src/test/test-ellipsize.c44
-rw-r--r--src/test/test-engine.c112
-rw-r--r--src/test/test-env-replace.c217
-rw-r--r--src/test/test-execute.c183
-rw-r--r--src/test/test-fdset.c166
-rw-r--r--src/test/test-fileio.c410
-rw-r--r--src/test/test-fstab-util.c138
-rw-r--r--src/test/test-fw-util.c60
-rw-r--r--src/test/test-hashmap-plain.c869
-rw-r--r--src/test/test-hashmap.c88
-rw-r--r--src/test/test-helper.h31
-rw-r--r--src/test/test-hostname.c34
-rw-r--r--src/test/test-id128.c78
-rw-r--r--src/test/test-install.c261
-rw-r--r--src/test/test-ipcrm.c32
-rw-r--r--src/test/test-job-type.c102
-rw-r--r--src/test/test-json.c106
-rw-r--r--src/test/test-libudev.c475
-rw-r--r--src/test/test-list.c154
-rw-r--r--src/test/test-locale-util.c58
-rw-r--r--src/test/test-log.c54
-rw-r--r--src/test/test-loopback.c38
-rw-r--r--src/test/test-namespace.c144
-rw-r--r--src/test/test-ns.c72
-rw-r--r--src/test/test-path-lookup.c73
-rw-r--r--src/test/test-path-util.c293
-rw-r--r--src/test/test-path.c267
-rw-r--r--src/test/test-prioq.c175
-rw-r--r--src/test/test-pty.c141
-rw-r--r--src/test/test-ratelimit.c49
-rw-r--r--src/test/test-replace-var.c46
-rw-r--r--src/test/test-ring.c130
-rw-r--r--src/test/test-rtnl-manual.c147
-rw-r--r--src/test/test-sched-prio.c94
-rw-r--r--src/test/test-set.c46
-rw-r--r--src/test/test-sigbus.c62
-rw-r--r--src/test/test-sleep.c64
-rw-r--r--src/test/test-socket-util.c333
-rw-r--r--src/test/test-strbuf.c92
-rw-r--r--src/test/test-strip-tab-ansi.c52
-rw-r--r--src/test/test-strv.c603
-rw-r--r--src/test/test-strxcpyx.c100
-rw-r--r--src/test/test-tables.c126
-rw-r--r--src/test/test-time.c172
-rw-r--r--src/test/test-tmpfiles.c49
-rw-r--r--src/test/test-udev.c161
-rw-r--r--src/test/test-uid-range.c91
-rw-r--r--src/test/test-unaligned.c93
-rw-r--r--src/test/test-unit-file.c527
-rw-r--r--src/test/test-unit-name.c364
-rw-r--r--src/test/test-utf8.c118
-rw-r--r--src/test/test-util.c1606
-rw-r--r--src/test/test-verbs.c78
-rw-r--r--src/test/test-watchdog.c50
-rw-r--r--src/test/test-xml.c83
74 files changed, 0 insertions, 12456 deletions
diff --git a/src/test/.gitignore b/src/test/.gitignore
deleted file mode 100644
index e4c198a4f7..0000000000
--- a/src/test/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-test-hashmap-ordered.c
diff --git a/src/test/Makefile b/src/test/Makefile
deleted file mode 120000
index d0b0e8e008..0000000000
--- a/src/test/Makefile
+++ /dev/null
@@ -1 +0,0 @@
-../Makefile \ No newline at end of file
diff --git a/src/test/test-architecture.c b/src/test/test-architecture.c
deleted file mode 100644
index 30bdec45e5..0000000000
--- a/src/test/test-architecture.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2014 Kay Sievers
-
- 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 "virt.h"
-#include "architecture.h"
-#include "util.h"
-#include "log.h"
-
-int main(int argc, char *argv[]) {
- const char *id = NULL;
- int a, v;
-
- v = detect_virtualization(&id);
- if (v == -EPERM || v == -EACCES)
- return EXIT_TEST_SKIP;
-
- assert_se(v >= 0);
-
- log_info("virtualization=%s id=%s",
- v == VIRTUALIZATION_CONTAINER ? "container" : v == VIRTUALIZATION_VM ? "vm" : "n/a",
- strna(id));
-
- a = uname_architecture();
- assert_se(a >= 0);
-
- log_info("uname architecture=%s", architecture_to_string(a));
-
- a = native_architecture();
- assert_se(a >= 0);
-
- log_info("native architecture=%s", architecture_to_string(a));
-
- log_info("primary library architecture=" LIB_ARCH_TUPLE);
-
- return 0;
-}
diff --git a/src/test/test-async.c b/src/test/test-async.c
deleted file mode 100644
index abd36d693c..0000000000
--- a/src/test/test-async.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/***
- This file is part of systemd
-
- Copyright 2014 Ronny Chevalier
-
- 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 <unistd.h>
-
-#include "async.h"
-#include "util.h"
-#include "macro.h"
-
-static bool test_async = false;
-
-static void *async_func(void *arg) {
- test_async = true;
-
- return NULL;
-}
-
-int main(int argc, char *argv[]) {
- int fd;
- char name[] = "/tmp/test-asynchronous_close.XXXXXX";
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- asynchronous_close(fd);
-
- assert_se(asynchronous_job(async_func, NULL) >= 0);
-
- assert_se(asynchronous_sync() >= 0);
-
- sleep(1);
-
- assert_se(fcntl(fd, F_GETFD) == -1);
- assert_se(test_async);
-
- unlink(name);
-
- return 0;
-}
diff --git a/src/test/test-barrier.c b/src/test/test-barrier.c
deleted file mode 100644
index 2d109a30e7..0000000000
--- a/src/test/test-barrier.c
+++ /dev/null
@@ -1,462 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2014 David Herrmann <dh.herrmann@gmail.com>
-
- 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/>.
-***/
-
-/*
- * IPC barrier tests
- * These tests verify the correct behavior of the IPC Barrier implementation.
- * Note that the tests use alarm-timers to verify dead-locks and timeouts. These
- * might not work on slow machines where 20ms are too short to perform specific
- * operations (though, very unlikely). In case that turns out true, we have to
- * increase it at the slightly cost of lengthen test-duration on other machines.
- */
-
-#include <stdio.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-#include "barrier.h"
-#include "util.h"
-
-/* 20ms to test deadlocks; All timings use multiples of this constant as
- * alarm/sleep timers. If this timeout is too small for slow machines to perform
- * the requested operations, we have to increase it. On an i7 this works fine
- * with 1ms base-time, so 20ms should be just fine for everyone. */
-#define BASE_TIME (20 * USEC_PER_MSEC)
-
-static void set_alarm(usec_t usecs) {
- struct itimerval v = { };
-
- timeval_store(&v.it_value, usecs);
- assert_se(setitimer(ITIMER_REAL, &v, NULL) >= 0);
-}
-
-static void sleep_for(usec_t usecs) {
- /* stupid usleep() might fail if >1000000 */
- assert_se(usecs < USEC_PER_SEC);
- usleep(usecs);
-}
-
-#define TEST_BARRIER(_FUNCTION, _CHILD_CODE, _WAIT_CHILD, _PARENT_CODE, _WAIT_PARENT) \
- static void _FUNCTION(void) { \
- Barrier b = BARRIER_NULL; \
- pid_t pid1, pid2; \
- \
- assert_se(barrier_create(&b) >= 0); \
- assert_se(b.me > 0); \
- assert_se(b.them > 0); \
- assert_se(b.pipe[0] > 0); \
- assert_se(b.pipe[1] > 0); \
- \
- pid1 = fork(); \
- assert_se(pid1 >= 0); \
- if (pid1 == 0) { \
- barrier_set_role(&b, BARRIER_CHILD); \
- { _CHILD_CODE; } \
- exit(42); \
- } \
- \
- pid2 = fork(); \
- assert_se(pid2 >= 0); \
- if (pid2 == 0) { \
- barrier_set_role(&b, BARRIER_PARENT); \
- { _PARENT_CODE; } \
- exit(42); \
- } \
- \
- barrier_destroy(&b); \
- set_alarm(999999); \
- { _WAIT_CHILD; } \
- { _WAIT_PARENT; } \
- set_alarm(0); \
- }
-
-#define TEST_BARRIER_WAIT_SUCCESS(_pid) \
- ({ \
- int pidr, status; \
- pidr = waitpid(_pid, &status, 0); \
- assert_se(pidr == _pid); \
- assert_se(WIFEXITED(status)); \
- assert_se(WEXITSTATUS(status) == 42); \
- })
-
-#define TEST_BARRIER_WAIT_ALARM(_pid) \
- ({ \
- int pidr, status; \
- pidr = waitpid(_pid, &status, 0); \
- assert_se(pidr == _pid); \
- assert_se(WIFSIGNALED(status)); \
- assert_se(WTERMSIG(status) == SIGALRM); \
- })
-
-/*
- * Test basic sync points
- * This places a barrier in both processes and waits synchronously for them.
- * The timeout makes sure the sync works as expected. The sleep_for() on one side
- * makes sure the exit of the parent does not overwrite previous barriers. Due
- * to the sleep_for(), we know that the parent already exited, thus there's a
- * pending HUP on the pipe. However, the barrier_sync() prefers reads on the
- * eventfd, thus we can safely wait on the barrier.
- */
-TEST_BARRIER(test_barrier_sync,
- ({
- set_alarm(BASE_TIME * 10);
- assert_se(barrier_place(&b));
- sleep_for(BASE_TIME * 2);
- assert_se(barrier_sync(&b));
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid1),
- ({
- set_alarm(BASE_TIME * 10);
- assert_se(barrier_place(&b));
- assert_se(barrier_sync(&b));
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid2));
-
-/*
- * Test wait_next()
- * This places a barrier in the parent and syncs on it. The child sleeps while
- * the parent places the barrier and then waits for a barrier. The wait will
- * succeed as the child hasn't read the parent's barrier, yet. The following
- * barrier and sync synchronize the exit.
- */
-TEST_BARRIER(test_barrier_wait_next,
- ({
- sleep_for(BASE_TIME);
- set_alarm(BASE_TIME * 10);
- assert_se(barrier_wait_next(&b));
- assert_se(barrier_place(&b));
- assert_se(barrier_sync(&b));
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid1),
- ({
- set_alarm(BASE_TIME * 4);
- assert_se(barrier_place(&b));
- assert_se(barrier_sync(&b));
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid2));
-
-/*
- * Test wait_next() multiple times
- * This places two barriers in the parent and waits for the child to exit. The
- * child sleeps 20ms so both barriers _should_ be in place. It then waits for
- * the parent to place the next barrier twice. The first call will fetch both
- * barriers and return. However, the second call will stall as the parent does
- * not place a 3rd barrier (the sleep caught two barriers). wait_next() is does
- * not look at barrier-links so this stall is expected. Thus this test times
- * out.
- */
-TEST_BARRIER(test_barrier_wait_next_twice,
- ({
- sleep_for(BASE_TIME);
- set_alarm(BASE_TIME);
- assert_se(barrier_wait_next(&b));
- assert_se(barrier_wait_next(&b));
- assert_se(0);
- }),
- TEST_BARRIER_WAIT_ALARM(pid1),
- ({
- set_alarm(BASE_TIME * 10);
- assert_se(barrier_place(&b));
- assert_se(barrier_place(&b));
- sleep_for(BASE_TIME * 4);
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid2));
-
-/*
- * Test wait_next() with local barriers
- * This is the same as test_barrier_wait_next_twice, but places local barriers
- * between both waits. This does not have any effect on the wait so it times out
- * like the other test.
- */
-TEST_BARRIER(test_barrier_wait_next_twice_local,
- ({
- sleep_for(BASE_TIME);
- set_alarm(BASE_TIME);
- assert_se(barrier_wait_next(&b));
- assert_se(barrier_place(&b));
- assert_se(barrier_place(&b));
- assert_se(barrier_wait_next(&b));
- assert_se(0);
- }),
- TEST_BARRIER_WAIT_ALARM(pid1),
- ({
- set_alarm(BASE_TIME * 10);
- assert_se(barrier_place(&b));
- assert_se(barrier_place(&b));
- sleep_for(BASE_TIME * 4);
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid2));
-
-/*
- * Test wait_next() with sync_next()
- * This is again the same as test_barrier_wait_next_twice but uses a
- * synced wait as the second wait. This works just fine because the local state
- * has no barriers placed, therefore, the remote is always in sync.
- */
-TEST_BARRIER(test_barrier_wait_next_twice_sync,
- ({
- sleep_for(BASE_TIME);
- set_alarm(BASE_TIME);
- assert_se(barrier_wait_next(&b));
- assert_se(barrier_sync_next(&b));
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid1),
- ({
- set_alarm(BASE_TIME * 10);
- assert_se(barrier_place(&b));
- assert_se(barrier_place(&b));
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid2));
-
-/*
- * Test wait_next() with sync_next() and local barriers
- * This is again the same as test_barrier_wait_next_twice_local but uses a
- * synced wait as the second wait. This works just fine because the local state
- * is in sync with the remote.
- */
-TEST_BARRIER(test_barrier_wait_next_twice_local_sync,
- ({
- sleep_for(BASE_TIME);
- set_alarm(BASE_TIME);
- assert_se(barrier_wait_next(&b));
- assert_se(barrier_place(&b));
- assert_se(barrier_place(&b));
- assert_se(barrier_sync_next(&b));
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid1),
- ({
- set_alarm(BASE_TIME * 10);
- assert_se(barrier_place(&b));
- assert_se(barrier_place(&b));
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid2));
-
-/*
- * Test sync_next() and sync()
- * This tests sync_*() synchronizations and makes sure they work fine if the
- * local state is behind the remote state.
- */
-TEST_BARRIER(test_barrier_sync_next,
- ({
- set_alarm(BASE_TIME * 10);
- assert_se(barrier_sync_next(&b));
- assert_se(barrier_sync(&b));
- assert_se(barrier_place(&b));
- assert_se(barrier_place(&b));
- assert_se(barrier_sync_next(&b));
- assert_se(barrier_sync_next(&b));
- assert_se(barrier_sync(&b));
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid1),
- ({
- set_alarm(BASE_TIME * 10);
- sleep_for(BASE_TIME);
- assert_se(barrier_place(&b));
- assert_se(barrier_place(&b));
- assert_se(barrier_sync(&b));
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid2));
-
-/*
- * Test sync_next() and sync() with local barriers
- * This tests timeouts if sync_*() is used if local barriers are placed but the
- * remote didn't place any.
- */
-TEST_BARRIER(test_barrier_sync_next_local,
- ({
- set_alarm(BASE_TIME);
- assert_se(barrier_place(&b));
- assert_se(barrier_sync_next(&b));
- assert_se(0);
- }),
- TEST_BARRIER_WAIT_ALARM(pid1),
- ({
- sleep_for(BASE_TIME * 2);
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid2));
-
-/*
- * Test sync_next() and sync() with local barriers and abortion
- * This is the same as test_barrier_sync_next_local but aborts the sync in the
- * parent. Therefore, the sync_next() succeeds just fine due to the abortion.
- */
-TEST_BARRIER(test_barrier_sync_next_local_abort,
- ({
- set_alarm(BASE_TIME * 10);
- assert_se(barrier_place(&b));
- assert_se(!barrier_sync_next(&b));
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid1),
- ({
- assert_se(barrier_abort(&b));
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid2));
-
-/*
- * Test matched wait_abortion()
- * This runs wait_abortion() with remote abortion.
- */
-TEST_BARRIER(test_barrier_wait_abortion,
- ({
- set_alarm(BASE_TIME * 10);
- assert_se(barrier_wait_abortion(&b));
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid1),
- ({
- assert_se(barrier_abort(&b));
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid2));
-
-/*
- * Test unmatched wait_abortion()
- * This runs wait_abortion() without any remote abortion going on. It thus must
- * timeout.
- */
-TEST_BARRIER(test_barrier_wait_abortion_unmatched,
- ({
- set_alarm(BASE_TIME);
- assert_se(barrier_wait_abortion(&b));
- assert_se(0);
- }),
- TEST_BARRIER_WAIT_ALARM(pid1),
- ({
- sleep_for(BASE_TIME * 2);
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid2));
-
-/*
- * Test matched wait_abortion() with local abortion
- * This runs wait_abortion() with local and remote abortion.
- */
-TEST_BARRIER(test_barrier_wait_abortion_local,
- ({
- set_alarm(BASE_TIME * 10);
- assert_se(barrier_abort(&b));
- assert_se(!barrier_wait_abortion(&b));
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid1),
- ({
- assert_se(barrier_abort(&b));
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid2));
-
-/*
- * Test unmatched wait_abortion() with local abortion
- * This runs wait_abortion() with only local abortion. This must time out.
- */
-TEST_BARRIER(test_barrier_wait_abortion_local_unmatched,
- ({
- set_alarm(BASE_TIME);
- assert_se(barrier_abort(&b));
- assert_se(!barrier_wait_abortion(&b));
- assert_se(0);
- }),
- TEST_BARRIER_WAIT_ALARM(pid1),
- ({
- sleep_for(BASE_TIME * 2);
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid2));
-
-/*
- * Test child exit
- * Place barrier and sync with the child. The child only exits()s, which should
- * cause an implicit abortion and wake the parent.
- */
-TEST_BARRIER(test_barrier_exit,
- ({
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid1),
- ({
- set_alarm(BASE_TIME * 10);
- assert_se(barrier_place(&b));
- assert_se(!barrier_sync(&b));
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid2));
-
-/*
- * Test child exit with sleep
- * Same as test_barrier_exit but verifies the test really works due to the
- * child-exit. We add a usleep() which triggers the alarm in the parent and
- * causes the test to time out.
- */
-TEST_BARRIER(test_barrier_no_exit,
- ({
- sleep_for(BASE_TIME * 2);
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid1),
- ({
- set_alarm(BASE_TIME);
- assert_se(barrier_place(&b));
- assert_se(!barrier_sync(&b));
- }),
- TEST_BARRIER_WAIT_ALARM(pid2));
-
-/*
- * Test pending exit against sync
- * The parent places a barrier *and* exits. The 20ms wait in the child
- * guarantees both are pending. However, our logic prefers pending barriers over
- * pending exit-abortions (unlike normal abortions), thus the wait_next() must
- * succeed, same for the sync_next() as our local barrier-count is smaller than
- * the remote. Once we place a barrier our count is equal, so the sync still
- * succeeds. Only if we place one more barrier, we're ahead of the remote, thus
- * we will fail due to HUP on the pipe.
- */
-TEST_BARRIER(test_barrier_pending_exit,
- ({
- set_alarm(BASE_TIME * 4);
- sleep_for(BASE_TIME * 2);
- assert_se(barrier_wait_next(&b));
- assert_se(barrier_sync_next(&b));
- assert_se(barrier_place(&b));
- assert_se(barrier_sync_next(&b));
- assert_se(barrier_place(&b));
- assert_se(!barrier_sync_next(&b));
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid1),
- ({
- assert_se(barrier_place(&b));
- }),
- TEST_BARRIER_WAIT_SUCCESS(pid2));
-
-int main(int argc, char *argv[]) {
- log_parse_environment();
- log_open();
-
- test_barrier_sync();
- test_barrier_wait_next();
- test_barrier_wait_next_twice();
- test_barrier_wait_next_twice_sync();
- test_barrier_wait_next_twice_local();
- test_barrier_wait_next_twice_local_sync();
- test_barrier_sync_next();
- test_barrier_sync_next_local();
- test_barrier_sync_next_local_abort();
- test_barrier_wait_abortion();
- test_barrier_wait_abortion_unmatched();
- test_barrier_wait_abortion_local();
- test_barrier_wait_abortion_local_unmatched();
- test_barrier_exit();
- test_barrier_no_exit();
- test_barrier_pending_exit();
-
- return 0;
-}
diff --git a/src/test/test-boot-timestamps.c b/src/test/test-boot-timestamps.c
deleted file mode 100644
index 06d93af533..0000000000
--- a/src/test/test-boot-timestamps.c
+++ /dev/null
@@ -1,98 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 Lennart Poettering
- Copyright 2013 Kay Sievers
-
- 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 "util.h"
-#include "log.h"
-#include "boot-timestamps.h"
-#include "efivars.h"
-#include "acpi-fpdt.h"
-
-static int test_acpi_fpdt(void) {
- usec_t loader_start;
- usec_t loader_exit;
- char ts_start[FORMAT_TIMESPAN_MAX];
- char ts_exit[FORMAT_TIMESPAN_MAX];
- char ts_span[FORMAT_TIMESPAN_MAX];
- int r;
-
- r = acpi_get_boot_usec(&loader_start, &loader_exit);
- if (r < 0) {
- if (r != -ENOENT)
- log_error_errno(r, "Failed to read ACPI FPDT: %m");
- return r;
- }
-
- log_info("ACPI FPDT: loader start=%s exit=%s duration=%s",
- format_timespan(ts_start, sizeof(ts_start), loader_start, USEC_PER_MSEC),
- format_timespan(ts_exit, sizeof(ts_exit), loader_exit, USEC_PER_MSEC),
- format_timespan(ts_span, sizeof(ts_span), loader_exit - loader_start, USEC_PER_MSEC));
-
- return 0;
-}
-
-static int test_efi_loader(void) {
- usec_t loader_start;
- usec_t loader_exit;
- char ts_start[FORMAT_TIMESPAN_MAX];
- char ts_exit[FORMAT_TIMESPAN_MAX];
- char ts_span[FORMAT_TIMESPAN_MAX];
- int r;
-
- r = efi_loader_get_boot_usec(&loader_start, &loader_exit);
- if (r < 0) {
- if (r != -ENOENT)
- log_error_errno(r, "Failed to read EFI loader data: %m");
- return r;
- }
-
- log_info("EFI Loader: start=%s exit=%s duration=%s",
- format_timespan(ts_start, sizeof(ts_start), loader_start, USEC_PER_MSEC),
- format_timespan(ts_exit, sizeof(ts_exit), loader_exit, USEC_PER_MSEC),
- format_timespan(ts_span, sizeof(ts_span), loader_exit - loader_start, USEC_PER_MSEC));
-
- return 0;
-}
-
-int main(int argc, char* argv[]) {
- char s[MAX(FORMAT_TIMESPAN_MAX, FORMAT_TIMESTAMP_MAX)];
- int r;
- dual_timestamp fw, l, k;
-
- test_acpi_fpdt();
- test_efi_loader();
-
- dual_timestamp_from_monotonic(&k, 0);
-
- r = boot_timestamps(NULL, &fw, &l);
- if (r < 0) {
- log_error_errno(r, "Failed to read variables: %m");
- return 1;
- }
-
- log_info("Firmware began %s before kernel.", format_timespan(s, sizeof(s), fw.monotonic, 0));
- log_info("Loader began %s before kernel.", format_timespan(s, sizeof(s), l.monotonic, 0));
- log_info("Firmware began %s.", format_timestamp(s, sizeof(s), fw.realtime));
- log_info("Loader began %s.", format_timestamp(s, sizeof(s), l.realtime));
- log_info("Kernel began %s.", format_timestamp(s, sizeof(s), k.realtime));
-
- return 0;
-}
diff --git a/src/test/test-btrfs.c b/src/test/test-btrfs.c
deleted file mode 100644
index 9e6538e735..0000000000
--- a/src/test/test-btrfs.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2014 Lennart Poettering
-
- 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 <fcntl.h>
-
-#include "log.h"
-#include "fileio.h"
-#include "util.h"
-#include "btrfs-util.h"
-
-int main(int argc, char *argv[]) {
- int r;
- int fd;
-
- fd = open("/", O_RDONLY|O_CLOEXEC|O_DIRECTORY);
- if (fd < 0)
- log_error_errno(errno, "Failed to open root directory: %m");
- else {
- BtrfsSubvolInfo info;
- BtrfsQuotaInfo quota;
- char ts[FORMAT_TIMESTAMP_MAX], bs[FORMAT_BYTES_MAX];
-
- r = btrfs_subvol_get_info_fd(fd, &info);
- if (r < 0)
- log_error_errno(r, "Failed to get subvolume info: %m");
- else {
- log_info("otime: %s", format_timestamp(ts, sizeof(ts), info.otime));
- log_info("read-only (search): %s", yes_no(info.read_only));
- }
-
- r = btrfs_subvol_get_quota_fd(fd, &quota);
- if (r < 0)
- log_error_errno(r, "Failed to get quota info: %m");
- else {
- log_info("referenced: %s", strna(format_bytes(bs, sizeof(bs), quota.referenced)));
- log_info("exclusive: %s", strna(format_bytes(bs, sizeof(bs), quota.exclusive)));
- log_info("referenced_max: %s", strna(format_bytes(bs, sizeof(bs), quota.referenced_max)));
- log_info("exclusive_max: %s", strna(format_bytes(bs, sizeof(bs), quota.exclusive_max)));
- }
-
- r = btrfs_subvol_get_read_only_fd(fd);
- if (r < 0)
- log_error_errno(r, "Failed to get read only flag: %m");
- else
- log_info("read-only (ioctl): %s", yes_no(r));
-
- safe_close(fd);
- }
-
- r = btrfs_subvol_make("/xxxtest");
- if (r < 0)
- log_error_errno(r, "Failed to make subvolume: %m");
-
- r = write_string_file("/xxxtest/afile", "ljsadhfljasdkfhlkjdsfha");
- if (r < 0)
- log_error_errno(r, "Failed to write file: %m");
-
- r = btrfs_subvol_snapshot("/xxxtest", "/xxxtest2", false, false);
- if (r < 0)
- log_error_errno(r, "Failed to make snapshot: %m");
-
- r = btrfs_subvol_snapshot("/xxxtest", "/xxxtest3", true, false);
- if (r < 0)
- log_error_errno(r, "Failed to make snapshot: %m");
-
- r = btrfs_subvol_remove("/xxxtest");
- if (r < 0)
- log_error_errno(r, "Failed to remove subvolume: %m");
-
- r = btrfs_subvol_remove("/xxxtest2");
- if (r < 0)
- log_error_errno(r, "Failed to remove subvolume: %m");
-
- r = btrfs_subvol_remove("/xxxtest3");
- if (r < 0)
- log_error_errno(r, "Failed to remove subvolume: %m");
-
- r = btrfs_subvol_snapshot("/etc", "/etc2", true, true);
- if (r < 0)
- log_error_errno(r, "Failed to make snapshot: %m");
-
- r = btrfs_subvol_remove("/etc2");
- if (r < 0)
- log_error_errno(r, "Failed to remove subvolume: %m");
-
- return 0;
-}
diff --git a/src/test/test-calendarspec.c b/src/test/test-calendarspec.c
deleted file mode 100644
index 87e1da1258..0000000000
--- a/src/test/test-calendarspec.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2012 Lennart Poettering
-
- 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 <string.h>
-
-#include "calendarspec.h"
-#include "util.h"
-
-static void test_one(const char *input, const char *output) {
- CalendarSpec *c;
- _cleanup_free_ char *p = NULL, *q = NULL;
- usec_t u;
- char buf[FORMAT_TIMESTAMP_MAX];
- int r;
-
- assert_se(calendar_spec_from_string(input, &c) >= 0);
-
- assert_se(calendar_spec_to_string(c, &p) >= 0);
- printf("\"%s\" → \"%s\"\n", input, p);
-
- assert_se(streq(p, output));
-
- u = now(CLOCK_REALTIME);
- r = calendar_spec_next_usec(c, u, &u);
- printf("Next: %s\n", r < 0 ? strerror(-r) : format_timestamp(buf, sizeof(buf), u));
- calendar_spec_free(c);
-
- assert_se(calendar_spec_from_string(p, &c) >= 0);
- assert_se(calendar_spec_to_string(c, &q) >= 0);
- calendar_spec_free(c);
-
- assert_se(streq(q, p));
-}
-
-int main(int argc, char* argv[]) {
- CalendarSpec *c;
-
- test_one("Sat,Thu,Mon-Wed,Sat-Sun", "Mon-Thu,Sat,Sun *-*-* 00:00:00");
- test_one("Mon,Sun 12-*-* 2,1:23", "Mon,Sun 2012-*-* 01,02:23:00");
- test_one("Wed *-1", "Wed *-*-01 00:00:00");
- test_one("Wed-Wed,Wed *-1", "Wed *-*-01 00:00:00");
- test_one("Wed, 17:48", "Wed *-*-* 17:48:00");
- test_one("Wed-Sat,Tue 12-10-15 1:2:3", "Tue-Sat 2012-10-15 01:02:03");
- test_one("*-*-7 0:0:0", "*-*-07 00:00:00");
- test_one("10-15", "*-10-15 00:00:00");
- test_one("monday *-12-* 17:00", "Mon *-12-* 17:00:00");
- test_one("Mon,Fri *-*-3,1,2 *:30:45", "Mon,Fri *-*-01,02,03 *:30:45");
- test_one("12,14,13,12:20,10,30", "*-*-* 12,13,14:10,20,30:00");
- test_one("mon,fri *-1/2-1,3 *:30:45", "Mon,Fri *-01/2-01,03 *:30:45");
- test_one("03-05 08:05:40", "*-03-05 08:05:40");
- test_one("08:05:40", "*-*-* 08:05:40");
- test_one("05:40", "*-*-* 05:40:00");
- test_one("Sat,Sun 12-05 08:05:40", "Sat,Sun *-12-05 08:05:40");
- test_one("Sat,Sun 08:05:40", "Sat,Sun *-*-* 08:05:40");
- test_one("2003-03-05 05:40", "2003-03-05 05:40:00");
- test_one("2003-03-05", "2003-03-05 00:00:00");
- test_one("03-05", "*-03-05 00:00:00");
- test_one("hourly", "*-*-* *:00:00");
- test_one("daily", "*-*-* 00:00:00");
- test_one("monthly", "*-*-01 00:00:00");
- test_one("weekly", "Mon *-*-* 00:00:00");
- test_one("minutely", "*-*-* *:*:00");
- test_one("quarterly", "*-01,04,07,10-01 00:00:00");
- test_one("semi-annually", "*-01,07-01 00:00:00");
- test_one("annually", "*-01-01 00:00:00");
- test_one("*:2/3", "*-*-* *:02/3:00");
-
- assert_se(calendar_spec_from_string("test", &c) < 0);
- assert_se(calendar_spec_from_string("", &c) < 0);
- assert_se(calendar_spec_from_string("7", &c) < 0);
- assert_se(calendar_spec_from_string("121212:1:2", &c) < 0);
-
- return 0;
-}
diff --git a/src/test/test-cap-list.c b/src/test/test-cap-list.c
deleted file mode 100644
index 43a2d35b80..0000000000
--- a/src/test/test-cap-list.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2014 Lennart Poettering
-
- 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 "util.h"
-#include "fileio.h"
-#include "cap-list.h"
-#include "capability.h"
-#include <sys/prctl.h>
-
-/* verify the capability parser */
-static void test_cap_list(void) {
- int i;
-
- assert_se(!capability_to_name(-1));
- assert_se(!capability_to_name(capability_list_length()));
-
- for (i = 0; i < capability_list_length(); i++) {
- const char *n;
-
- assert_se(n = capability_to_name(i));
- assert_se(capability_from_name(n) == i);
- printf("%s = %i\n", n, i);
- }
-
- assert_se(capability_from_name("asdfbsd") == -EINVAL);
- assert_se(capability_from_name("CAP_AUDIT_READ") == CAP_AUDIT_READ);
- assert_se(capability_from_name("cap_audit_read") == CAP_AUDIT_READ);
- assert_se(capability_from_name("cAp_aUdIt_rEAd") == CAP_AUDIT_READ);
- assert_se(capability_from_name("0") == 0);
- assert_se(capability_from_name("15") == 15);
- assert_se(capability_from_name("-1") == -EINVAL);
-
- for (i = 0; i < capability_list_length(); i++) {
- _cleanup_cap_free_charp_ char *a = NULL;
- const char *b;
- unsigned u;
-
- assert_se(a = cap_to_name(i));
-
- /* quit the loop as soon as libcap starts returning
- * numeric ids, formatted as strings */
- if (safe_atou(a, &u) >= 0)
- break;
-
- assert_se(b = capability_to_name(i));
-
- printf("%s vs. %s\n", a, b);
-
- assert_se(strcasecmp(a, b) == 0);
- }
-}
-
-/* verify cap_last_cap() against /proc/sys/kernel/cap_last_cap */
-static void test_last_cap_file(void) {
- _cleanup_free_ char *content = NULL;
- unsigned long val = 0;
- int r;
-
- r = read_one_line_file("/proc/sys/kernel/cap_last_cap", &content);
- assert_se(r >= 0);
-
- r = safe_atolu(content, &val);
- assert_se(r >= 0);
- assert_se(val != 0);
- assert_se(val == cap_last_cap());
-}
-
-/* verify cap_last_cap() against syscall probing */
-static void test_last_cap_probe(void) {
- unsigned long p = (unsigned long)CAP_LAST_CAP;
-
- if (prctl(PR_CAPBSET_READ, p) < 0) {
- for (p--; p > 0; p --)
- if (prctl(PR_CAPBSET_READ, p) >= 0)
- break;
- } else {
- for (;; p++)
- if (prctl(PR_CAPBSET_READ, p+1) < 0)
- break;
- }
-
- assert_se(p != 0);
- assert_se(p == cap_last_cap());
-}
-
-int main(int argc, char *argv[]) {
- test_cap_list();
- test_last_cap_file();
- test_last_cap_probe();
-
- return 0;
-}
diff --git a/src/test/test-capability.c b/src/test/test-capability.c
deleted file mode 100644
index f47452ce72..0000000000
--- a/src/test/test-capability.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/***
- This file is part of systemd
-
- Copyright 2014 Ronny Chevalier
-
- 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 <sys/wait.h>
-#include <sys/capability.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <pwd.h>
-#include <unistd.h>
-
-#include "capability.h"
-#include "util.h"
-#include "macro.h"
-
-static uid_t test_uid = -1;
-static gid_t test_gid = -1;
-// We keep CAP_DAC_OVERRIDE to avoid errors with gcov when doing test coverage
-static uint64_t test_flags = 1ULL << CAP_DAC_OVERRIDE;
-
-static void fork_test(void (*test_func)(void)) {
- pid_t pid = 0;
-
- pid = fork();
- assert_se(pid >= 0);
- if (pid == 0) {
- test_func();
- exit(0);
- } else if (pid > 0) {
- int status;
-
- assert_se(waitpid(pid, &status, 0) > 0);
- assert_se(WIFEXITED(status) && WEXITSTATUS(status) == 0);
- }
-}
-
-static void show_capabilities(void) {
- cap_t caps;
- char *text;
-
- caps = cap_get_proc();
- assert_se(caps);
-
- text = cap_to_text(caps, NULL);
- assert_se(text);
-
- log_info("Capabilities:%s", text);
- cap_free(caps);
- cap_free(text);
-}
-
-static int setup_tests(void) {
- struct passwd *nobody;
-
- nobody = getpwnam("nobody");
- if (!nobody) {
- log_error_errno(errno, "Could not find nobody user: %m");
- return -EXIT_TEST_SKIP;
- }
- test_uid = nobody->pw_uid;
- test_gid = nobody->pw_gid;
-
- return 0;
-}
-
-static void test_drop_privileges_keep_net_raw(void) {
- int sock;
-
- sock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
- assert_se(sock >= 0);
- safe_close(sock);
-
- assert_se(drop_privileges(test_uid, test_gid, test_flags | (1ULL << CAP_NET_RAW)) >= 0);
- assert_se(getuid() == test_uid);
- assert_se(getgid() == test_gid);
- show_capabilities();
-
- sock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
- assert_se(sock >= 0);
- safe_close(sock);
-}
-
-static void test_drop_privileges_dontkeep_net_raw(void) {
- int sock;
-
- sock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
- assert_se(sock >= 0);
- safe_close(sock);
-
- assert_se(drop_privileges(test_uid, test_gid, test_flags) >= 0);
- assert_se(getuid() == test_uid);
- assert_se(getgid() == test_gid);
- show_capabilities();
-
- sock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
- assert_se(sock < 0);
-}
-
-static void test_drop_privileges_fail(void) {
- assert_se(drop_privileges(test_uid, test_gid, test_flags) >= 0);
- assert_se(getuid() == test_uid);
- assert_se(getgid() == test_gid);
-
- assert_se(drop_privileges(test_uid, test_gid, test_flags) < 0);
- assert_se(drop_privileges(0, 0, test_flags) < 0);
-}
-
-static void test_drop_privileges(void) {
- fork_test(test_drop_privileges_keep_net_raw);
- fork_test(test_drop_privileges_dontkeep_net_raw);
- fork_test(test_drop_privileges_fail);
-}
-
-static void test_have_effective_cap(void) {
- assert_se(have_effective_cap(CAP_KILL));
- assert_se(have_effective_cap(CAP_CHOWN));
-
- assert_se(drop_privileges(test_uid, test_gid, test_flags | (1ULL << CAP_KILL)) >= 0);
- assert_se(getuid() == test_uid);
- assert_se(getgid() == test_gid);
-
- assert_se(have_effective_cap(CAP_KILL));
- assert_se(!have_effective_cap(CAP_CHOWN));
-}
-
-int main(int argc, char *argv[]) {
- int r;
-
- log_parse_environment();
- log_open();
-
- if (getuid() != 0)
- return EXIT_TEST_SKIP;
-
- r = setup_tests();
- if (r < 0)
- return -r;
-
- show_capabilities();
-
- test_drop_privileges();
- fork_test(test_have_effective_cap);
-
- return 0;
-}
diff --git a/src/test/test-cgroup-mask.c b/src/test/test-cgroup-mask.c
deleted file mode 100644
index d14a07e1f4..0000000000
--- a/src/test/test-cgroup-mask.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 David Strauss
-
- 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 <stdio.h>
-
-#include "manager.h"
-#include "unit.h"
-#include "macro.h"
-#include "test-helper.h"
-
-static int test_cgroup_mask(void) {
- Manager *m = NULL;
- Unit *son, *daughter, *parent, *root, *grandchild, *parent_deep;
- FILE *serial = NULL;
- FDSet *fdset = NULL;
- int r;
-
- /* Prepare the manager. */
- assert_se(set_unit_path(TEST_DIR) >= 0);
- r = manager_new(SYSTEMD_USER, true, &m);
- if (r == -EPERM || r == -EACCES) {
- puts("manager_new: Permission denied. Skipping test.");
- return EXIT_TEST_SKIP;
- }
- assert_se(r >= 0);
- assert_se(manager_startup(m, serial, fdset) >= 0);
-
- /* Load units and verify hierarchy. */
- assert_se(manager_load_unit(m, "parent.slice", NULL, NULL, &parent) >= 0);
- assert_se(manager_load_unit(m, "son.service", NULL, NULL, &son) >= 0);
- assert_se(manager_load_unit(m, "daughter.service", NULL, NULL, &daughter) >= 0);
- assert_se(manager_load_unit(m, "grandchild.service", NULL, NULL, &grandchild) >= 0);
- assert_se(manager_load_unit(m, "parent-deep.slice", NULL, NULL, &parent_deep) >= 0);
- assert_se(parent->load_state == UNIT_LOADED);
- assert_se(son->load_state == UNIT_LOADED);
- assert_se(daughter->load_state == UNIT_LOADED);
- assert_se(grandchild->load_state == UNIT_LOADED);
- assert_se(parent_deep->load_state == UNIT_LOADED);
- assert_se(UNIT_DEREF(son->slice) == parent);
- assert_se(UNIT_DEREF(daughter->slice) == parent);
- assert_se(UNIT_DEREF(parent_deep->slice) == parent);
- assert_se(UNIT_DEREF(grandchild->slice) == parent_deep);
- root = UNIT_DEREF(parent->slice);
-
- /* Verify per-unit cgroups settings. */
- assert_se(unit_get_cgroup_mask(son) == (CGROUP_CPU | CGROUP_CPUACCT));
- assert_se(unit_get_cgroup_mask(daughter) == 0);
- assert_se(unit_get_cgroup_mask(grandchild) == 0);
- assert_se(unit_get_cgroup_mask(parent_deep) == CGROUP_MEMORY);
- assert_se(unit_get_cgroup_mask(parent) == CGROUP_BLKIO);
- assert_se(unit_get_cgroup_mask(root) == 0);
-
- /* Verify aggregation of member masks */
- assert_se(unit_get_members_mask(son) == 0);
- assert_se(unit_get_members_mask(daughter) == 0);
- assert_se(unit_get_members_mask(grandchild) == 0);
- assert_se(unit_get_members_mask(parent_deep) == 0);
- assert_se(unit_get_members_mask(parent) == (CGROUP_CPU | CGROUP_CPUACCT | CGROUP_MEMORY));
- assert_se(unit_get_members_mask(root) == (CGROUP_CPU | CGROUP_CPUACCT | CGROUP_BLKIO | CGROUP_MEMORY));
-
- /* Verify aggregation of sibling masks. */
- assert_se(unit_get_siblings_mask(son) == ((CGROUP_CPU | CGROUP_CPUACCT | CGROUP_MEMORY) & m->cgroup_supported));
- assert_se(unit_get_siblings_mask(daughter) == ((CGROUP_CPU | CGROUP_CPUACCT | CGROUP_MEMORY) & m->cgroup_supported));
- assert_se(unit_get_siblings_mask(grandchild) == 0);
- assert_se(unit_get_siblings_mask(parent_deep) == ((CGROUP_CPU | CGROUP_CPUACCT | CGROUP_MEMORY) & m->cgroup_supported));
- assert_se(unit_get_siblings_mask(parent) == ((CGROUP_CPU | CGROUP_CPUACCT | CGROUP_BLKIO | CGROUP_MEMORY) & m->cgroup_supported));
- assert_se(unit_get_siblings_mask(root) == ((CGROUP_CPU | CGROUP_CPUACCT | CGROUP_BLKIO | CGROUP_MEMORY) & m->cgroup_supported));
-
- /* Verify aggregation of target masks. */
- assert_se(unit_get_target_mask(son) == ((CGROUP_CPU | CGROUP_CPUACCT | CGROUP_MEMORY) & m->cgroup_supported));
- assert_se(unit_get_target_mask(daughter) == ((CGROUP_CPU | CGROUP_CPUACCT | CGROUP_MEMORY) & m->cgroup_supported));
- assert_se(unit_get_target_mask(grandchild) == 0);
- assert_se(unit_get_target_mask(parent_deep) == ((CGROUP_CPU | CGROUP_CPUACCT | CGROUP_MEMORY) & m->cgroup_supported));
- assert_se(unit_get_target_mask(parent) == ((CGROUP_CPU | CGROUP_CPUACCT | CGROUP_BLKIO | CGROUP_MEMORY) & m->cgroup_supported));
- assert_se(unit_get_target_mask(root) == ((CGROUP_CPU | CGROUP_CPUACCT | CGROUP_BLKIO | CGROUP_MEMORY) & m->cgroup_supported));
-
- manager_free(m);
-
- return 0;
-}
-
-int main(int argc, char* argv[]) {
- int rc = 0;
- TEST_REQ_RUNNING_SYSTEMD(rc = test_cgroup_mask());
- return rc;
-}
diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c
deleted file mode 100644
index 9834a6a130..0000000000
--- a/src/test/test-cgroup-util.c
+++ /dev/null
@@ -1,264 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 Zbigniew Jędrzejewski-Szmek
-
- 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 "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;
- int r;
-
- r = cg_path_decode_unit(path, &unit);
- printf("%s: %s → %s %d expected %s %d\n", __func__, path, unit, r, result, code);
- assert_se(r == code);
- assert_se(streq_ptr(unit, result));
-}
-
-static void test_path_decode_unit(void) {
- check_p_d_u("getty@tty2.service", 0, "getty@tty2.service");
- check_p_d_u("getty@tty2.service/", 0, "getty@tty2.service");
- check_p_d_u("getty@tty2.service/xxx", 0, "getty@tty2.service");
- check_p_d_u("getty@.service/", -EINVAL, NULL);
- check_p_d_u("getty@.service", -EINVAL, NULL);
- check_p_d_u("getty.service", 0, "getty.service");
- check_p_d_u("getty", -EINVAL, NULL);
- check_p_d_u("getty/waldo", -EINVAL, NULL);
- check_p_d_u("_cpu.service", 0, "cpu.service");
-}
-
-static void check_p_g_u(const char *path, int code, const char *result) {
- _cleanup_free_ char *unit = NULL;
- int r;
-
- r = cg_path_get_unit(path, &unit);
- printf("%s: %s → %s %d expected %s %d\n", __func__, path, unit, r, result, code);
- assert_se(r == code);
- assert_se(streq_ptr(unit, result));
-}
-
-static void test_path_get_unit(void) {
- check_p_g_u("/system.slice/foobar.service/sdfdsaf", 0, "foobar.service");
- check_p_g_u("/system.slice/getty@tty5.service", 0, "getty@tty5.service");
- check_p_g_u("/system.slice/getty@tty5.service/aaa/bbb", 0, "getty@tty5.service");
- check_p_g_u("/system.slice/getty@tty5.service/", 0, "getty@tty5.service");
- check_p_g_u("/system.slice/getty@tty6.service/tty5", 0, "getty@tty6.service");
- check_p_g_u("sadfdsafsda", -EINVAL, NULL);
- check_p_g_u("/system.slice/getty####@tty6.service/xxx", -EINVAL, NULL);
- check_p_g_u("/system.slice/system-waldo.slice/foobar.service/sdfdsaf", 0, "foobar.service");
- check_p_g_u("/system.slice/system-waldo.slice/_cpu.service/sdfdsaf", 0, "cpu.service");
- check_p_g_u("/user.slice/user-1000.slice/user@1000.service/server.service", 0, "user@1000.service");
- check_p_g_u("/user.slice/user-1000.slice/user@.service/server.service", -EINVAL, NULL);
-}
-
-static void check_p_g_u_u(const char *path, int code, const char *result) {
- _cleanup_free_ char *unit = NULL;
- int r;
-
- r = cg_path_get_user_unit(path, &unit);
- printf("%s: %s → %s %d expected %s %d\n", __func__, path, unit, r, result, code);
- assert_se(r == code);
- assert_se(streq_ptr(unit, result));
-}
-
-static void test_path_get_user_unit(void) {
- check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/foobar.service", 0, "foobar.service");
- check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/waldo.slice/foobar.service", 0, "foobar.service");
- check_p_g_u_u("/user.slice/user-1002.slice/session-2.scope/foobar.service/waldo", 0, "foobar.service");
- check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/foobar.service/waldo/uuuux", 0, "foobar.service");
- check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/waldo/waldo/uuuux", -EINVAL, NULL);
- check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/foobar@pie.service/pa/po", 0, "foobar@pie.service");
- check_p_g_u_u("/session-2.scope/foobar@pie.service/pa/po", 0, "foobar@pie.service");
- check_p_g_u_u("/xyz.slice/xyz-waldo.slice/session-77.scope/foobar@pie.service/pa/po", 0, "foobar@pie.service");
- check_p_g_u_u("/meh.service", -ENOENT, NULL);
- check_p_g_u_u("/session-3.scope/_cpu.service", 0, "cpu.service");
- check_p_g_u_u("/user.slice/user-1000.slice/user@1000.service/server.service", 0, "server.service");
- check_p_g_u_u("/user.slice/user-1000.slice/user@1000.service/foobar.slice/foobar@pie.service", 0, "foobar@pie.service");
- check_p_g_u_u("/user.slice/user-1000.slice/user@.service/server.service", -ENOENT, NULL);
-}
-
-static void check_p_g_s(const char *path, int code, const char *result) {
- _cleanup_free_ char *s = NULL;
-
- assert_se(cg_path_get_session(path, &s) == code);
- assert_se(streq_ptr(s, result));
-}
-
-static void test_path_get_session(void) {
- check_p_g_s("/user.slice/user-1000.slice/session-2.scope/foobar.service", 0, "2");
- check_p_g_s("/session-3.scope", 0, "3");
- check_p_g_s("/session-.scope", -ENOENT, NULL);
- check_p_g_s("", -ENOENT, NULL);
-}
-
-static void check_p_g_o_u(const char *path, int code, uid_t result) {
- uid_t uid = 0;
-
- assert_se(cg_path_get_owner_uid(path, &uid) == code);
- assert_se(uid == result);
-}
-
-static void test_path_get_owner_uid(void) {
- check_p_g_o_u("/user.slice/user-1000.slice/session-2.scope/foobar.service", 0, 1000);
- check_p_g_o_u("/user.slice/user-1006.slice", 0, 1006);
- check_p_g_o_u("", -ENOENT, 0);
-}
-
-static void test_get_paths(void) {
- _cleanup_free_ char *a = NULL;
-
- assert_se(cg_get_root_path(&a) >= 0);
- log_info("Root = %s", a);
-}
-
-static void test_proc(void) {
- _cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
- int r;
-
- d = opendir("/proc");
- assert_se(d);
-
- FOREACH_DIRENT(de, d, break) {
- _cleanup_free_ char *path = NULL, *path_shifted = NULL, *session = NULL, *unit = NULL, *user_unit = NULL, *machine = NULL, *slice = NULL;
- pid_t pid;
- uid_t uid = UID_INVALID;
-
- if (de->d_type != DT_DIR &&
- de->d_type != DT_UNKNOWN)
- continue;
-
- r = parse_pid(de->d_name, &pid);
- if (r < 0)
- continue;
-
- if (is_kernel_thread(pid))
- continue;
-
- cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &path);
- cg_pid_get_path_shifted(pid, NULL, &path_shifted);
- cg_pid_get_owner_uid(pid, &uid);
- cg_pid_get_session(pid, &session);
- cg_pid_get_unit(pid, &unit);
- cg_pid_get_user_unit(pid, &user_unit);
- cg_pid_get_machine_name(pid, &machine);
- cg_pid_get_slice(pid, &slice);
-
- printf(PID_FMT"\t%s\t%s\t"UID_FMT"\t%s\t%s\t%s\t%s\t%s\n",
- pid,
- path,
- path_shifted,
- uid,
- session,
- unit,
- user_unit,
- machine,
- slice);
- }
-}
-
-static void test_escape_one(const char *s, const char *r) {
- _cleanup_free_ char *b;
-
- b = cg_escape(s);
- assert_se(b);
- assert_se(streq(b, r));
-
- assert_se(streq(cg_unescape(b), s));
-}
-
-static void test_escape(void) {
- test_escape_one("foobar", "foobar");
- test_escape_one(".foobar", "_.foobar");
- test_escape_one("foobar.service", "foobar.service");
- test_escape_one("cgroup.service", "_cgroup.service");
- test_escape_one("tasks", "_tasks");
- if (access("/sys/fs/cgroup/cpu", F_OK) == 0)
- test_escape_one("cpu.service", "_cpu.service");
- test_escape_one("_foobar", "__foobar");
- test_escape_one("", "_");
- test_escape_one("_", "__");
- test_escape_one(".", "_.");
-}
-
-static void test_controller_is_valid(void) {
- assert_se(cg_controller_is_valid("foobar", false));
- assert_se(cg_controller_is_valid("foo_bar", false));
- assert_se(cg_controller_is_valid("name=foo", true));
- assert_se(!cg_controller_is_valid("", false));
- assert_se(!cg_controller_is_valid("name=", true));
- assert_se(!cg_controller_is_valid("=", false));
- assert_se(!cg_controller_is_valid("cpu,cpuacct", false));
- assert_se(!cg_controller_is_valid("_", false));
- assert_se(!cg_controller_is_valid("_foobar", false));
- assert_se(!cg_controller_is_valid("tatü", false));
-}
-
-static void test_slice_to_path_one(const char *unit, const char *path, int error) {
- _cleanup_free_ char *ret = NULL;
-
- assert_se(cg_slice_to_path(unit, &ret) == error);
- assert_se(streq_ptr(ret, path));
-}
-
-static void test_slice_to_path(void) {
-
- test_slice_to_path_one("foobar.slice", "foobar.slice", 0);
- test_slice_to_path_one("foobar-waldo.slice", "foobar.slice/foobar-waldo.slice", 0);
- test_slice_to_path_one("foobar-waldo.service", NULL, -EINVAL);
- test_slice_to_path_one("-.slice", NULL, -EINVAL);
- test_slice_to_path_one("-foo-.slice", NULL, -EINVAL);
- test_slice_to_path_one("-foo.slice", NULL, -EINVAL);
- test_slice_to_path_one("a-b.slice", "a.slice/a-b.slice", 0);
- test_slice_to_path_one("a-b-c-d-e.slice", "a.slice/a-b.slice/a-b-c.slice/a-b-c-d.slice/a-b-c-d-e.slice", 0);
-}
-
-static void test_shift_path_one(const char *raw, const char *root, const char *shifted) {
- const char *s = NULL;
-
- assert_se(cg_shift_path(raw, root, &s) >= 0);
- assert_se(streq(s, shifted));
-}
-
-static void test_shift_path(void) {
-
- test_shift_path_one("/foobar/waldo", "/", "/foobar/waldo");
- test_shift_path_one("/foobar/waldo", "", "/foobar/waldo");
- test_shift_path_one("/foobar/waldo", "/foobar", "/waldo");
- test_shift_path_one("/foobar/waldo", "/fuckfuck", "/foobar/waldo");
-}
-
-int main(void) {
- test_path_decode_unit();
- test_path_get_unit();
- test_path_get_user_unit();
- test_path_get_session();
- test_path_get_owner_uid();
- TEST_REQ_RUNNING_SYSTEMD(test_get_paths());
- test_proc();
- TEST_REQ_RUNNING_SYSTEMD(test_escape());
- test_controller_is_valid();
- test_slice_to_path();
- test_shift_path();
-
- return 0;
-}
diff --git a/src/test/test-cgroup.c b/src/test/test-cgroup.c
deleted file mode 100644
index 4be69a408d..0000000000
--- a/src/test/test-cgroup.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2010 Lennart Poettering
-
- 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 <unistd.h>
-#include <string.h>
-
-#include "cgroup-util.h"
-#include "path-util.h"
-#include "util.h"
-
-int main(int argc, char*argv[]) {
- char *path;
- char *c, *p;
-
- assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, "/test-a") == 0);
- assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, "/test-a") == 0);
- assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, "/test-b") == 0);
- assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, "/test-b/test-c") == 0);
- assert_se(cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, "/test-b", 0) == 0);
-
- assert_se(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid(), &path) == 0);
- assert_se(streq(path, "/test-b"));
- free(path);
-
- assert_se(cg_attach(SYSTEMD_CGROUP_CONTROLLER, "/test-a", 0) == 0);
-
- assert_se(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid(), &path) == 0);
- assert_se(path_equal(path, "/test-a"));
- free(path);
-
- assert_se(cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, "/test-b/test-d", 0) == 0);
-
- assert_se(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid(), &path) == 0);
- assert_se(path_equal(path, "/test-b/test-d"));
- free(path);
-
- assert_se(cg_get_path(SYSTEMD_CGROUP_CONTROLLER, "/test-b/test-d", NULL, &path) == 0);
- assert_se(path_equal(path, "/sys/fs/cgroup/systemd/test-b/test-d"));
- free(path);
-
- assert_se(cg_is_empty(SYSTEMD_CGROUP_CONTROLLER, "/test-a", false) > 0);
- assert_se(cg_is_empty(SYSTEMD_CGROUP_CONTROLLER, "/test-b", false) > 0);
- assert_se(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-a", false) > 0);
- assert_se(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-b", false) == 0);
-
- assert_se(cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-a", 0, false, false, false, NULL) == 0);
- assert_se(cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-b", 0, false, false, false, NULL) > 0);
-
- assert_se(cg_migrate_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-b", SYSTEMD_CGROUP_CONTROLLER, "/test-a", false, false) > 0);
-
- assert_se(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-a", false) == 0);
- assert_se(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-b", false) > 0);
-
- assert_se(cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-a", 0, false, false, false, NULL) > 0);
- assert_se(cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-b", 0, false, false, false, NULL) == 0);
-
- cg_trim(SYSTEMD_CGROUP_CONTROLLER, "/", false);
-
- assert_se(cg_delete(SYSTEMD_CGROUP_CONTROLLER, "/test-b") < 0);
- assert_se(cg_delete(SYSTEMD_CGROUP_CONTROLLER, "/test-a") >= 0);
-
- assert_se(cg_split_spec("foobar:/", &c, &p) == 0);
- assert_se(streq(c, "foobar"));
- assert_se(streq(p, "/"));
- free(c);
- free(p);
-
- assert_se(cg_split_spec("foobar:", &c, &p) < 0);
- assert_se(cg_split_spec("foobar:asdfd", &c, &p) < 0);
- assert_se(cg_split_spec(":///", &c, &p) < 0);
- assert_se(cg_split_spec(":", &c, &p) < 0);
- assert_se(cg_split_spec("", &c, &p) < 0);
- assert_se(cg_split_spec("fo/obar:/", &c, &p) < 0);
-
- assert_se(cg_split_spec("/", &c, &p) >= 0);
- assert_se(c == NULL);
- assert_se(streq(p, "/"));
- free(p);
-
- assert_se(cg_split_spec("foo", &c, &p) >= 0);
- assert_se(streq(c, "foo"));
- assert_se(p == NULL);
- free(c);
-
- return 0;
-}
diff --git a/src/test/test-condition.c b/src/test/test-condition.c
deleted file mode 100644
index 88147c8e0a..0000000000
--- a/src/test/test-condition.c
+++ /dev/null
@@ -1,237 +0,0 @@
-/***
- This file is part of systemd
-
- Copyright 2014 Ronny Chevalier
-
- 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 "condition.h"
-#include "macro.h"
-#include "util.h"
-#include "log.h"
-#include "architecture.h"
-#include "sd-id128.h"
-#include "selinux-util.h"
-#include "audit.h"
-#include "ima-util.h"
-#include "apparmor-util.h"
-#include "smack-util.h"
-
-static void test_condition_test_path(void) {
- Condition *condition;
-
- condition = condition_new(CONDITION_PATH_EXISTS, "/bin/sh", false, false);
- assert_se(condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_PATH_EXISTS, "/bin/s?", false, false);
- assert_se(!condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_PATH_EXISTS_GLOB, "/bin/s?", false, false);
- assert_se(condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_PATH_EXISTS_GLOB, "/bin/s?", false, true);
- assert_se(!condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_PATH_EXISTS, "/thiscertainlywontexist", false, false);
- assert_se(!condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_PATH_EXISTS, "/thiscertainlywontexist", false, true);
- assert_se(condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_PATH_IS_DIRECTORY, "/bin", false, false);
- assert_se(condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_DIRECTORY_NOT_EMPTY, "/bin", false, false);
- assert_se(condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_FILE_NOT_EMPTY, "/bin/sh", false, false);
- assert_se(condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_FILE_IS_EXECUTABLE, "/bin/sh", false, false);
- assert_se(condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_FILE_IS_EXECUTABLE, "/etc/passwd", false, false);
- assert_se(!condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_PATH_IS_MOUNT_POINT, "/proc", false, false);
- assert_se(condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_PATH_IS_MOUNT_POINT, "/", false, false);
- assert_se(condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_PATH_IS_MOUNT_POINT, "/bin", false, false);
- assert_se(!condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_PATH_IS_READ_WRITE, "/tmp", false, false);
- assert_se(condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_PATH_IS_SYMBOLIC_LINK, "/dev/stdout", false, false);
- assert_se(condition_test(condition));
- condition_free(condition);
-}
-
-static void test_condition_test_ac_power(void) {
- Condition *condition;
-
- condition = condition_new(CONDITION_AC_POWER, "true", false, false);
- assert_se(condition_test(condition) == on_ac_power());
- condition_free(condition);
-
- condition = condition_new(CONDITION_AC_POWER, "false", false, false);
- assert_se(condition_test(condition) != on_ac_power());
- condition_free(condition);
-
- condition = condition_new(CONDITION_AC_POWER, "false", false, true);
- assert_se(condition_test(condition) == on_ac_power());
- condition_free(condition);
-}
-
-static void test_condition_test_host(void) {
- Condition *condition;
- sd_id128_t id;
- int r;
- char sid[SD_ID128_STRING_MAX];
- _cleanup_free_ char *hostname = NULL;
-
- r = sd_id128_get_machine(&id);
- assert_se(r >= 0);
- assert_se(sd_id128_to_string(id, sid));
-
- condition = condition_new(CONDITION_HOST, sid, false, false);
- assert_se(condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_HOST, "garbage value jjjjjjjjjjjjjj", false, false);
- assert_se(!condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_HOST, sid, false, true);
- assert_se(!condition_test(condition));
- condition_free(condition);
-
- hostname = gethostname_malloc();
- assert_se(hostname);
-
- condition = condition_new(CONDITION_HOST, hostname, false, false);
- assert_se(condition_test(condition));
- condition_free(condition);
-}
-
-static void test_condition_test_architecture(void) {
- Condition *condition;
- const char *sa;
- int a;
-
- a = uname_architecture();
- assert_se(a >= 0);
-
- sa = architecture_to_string(a);
- assert_se(sa);
-
- condition = condition_new(CONDITION_ARCHITECTURE, sa, false, false);
- assert_se(condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_ARCHITECTURE, "garbage value", false, false);
- assert_se(condition_test(condition) < 0);
- condition_free(condition);
-
- condition = condition_new(CONDITION_ARCHITECTURE, sa, false, true);
- assert_se(!condition_test(condition));
- condition_free(condition);
-}
-
-static void test_condition_test_kernel_command_line(void) {
- Condition *condition;
-
- condition = condition_new(CONDITION_KERNEL_COMMAND_LINE, "thisreallyshouldntbeonthekernelcommandline", false, false);
- assert_se(!condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_KERNEL_COMMAND_LINE, "andthis=neither", false, false);
- assert_se(!condition_test(condition));
- condition_free(condition);
-}
-
-static void test_condition_test_null(void) {
- Condition *condition;
-
- condition = condition_new(CONDITION_NULL, NULL, false, false);
- assert_se(condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_NULL, NULL, false, true);
- assert_se(!condition_test(condition));
- condition_free(condition);
-}
-
-static void test_condition_test_security(void) {
- Condition *condition;
-
- condition = condition_new(CONDITION_SECURITY, "garbage oifdsjfoidsjoj", false, false);
- assert_se(!condition_test(condition));
- condition_free(condition);
-
- condition = condition_new(CONDITION_SECURITY, "selinux", false, true);
- assert_se(condition_test(condition) != mac_selinux_use());
- condition_free(condition);
-
- condition = condition_new(CONDITION_SECURITY, "ima", false, false);
- assert_se(condition_test(condition) == use_ima());
- condition_free(condition);
-
- condition = condition_new(CONDITION_SECURITY, "apparmor", false, false);
- assert_se(condition_test(condition) == mac_apparmor_use());
- condition_free(condition);
-
- condition = condition_new(CONDITION_SECURITY, "smack", false, false);
- assert_se(condition_test(condition) == mac_smack_use());
- condition_free(condition);
-
- condition = condition_new(CONDITION_SECURITY, "audit", false, false);
- assert_se(condition_test(condition) == use_audit());
- condition_free(condition);
-}
-
-
-int main(int argc, char *argv[]) {
- log_parse_environment();
- log_open();
-
- test_condition_test_path();
- test_condition_test_ac_power();
- test_condition_test_host();
- test_condition_test_architecture();
- test_condition_test_kernel_command_line();
- test_condition_test_null();
- test_condition_test_security();
-
- return 0;
-}
diff --git a/src/test/test-conf-files.c b/src/test/test-conf-files.c
deleted file mode 100644
index 894c7f742f..0000000000
--- a/src/test/test-conf-files.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2014 Michael Marineau
-
- 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 <stdio.h>
-#include <stdarg.h>
-
-#include "conf-files.h"
-#include "macro.h"
-#include "strv.h"
-#include "util.h"
-
-
-static void setup_test_dir(char *tmp_dir, const char *files, ...) {
- va_list ap;
-
- assert_se(mkdtemp(tmp_dir) != NULL);
-
- va_start(ap, files);
- while (files != NULL) {
- _cleanup_free_ char *path = strappend(tmp_dir, files);
- assert_se(touch_file(path, true, USEC_INFINITY, UID_INVALID, GID_INVALID, 0) == 0);
- files = va_arg(ap, const char *);
- }
- va_end(ap);
-}
-
-static void test_conf_files_list(bool use_root) {
- char tmp_dir[] = "/tmp/test-conf-files-XXXXXX";
- _cleanup_strv_free_ char **found_files = NULL;
- const char *root_dir, *search_1, *search_2, *expect_a, *expect_b;
-
- setup_test_dir(tmp_dir,
- "/dir1/a.conf",
- "/dir2/a.conf",
- "/dir2/b.conf",
- NULL);
-
- if (use_root) {
- root_dir = tmp_dir;
- search_1 = "/dir1";
- search_2 = "/dir2";
- } else {
- root_dir = NULL;
- search_1 = strjoina(tmp_dir, "/dir1");
- search_2 = strjoina(tmp_dir, "/dir2");
- }
-
- expect_a = strjoina(tmp_dir, "/dir1/a.conf");
- expect_b = strjoina(tmp_dir, "/dir2/b.conf");
-
- assert_se(conf_files_list(&found_files, ".conf", root_dir, search_1, search_2, NULL) == 0);
- strv_print(found_files);
-
- assert_se(found_files);
- assert_se(streq_ptr(found_files[0], expect_a));
- assert_se(streq_ptr(found_files[1], expect_b));
- assert_se(found_files[2] == NULL);
-
- assert_se(rm_rf_dangerous(tmp_dir, false, true, false) == 0);
-}
-
-int main(int argc, char **argv) {
- test_conf_files_list(false);
- test_conf_files_list(true);
- return 0;
-}
diff --git a/src/test/test-copy.c b/src/test/test-copy.c
deleted file mode 100644
index 5c96f61005..0000000000
--- a/src/test/test-copy.c
+++ /dev/null
@@ -1,141 +0,0 @@
-/***
- This file is part of systemd
-
- Copyright 2014 Ronny Chevalier
-
- 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 <unistd.h>
-
-#include "copy.h"
-#include "path-util.h"
-#include "fileio.h"
-#include "mkdir.h"
-#include "strv.h"
-#include "macro.h"
-#include "util.h"
-
-static void test_copy_file(void) {
- _cleanup_free_ char *buf = NULL;
- char fn[] = "/tmp/test-copy_file.XXXXXX";
- char fn_copy[] = "/tmp/test-copy_file.XXXXXX";
- size_t sz = 0;
- int fd;
-
- fd = mkostemp_safe(fn, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- close(fd);
-
- fd = mkostemp_safe(fn_copy, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- close(fd);
-
- assert_se(write_string_file(fn, "foo bar bar bar foo") == 0);
-
- assert_se(copy_file(fn, fn_copy, 0, 0644, 0) == 0);
-
- assert_se(read_full_file(fn_copy, &buf, &sz) == 0);
- assert_se(streq(buf, "foo bar bar bar foo\n"));
- assert_se(sz == 20);
-
- unlink(fn);
- unlink(fn_copy);
-}
-
-static void test_copy_file_fd(void) {
- char in_fn[] = "/tmp/test-copy-file-fd-XXXXXX";
- char out_fn[] = "/tmp/test-copy-file-fd-XXXXXX";
- _cleanup_close_ int in_fd = -1, out_fd = -1;
- char text[] = "boohoo\nfoo\n\tbar\n";
- char buf[64] = {0};
-
- in_fd = mkostemp_safe(in_fn, O_RDWR);
- assert_se(in_fd >= 0);
- out_fd = mkostemp_safe(out_fn, O_RDWR);
- assert_se(out_fd >= 0);
-
- assert_se(write_string_file(in_fn, text) == 0);
- assert_se(copy_file_fd("/a/file/which/does/not/exist/i/guess", out_fd, true) < 0);
- assert_se(copy_file_fd(in_fn, out_fd, true) >= 0);
- assert_se(lseek(out_fd, SEEK_SET, 0) == 0);
-
- assert_se(read(out_fd, buf, sizeof(buf)) == sizeof(text) - 1);
- assert_se(streq(buf, text));
-
- unlink(in_fn);
- unlink(out_fn);
-}
-
-static void test_copy_tree(void) {
- char original_dir[] = "/tmp/test-copy_tree/";
- char copy_dir[] = "/tmp/test-copy_tree-copy/";
- char **files = STRV_MAKE("file", "dir1/file", "dir1/dir2/file", "dir1/dir2/dir3/dir4/dir5/file");
- char **links = STRV_MAKE("link", "file",
- "link2", "dir1/file");
- char **p, **link;
-
- rm_rf_dangerous(copy_dir, false, true, false);
- rm_rf_dangerous(original_dir, false, true, false);
-
- STRV_FOREACH(p, files) {
- char *f = strjoina(original_dir, *p);
-
- assert_se(mkdir_parents(f, 0755) >= 0);
- assert_se(write_string_file(f, "file") == 0);
- }
-
- STRV_FOREACH_PAIR(link, p, links) {
- char *f = strjoina(original_dir, *p);
- char *l = strjoina(original_dir, *link);
-
- assert_se(mkdir_parents(l, 0755) >= 0);
- assert_se(symlink(f, l) == 0);
- }
-
- assert_se(copy_tree(original_dir, copy_dir, true) == 0);
-
- STRV_FOREACH(p, files) {
- _cleanup_free_ char *buf = NULL;
- size_t sz = 0;
- char *f = strjoina(copy_dir, *p);
-
- assert_se(access(f, F_OK) == 0);
- assert_se(read_full_file(f, &buf, &sz) == 0);
- assert_se(streq(buf, "file\n"));
- }
-
- STRV_FOREACH_PAIR(link, p, links) {
- _cleanup_free_ char *target = NULL;
- char *f = strjoina(original_dir, *p);
- char *l = strjoina(copy_dir, *link);
-
- assert_se(readlink_and_canonicalize(l, &target) == 0);
- assert_se(path_equal(f, target));
- }
-
- assert_se(copy_tree(original_dir, copy_dir, false) < 0);
- assert_se(copy_tree("/tmp/inexistent/foo/bar/fsdoi", copy_dir, false) < 0);
-
- rm_rf_dangerous(copy_dir, false, true, false);
- rm_rf_dangerous(original_dir, false, true, false);
-}
-
-int main(int argc, char *argv[]) {
- test_copy_file();
- test_copy_file_fd();
- test_copy_tree();
-
- return 0;
-}
diff --git a/src/test/test-daemon.c b/src/test/test-daemon.c
deleted file mode 100644
index 7e0ac754d1..0000000000
--- a/src/test/test-daemon.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2010 Lennart Poettering
-
- 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 <unistd.h>
-
-#include "systemd/sd-daemon.h"
-
-int main(int argc, char*argv[]) {
-
- sd_notify(0,
- "STATUS=Starting up");
- sleep(5);
-
- sd_notify(0,
- "STATUS=Running\n"
- "READY=1");
- sleep(5);
-
- sd_notify(0,
- "STATUS=Reloading\n"
- "RELOADING=1");
- sleep(5);
-
- sd_notify(0,
- "STATUS=Running\n"
- "READY=1");
- sleep(5);
-
- sd_notify(0,
- "STATUS=Quitting\n"
- "STOPPING=1");
- sleep(5);
-
- return 0;
-}
diff --git a/src/test/test-date.c b/src/test/test-date.c
deleted file mode 100644
index 00b569080c..0000000000
--- a/src/test/test-date.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2012 Lennart Poettering
-
- 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 <string.h>
-
-#include "util.h"
-
-static void test_one(const char *p) {
- usec_t t, q;
- char buf[FORMAT_TIMESTAMP_MAX], buf_relative[FORMAT_TIMESTAMP_RELATIVE_MAX];
-
- assert_se(parse_timestamp(p, &t) >= 0);
- format_timestamp(buf, sizeof(buf), t);
- log_info("%s", buf);
-
- /* Chop off timezone */
- *strrchr(buf, ' ') = 0;
-
- assert_se(parse_timestamp(buf, &q) >= 0);
- assert_se(q == t);
-
- format_timestamp_relative(buf_relative, sizeof(buf_relative), t);
- log_info("%s", strna(buf_relative));
- assert_se(parse_timestamp(buf, &q) >= 0);
-}
-
-int main(int argc, char *argv[]) {
- test_one("17:41");
- test_one("18:42:44");
- test_one("12-10-02 12:13:14");
- test_one("12-10-2 12:13:14");
- test_one("12-10-03 12:13");
- test_one("2012-12-30 18:42");
- test_one("2012-10-02");
- test_one("Tue 2012-10-02");
- test_one("now");
- test_one("yesterday");
- test_one("today");
- test_one("tomorrow");
- test_one("+2d");
- test_one("+2y 4d");
- test_one("5months ago");
- test_one("@1395716396");
-
- return 0;
-}
diff --git a/src/test/test-device-nodes.c b/src/test/test-device-nodes.c
deleted file mode 100644
index 59ba4be087..0000000000
--- a/src/test/test-device-nodes.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 Dave Reisner
-
- 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 <sys/types.h>
-
-#include "device-nodes.h"
-#include "util.h"
-
-/* helpers for test_encode_devnode_name */
-static char *do_encode_string(const char *in) {
- size_t out_len = strlen(in) * 4 + 1;
- char *out = malloc(out_len);
-
- assert_se(out);
- assert_se(encode_devnode_name(in, out, out_len) >= 0);
- puts(out);
-
- return out;
-}
-
-static bool expect_encoded_as(const char *in, const char *expected) {
- _cleanup_free_ char *encoded = do_encode_string(in);
- return streq(encoded, expected);
-}
-
-static void test_encode_devnode_name(void) {
- assert_se(expect_encoded_as("systemd sucks", "systemd\\x20sucks"));
- assert_se(expect_encoded_as("pinkiepie", "pinkiepie"));
- assert_se(expect_encoded_as("valíd\\ųtf8", "valíd\\x5cųtf8"));
- assert_se(expect_encoded_as("s/ash/ng", "s\\x2fash\\x2fng"));
- assert_se(expect_encoded_as("/", "\\x2f"));
- assert_se(expect_encoded_as("!", "\\x21"));
-}
-
-int main(int argc, char *argv[]) {
- test_encode_devnode_name();
-
- return 0;
-}
diff --git a/src/test/test-ellipsize.c b/src/test/test-ellipsize.c
deleted file mode 100644
index 6a2f9aa943..0000000000
--- a/src/test/test-ellipsize.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 Shawn Landden
-
- 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 <stdio.h>
-
-#include "util.h"
-#include "def.h"
-
-static void test_one(const char *p) {
- _cleanup_free_ char *t;
- t = ellipsize(p, columns(), 70);
- puts(t);
-}
-
-int main(int argc, char *argv[]) {
- test_one(DIGITS LETTERS DIGITS LETTERS);
- test_one("한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어");
- test_one("-日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国");
- test_one("中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国-中国中国中国中国中国中国中国中国中国中国中国中国中国");
- test_one("sÿstëmd sÿstëmd sÿstëmd sÿstëmd sÿstëmd sÿstëmd sÿstëmd sÿstëmd sÿstëmd sÿstëmd sÿstëmd sÿstëmd sÿstëmd");
- test_one("🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮🐮");
- test_one("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
- test_one("shórt");
-
- return 0;
-}
diff --git a/src/test/test-engine.c b/src/test/test-engine.c
deleted file mode 100644
index d543d23b7a..0000000000
--- a/src/test/test-engine.c
+++ /dev/null
@@ -1,112 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2010 Lennart Poettering
-
- 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 <stdio.h>
-#include <errno.h>
-#include <string.h>
-
-#include "manager.h"
-#include "bus-util.h"
-
-int main(int argc, char *argv[]) {
- _cleanup_bus_error_free_ sd_bus_error err = SD_BUS_ERROR_NULL;
- Manager *m = NULL;
- Unit *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL, *g = NULL, *h = NULL;
- FILE *serial = NULL;
- FDSet *fdset = NULL;
- Job *j;
- int r;
-
- /* prepare the test */
- assert_se(set_unit_path(TEST_DIR) >= 0);
- r = manager_new(SYSTEMD_USER, true, &m);
- if (IN_SET(r, -EPERM, -EACCES, -EADDRINUSE, -EHOSTDOWN, -ENOENT)) {
- printf("Skipping test: manager_new: %s", strerror(-r));
- return EXIT_TEST_SKIP;
- }
- assert_se(r >= 0);
- assert_se(manager_startup(m, serial, fdset) >= 0);
-
- printf("Load1:\n");
- assert_se(manager_load_unit(m, "a.service", NULL, NULL, &a) >= 0);
- assert_se(manager_load_unit(m, "b.service", NULL, NULL, &b) >= 0);
- assert_se(manager_load_unit(m, "c.service", NULL, NULL, &c) >= 0);
- manager_dump_units(m, stdout, "\t");
-
- printf("Test1: (Trivial)\n");
- r = manager_add_job(m, JOB_START, c, JOB_REPLACE, false, &err, &j);
- if (sd_bus_error_is_set(&err))
- log_error("error: %s: %s", err.name, err.message);
- assert_se(r == 0);
- manager_dump_jobs(m, stdout, "\t");
-
- printf("Load2:\n");
- manager_clear_jobs(m);
- assert_se(manager_load_unit(m, "d.service", NULL, NULL, &d) >= 0);
- assert_se(manager_load_unit(m, "e.service", NULL, NULL, &e) >= 0);
- manager_dump_units(m, stdout, "\t");
-
- printf("Test2: (Cyclic Order, Unfixable)\n");
- assert_se(manager_add_job(m, JOB_START, d, JOB_REPLACE, false, NULL, &j) == -EDEADLK);
- manager_dump_jobs(m, stdout, "\t");
-
- printf("Test3: (Cyclic Order, Fixable, Garbage Collector)\n");
- assert_se(manager_add_job(m, JOB_START, e, JOB_REPLACE, false, NULL, &j) == 0);
- manager_dump_jobs(m, stdout, "\t");
-
- printf("Test4: (Identical transaction)\n");
- assert_se(manager_add_job(m, JOB_START, e, JOB_FAIL, false, NULL, &j) == 0);
- manager_dump_jobs(m, stdout, "\t");
-
- printf("Load3:\n");
- assert_se(manager_load_unit(m, "g.service", NULL, NULL, &g) >= 0);
- manager_dump_units(m, stdout, "\t");
-
- printf("Test5: (Colliding transaction, fail)\n");
- assert_se(manager_add_job(m, JOB_START, g, JOB_FAIL, false, NULL, &j) == -EDEADLK);
-
- printf("Test6: (Colliding transaction, replace)\n");
- assert_se(manager_add_job(m, JOB_START, g, JOB_REPLACE, false, NULL, &j) == 0);
- manager_dump_jobs(m, stdout, "\t");
-
- printf("Test7: (Unmergeable job type, fail)\n");
- assert_se(manager_add_job(m, JOB_STOP, g, JOB_FAIL, false, NULL, &j) == -EDEADLK);
-
- printf("Test8: (Mergeable job type, fail)\n");
- assert_se(manager_add_job(m, JOB_RESTART, g, JOB_FAIL, false, NULL, &j) == 0);
- manager_dump_jobs(m, stdout, "\t");
-
- printf("Test9: (Unmergeable job type, replace)\n");
- assert_se(manager_add_job(m, JOB_STOP, g, JOB_REPLACE, false, NULL, &j) == 0);
- manager_dump_jobs(m, stdout, "\t");
-
- printf("Load4:\n");
- assert_se(manager_load_unit(m, "h.service", NULL, NULL, &h) >= 0);
- manager_dump_units(m, stdout, "\t");
-
- printf("Test10: (Unmergeable job type of auxiliary job, fail)\n");
- assert_se(manager_add_job(m, JOB_START, h, JOB_FAIL, false, NULL, &j) == 0);
- manager_dump_jobs(m, stdout, "\t");
-
- manager_free(m);
-
- return 0;
-}
diff --git a/src/test/test-env-replace.c b/src/test/test-env-replace.c
deleted file mode 100644
index 8f1fcd992c..0000000000
--- a/src/test/test-env-replace.c
+++ /dev/null
@@ -1,217 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2010 Lennart Poettering
-
- 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 <string.h>
-
-#include "util.h"
-#include "strv.h"
-#include "env-util.h"
-
-static void test_strv_env_delete(void) {
- _cleanup_strv_free_ char **a = NULL, **b = NULL, **c = NULL, **d = NULL;
-
- a = strv_new("FOO=BAR", "WALDO=WALDO", "WALDO=", "PIEP", "SCHLUMPF=SMURF", NULL);
- assert_se(a);
-
- b = strv_new("PIEP", "FOO", NULL);
- assert_se(b);
-
- c = strv_new("SCHLUMPF", NULL);
- assert_se(c);
-
- d = strv_env_delete(a, 2, b, c);
- assert_se(d);
-
- assert_se(streq(d[0], "WALDO=WALDO"));
- assert_se(streq(d[1], "WALDO="));
- assert_se(strv_length(d) == 2);
-}
-
-static void test_strv_env_unset(void) {
- _cleanup_strv_free_ char **l = NULL;
-
- l = strv_new("PIEP", "SCHLUMPF=SMURFF", "NANANANA=YES", NULL);
- assert_se(l);
-
- assert_se(strv_env_unset(l, "SCHLUMPF") == l);
-
- assert_se(streq(l[0], "PIEP"));
- assert_se(streq(l[1], "NANANANA=YES"));
- assert_se(strv_length(l) == 2);
-}
-
-static void test_strv_env_set(void) {
- _cleanup_strv_free_ char **l = NULL, **r = NULL;
-
- l = strv_new("PIEP", "SCHLUMPF=SMURFF", "NANANANA=YES", NULL);
- assert_se(l);
-
- r = strv_env_set(l, "WALDO=WALDO");
- assert_se(r);
-
- assert_se(streq(r[0], "PIEP"));
- assert_se(streq(r[1], "SCHLUMPF=SMURFF"));
- assert_se(streq(r[2], "NANANANA=YES"));
- assert_se(streq(r[3], "WALDO=WALDO"));
- assert_se(strv_length(r) == 4);
-}
-
-static void test_strv_env_merge(void) {
- _cleanup_strv_free_ char **a = NULL, **b = NULL, **r = NULL;
-
- a = strv_new("FOO=BAR", "WALDO=WALDO", "WALDO=", "PIEP", "SCHLUMPF=SMURF", NULL);
- assert_se(a);
-
- b = strv_new("FOO=KKK", "FOO=", "PIEP=", "SCHLUMPF=SMURFF", "NANANANA=YES", NULL);
- assert_se(b);
-
- r = strv_env_merge(2, a, b);
- assert_se(r);
- assert_se(streq(r[0], "FOO="));
- assert_se(streq(r[1], "WALDO="));
- assert_se(streq(r[2], "PIEP"));
- assert_se(streq(r[3], "SCHLUMPF=SMURFF"));
- assert_se(streq(r[4], "PIEP="));
- assert_se(streq(r[5], "NANANANA=YES"));
- assert_se(strv_length(r) == 6);
-
- assert_se(strv_env_clean(r) == r);
- assert_se(streq(r[0], "FOO="));
- assert_se(streq(r[1], "WALDO="));
- assert_se(streq(r[2], "SCHLUMPF=SMURFF"));
- assert_se(streq(r[3], "PIEP="));
- assert_se(streq(r[4], "NANANANA=YES"));
- assert_se(strv_length(r) == 5);
-}
-
-static void test_replace_env_arg(void) {
- const char *env[] = {
- "FOO=BAR BAR",
- "BAR=waldo",
- NULL
- };
- const char *line[] = {
- "FOO$FOO",
- "FOO$FOOFOO",
- "FOO${FOO}$FOO",
- "FOO${FOO}",
- "${FOO}",
- "$FOO",
- "$FOO$FOO",
- "${FOO}${BAR}",
- "${FOO",
- NULL
- };
- _cleanup_strv_free_ char **r = NULL;
-
- r = replace_env_argv((char**) line, (char**) env);
- assert_se(r);
- assert_se(streq(r[0], "FOO$FOO"));
- assert_se(streq(r[1], "FOO$FOOFOO"));
- assert_se(streq(r[2], "FOOBAR BAR$FOO"));
- assert_se(streq(r[3], "FOOBAR BAR"));
- assert_se(streq(r[4], "BAR BAR"));
- assert_se(streq(r[5], "BAR"));
- assert_se(streq(r[6], "BAR"));
- assert_se(streq(r[7], "BAR BARwaldo"));
- assert_se(streq(r[8], "${FOO"));
- assert_se(strv_length(r) == 9);
-}
-
-static void test_one_normalize(const char *input, const char *output) {
- _cleanup_free_ char *t;
-
- t = normalize_env_assignment(input);
- assert_se(t);
- assert_se(streq(t, output));
-}
-
-static void test_normalize_env_assignment(void) {
- test_one_normalize("foo=bar", "foo=bar");
- test_one_normalize("=bar", "=bar");
- test_one_normalize("foo=", "foo=");
- test_one_normalize("=", "=");
- test_one_normalize("", "");
- test_one_normalize("a=\"waldo\"", "a=waldo");
- test_one_normalize("a=\"waldo", "a=\"waldo");
- test_one_normalize("a=waldo\"", "a=waldo\"");
- test_one_normalize("a=\'", "a='");
- test_one_normalize("a=\'\'", "a=");
- test_one_normalize(" xyz ", "xyz");
- test_one_normalize(" xyz = bar ", "xyz=bar");
- test_one_normalize(" xyz = 'bar ' ", "xyz=bar ");
- test_one_normalize(" ' xyz' = 'bar ' ", "' xyz'=bar ");
-}
-
-static void test_env_clean(void) {
- _cleanup_strv_free_ char **e;
-
- e = strv_new("FOOBAR=WALDO",
- "FOOBAR=WALDO",
- "FOOBAR",
- "F",
- "X=",
- "F=F",
- "=",
- "=F",
- "",
- "0000=000",
- "äöüß=abcd",
- "abcd=äöüß",
- "xyz\n=xyz",
- "xyz=xyz\n",
- "another=one",
- "another=final one",
- NULL);
- assert_se(e);
- assert_se(!strv_env_is_valid(e));
- assert_se(strv_env_clean(e) == e);
- assert_se(strv_env_is_valid(e));
-
- assert_se(streq(e[0], "FOOBAR=WALDO"));
- assert_se(streq(e[1], "X="));
- assert_se(streq(e[2], "F=F"));
- assert_se(streq(e[3], "abcd=äöüß"));
- assert_se(streq(e[4], "another=final one"));
- assert_se(e[5] == NULL);
-}
-
-static void test_env_name_is_valid(void) {
- assert_se(env_name_is_valid("test"));
-
- assert_se(!env_name_is_valid(NULL));
- assert_se(!env_name_is_valid(""));
- assert_se(!env_name_is_valid("5_starting_with_a_number_is_wrong"));
- assert_se(!env_name_is_valid("#¤%&?_only_numbers_letters_and_underscore_allowed"));
-}
-
-int main(int argc, char *argv[]) {
- test_strv_env_delete();
- test_strv_env_unset();
- test_strv_env_set();
- test_strv_env_merge();
- test_replace_env_arg();
- test_normalize_env_assignment();
- test_env_clean();
- test_env_name_is_valid();
-
- return 0;
-}
diff --git a/src/test/test-execute.c b/src/test/test-execute.c
deleted file mode 100644
index 428fd32600..0000000000
--- a/src/test/test-execute.c
+++ /dev/null
@@ -1,183 +0,0 @@
-/***
- This file is part of systemd.
-
- Copyright 2014 Ronny Chevalier
-
- 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 <stdio.h>
-
-#include "unit.h"
-#include "manager.h"
-#include "util.h"
-#include "macro.h"
-#include "mkdir.h"
-
-typedef void (*test_function_t)(Manager *m);
-
-static void check(Manager *m, Unit *unit, int status_expected, int code_expected) {
- Service *service = NULL;
- usec_t ts;
- usec_t timeout = 2 * USEC_PER_SEC;
-
- assert_se(m);
- assert_se(unit);
-
- service = SERVICE(unit);
- printf("%s\n", unit->id);
- exec_context_dump(&service->exec_context, stdout, "\t");
- ts = now(CLOCK_MONOTONIC);
- while (service->state != SERVICE_DEAD && service->state != SERVICE_FAILED) {
- int r;
- usec_t n;
-
- r = sd_event_run(m->event, 100 * USEC_PER_MSEC);
- assert_se(r >= 0);
-
- n = now(CLOCK_MONOTONIC);
- if (ts + timeout < n) {
- log_error("Test timeout when testing %s", unit->id);
- exit(EXIT_FAILURE);
- }
- }
- exec_status_dump(&service->main_exec_status, stdout, "\t");
- assert_se(service->main_exec_status.status == status_expected);
- assert_se(service->main_exec_status.code == code_expected);
-}
-
-static void test(Manager *m, const char *unit_name, int status_expected, int code_expected) {
- Unit *unit;
-
- assert_se(unit_name);
-
- assert_se(manager_load_unit(m, unit_name, NULL, NULL, &unit) >= 0);
- assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
- check(m, unit, status_expected, code_expected);
-}
-
-static void test_exec_workingdirectory(Manager *m) {
- assert_se(mkdir_p("/tmp/test-exec_workingdirectory", 0755) >= 0);
-
- test(m, "exec-workingdirectory.service", 0, CLD_EXITED);
-
- rm_rf_dangerous("/tmp/test-exec_workingdirectory", false, true, false);
-}
-
-static void test_exec_personality(Manager *m) {
- test(m, "exec-personality-x86.service", 0, CLD_EXITED);
-
-#if defined(__x86_64__)
- test(m, "exec-personality-x86-64.service", 0, CLD_EXITED);
-#endif
-}
-
-static void test_exec_ignoresigpipe(Manager *m) {
- test(m, "exec-ignoresigpipe-yes.service", 0, CLD_EXITED);
- test(m, "exec-ignoresigpipe-no.service", SIGPIPE, CLD_KILLED);
-}
-
-static void test_exec_privatetmp(Manager *m) {
- assert_se(touch("/tmp/test-exec_privatetmp") >= 0);
-
- test(m, "exec-privatetmp-yes.service", 0, CLD_EXITED);
- test(m, "exec-privatetmp-no.service", 0, CLD_EXITED);
-
- unlink("/tmp/test-exec_privatetmp");
-}
-
-static void test_exec_privatedevices(Manager *m) {
- test(m, "exec-privatedevices-yes.service", 0, CLD_EXITED);
- test(m, "exec-privatedevices-no.service", 0, CLD_EXITED);
-}
-
-static void test_exec_systemcallfilter(Manager *m) {
-#ifdef HAVE_SECCOMP
- test(m, "exec-systemcallfilter-not-failing.service", 0, CLD_EXITED);
- test(m, "exec-systemcallfilter-not-failing2.service", 0, CLD_EXITED);
- test(m, "exec-systemcallfilter-failing.service", SIGSYS, CLD_KILLED);
- test(m, "exec-systemcallfilter-failing2.service", SIGSYS, CLD_KILLED);
-#endif
-}
-
-static void test_exec_systemcallerrornumber(Manager *m) {
-#ifdef HAVE_SECCOMP
- test(m, "exec-systemcallerrornumber.service", 1, CLD_EXITED);
-#endif
-}
-
-static void test_exec_user(Manager *m) {
- test(m, "exec-user.service", 0, CLD_EXITED);
-}
-
-static void test_exec_group(Manager *m) {
- test(m, "exec-group.service", 0, CLD_EXITED);
-}
-
-static void test_exec_environment(Manager *m) {
- test(m, "exec-environment.service", 0, CLD_EXITED);
- test(m, "exec-environment-multiple.service", 0, CLD_EXITED);
- test(m, "exec-environment-empty.service", 0, CLD_EXITED);
-}
-
-static void test_exec_umask(Manager *m) {
- test(m, "exec-umask-default.service", 0, CLD_EXITED);
- test(m, "exec-umask-0177.service", 0, CLD_EXITED);
-}
-
-int main(int argc, char *argv[]) {
- test_function_t tests[] = {
- test_exec_workingdirectory,
- test_exec_personality,
- test_exec_ignoresigpipe,
- test_exec_privatetmp,
- test_exec_privatedevices,
- test_exec_systemcallfilter,
- test_exec_systemcallerrornumber,
- test_exec_user,
- test_exec_group,
- test_exec_environment,
- test_exec_umask,
- NULL,
- };
- test_function_t *test = NULL;
- Manager *m = NULL;
- int r;
-
- log_parse_environment();
- log_open();
-
- /* It is needed otherwise cgroup creation fails */
- if (getuid() != 0) {
- printf("Skipping test: not root\n");
- return EXIT_TEST_SKIP;
- }
-
- assert_se(set_unit_path(TEST_DIR ":") >= 0);
-
- r = manager_new(SYSTEMD_USER, true, &m);
- if (IN_SET(r, -EPERM, -EACCES, -EADDRINUSE, -EHOSTDOWN, -ENOENT)) {
- printf("Skipping test: manager_new: %s", strerror(-r));
- return EXIT_TEST_SKIP;
- }
- assert_se(r >= 0);
- assert_se(manager_startup(m, NULL, NULL) >= 0);
-
- for (test = tests; test && *test; test++)
- (*test)(m);
-
- manager_free(m);
-
- return 0;
-}
diff --git a/src/test/test-fdset.c b/src/test/test-fdset.c
deleted file mode 100644
index 91df7eb663..0000000000
--- a/src/test/test-fdset.c
+++ /dev/null
@@ -1,166 +0,0 @@
-/***
- This file is part of systemd
-
- Copyright 2014 Ronny Chevalier
-
- 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 <fcntl.h>
-#include <unistd.h>
-
-#include "fdset.h"
-#include "util.h"
-#include "macro.h"
-
-static void test_fdset_new_fill(void) {
- int fd = -1;
- _cleanup_fdset_free_ FDSet *fdset = NULL;
- char name[] = "/tmp/test-fdset_new_fill.XXXXXX";
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- assert_se(fdset_new_fill(&fdset) >= 0);
- assert_se(fdset_contains(fdset, fd));
-
- unlink(name);
-}
-
-static void test_fdset_put_dup(void) {
- _cleanup_close_ int fd = -1;
- int copyfd = -1;
- _cleanup_fdset_free_ FDSet *fdset = NULL;
- char name[] = "/tmp/test-fdset_put_dup.XXXXXX";
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
-
- fdset = fdset_new();
- assert_se(fdset);
- copyfd = fdset_put_dup(fdset, fd);
- assert_se(copyfd >= 0 && copyfd != fd);
- assert_se(fdset_contains(fdset, copyfd));
- assert_se(!fdset_contains(fdset, fd));
-
- unlink(name);
-}
-
-static void test_fdset_cloexec(void) {
- int fd = -1;
- _cleanup_fdset_free_ FDSet *fdset = NULL;
- int flags = -1;
- char name[] = "/tmp/test-fdset_cloexec.XXXXXX";
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
-
- fdset = fdset_new();
- assert_se(fdset);
- assert_se(fdset_put(fdset, fd));
-
- assert_se(fdset_cloexec(fdset, false) >= 0);
- flags = fcntl(fd, F_GETFD);
- assert_se(flags >= 0);
- assert_se(!(flags & FD_CLOEXEC));
-
- assert_se(fdset_cloexec(fdset, true) >= 0);
- flags = fcntl(fd, F_GETFD);
- assert_se(flags >= 0);
- assert_se(flags & FD_CLOEXEC);
-
- unlink(name);
-}
-
-static void test_fdset_close_others(void) {
- int fd = -1;
- int copyfd = -1;
- _cleanup_fdset_free_ FDSet *fdset = NULL;
- int flags = -1;
- char name[] = "/tmp/test-fdset_close_others.XXXXXX";
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
-
- fdset = fdset_new();
- assert_se(fdset);
- copyfd = fdset_put_dup(fdset, fd);
- assert_se(copyfd >= 0);
-
- assert_se(fdset_close_others(fdset) >= 0);
- flags = fcntl(fd, F_GETFD);
- assert_se(flags < 0);
- flags = fcntl(copyfd, F_GETFD);
- assert_se(flags >= 0);
-
- unlink(name);
-}
-
-static void test_fdset_remove(void) {
- _cleanup_close_ int fd = -1;
- FDSet *fdset = NULL;
- char name[] = "/tmp/test-fdset_remove.XXXXXX";
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
-
- fdset = fdset_new();
- assert_se(fdset);
- assert_se(fdset_put(fdset, fd) >= 0);
- assert_se(fdset_remove(fdset, fd) >= 0);
- assert_se(!fdset_contains(fdset, fd));
- fdset_free(fdset);
-
- assert_se(fcntl(fd, F_GETFD) >= 0);
-
- unlink(name);
-}
-
-static void test_fdset_iterate(void) {
- int fd = -1;
- FDSet *fdset = NULL;
- char name[] = "/tmp/test-fdset_iterate.XXXXXX";
- Iterator i;
- int c = 0;
- int a;
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
-
- fdset = fdset_new();
- assert_se(fdset);
- assert_se(fdset_put(fdset, fd) >= 0);
- assert_se(fdset_put(fdset, fd) >= 0);
- assert_se(fdset_put(fdset, fd) >= 0);
-
- FDSET_FOREACH(a, fdset, i) {
- c++;
- assert_se(a == fd);
- }
- assert_se(c == 1);
-
- fdset_free(fdset);
-
- unlink(name);
-}
-
-int main(int argc, char *argv[]) {
- test_fdset_new_fill();
- test_fdset_put_dup();
- test_fdset_cloexec();
- test_fdset_close_others();
- test_fdset_remove();
- test_fdset_iterate();
-
- return 0;
-}
diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c
deleted file mode 100644
index 63e4a19b76..0000000000
--- a/src/test/test-fileio.c
+++ /dev/null
@@ -1,410 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 Lennart Poettering
-
- 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 <stdio.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-#include "util.h"
-#include "fileio.h"
-#include "strv.h"
-#include "env-util.h"
-#include "def.h"
-#include "ctype.h"
-
-static void test_parse_env_file(void) {
- char t[] = "/tmp/test-fileio-in-XXXXXX",
- p[] = "/tmp/test-fileio-out-XXXXXX";
- int fd, r;
- FILE *f;
- _cleanup_free_ char *one = NULL, *two = NULL, *three = NULL, *four = NULL, *five = NULL,
- *six = NULL, *seven = NULL, *eight = NULL, *nine = NULL, *ten = NULL;
- _cleanup_strv_free_ char **a = NULL, **b = NULL;
- char **i;
- unsigned k;
-
- fd = mkostemp_safe(p, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- close(fd);
-
- fd = mkostemp_safe(t, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
-
- f = fdopen(fd, "w");
- assert_se(f);
-
- fputs("one=BAR \n"
- "# comment\n"
- " # comment \n"
- " ; comment \n"
- " two = bar \n"
- "invalid line\n"
- "invalid line #comment\n"
- "three = \"333\n"
- "xxxx\"\n"
- "four = \'44\\\"44\'\n"
- "five = \'55\\\'55\' \"FIVE\" cinco \n"
- "six = seis sechs\\\n"
- " sis\n"
- "seven=\"sevenval\" #nocomment\n"
- "eight=eightval #nocomment\n"
- "export nine=nineval\n"
- "ten=", f);
-
- fflush(f);
- fclose(f);
-
- r = load_env_file(NULL, t, NULL, &a);
- assert_se(r >= 0);
-
- STRV_FOREACH(i, a)
- log_info("Got: <%s>", *i);
-
- assert_se(streq_ptr(a[0], "one=BAR"));
- assert_se(streq_ptr(a[1], "two=bar"));
- assert_se(streq_ptr(a[2], "three=333\nxxxx"));
- assert_se(streq_ptr(a[3], "four=44\"44"));
- assert_se(streq_ptr(a[4], "five=55\'55FIVEcinco"));
- assert_se(streq_ptr(a[5], "six=seis sechs sis"));
- assert_se(streq_ptr(a[6], "seven=sevenval#nocomment"));
- assert_se(streq_ptr(a[7], "eight=eightval #nocomment"));
- assert_se(streq_ptr(a[8], "export nine=nineval"));
- assert_se(streq_ptr(a[9], "ten="));
- assert_se(a[10] == NULL);
-
- strv_env_clean(a);
-
- k = 0;
- STRV_FOREACH(i, b) {
- log_info("Got2: <%s>", *i);
- assert_se(streq(*i, a[k++]));
- }
-
- r = parse_env_file(
- t, NULL,
- "one", &one,
- "two", &two,
- "three", &three,
- "four", &four,
- "five", &five,
- "six", &six,
- "seven", &seven,
- "eight", &eight,
- "export nine", &nine,
- "ten", &ten,
- NULL);
-
- assert_se(r >= 0);
-
- log_info("one=[%s]", strna(one));
- log_info("two=[%s]", strna(two));
- log_info("three=[%s]", strna(three));
- log_info("four=[%s]", strna(four));
- log_info("five=[%s]", strna(five));
- log_info("six=[%s]", strna(six));
- log_info("seven=[%s]", strna(seven));
- log_info("eight=[%s]", strna(eight));
- log_info("export nine=[%s]", strna(nine));
- log_info("ten=[%s]", strna(nine));
-
- assert_se(streq(one, "BAR"));
- assert_se(streq(two, "bar"));
- assert_se(streq(three, "333\nxxxx"));
- assert_se(streq(four, "44\"44"));
- assert_se(streq(five, "55\'55FIVEcinco"));
- assert_se(streq(six, "seis sechs sis"));
- assert_se(streq(seven, "sevenval#nocomment"));
- assert_se(streq(eight, "eightval #nocomment"));
- assert_se(streq(nine, "nineval"));
- assert_se(ten == NULL);
-
- r = write_env_file(p, a);
- assert_se(r >= 0);
-
- r = load_env_file(NULL, p, NULL, &b);
- assert_se(r >= 0);
-
- unlink(t);
- unlink(p);
-}
-
-static void test_parse_multiline_env_file(void) {
- char t[] = "/tmp/test-fileio-in-XXXXXX",
- p[] = "/tmp/test-fileio-out-XXXXXX";
- int fd, r;
- FILE *f;
- _cleanup_strv_free_ char **a = NULL, **b = NULL;
- char **i;
-
- fd = mkostemp_safe(p, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- close(fd);
-
- fd = mkostemp_safe(t, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
-
- f = fdopen(fd, "w");
- assert_se(f);
-
- fputs("one=BAR\\\n"
- " VAR\\\n"
- "\tGAR\n"
- "#comment\n"
- "two=\"bar\\\n"
- " var\\\n"
- "\tgar\"\n"
- "#comment\n"
- "tri=\"bar \\\n"
- " var \\\n"
- "\tgar \"\n", f);
-
- fflush(f);
- fclose(f);
-
- r = load_env_file(NULL, t, NULL, &a);
- assert_se(r >= 0);
-
- STRV_FOREACH(i, a)
- log_info("Got: <%s>", *i);
-
- assert_se(streq_ptr(a[0], "one=BAR VAR\tGAR"));
- assert_se(streq_ptr(a[1], "two=bar var\tgar"));
- assert_se(streq_ptr(a[2], "tri=bar var \tgar "));
- assert_se(a[3] == NULL);
-
- r = write_env_file(p, a);
- assert_se(r >= 0);
-
- r = load_env_file(NULL, p, NULL, &b);
- assert_se(r >= 0);
-
- unlink(t);
- unlink(p);
-}
-
-
-static void test_executable_is_script(void) {
- char t[] = "/tmp/test-executable-XXXXXX";
- int fd, r;
- FILE *f;
- char *command;
-
- fd = mkostemp_safe(t, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
-
- f = fdopen(fd, "w");
- assert_se(f);
-
- fputs("#! /bin/script -a -b \ngoo goo", f);
- fflush(f);
-
- r = executable_is_script(t, &command);
- assert_se(r > 0);
- assert_se(streq(command, "/bin/script"));
- free(command);
-
- r = executable_is_script("/bin/sh", &command);
- assert_se(r == 0);
-
- r = executable_is_script("/usr/bin/yum", &command);
- assert_se(r > 0 || r == -ENOENT);
- if (r > 0) {
- assert_se(startswith(command, "/"));
- free(command);
- }
-
- fclose(f);
- unlink(t);
-}
-
-static void test_status_field(void) {
- _cleanup_free_ char *t = NULL, *p = NULL, *s = NULL, *z = NULL;
- unsigned long long total = 0, buffers = 0;
- int r;
-
- assert_se(get_status_field("/proc/self/status", "\nThreads:", &t) == 0);
- puts(t);
- assert_se(streq(t, "1"));
-
- r = get_status_field("/proc/meminfo", "MemTotal:", &p);
- if (r != -ENOENT) {
- assert_se(r == 0);
- puts(p);
- assert_se(safe_atollu(p, &total) == 0);
- }
-
- r = get_status_field("/proc/meminfo", "\nBuffers:", &s);
- if (r != -ENOENT) {
- assert_se(r == 0);
- puts(s);
- assert_se(safe_atollu(s, &buffers) == 0);
- }
-
- if (p)
- assert_se(buffers < total);
-
- /* Seccomp should be a good test for field full of zeros. */
- r = get_status_field("/proc/meminfo", "\nSeccomp:", &z);
- if (r != -ENOENT) {
- assert_se(r == 0);
- puts(z);
- assert_se(safe_atollu(z, &buffers) == 0);
- }
-}
-
-static void test_capeff(void) {
- int pid, p;
-
- for (pid = 0; pid < 2; pid++) {
- _cleanup_free_ char *capeff = NULL;
- int r;
-
- r = get_process_capeff(0, &capeff);
- log_info("capeff: '%s' (r=%d)", capeff, r);
-
- if (r == -ENOENT || r == -EPERM)
- return;
-
- assert_se(r == 0);
- assert_se(*capeff);
- p = capeff[strspn(capeff, DIGITS "abcdefABCDEF")];
- assert_se(!p || isspace(p));
- }
-}
-
-static void test_write_string_stream(void) {
- char fn[] = "/tmp/test-write_string_stream-XXXXXX";
- _cleanup_fclose_ FILE *f = NULL;
- int fd;
- char buf[64];
-
- fd = mkostemp_safe(fn, O_RDWR);
- assert_se(fd >= 0);
-
- f = fdopen(fd, "r");
- assert_se(f);
- assert_se(write_string_stream(f, "boohoo") < 0);
-
- f = freopen(fn, "r+", f);
- assert_se(f);
-
- assert_se(write_string_stream(f, "boohoo") == 0);
- rewind(f);
-
- assert_se(fgets(buf, sizeof(buf), f));
- assert_se(streq(buf, "boohoo\n"));
-
- unlink(fn);
-}
-
-static void test_write_string_file(void) {
- char fn[] = "/tmp/test-write_string_file-XXXXXX";
- char buf[64] = {};
- _cleanup_close_ int fd;
-
- fd = mkostemp_safe(fn, O_RDWR);
- assert_se(fd >= 0);
-
- assert_se(write_string_file(fn, "boohoo") == 0);
-
- assert_se(read(fd, buf, sizeof(buf)) == 7);
- assert_se(streq(buf, "boohoo\n"));
-
- unlink(fn);
-}
-
-static void test_write_string_file_no_create(void) {
- char fn[] = "/tmp/test-write_string_file_no_create-XXXXXX";
- _cleanup_close_ int fd;
- char buf[64] = {0};
-
- fd = mkostemp_safe(fn, O_RDWR);
- assert_se(fd >= 0);
-
- assert_se(write_string_file_no_create("/a/file/which/does/not/exists/i/guess", "boohoo") < 0);
- assert_se(write_string_file_no_create(fn, "boohoo") == 0);
-
- assert_se(read(fd, buf, sizeof(buf)) == strlen("boohoo\n"));
- assert_se(streq(buf, "boohoo\n"));
-
- unlink(fn);
-}
-
-static void test_load_env_file_pairs(void) {
- char fn[] = "/tmp/test-load_env_file_pairs-XXXXXX";
- int fd;
- int r;
- _cleanup_fclose_ FILE *f = NULL;
- _cleanup_strv_free_ char **l = NULL;
- char **k, **v;
-
- fd = mkostemp_safe(fn, O_RDWR);
- assert_se(fd >= 0);
-
- r = write_string_file(fn,
- "NAME=\"Arch Linux\"\n"
- "ID=arch\n"
- "PRETTY_NAME=\"Arch Linux\"\n"
- "ANSI_COLOR=\"0;36\"\n"
- "HOME_URL=\"https://www.archlinux.org/\"\n"
- "SUPPORT_URL=\"https://bbs.archlinux.org/\"\n"
- "BUG_REPORT_URL=\"https://bugs.archlinux.org/\"\n"
- );
- assert_se(r == 0);
-
- f = fdopen(fd, "r");
- assert_se(f);
-
- r = load_env_file_pairs(f, fn, NULL, &l);
- assert_se(r >= 0);
-
- assert_se(strv_length(l) == 14);
- STRV_FOREACH_PAIR(k, v, l) {
- assert_se(STR_IN_SET(*k, "NAME", "ID", "PRETTY_NAME", "ANSI_COLOR", "HOME_URL", "SUPPORT_URL", "BUG_REPORT_URL"));
- printf("%s=%s\n", *k, *v);
- if (streq(*k, "NAME")) assert_se(streq(*v, "Arch Linux"));
- if (streq(*k, "ID")) assert_se(streq(*v, "arch"));
- if (streq(*k, "PRETTY_NAME")) assert_se(streq(*v, "Arch Linux"));
- if (streq(*k, "ANSI_COLOR")) assert_se(streq(*v, "0;36"));
- if (streq(*k, "HOME_URL")) assert_se(streq(*v, "https://www.archlinux.org/"));
- if (streq(*k, "SUPPORT_URL")) assert_se(streq(*v, "https://bbs.archlinux.org/"));
- if (streq(*k, "BUG_REPORT_URL")) assert_se(streq(*v, "https://bugs.archlinux.org/"));
- }
-
- unlink(fn);
-}
-
-int main(int argc, char *argv[]) {
- log_parse_environment();
- log_open();
-
- test_parse_env_file();
- test_parse_multiline_env_file();
- test_executable_is_script();
- test_status_field();
- test_capeff();
- test_write_string_stream();
- test_write_string_file();
- test_write_string_file_no_create();
- test_load_env_file_pairs();
-
- return 0;
-}
diff --git a/src/test/test-fstab-util.c b/src/test/test-fstab-util.c
deleted file mode 100644
index 50e5dee0a7..0000000000
--- a/src/test/test-fstab-util.c
+++ /dev/null
@@ -1,138 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2015 Zbigniew Jędrzejewski-Szmek
-
- 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 "fstab-util.h"
-#include "util.h"
-#include "log.h"
-
-/*
-int fstab_filter_options(const char *opts, const char *names,
- const char **namefound, char **value, char **filtered);
-*/
-
-static void do_fstab_filter_options(const char *opts,
- const char *remove,
- int r_expected,
- const char *name_expected,
- const char *value_expected,
- const char *filtered_expected) {
-
- int r;
- const char *name;
- _cleanup_free_ char *value, *filtered;
-
- r = fstab_filter_options(opts, remove, &name, &value, &filtered);
- log_info("\"%s\" → %d, \"%s\", \"%s\", \"%s\", expected %d, \"%s\", \"%s\", \"%s\"",
- opts, r, name, value, filtered,
- r_expected, name_expected, value_expected, filtered_expected ?: opts);
- assert_se(r == r_expected);
- assert_se(streq_ptr(name, name_expected));
- assert_se(streq_ptr(value, value_expected));
- assert_se(streq_ptr(filtered, filtered_expected ?: opts));
-
- /* also test the malloc-less mode */
- r = fstab_filter_options(opts, remove, &name, NULL, NULL);
- log_info("\"%s\" → %d, \"%s\", expected %d, \"%s\"",
- opts, r, name,
- r_expected, name_expected);
- assert_se(r == r_expected);
- assert_se(streq_ptr(name, name_expected));
-}
-
-static void test_fstab_filter_options(void) {
- do_fstab_filter_options("opt=0", "opt\0x-opt\0", 1, "opt", "0", "");
- do_fstab_filter_options("opt=0", "x-opt\0opt\0", 1, "opt", "0", "");
- do_fstab_filter_options("opt", "opt\0x-opt\0", 1, "opt", NULL, "");
- do_fstab_filter_options("opt", "x-opt\0opt\0", 1, "opt", NULL, "");
- do_fstab_filter_options("x-opt", "x-opt\0opt\0", 1, "x-opt", NULL, "");
-
- do_fstab_filter_options("opt=0,other", "opt\0x-opt\0", 1, "opt", "0", "other");
- do_fstab_filter_options("opt=0,other", "x-opt\0opt\0", 1, "opt", "0", "other");
- do_fstab_filter_options("opt,other", "opt\0x-opt\0", 1, "opt", NULL, "other");
- do_fstab_filter_options("opt,other", "x-opt\0opt\0", 1, "opt", NULL, "other");
- do_fstab_filter_options("x-opt,other", "opt\0x-opt\0", 1, "x-opt", NULL, "other");
-
- do_fstab_filter_options("opto=0,other", "opt\0x-opt\0", 0, NULL, NULL, NULL);
- do_fstab_filter_options("opto,other", "opt\0x-opt\0", 0, NULL, NULL, NULL);
- do_fstab_filter_options("x-opto,other", "opt\0x-opt\0", 0, NULL, NULL, NULL);
-
- do_fstab_filter_options("first,opt=0", "opt\0x-opt\0", 1, "opt", "0", "first");
- do_fstab_filter_options("first=1,opt=0", "opt\0x-opt\0", 1, "opt", "0", "first=1");
- do_fstab_filter_options("first,opt=", "opt\0x-opt\0", 1, "opt", "", "first");
- do_fstab_filter_options("first=1,opt", "opt\0x-opt\0", 1, "opt", NULL, "first=1");
- do_fstab_filter_options("first=1,x-opt", "opt\0x-opt\0", 1, "x-opt", NULL, "first=1");
-
- do_fstab_filter_options("first,opt=0,last=1", "opt\0x-opt\0", 1, "opt", "0", "first,last=1");
- do_fstab_filter_options("first=1,opt=0,last=2", "x-opt\0opt\0", 1, "opt", "0", "first=1,last=2");
- do_fstab_filter_options("first,opt,last", "opt\0", 1, "opt", NULL, "first,last");
- do_fstab_filter_options("first=1,opt,last", "x-opt\0opt\0", 1, "opt", NULL, "first=1,last");
- do_fstab_filter_options("first=,opt,last", "opt\0noopt\0", 1, "opt", NULL, "first=,last");
-
- /* check repeated options */
- do_fstab_filter_options("first,opt=0,noopt=1,last=1", "opt\0noopt\0", 1, "noopt", "1", "first,last=1");
- do_fstab_filter_options("first=1,opt=0,last=2,opt=1", "opt\0", 1, "opt", "1", "first=1,last=2");
- do_fstab_filter_options("x-opt=0,x-opt=1", "opt\0x-opt\0", 1, "x-opt", "1", "");
- do_fstab_filter_options("opt=0,x-opt=1", "opt\0x-opt\0", 1, "x-opt", "1", "");
-
- /* check that semicolons are not misinterpreted */
- do_fstab_filter_options("opt=0;", "opt\0", 1, "opt", "0;", "");
- do_fstab_filter_options("opt;=0", "x-opt\0opt\0noopt\0x-noopt\0", 0, NULL, NULL, NULL);
- do_fstab_filter_options("opt;", "opt\0x-opt\0", 0, NULL, NULL, NULL);
-
- /* check that spaces are not misinterpreted */
- do_fstab_filter_options("opt=0 ", "opt\0", 1, "opt", "0 ", "");
- do_fstab_filter_options("opt =0", "x-opt\0opt\0noopt\0x-noopt\0", 0, NULL, NULL, NULL);
- do_fstab_filter_options(" opt ", "opt\0x-opt\0", 0, NULL, NULL, NULL);
-
- /* check function will NULL args */
- do_fstab_filter_options(NULL, "opt\0", 0, NULL, NULL, "");
- do_fstab_filter_options("", "opt\0", 0, NULL, NULL, "");
-}
-
-static void test_fstab_find_pri(void) {
- int pri = -1;
-
- assert_se(fstab_find_pri("pri", &pri) == 0);
- assert_se(pri == -1);
-
- assert_se(fstab_find_pri("pri=11", &pri) == 1);
- assert_se(pri == 11);
-
- assert_se(fstab_find_pri("opt,pri=12,opt", &pri) == 1);
- assert_se(pri == 12);
-
- assert_se(fstab_find_pri("opt,opt,pri=12,pri=13", &pri) == 1);
- assert_se(pri == 13);
-}
-
-static void test_fstab_yes_no_option(void) {
- assert_se(fstab_test_yes_no_option("nofail,fail,nofail", "nofail\0fail\0") == true);
- assert_se(fstab_test_yes_no_option("nofail,nofail,fail", "nofail\0fail\0") == false);
- assert_se(fstab_test_yes_no_option("abc,cde,afail", "nofail\0fail\0") == false);
- assert_se(fstab_test_yes_no_option("nofail,fail=0,nofail=0", "nofail\0fail\0") == true);
- assert_se(fstab_test_yes_no_option("nofail,nofail=0,fail=0", "nofail\0fail\0") == false);
-}
-
-int main(void) {
- test_fstab_filter_options();
- test_fstab_find_pri();
- test_fstab_yes_no_option();
-}
diff --git a/src/test/test-fw-util.c b/src/test/test-fw-util.c
deleted file mode 100644
index ab891aa0c4..0000000000
--- a/src/test/test-fw-util.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2015 Lennart Poettering
-
- 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 "log.h"
-#include "fw-util.h"
-
-#define MAKE_IN_ADDR_UNION(a,b,c,d) (union in_addr_union) { .in.s_addr = htobe32((uint32_t) (a) << 24 | (uint32_t) (b) << 16 | (uint32_t) (c) << 8 | (uint32_t) (d))}
-
-int main(int argc, char *argv[]) {
- int r;
- log_set_max_level(LOG_DEBUG);
-
- r = fw_add_masquerade(true, AF_INET, 0, NULL, 0, "foobar", NULL, 0);
- if (r < 0)
- log_error_errno(r, "Failed to modify firewall: %m");
-
- r = fw_add_masquerade(true, AF_INET, 0, NULL, 0, "foobar", NULL, 0);
- if (r < 0)
- log_error_errno(r, "Failed to modify firewall: %m");
-
- r = fw_add_masquerade(false, AF_INET, 0, NULL, 0, "foobar", NULL, 0);
- if (r < 0)
- log_error_errno(r, "Failed to modify firewall: %m");
-
- r = fw_add_local_dnat(true, AF_INET, IPPROTO_TCP, NULL, NULL, 0, NULL, 0, 4711, &MAKE_IN_ADDR_UNION(1, 2, 3, 4), 815, NULL);
- if (r < 0)
- log_error_errno(r, "Failed to modify firewall: %m");
-
- r = fw_add_local_dnat(true, AF_INET, IPPROTO_TCP, NULL, NULL, 0, NULL, 0, 4711, &MAKE_IN_ADDR_UNION(1, 2, 3, 4), 815, NULL);
- if (r < 0)
- log_error_errno(r, "Failed to modify firewall: %m");
-
- r = fw_add_local_dnat(true, AF_INET, IPPROTO_TCP, NULL, NULL, 0, NULL, 0, 4711, &MAKE_IN_ADDR_UNION(1, 2, 3, 5), 815, &MAKE_IN_ADDR_UNION(1, 2, 3, 4));
- if (r < 0)
- log_error_errno(r, "Failed to modify firewall: %m");
-
- r = fw_add_local_dnat(false, AF_INET, IPPROTO_TCP, NULL, NULL, 0, NULL, 0, 4711, &MAKE_IN_ADDR_UNION(1, 2, 3, 5), 815, NULL);
- if (r < 0)
- log_error_errno(r, "Failed to modify firewall: %m");
-
- return 0;
-}
diff --git a/src/test/test-hashmap-plain.c b/src/test/test-hashmap-plain.c
deleted file mode 100644
index 84b508f874..0000000000
--- a/src/test/test-hashmap-plain.c
+++ /dev/null
@@ -1,869 +0,0 @@
-/***
- This file is part of systemd
-
- Copyright 2013 Daniel Buch
-
- 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 "strv.h"
-#include "util.h"
-#include "hashmap.h"
-
-void test_hashmap_funcs(void);
-
-static void test_hashmap_replace(void) {
- Hashmap *m;
- char *val1, *val2, *val3, *val4, *val5, *r;
-
- m = hashmap_new(&string_hash_ops);
-
- val1 = strdup("val1");
- assert_se(val1);
- val2 = strdup("val2");
- assert_se(val2);
- val3 = strdup("val3");
- assert_se(val3);
- val4 = strdup("val4");
- assert_se(val4);
- val5 = strdup("val5");
- assert_se(val5);
-
- hashmap_put(m, "key 1", val1);
- hashmap_put(m, "key 2", val2);
- hashmap_put(m, "key 3", val3);
- hashmap_put(m, "key 4", val4);
-
- hashmap_replace(m, "key 3", val1);
- r = hashmap_get(m, "key 3");
- assert_se(streq(r, "val1"));
-
- hashmap_replace(m, "key 5", val5);
- r = hashmap_get(m, "key 5");
- assert_se(streq(r, "val5"));
-
- free(val1);
- free(val2);
- free(val3);
- free(val4);
- free(val5);
- hashmap_free(m);
-}
-
-static void test_hashmap_copy(void) {
- Hashmap *m, *copy;
- char *val1, *val2, *val3, *val4, *r;
-
- val1 = strdup("val1");
- assert_se(val1);
- val2 = strdup("val2");
- assert_se(val2);
- val3 = strdup("val3");
- assert_se(val3);
- val4 = strdup("val4");
- assert_se(val4);
-
- m = hashmap_new(&string_hash_ops);
-
- hashmap_put(m, "key 1", val1);
- hashmap_put(m, "key 2", val2);
- hashmap_put(m, "key 3", val3);
- hashmap_put(m, "key 4", val4);
-
- copy = hashmap_copy(m);
-
- r = hashmap_get(copy, "key 1");
- assert_se(streq(r, "val1"));
- r = hashmap_get(copy, "key 2");
- assert_se(streq(r, "val2"));
- r = hashmap_get(copy, "key 3");
- assert_se(streq(r, "val3"));
- r = hashmap_get(copy, "key 4");
- assert_se(streq(r, "val4"));
-
- hashmap_free_free(copy);
- hashmap_free(m);
-}
-
-static void test_hashmap_get_strv(void) {
- Hashmap *m;
- char **strv;
- char *val1, *val2, *val3, *val4;
-
- val1 = strdup("val1");
- assert_se(val1);
- val2 = strdup("val2");
- assert_se(val2);
- val3 = strdup("val3");
- assert_se(val3);
- val4 = strdup("val4");
- assert_se(val4);
-
- m = hashmap_new(&string_hash_ops);
-
- hashmap_put(m, "key 1", val1);
- hashmap_put(m, "key 2", val2);
- hashmap_put(m, "key 3", val3);
- hashmap_put(m, "key 4", val4);
-
- strv = hashmap_get_strv(m);
-
-#ifndef ORDERED
- strv = strv_sort(strv);
-#endif
-
- assert_se(streq(strv[0], "val1"));
- assert_se(streq(strv[1], "val2"));
- assert_se(streq(strv[2], "val3"));
- assert_se(streq(strv[3], "val4"));
-
- strv_free(strv);
-
- hashmap_free(m);
-}
-
-static void test_hashmap_move_one(void) {
- Hashmap *m, *n;
- char *val1, *val2, *val3, *val4, *r;
-
- val1 = strdup("val1");
- assert_se(val1);
- val2 = strdup("val2");
- assert_se(val2);
- val3 = strdup("val3");
- assert_se(val3);
- val4 = strdup("val4");
- assert_se(val4);
-
- m = hashmap_new(&string_hash_ops);
- n = hashmap_new(&string_hash_ops);
-
- hashmap_put(m, "key 1", val1);
- hashmap_put(m, "key 2", val2);
- hashmap_put(m, "key 3", val3);
- hashmap_put(m, "key 4", val4);
-
- assert_se(hashmap_move_one(n, NULL, "key 3") == -ENOENT);
- assert_se(hashmap_move_one(n, m, "key 5") == -ENOENT);
- assert_se(hashmap_move_one(n, m, "key 3") == 0);
- assert_se(hashmap_move_one(n, m, "key 4") == 0);
-
- r = hashmap_get(n, "key 3");
- assert_se(r && streq(r, "val3"));
- r = hashmap_get(n, "key 4");
- assert_se(r && streq(r, "val4"));
- r = hashmap_get(m, "key 3");
- assert_se(!r);
-
- assert_se(hashmap_move_one(n, m, "key 3") == -EEXIST);
-
- hashmap_free_free(m);
- hashmap_free_free(n);
-}
-
-static void test_hashmap_move(void) {
- Hashmap *m, *n;
- char *val1, *val2, *val3, *val4, *r;
-
- val1 = strdup("val1");
- assert_se(val1);
- val2 = strdup("val2");
- assert_se(val2);
- val3 = strdup("val3");
- assert_se(val3);
- val4 = strdup("val4");
- assert_se(val4);
-
- m = hashmap_new(&string_hash_ops);
- n = hashmap_new(&string_hash_ops);
-
- hashmap_put(n, "key 1", strdup(val1));
- hashmap_put(m, "key 1", val1);
- hashmap_put(m, "key 2", val2);
- hashmap_put(m, "key 3", val3);
- hashmap_put(m, "key 4", val4);
-
- assert_se(hashmap_move(n, NULL) == 0);
- assert_se(hashmap_move(n, m) == 0);
-
- assert_se(hashmap_size(m) == 1);
- r = hashmap_get(m, "key 1");
- assert_se(r && streq(r, "val1"));
-
- r = hashmap_get(n, "key 1");
- assert_se(r && streq(r, "val1"));
- r = hashmap_get(n, "key 2");
- assert_se(r && streq(r, "val2"));
- r = hashmap_get(n, "key 3");
- assert_se(r && streq(r, "val3"));
- r = hashmap_get(n, "key 4");
- assert_se(r && streq(r, "val4"));
-
- hashmap_free_free(m);
- hashmap_free_free(n);
-}
-
-static void test_hashmap_update(void) {
- Hashmap *m;
- char *val1, *val2, *r;
-
- m = hashmap_new(&string_hash_ops);
- val1 = strdup("old_value");
- assert_se(val1);
- val2 = strdup("new_value");
- assert_se(val2);
-
- hashmap_put(m, "key 1", val1);
- r = hashmap_get(m, "key 1");
- assert_se(streq(r, "old_value"));
-
- assert_se(hashmap_update(m, "key 2", val2) == -ENOENT);
- r = hashmap_get(m, "key 1");
- assert_se(streq(r, "old_value"));
-
- assert_se(hashmap_update(m, "key 1", val2) == 0);
- r = hashmap_get(m, "key 1");
- assert_se(streq(r, "new_value"));
-
- free(val1);
- free(val2);
- hashmap_free(m);
-}
-
-static void test_hashmap_put(void) {
- Hashmap *m = NULL;
- int valid_hashmap_put;
- void *val1 = (void*) "val 1";
- void *val2 = (void*) "val 2";
- _cleanup_free_ char* key1 = NULL;
-
- assert_se(hashmap_ensure_allocated(&m, &string_hash_ops) >= 0);
- assert_se(m);
-
- valid_hashmap_put = hashmap_put(m, "key 1", val1);
- assert_se(valid_hashmap_put == 1);
- assert_se(hashmap_put(m, "key 1", val1) == 0);
- assert_se(hashmap_put(m, "key 1", val2) == -EEXIST);
- key1 = strdup("key 1");
- assert_se(hashmap_put(m, key1, val1) == 0);
- assert_se(hashmap_put(m, key1, val2) == -EEXIST);
-
- hashmap_free(m);
-}
-
-static void test_hashmap_remove(void) {
- _cleanup_hashmap_free_ Hashmap *m = NULL;
- char *r;
-
- r = hashmap_remove(NULL, "key 1");
- assert_se(r == NULL);
-
- m = hashmap_new(&string_hash_ops);
- assert_se(m);
-
- r = hashmap_remove(m, "no such key");
- assert_se(r == NULL);
-
- hashmap_put(m, "key 1", (void*) "val 1");
- hashmap_put(m, "key 2", (void*) "val 2");
-
- r = hashmap_remove(m, "key 1");
- assert_se(streq(r, "val 1"));
-
- r = hashmap_get(m, "key 2");
- assert_se(streq(r, "val 2"));
- assert_se(!hashmap_get(m, "key 1"));
-}
-
-static void test_hashmap_remove2(void) {
- _cleanup_hashmap_free_free_free_ Hashmap *m = NULL;
- char key1[] = "key 1";
- char key2[] = "key 2";
- char val1[] = "val 1";
- char val2[] = "val 2";
- void *r, *r2;
-
- r = hashmap_remove2(NULL, "key 1", &r2);
- assert_se(r == NULL);
-
- m = hashmap_new(&string_hash_ops);
- assert_se(m);
-
- r = hashmap_remove2(m, "no such key", &r2);
- assert_se(r == NULL);
-
- hashmap_put(m, strdup(key1), strdup(val1));
- hashmap_put(m, strdup(key2), strdup(val2));
-
- r = hashmap_remove2(m, key1, &r2);
- assert_se(streq(r, val1));
- assert_se(streq(r2, key1));
- free(r);
- free(r2);
-
- r = hashmap_get(m, key2);
- assert_se(streq(r, val2));
- assert_se(!hashmap_get(m, key1));
-}
-
-static void test_hashmap_remove_value(void) {
- _cleanup_hashmap_free_ Hashmap *m = NULL;
- char *r;
-
- r = hashmap_remove_value(NULL, "key 1", (void*) "val 1");
- assert_se(r == NULL);
-
- m = hashmap_new(&string_hash_ops);
- assert_se(m);
-
- r = hashmap_remove_value(m, "key 1", (void*) "val 1");
- assert_se(r == NULL);
-
- hashmap_put(m, "key 1", (void*) "val 1");
- hashmap_put(m, "key 2", (void*) "val 2");
-
- r = hashmap_remove_value(m, "key 1", (void*) "val 1");
- assert_se(streq(r, "val 1"));
-
- r = hashmap_get(m, "key 2");
- assert_se(streq(r, "val 2"));
- assert_se(!hashmap_get(m, "key 1"));
-
- r = hashmap_remove_value(m, "key 2", (void*) "val 1");
- assert_se(r == NULL);
-
- r = hashmap_get(m, "key 2");
- assert_se(streq(r, "val 2"));
- assert_se(!hashmap_get(m, "key 1"));
-}
-
-static void test_hashmap_remove_and_put(void) {
- _cleanup_hashmap_free_ Hashmap *m = NULL;
- int valid;
- char *r;
-
- m = hashmap_new(&string_hash_ops);
- assert_se(m);
-
- valid = hashmap_remove_and_put(m, "invalid key", "new key", NULL);
- assert_se(valid == -ENOENT);
-
- valid = hashmap_put(m, "key 1", (void*) (const char *) "val 1");
- assert_se(valid == 1);
-
- valid = hashmap_remove_and_put(NULL, "key 1", "key 2", (void*) (const char *) "val 2");
- assert_se(valid == -ENOENT);
-
- valid = hashmap_remove_and_put(m, "key 1", "key 2", (void*) (const char *) "val 2");
- assert_se(valid == 0);
-
- r = hashmap_get(m, "key 2");
- assert_se(streq(r, "val 2"));
- assert_se(!hashmap_get(m, "key 1"));
-
- valid = hashmap_put(m, "key 3", (void*) (const char *) "val 3");
- assert_se(valid == 1);
- valid = hashmap_remove_and_put(m, "key 3", "key 2", (void*) (const char *) "val 2");
- assert_se(valid == -EEXIST);
-}
-
-static void test_hashmap_remove_and_replace(void) {
- _cleanup_hashmap_free_ Hashmap *m = NULL;
- int valid;
- void *key1 = UINT_TO_PTR(1);
- void *key2 = UINT_TO_PTR(2);
- void *key3 = UINT_TO_PTR(3);
- void *r;
- int i, j;
-
- m = hashmap_new(&trivial_hash_ops);
- assert_se(m);
-
- valid = hashmap_remove_and_replace(m, key1, key2, NULL);
- assert_se(valid == -ENOENT);
-
- valid = hashmap_put(m, key1, key1);
- assert_se(valid == 1);
-
- valid = hashmap_remove_and_replace(NULL, key1, key2, key2);
- assert_se(valid == -ENOENT);
-
- valid = hashmap_remove_and_replace(m, key1, key2, key2);
- assert_se(valid == 0);
-
- r = hashmap_get(m, key2);
- assert_se(r == key2);
- assert_se(!hashmap_get(m, key1));
-
- valid = hashmap_put(m, key3, key3);
- assert_se(valid == 1);
- valid = hashmap_remove_and_replace(m, key3, key2, key2);
- assert_se(valid == 0);
- r = hashmap_get(m, key2);
- assert_se(r == key2);
- assert_se(!hashmap_get(m, key3));
-
- /* Repeat this test several times to increase the chance of hitting
- * the less likely case in hashmap_remove_and_replace where it
- * compensates for the backward shift. */
- for (i = 0; i < 20; i++) {
- hashmap_clear(m);
-
- for (j = 1; j < 7; j++)
- hashmap_put(m, UINT_TO_PTR(10*i + j), UINT_TO_PTR(10*i + j));
- valid = hashmap_remove_and_replace(m, UINT_TO_PTR(10*i + 1),
- UINT_TO_PTR(10*i + 2),
- UINT_TO_PTR(10*i + 2));
- assert_se(valid == 0);
- assert_se(!hashmap_get(m, UINT_TO_PTR(10*i + 1)));
- for (j = 2; j < 7; j++) {
- r = hashmap_get(m, UINT_TO_PTR(10*i + j));
- assert_se(r == UINT_TO_PTR(10*i + j));
- }
- }
-}
-
-static void test_hashmap_ensure_allocated(void) {
- Hashmap *m;
- int valid_hashmap;
-
- m = hashmap_new(&string_hash_ops);
-
- valid_hashmap = hashmap_ensure_allocated(&m, &string_hash_ops);
- assert_se(valid_hashmap == 0);
-
- assert_se(m);
- hashmap_free(m);
-}
-
-static void test_hashmap_foreach_key(void) {
- Hashmap *m;
- Iterator i;
- bool key_found[] = { false, false, false, false };
- const char *s;
- const char *key;
- static const char key_table[] =
- "key 1\0"
- "key 2\0"
- "key 3\0"
- "key 4\0";
-
- m = hashmap_new(&string_hash_ops);
-
- NULSTR_FOREACH(key, key_table)
- hashmap_put(m, key, (void*) (const char*) "my dummy val");
-
- HASHMAP_FOREACH_KEY(s, key, m, i) {
- if (!key_found[0] && streq(key, "key 1"))
- key_found[0] = true;
- else if (!key_found[1] && streq(key, "key 2"))
- key_found[1] = true;
- else if (!key_found[2] && streq(key, "key 3"))
- key_found[2] = true;
- else if (!key_found[3] && streq(key, "fail"))
- key_found[3] = true;
- }
-
- assert_se(m);
- assert_se(key_found[0] && key_found[1] && key_found[2] && !key_found[3]);
-
- hashmap_free(m);
-}
-
-static void test_hashmap_foreach(void) {
- Hashmap *m;
- Iterator i;
- bool value_found[] = { false, false, false, false };
- char *val1, *val2, *val3, *val4, *s;
- unsigned count;
-
- val1 = strdup("my val1");
- assert_se(val1);
- val2 = strdup("my val2");
- assert_se(val2);
- val3 = strdup("my val3");
- assert_se(val3);
- val4 = strdup("my val4");
- assert_se(val4);
-
- m = NULL;
-
- count = 0;
- HASHMAP_FOREACH(s, m, i)
- count++;
- assert_se(count == 0);
-
- m = hashmap_new(&string_hash_ops);
-
- count = 0;
- HASHMAP_FOREACH(s, m, i)
- count++;
- assert_se(count == 0);
-
- hashmap_put(m, "Key 1", val1);
- hashmap_put(m, "Key 2", val2);
- hashmap_put(m, "Key 3", val3);
- hashmap_put(m, "Key 4", val4);
-
- HASHMAP_FOREACH(s, m, i) {
- if (!value_found[0] && streq(s, val1))
- value_found[0] = true;
- else if (!value_found[1] && streq(s, val2))
- value_found[1] = true;
- else if (!value_found[2] && streq(s, val3))
- value_found[2] = true;
- else if (!value_found[3] && streq(s, val4))
- value_found[3] = true;
- }
-
- assert_se(m);
- assert_se(value_found[0] && value_found[1] && value_found[2] && value_found[3]);
-
- hashmap_free_free(m);
-}
-
-static void test_hashmap_merge(void) {
- Hashmap *m;
- Hashmap *n;
- char *val1, *val2, *val3, *val4, *r;
-
- val1 = strdup("my val1");
- assert_se(val1);
- val2 = strdup("my val2");
- assert_se(val2);
- val3 = strdup("my val3");
- assert_se(val3);
- val4 = strdup("my val4");
- assert_se(val4);
-
- n = hashmap_new(&string_hash_ops);
- m = hashmap_new(&string_hash_ops);
-
- hashmap_put(m, "Key 1", val1);
- hashmap_put(m, "Key 2", val2);
- hashmap_put(n, "Key 3", val3);
- hashmap_put(n, "Key 4", val4);
-
- assert_se(hashmap_merge(m, n) == 0);
- r = hashmap_get(m, "Key 3");
- assert_se(r && streq(r, "my val3"));
- r = hashmap_get(m, "Key 4");
- assert_se(r && streq(r, "my val4"));
-
- assert_se(n);
- assert_se(m);
- hashmap_free(n);
- hashmap_free_free(m);
-}
-
-static void test_hashmap_contains(void) {
- Hashmap *m;
- char *val1;
-
- val1 = strdup("my val");
- assert_se(val1);
-
- m = hashmap_new(&string_hash_ops);
-
- assert_se(!hashmap_contains(m, "Key 1"));
- hashmap_put(m, "Key 1", val1);
- assert_se(hashmap_contains(m, "Key 1"));
- assert_se(!hashmap_contains(m, "Key 2"));
-
- assert_se(!hashmap_contains(NULL, "Key 1"));
-
- assert_se(m);
- hashmap_free_free(m);
-}
-
-static void test_hashmap_isempty(void) {
- Hashmap *m;
- char *val1;
-
- val1 = strdup("my val");
- assert_se(val1);
-
- m = hashmap_new(&string_hash_ops);
-
- assert_se(hashmap_isempty(m));
- hashmap_put(m, "Key 1", val1);
- assert_se(!hashmap_isempty(m));
-
- assert_se(m);
- hashmap_free_free(m);
-}
-
-static void test_hashmap_size(void) {
- Hashmap *m;
- char *val1, *val2, *val3, *val4;
-
- val1 = strdup("my val");
- assert_se(val1);
- val2 = strdup("my val");
- assert_se(val2);
- val3 = strdup("my val");
- assert_se(val3);
- val4 = strdup("my val");
- assert_se(val4);
-
- assert_se(hashmap_size(NULL) == 0);
- assert_se(hashmap_buckets(NULL) == 0);
-
- m = hashmap_new(&string_hash_ops);
-
- hashmap_put(m, "Key 1", val1);
- hashmap_put(m, "Key 2", val2);
- hashmap_put(m, "Key 3", val3);
- hashmap_put(m, "Key 4", val4);
-
- assert_se(m);
- assert_se(hashmap_size(m) == 4);
- assert_se(hashmap_buckets(m) >= 4);
- hashmap_free_free(m);
-}
-
-static void test_hashmap_get(void) {
- Hashmap *m;
- char *r;
- char *val;
-
- val = strdup("my val");
- assert_se(val);
-
- r = hashmap_get(NULL, "Key 1");
- assert_se(r == NULL);
-
- m = hashmap_new(&string_hash_ops);
-
- hashmap_put(m, "Key 1", val);
-
- r = hashmap_get(m, "Key 1");
- assert_se(streq(r, val));
-
- r = hashmap_get(m, "no such key");
- assert_se(r == NULL);
-
- assert_se(m);
- hashmap_free_free(m);
-}
-
-static void test_hashmap_get2(void) {
- Hashmap *m;
- char *r;
- char *val;
- char key_orig[] = "Key 1";
- void *key_copy;
-
- val = strdup("my val");
- assert_se(val);
-
- key_copy = strdup(key_orig);
- assert_se(key_copy);
-
- r = hashmap_get2(NULL, key_orig, &key_copy);
- assert_se(r == NULL);
-
- m = hashmap_new(&string_hash_ops);
-
- hashmap_put(m, key_copy, val);
- key_copy = NULL;
-
- r = hashmap_get2(m, key_orig, &key_copy);
- assert_se(streq(r, val));
- assert_se(key_orig != key_copy);
- assert_se(streq(key_orig, key_orig));
-
- r = hashmap_get2(m, "no such key", NULL);
- assert_se(r == NULL);
-
- assert_se(m);
- hashmap_free_free_free(m);
-}
-
-static unsigned long crippled_hashmap_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) {
- return trivial_hash_func(p, hash_key) & 0xff;
-}
-
-static const struct hash_ops crippled_hashmap_ops = {
- .hash = crippled_hashmap_func,
- .compare = trivial_compare_func,
-};
-
-static void test_hashmap_many(void) {
- Hashmap *h;
- unsigned i, j;
- void *v, *k;
- static const struct {
- const struct hash_ops *ops;
- unsigned n_entries;
- } tests[] = {
- { .ops = NULL, .n_entries = 1 << 20 },
- { .ops = &crippled_hashmap_ops, .n_entries = 1 << 11 },
- };
-
-
- for (j = 0; j < ELEMENTSOF(tests); j++) {
- assert_se(h = hashmap_new(tests[j].ops));
-
- for (i = 1; i < tests[j].n_entries*3; i+=3) {
- assert_se(hashmap_put(h, UINT_TO_PTR(i), UINT_TO_PTR(i)) >= 0);
- assert_se(PTR_TO_UINT(hashmap_get(h, UINT_TO_PTR(i))) == i);
- }
-
- for (i = 1; i < tests[j].n_entries*3; i++)
- assert_se(hashmap_contains(h, UINT_TO_PTR(i)) == (i % 3 == 1));
-
- log_info("%u <= %u * 0.8 = %g", hashmap_size(h), hashmap_buckets(h), hashmap_buckets(h) * 0.8);
-
- assert_se(hashmap_size(h) <= hashmap_buckets(h) * 0.8);
- assert_se(hashmap_size(h) == tests[j].n_entries);
-
- while (!hashmap_isempty(h)) {
- k = hashmap_first_key(h);
- v = hashmap_remove(h, k);
- assert_se(v == k);
- }
-
- hashmap_free(h);
- }
-}
-
-static void test_hashmap_first(void) {
- _cleanup_hashmap_free_ Hashmap *m = NULL;
-
- m = hashmap_new(&string_hash_ops);
- assert_se(m);
-
- assert_se(!hashmap_first(m));
- assert_se(hashmap_put(m, "key 1", (void*) "val 1") == 1);
- assert_se(streq(hashmap_first(m), "val 1"));
- assert_se(hashmap_put(m, "key 2", (void*) "val 2") == 1);
-#ifdef ORDERED
- assert_se(streq(hashmap_first(m), "val 1"));
- assert_se(hashmap_remove(m, "key 1"));
- assert_se(streq(hashmap_first(m), "val 2"));
-#endif
-}
-
-static void test_hashmap_first_key(void) {
- _cleanup_hashmap_free_ Hashmap *m = NULL;
-
- m = hashmap_new(&string_hash_ops);
- assert_se(m);
-
- assert_se(!hashmap_first_key(m));
- assert_se(hashmap_put(m, "key 1", NULL) == 1);
- assert_se(streq(hashmap_first_key(m), "key 1"));
- assert_se(hashmap_put(m, "key 2", NULL) == 1);
-#ifdef ORDERED
- assert_se(streq(hashmap_first_key(m), "key 1"));
- assert_se(hashmap_remove(m, "key 1") == NULL);
- assert_se(streq(hashmap_first_key(m), "key 2"));
-#endif
-}
-
-static void test_hashmap_steal_first_key(void) {
- _cleanup_hashmap_free_ Hashmap *m = NULL;
-
- m = hashmap_new(&string_hash_ops);
- assert_se(m);
-
- assert_se(!hashmap_steal_first_key(m));
- assert_se(hashmap_put(m, "key 1", NULL) == 1);
- assert_se(streq(hashmap_steal_first_key(m), "key 1"));
-
- assert_se(hashmap_isempty(m));
-}
-
-static void test_hashmap_steal_first(void) {
- _cleanup_hashmap_free_ Hashmap *m = NULL;
- int seen[3] = {};
- char *val;
-
- m = hashmap_new(&string_hash_ops);
- assert_se(m);
-
- assert_se(hashmap_put(m, "key 1", (void*) "1") == 1);
- assert_se(hashmap_put(m, "key 2", (void*) "22") == 1);
- assert_se(hashmap_put(m, "key 3", (void*) "333") == 1);
-
- while ((val = hashmap_steal_first(m)))
- seen[strlen(val) - 1]++;
-
- assert_se(seen[0] == 1 && seen[1] == 1 && seen[2] == 1);
-
- assert_se(hashmap_isempty(m));
-}
-
-static void test_hashmap_clear_free_free(void) {
- _cleanup_hashmap_free_ Hashmap *m = NULL;
-
- m = hashmap_new(&string_hash_ops);
- assert_se(m);
-
- assert_se(hashmap_put(m, strdup("key 1"), NULL) == 1);
- assert_se(hashmap_put(m, strdup("key 2"), NULL) == 1);
- assert_se(hashmap_put(m, strdup("key 3"), NULL) == 1);
-
- hashmap_clear_free_free(m);
- assert_se(hashmap_isempty(m));
-}
-
-static void test_hashmap_reserve(void) {
- _cleanup_hashmap_free_ Hashmap *m = NULL;
-
- m = hashmap_new(&string_hash_ops);
-
- assert_se(hashmap_reserve(m, 1) == 0);
- assert_se(hashmap_buckets(m) < 1000);
- assert_se(hashmap_reserve(m, 1000) == 0);
- assert_se(hashmap_buckets(m) >= 1000);
- assert_se(hashmap_isempty(m));
-
- assert_se(hashmap_put(m, "key 1", (void*) "val 1") == 1);
-
- assert_se(hashmap_reserve(m, UINT_MAX) == -ENOMEM);
- assert_se(hashmap_reserve(m, UINT_MAX - 1) == -ENOMEM);
-}
-
-void test_hashmap_funcs(void) {
- test_hashmap_copy();
- test_hashmap_get_strv();
- test_hashmap_move_one();
- test_hashmap_move();
- test_hashmap_replace();
- test_hashmap_update();
- test_hashmap_put();
- test_hashmap_remove();
- test_hashmap_remove2();
- test_hashmap_remove_value();
- test_hashmap_remove_and_put();
- test_hashmap_remove_and_replace();
- test_hashmap_ensure_allocated();
- test_hashmap_foreach();
- test_hashmap_foreach_key();
- test_hashmap_contains();
- test_hashmap_merge();
- test_hashmap_isempty();
- test_hashmap_get();
- test_hashmap_get2();
- test_hashmap_size();
- test_hashmap_many();
- test_hashmap_first();
- test_hashmap_first_key();
- test_hashmap_steal_first_key();
- test_hashmap_steal_first();
- test_hashmap_clear_free_free();
- test_hashmap_reserve();
-}
diff --git a/src/test/test-hashmap.c b/src/test/test-hashmap.c
deleted file mode 100644
index 767cbd90e9..0000000000
--- a/src/test/test-hashmap.c
+++ /dev/null
@@ -1,88 +0,0 @@
-/***
- This file is part of systemd
-
- Copyright 2013 Daniel Buch
-
- 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 "util.h"
-#include "hashmap.h"
-
-void test_hashmap_funcs(void);
-void test_ordered_hashmap_funcs(void);
-
-static void test_ordered_hashmap_next(void) {
- OrderedHashmap *m;
- char *val1, *val2, *val3, *val4, *r;
-
- m = ordered_hashmap_new(&string_hash_ops);
- val1 = strdup("val1");
- assert_se(val1);
- val2 = strdup("val2");
- assert_se(val2);
- val3 = strdup("val3");
- assert_se(val3);
- val4 = strdup("val4");
- assert_se(val4);
-
- ordered_hashmap_put(m, "key 1", val1);
- ordered_hashmap_put(m, "key 2", val2);
- ordered_hashmap_put(m, "key 3", val3);
- ordered_hashmap_put(m, "key 4", val4);
-
- r = ordered_hashmap_next(m, "key 1");
- assert_se(streq(r, val2));
- r = ordered_hashmap_next(m, "key 2");
- assert_se(streq(r, val3));
- r = ordered_hashmap_next(m, "key 3");
- assert_se(streq(r, val4));
- r = ordered_hashmap_next(m, "key 4");
- assert_se(!r);
- r = ordered_hashmap_next(NULL, "key 1");
- assert_se(!r);
- r = ordered_hashmap_next(m, "key 5");
- assert_se(!r);
-
- ordered_hashmap_free_free(m);
-}
-
-static void test_uint64_compare_func(void) {
- const uint64_t a = 0x100, b = 0x101;
-
- assert_se(uint64_compare_func(&a, &a) == 0);
- assert_se(uint64_compare_func(&a, &b) == -1);
- assert_se(uint64_compare_func(&b, &a) == 1);
-}
-
-static void test_trivial_compare_func(void) {
- assert_se(trivial_compare_func(INT_TO_PTR('a'), INT_TO_PTR('a')) == 0);
- assert_se(trivial_compare_func(INT_TO_PTR('a'), INT_TO_PTR('b')) == -1);
- assert_se(trivial_compare_func(INT_TO_PTR('b'), INT_TO_PTR('a')) == 1);
-}
-
-static void test_string_compare_func(void) {
- assert_se(string_compare_func("fred", "wilma") != 0);
- assert_se(string_compare_func("fred", "fred") == 0);
-}
-
-int main(int argc, const char *argv[]) {
- test_hashmap_funcs();
- test_ordered_hashmap_funcs();
-
- test_ordered_hashmap_next();
- test_uint64_compare_func();
- test_trivial_compare_func();
- test_string_compare_func();
-}
diff --git a/src/test/test-helper.h b/src/test/test-helper.h
deleted file mode 100644
index f75dd3374a..0000000000
--- a/src/test/test-helper.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*-*- 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-hostname.c b/src/test/test-hostname.c
deleted file mode 100644
index c7e5de896b..0000000000
--- a/src/test/test-hostname.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2010 Lennart Poettering
-
- 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 "hostname-setup.h"
-#include "util.h"
-
-int main(int argc, char* argv[]) {
- int r;
-
- r = hostname_setup();
- if (r < 0)
- log_error_errno(r, "hostname: %m");
-
- return 0;
-}
diff --git a/src/test/test-id128.c b/src/test/test-id128.c
deleted file mode 100644
index a6a0cd77a1..0000000000
--- a/src/test/test-id128.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2011 Lennart Poettering
-
- 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 <string.h>
-
-#include "systemd/sd-id128.h"
-
-#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"
-#define UUID_WALDI "01020304-0506-0708-090a-0b0c0d0e0f10"
-
-int main(int argc, char *argv[]) {
- sd_id128_t id, id2;
- char t[33];
- _cleanup_free_ char *b = NULL;
-
- assert_se(sd_id128_randomize(&id) == 0);
- printf("random: %s\n", sd_id128_to_string(id, t));
-
- assert_se(sd_id128_from_string(t, &id2) == 0);
- assert_se(sd_id128_equal(id, id2));
-
- 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));
- }
-
- printf("waldi: %s\n", sd_id128_to_string(ID128_WALDI, t));
- assert_se(streq(t, STR_WALDI));
-
- assert_se(asprintf(&b, SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(ID128_WALDI)) == 32);
- printf("waldi2: %s\n", b);
- assert_se(streq(t, b));
-
- assert_se(sd_id128_from_string(UUID_WALDI, &id) >= 0);
- assert_se(sd_id128_equal(id, ID128_WALDI));
-
- assert_se(sd_id128_from_string("", &id) < 0);
- assert_se(sd_id128_from_string("01020304-0506-0708-090a-0b0c0d0e0f101", &id) < 0);
- assert_se(sd_id128_from_string("01020304-0506-0708-090a-0b0c0d0e0f10-", &id) < 0);
- assert_se(sd_id128_from_string("01020304-0506-0708-090a0b0c0d0e0f10", &id) < 0);
- assert_se(sd_id128_from_string("010203040506-0708-090a-0b0c0d0e0f10", &id) < 0);
-
- assert_se(id128_is_valid(STR_WALDI));
- assert_se(id128_is_valid(UUID_WALDI));
- assert_se(!id128_is_valid(""));
- assert_se(!id128_is_valid("01020304-0506-0708-090a-0b0c0d0e0f101"));
- assert_se(!id128_is_valid("01020304-0506-0708-090a-0b0c0d0e0f10-"));
- assert_se(!id128_is_valid("01020304-0506-0708-090a0b0c0d0e0f10"));
- assert_se(!id128_is_valid("010203040506-0708-090a-0b0c0d0e0f10"));
-
- return 0;
-}
diff --git a/src/test/test-install.c b/src/test/test-install.c
deleted file mode 100644
index 5ee52e64cb..0000000000
--- a/src/test/test-install.c
+++ /dev/null
@@ -1,261 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2011 Lennart Poettering
-
- 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 <string.h>
-#include <stdio.h>
-
-#include "install.h"
-
-static void dump_changes(UnitFileChange *c, unsigned n) {
- unsigned i;
-
- assert_se(n == 0 || c);
-
- for (i = 0; i < n; i++) {
- if (c[i].type == UNIT_FILE_UNLINK)
- printf("rm '%s'\n", c[i].path);
- else if (c[i].type == UNIT_FILE_SYMLINK)
- printf("ln -s '%s' '%s'\n", c[i].source, c[i].path);
- }
-}
-
-int main(int argc, char* argv[]) {
- Hashmap *h;
- UnitFileList *p;
- Iterator i;
- int r;
- const char *const files[] = { "avahi-daemon.service", NULL };
- const char *const files2[] = { "/home/lennart/test.service", NULL };
- UnitFileChange *changes = NULL;
- unsigned n_changes = 0;
-
- h = hashmap_new(&string_hash_ops);
- r = unit_file_get_list(UNIT_FILE_SYSTEM, NULL, h);
- assert_se(r == 0);
-
- HASHMAP_FOREACH(p, h, i) {
- UnitFileState s;
-
- s = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(p->path));
-
- assert_se(p->state == s);
-
- fprintf(stderr, "%s (%s)\n",
- p->path,
- unit_file_state_to_string(p->state));
- }
-
- unit_file_list_free(h);
-
- log_error("enable");
-
- r = unit_file_enable(UNIT_FILE_SYSTEM, false, NULL, (char**) files, false, &changes, &n_changes);
- assert_se(r >= 0);
-
- log_error("enable2");
-
- r = unit_file_enable(UNIT_FILE_SYSTEM, false, NULL, (char**) files, false, &changes, &n_changes);
- assert_se(r >= 0);
-
- dump_changes(changes, n_changes);
- unit_file_changes_free(changes, n_changes);
-
- assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, files[0]) == UNIT_FILE_ENABLED);
-
- log_error("disable");
-
- changes = NULL;
- n_changes = 0;
-
- r = unit_file_disable(UNIT_FILE_SYSTEM, false, NULL, (char**) files, &changes, &n_changes);
- assert_se(r >= 0);
-
- dump_changes(changes, n_changes);
- unit_file_changes_free(changes, n_changes);
-
- assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, files[0]) == UNIT_FILE_DISABLED);
-
- log_error("mask");
- changes = NULL;
- n_changes = 0;
-
- r = unit_file_mask(UNIT_FILE_SYSTEM, false, NULL, (char**) files, false, &changes, &n_changes);
- assert_se(r >= 0);
- log_error("mask2");
- r = unit_file_mask(UNIT_FILE_SYSTEM, false, NULL, (char**) files, false, &changes, &n_changes);
- assert_se(r >= 0);
-
- dump_changes(changes, n_changes);
- unit_file_changes_free(changes, n_changes);
-
- assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, files[0]) == UNIT_FILE_MASKED);
-
- log_error("unmask");
- changes = NULL;
- n_changes = 0;
-
- r = unit_file_unmask(UNIT_FILE_SYSTEM, false, NULL, (char**) files, &changes, &n_changes);
- assert_se(r >= 0);
- log_error("unmask2");
- r = unit_file_unmask(UNIT_FILE_SYSTEM, false, NULL, (char**) files, &changes, &n_changes);
- assert_se(r >= 0);
-
- dump_changes(changes, n_changes);
- unit_file_changes_free(changes, n_changes);
-
- assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, files[0]) == UNIT_FILE_DISABLED);
-
- log_error("mask");
- changes = NULL;
- n_changes = 0;
-
- r = unit_file_mask(UNIT_FILE_SYSTEM, false, NULL, (char**) files, false, &changes, &n_changes);
- assert_se(r >= 0);
-
- dump_changes(changes, n_changes);
- unit_file_changes_free(changes, n_changes);
-
- assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, files[0]) == UNIT_FILE_MASKED);
-
- log_error("disable");
- changes = NULL;
- n_changes = 0;
-
- r = unit_file_disable(UNIT_FILE_SYSTEM, false, NULL, (char**) files, &changes, &n_changes);
- assert_se(r >= 0);
- log_error("disable2");
- r = unit_file_disable(UNIT_FILE_SYSTEM, false, NULL, (char**) files, &changes, &n_changes);
- assert_se(r >= 0);
-
- dump_changes(changes, n_changes);
- unit_file_changes_free(changes, n_changes);
-
- assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, files[0]) == UNIT_FILE_MASKED);
-
- log_error("umask");
- changes = NULL;
- n_changes = 0;
-
- r = unit_file_unmask(UNIT_FILE_SYSTEM, false, NULL, (char**) files, &changes, &n_changes);
- assert_se(r >= 0);
-
- dump_changes(changes, n_changes);
- unit_file_changes_free(changes, n_changes);
-
- assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, files[0]) == UNIT_FILE_DISABLED);
-
- log_error("enable files2");
- changes = NULL;
- n_changes = 0;
-
- r = unit_file_enable(UNIT_FILE_SYSTEM, false, NULL, (char**) files2, false, &changes, &n_changes);
- assert_se(r >= 0);
-
- dump_changes(changes, n_changes);
- unit_file_changes_free(changes, n_changes);
-
- assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0])) == UNIT_FILE_ENABLED);
-
- log_error("disable files2");
- changes = NULL;
- n_changes = 0;
-
- r = unit_file_disable(UNIT_FILE_SYSTEM, false, NULL, (char**) files2, &changes, &n_changes);
- assert_se(r >= 0);
-
- dump_changes(changes, n_changes);
- unit_file_changes_free(changes, n_changes);
-
- assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0])) == _UNIT_FILE_STATE_INVALID);
-
- log_error("link files2");
- changes = NULL;
- n_changes = 0;
-
- r = unit_file_link(UNIT_FILE_SYSTEM, false, NULL, (char**) files2, false, &changes, &n_changes);
- assert_se(r >= 0);
-
- dump_changes(changes, n_changes);
- unit_file_changes_free(changes, n_changes);
-
- assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0])) == UNIT_FILE_LINKED);
-
- log_error("disable files2");
- changes = NULL;
- n_changes = 0;
-
- r = unit_file_disable(UNIT_FILE_SYSTEM, false, NULL, (char**) files2, &changes, &n_changes);
- assert_se(r >= 0);
-
- dump_changes(changes, n_changes);
- unit_file_changes_free(changes, n_changes);
-
- assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0])) == _UNIT_FILE_STATE_INVALID);
-
- log_error("link files2");
- changes = NULL;
- n_changes = 0;
-
- r = unit_file_link(UNIT_FILE_SYSTEM, false, NULL, (char**) files2, false, &changes, &n_changes);
- assert_se(r >= 0);
-
- dump_changes(changes, n_changes);
- unit_file_changes_free(changes, n_changes);
-
- assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0])) == UNIT_FILE_LINKED);
-
- log_error("reenable files2");
- changes = NULL;
- n_changes = 0;
-
- r = unit_file_reenable(UNIT_FILE_SYSTEM, false, NULL, (char**) files2, false, &changes, &n_changes);
- assert_se(r >= 0);
-
- dump_changes(changes, n_changes);
- unit_file_changes_free(changes, n_changes);
-
- assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0])) == UNIT_FILE_ENABLED);
-
- log_error("disable files2");
- changes = NULL;
- n_changes = 0;
-
- r = unit_file_disable(UNIT_FILE_SYSTEM, false, NULL, (char**) files2, &changes, &n_changes);
- assert_se(r >= 0);
-
- dump_changes(changes, n_changes);
- unit_file_changes_free(changes, n_changes);
-
- assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0])) == _UNIT_FILE_STATE_INVALID);
- log_error("preset files");
- changes = NULL;
- n_changes = 0;
-
- r = unit_file_preset(UNIT_FILE_SYSTEM, false, NULL, (char**) files, UNIT_FILE_PRESET_FULL, false, &changes, &n_changes);
- assert_se(r >= 0);
-
- dump_changes(changes, n_changes);
- unit_file_changes_free(changes, n_changes);
-
- assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files[0])) == UNIT_FILE_ENABLED);
-
- return 0;
-}
diff --git a/src/test/test-ipcrm.c b/src/test/test-ipcrm.c
deleted file mode 100644
index 4944bf6ad9..0000000000
--- a/src/test/test-ipcrm.c
+++ /dev/null
@@ -1,32 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2014 Lennart Poettering
-
- 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 "util.h"
-#include "clean-ipc.h"
-
-int main(int argc, char *argv[]) {
- uid_t uid;
-
- assert_se(argc == 2);
- assert_se(parse_uid(argv[1], &uid) >= 0);
-
- return clean_ipc(uid) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
-}
diff --git a/src/test/test-job-type.c b/src/test/test-job-type.c
deleted file mode 100644
index af0d76e894..0000000000
--- a/src/test/test-job-type.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2010 Lennart Poettering
-
- 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 <stdio.h>
-
-#include "job.h"
-#include "unit.h"
-#include "service.h"
-
-int main(int argc, char*argv[]) {
- JobType a, b, c, ab, bc, ab_c, bc_a, a_bc;
- const ServiceState test_states[] = { SERVICE_DEAD, SERVICE_RUNNING };
- unsigned i;
- bool merged_ab;
-
- /* fake a unit */
- static Service s = {
- .meta.load_state = UNIT_LOADED,
- .type = SERVICE_SIMPLE,
- };
- Unit *u = UNIT(&s);
-
- for (i = 0; i < ELEMENTSOF(test_states); i++) {
- s.state = test_states[i];
- printf("\nWith collapsing for service state %s\n"
- "=========================================\n", service_state_to_string(s.state));
- for (a = 0; a < _JOB_TYPE_MAX_MERGING; a++) {
- for (b = 0; b < _JOB_TYPE_MAX_MERGING; b++) {
-
- ab = a;
- merged_ab = (job_type_merge_and_collapse(&ab, b, u) >= 0);
-
- if (!job_type_is_mergeable(a, b)) {
- assert_se(!merged_ab);
- printf("Not mergeable: %s + %s\n", job_type_to_string(a), job_type_to_string(b));
- continue;
- }
-
- assert_se(merged_ab);
- printf("%s + %s = %s\n", job_type_to_string(a), job_type_to_string(b), job_type_to_string(ab));
-
- for (c = 0; c < _JOB_TYPE_MAX_MERGING; c++) {
-
- /* Verify transitivity of mergeability of job types */
- assert_se(!job_type_is_mergeable(a, b) ||
- !job_type_is_mergeable(b, c) ||
- job_type_is_mergeable(a, c));
-
- /* Verify that merged entries can be merged with the same entries
- * they can be merged with separately */
- assert_se(!job_type_is_mergeable(a, c) || job_type_is_mergeable(ab, c));
- assert_se(!job_type_is_mergeable(b, c) || job_type_is_mergeable(ab, c));
-
- /* Verify that if a merged with b is not mergeable with c, then
- * either a or b is not mergeable with c either. */
- assert_se(job_type_is_mergeable(ab, c) || !job_type_is_mergeable(a, c) || !job_type_is_mergeable(b, c));
-
- bc = b;
- if (job_type_merge_and_collapse(&bc, c, u) >= 0) {
-
- /* Verify associativity */
-
- ab_c = ab;
- assert_se(job_type_merge_and_collapse(&ab_c, c, u) == 0);
-
- bc_a = bc;
- assert_se(job_type_merge_and_collapse(&bc_a, a, u) == 0);
-
- a_bc = a;
- assert_se(job_type_merge_and_collapse(&a_bc, bc, u) == 0);
-
- assert_se(ab_c == bc_a);
- assert_se(ab_c == a_bc);
-
- printf("%s + %s + %s = %s\n", job_type_to_string(a), job_type_to_string(b), job_type_to_string(c), job_type_to_string(ab_c));
- }
- }
- }
- }
- }
-
-
- return 0;
-}
diff --git a/src/test/test-json.c b/src/test/test-json.c
deleted file mode 100644
index 24dc7003bc..0000000000
--- a/src/test/test-json.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2014 Lennart Poettering
-
- 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 <math.h>
-
-#include "util.h"
-#include "json.h"
-
-static void test_one(const char *data, ...) {
- void *state = NULL;
- va_list ap;
-
- va_start(ap, data);
-
- for (;;) {
- _cleanup_free_ char *str = NULL;
- union json_value v = {};
- int t, tt;
-
- t = json_tokenize(&data, &str, &v, &state, NULL);
- tt = va_arg(ap, int);
-
- assert_se(t == tt);
-
- if (t == JSON_END || t < 0)
- break;
-
- else if (t == JSON_STRING) {
- const char *nn;
-
- nn = va_arg(ap, const char *);
- assert_se(streq_ptr(nn, str));
-
- } else if (t == JSON_REAL) {
- double d;
-
- d = va_arg(ap, double);
- assert_se(fabs(d - v.real) < 0.001);
-
- } else if (t == JSON_INTEGER) {
- intmax_t i;
-
- i = va_arg(ap, intmax_t);
- assert_se(i == v.integer);
-
- } else if (t == JSON_BOOLEAN) {
- bool b;
-
- b = va_arg(ap, int);
- assert_se(b == v.boolean);
- }
- }
-
- va_end(ap);
-}
-
-int main(int argc, char *argv[]) {
-
- test_one("x", -EINVAL);
- test_one("", JSON_END);
- test_one(" ", JSON_END);
- test_one("0", JSON_INTEGER, (intmax_t) 0, JSON_END);
- test_one("1234", JSON_INTEGER, (intmax_t) 1234, JSON_END);
- test_one("3.141", JSON_REAL, 3.141, JSON_END);
- test_one("0.0", JSON_REAL, 0.0, JSON_END);
- test_one("7e3", JSON_REAL, 7e3, JSON_END);
- test_one("-7e-3", JSON_REAL, -7e-3, JSON_END);
- test_one("true", JSON_BOOLEAN, true, JSON_END);
- test_one("false", JSON_BOOLEAN, false, JSON_END);
- test_one("null", JSON_NULL, JSON_END);
- test_one("{}", JSON_OBJECT_OPEN, JSON_OBJECT_CLOSE, JSON_END);
- test_one("\t {\n} \n", JSON_OBJECT_OPEN, JSON_OBJECT_CLOSE, JSON_END);
- test_one("[]", JSON_ARRAY_OPEN, JSON_ARRAY_CLOSE, JSON_END);
- test_one("\t [] \n\n", JSON_ARRAY_OPEN, JSON_ARRAY_CLOSE, JSON_END);
- test_one("\"\"", JSON_STRING, "", JSON_END);
- test_one("\"foo\"", JSON_STRING, "foo", JSON_END);
- test_one("\"foo\\nfoo\"", JSON_STRING, "foo\nfoo", JSON_END);
- test_one("{\"foo\" : \"bar\"}", JSON_OBJECT_OPEN, JSON_STRING, "foo", JSON_COLON, JSON_STRING, "bar", JSON_OBJECT_CLOSE, JSON_END);
- test_one("{\"foo\" : [true, false]}", JSON_OBJECT_OPEN, JSON_STRING, "foo", JSON_COLON, JSON_ARRAY_OPEN, JSON_BOOLEAN, true, JSON_COMMA, JSON_BOOLEAN, false, JSON_ARRAY_CLOSE, JSON_OBJECT_CLOSE, JSON_END);
- test_one("\"\xef\xbf\xbd\"", JSON_STRING, "\xef\xbf\xbd", JSON_END);
- test_one("\"\\ufffd\"", JSON_STRING, "\xef\xbf\xbd", JSON_END);
- test_one("\"\\uf\"", -EINVAL);
- test_one("\"\\ud800a\"", -EINVAL);
- test_one("\"\\udc00\\udc00\"", -EINVAL);
- test_one("\"\\ud801\\udc37\"", JSON_STRING, "\xf0\x90\x90\xb7", JSON_END);
-
- return 0;
-}
diff --git a/src/test/test-libudev.c b/src/test/test-libudev.c
deleted file mode 100644
index 2b004fdfb1..0000000000
--- a/src/test/test-libudev.c
+++ /dev/null
@@ -1,475 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-/***
- This file is part of systemd.
-
- Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
-
- 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 <stdio.h>
-#include <unistd.h>
-#include <getopt.h>
-#include <sys/epoll.h>
-
-#include "libudev.h"
-#include "udev-util.h"
-#include "util.h"
-
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-
-static void print_device(struct udev_device *device) {
- const char *str;
- dev_t devnum;
- int count;
- struct udev_list_entry *list_entry;
-
- printf("*** device: %p ***\n", device);
- str = udev_device_get_action(device);
- if (str != NULL)
- printf("action: '%s'\n", str);
-
- str = udev_device_get_syspath(device);
- printf("syspath: '%s'\n", str);
-
- str = udev_device_get_sysname(device);
- printf("sysname: '%s'\n", str);
-
- str = udev_device_get_sysnum(device);
- if (str != NULL)
- printf("sysnum: '%s'\n", str);
-
- str = udev_device_get_devpath(device);
- printf("devpath: '%s'\n", str);
-
- str = udev_device_get_subsystem(device);
- if (str != NULL)
- printf("subsystem: '%s'\n", str);
-
- str = udev_device_get_devtype(device);
- if (str != NULL)
- printf("devtype: '%s'\n", str);
-
- str = udev_device_get_driver(device);
- if (str != NULL)
- printf("driver: '%s'\n", str);
-
- str = udev_device_get_devnode(device);
- if (str != NULL)
- printf("devname: '%s'\n", str);
-
- devnum = udev_device_get_devnum(device);
- if (major(devnum) > 0)
- printf("devnum: %u:%u\n", major(devnum), minor(devnum));
-
- count = 0;
- udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device)) {
- printf("link: '%s'\n", udev_list_entry_get_name(list_entry));
- count++;
- }
- if (count > 0)
- printf("found %i links\n", count);
-
- count = 0;
- udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(device)) {
- printf("property: '%s=%s'\n",
- udev_list_entry_get_name(list_entry),
- udev_list_entry_get_value(list_entry));
- count++;
- }
- if (count > 0)
- printf("found %i properties\n", count);
-
- str = udev_device_get_property_value(device, "MAJOR");
- if (str != NULL)
- printf("MAJOR: '%s'\n", str);
-
- str = udev_device_get_sysattr_value(device, "dev");
- if (str != NULL)
- printf("attr{dev}: '%s'\n", str);
-
- printf("\n");
-}
-
-static int test_device(struct udev *udev, const char *syspath) {
- _cleanup_udev_device_unref_ struct udev_device *device;
-
- printf("looking at device: %s\n", syspath);
- device = udev_device_new_from_syspath(udev, syspath);
- if (device == NULL) {
- printf("no device found\n");
- return -1;
- }
- print_device(device);
-
- return 0;
-}
-
-static int test_device_parents(struct udev *udev, const char *syspath) {
- _cleanup_udev_device_unref_ struct udev_device *device;
- struct udev_device *device_parent;
-
- printf("looking at device: %s\n", syspath);
- device = udev_device_new_from_syspath(udev, syspath);
- if (device == NULL)
- return -1;
-
- printf("looking at parents\n");
- device_parent = device;
- do {
- print_device(device_parent);
- device_parent = udev_device_get_parent(device_parent);
- } while (device_parent != NULL);
-
- printf("looking at parents again\n");
- device_parent = device;
- do {
- print_device(device_parent);
- device_parent = udev_device_get_parent(device_parent);
- } while (device_parent != NULL);
-
- return 0;
-}
-
-static int test_device_devnum(struct udev *udev) {
- dev_t devnum = makedev(1, 3);
- struct udev_device *device;
-
- printf("looking up device: %u:%u\n", major(devnum), minor(devnum));
- device = udev_device_new_from_devnum(udev, 'c', devnum);
- if (device == NULL)
- return -1;
- print_device(device);
- udev_device_unref(device);
- return 0;
-}
-
-static int test_device_subsys_name(struct udev *udev) {
- struct udev_device *device;
-
- printf("looking up device: 'block':'sda'\n");
- device = udev_device_new_from_subsystem_sysname(udev, "block", "sda");
- if (device == NULL)
- return -1;
- print_device(device);
- udev_device_unref(device);
-
- printf("looking up device: 'subsystem':'pci'\n");
- device = udev_device_new_from_subsystem_sysname(udev, "subsystem", "pci");
- if (device == NULL)
- return -1;
- print_device(device);
- udev_device_unref(device);
-
- printf("looking up device: 'drivers':'scsi:sd'\n");
- device = udev_device_new_from_subsystem_sysname(udev, "drivers", "scsi:sd");
- if (device == NULL)
- return -1;
- print_device(device);
- udev_device_unref(device);
-
- printf("looking up device: 'module':'printk'\n");
- device = udev_device_new_from_subsystem_sysname(udev, "module", "printk");
- if (device == NULL)
- return -1;
- print_device(device);
- udev_device_unref(device);
- return 0;
-}
-
-static int test_enumerate_print_list(struct udev_enumerate *enumerate) {
- struct udev_list_entry *list_entry;
- int count = 0;
-
- udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(enumerate)) {
- struct udev_device *device;
-
- device = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerate),
- udev_list_entry_get_name(list_entry));
- if (device != NULL) {
- printf("device: '%s' (%s)\n",
- udev_device_get_syspath(device),
- udev_device_get_subsystem(device));
- udev_device_unref(device);
- count++;
- }
- }
- printf("found %i devices\n\n", count);
- return count;
-}
-
-static int test_monitor(struct udev *udev) {
- struct udev_monitor *udev_monitor = NULL;
- int fd_ep;
- int fd_udev = -1;
- struct epoll_event ep_udev, ep_stdin;
-
- fd_ep = epoll_create1(EPOLL_CLOEXEC);
- if (fd_ep < 0) {
- printf("error creating epoll fd: %m\n");
- goto out;
- }
-
- udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
- if (udev_monitor == NULL) {
- printf("no socket\n");
- goto out;
- }
- fd_udev = udev_monitor_get_fd(udev_monitor);
-
- if (udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "block", NULL) < 0 ||
- udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "tty", NULL) < 0 ||
- udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "usb", "usb_device") < 0) {
- printf("filter failed\n");
- goto out;
- }
-
- if (udev_monitor_enable_receiving(udev_monitor) < 0) {
- printf("bind failed\n");
- goto out;
- }
-
- memzero(&ep_udev, sizeof(struct epoll_event));
- ep_udev.events = EPOLLIN;
- ep_udev.data.fd = fd_udev;
- if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_udev, &ep_udev) < 0) {
- printf("fail to add fd to epoll: %m\n");
- goto out;
- }
-
- memzero(&ep_stdin, sizeof(struct epoll_event));
- ep_stdin.events = EPOLLIN;
- ep_stdin.data.fd = STDIN_FILENO;
- if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, STDIN_FILENO, &ep_stdin) < 0) {
- printf("fail to add fd to epoll: %m\n");
- goto out;
- }
-
- for (;;) {
- int fdcount;
- struct epoll_event ev[4];
- struct udev_device *device;
- int i;
-
- printf("waiting for events from udev, press ENTER to exit\n");
- fdcount = epoll_wait(fd_ep, ev, ARRAY_SIZE(ev), -1);
- printf("epoll fd count: %i\n", fdcount);
-
- for (i = 0; i < fdcount; i++) {
- if (ev[i].data.fd == fd_udev && ev[i].events & EPOLLIN) {
- device = udev_monitor_receive_device(udev_monitor);
- if (device == NULL) {
- printf("no device from socket\n");
- continue;
- }
- print_device(device);
- udev_device_unref(device);
- } else if (ev[i].data.fd == STDIN_FILENO && ev[i].events & EPOLLIN) {
- printf("exiting loop\n");
- goto out;
- }
- }
- }
-out:
- if (fd_ep >= 0)
- close(fd_ep);
- udev_monitor_unref(udev_monitor);
- return 0;
-}
-
-static int test_queue(struct udev *udev) {
- struct udev_queue *udev_queue;
-
- udev_queue = udev_queue_new(udev);
- if (udev_queue == NULL)
- return -1;
-
- if (udev_queue_get_queue_is_empty(udev_queue))
- printf("queue is empty\n");
-
- udev_queue_unref(udev_queue);
- return 0;
-}
-
-static int test_enumerate(struct udev *udev, const char *subsystem) {
- struct udev_enumerate *udev_enumerate;
-
- printf("enumerate '%s'\n", subsystem == NULL ? "<all>" : subsystem);
- udev_enumerate = udev_enumerate_new(udev);
- if (udev_enumerate == NULL)
- return -1;
- udev_enumerate_add_match_subsystem(udev_enumerate, subsystem);
- udev_enumerate_scan_devices(udev_enumerate);
- test_enumerate_print_list(udev_enumerate);
- udev_enumerate_unref(udev_enumerate);
-
- printf("enumerate 'net' + duplicated scan + null + zero\n");
- udev_enumerate = udev_enumerate_new(udev);
- if (udev_enumerate == NULL)
- return -1;
- udev_enumerate_add_match_subsystem(udev_enumerate, "net");
- udev_enumerate_scan_devices(udev_enumerate);
- udev_enumerate_scan_devices(udev_enumerate);
- udev_enumerate_add_syspath(udev_enumerate, "/sys/class/mem/zero");
- udev_enumerate_add_syspath(udev_enumerate, "/sys/class/mem/null");
- udev_enumerate_add_syspath(udev_enumerate, "/sys/class/mem/zero");
- udev_enumerate_add_syspath(udev_enumerate, "/sys/class/mem/null");
- udev_enumerate_add_syspath(udev_enumerate, "/sys/class/mem/zero");
- udev_enumerate_add_syspath(udev_enumerate, "/sys/class/mem/null");
- udev_enumerate_add_syspath(udev_enumerate, "/sys/class/mem/null");
- udev_enumerate_add_syspath(udev_enumerate, "/sys/class/mem/zero");
- udev_enumerate_add_syspath(udev_enumerate, "/sys/class/mem/zero");
- udev_enumerate_scan_devices(udev_enumerate);
- test_enumerate_print_list(udev_enumerate);
- udev_enumerate_unref(udev_enumerate);
-
- printf("enumerate 'block'\n");
- udev_enumerate = udev_enumerate_new(udev);
- if (udev_enumerate == NULL)
- return -1;
- udev_enumerate_add_match_subsystem(udev_enumerate,"block");
- udev_enumerate_add_match_is_initialized(udev_enumerate);
- udev_enumerate_scan_devices(udev_enumerate);
- test_enumerate_print_list(udev_enumerate);
- udev_enumerate_unref(udev_enumerate);
-
- printf("enumerate 'not block'\n");
- udev_enumerate = udev_enumerate_new(udev);
- if (udev_enumerate == NULL)
- return -1;
- udev_enumerate_add_nomatch_subsystem(udev_enumerate, "block");
- udev_enumerate_scan_devices(udev_enumerate);
- test_enumerate_print_list(udev_enumerate);
- udev_enumerate_unref(udev_enumerate);
-
- printf("enumerate 'pci, mem, vc'\n");
- udev_enumerate = udev_enumerate_new(udev);
- if (udev_enumerate == NULL)
- return -1;
- udev_enumerate_add_match_subsystem(udev_enumerate, "pci");
- udev_enumerate_add_match_subsystem(udev_enumerate, "mem");
- udev_enumerate_add_match_subsystem(udev_enumerate, "vc");
- udev_enumerate_scan_devices(udev_enumerate);
- test_enumerate_print_list(udev_enumerate);
- udev_enumerate_unref(udev_enumerate);
-
- printf("enumerate 'subsystem'\n");
- udev_enumerate = udev_enumerate_new(udev);
- if (udev_enumerate == NULL)
- return -1;
- udev_enumerate_scan_subsystems(udev_enumerate);
- test_enumerate_print_list(udev_enumerate);
- udev_enumerate_unref(udev_enumerate);
-
- printf("enumerate 'property IF_FS_*=filesystem'\n");
- udev_enumerate = udev_enumerate_new(udev);
- if (udev_enumerate == NULL)
- return -1;
- udev_enumerate_add_match_property(udev_enumerate, "ID_FS*", "filesystem");
- udev_enumerate_scan_devices(udev_enumerate);
- test_enumerate_print_list(udev_enumerate);
- udev_enumerate_unref(udev_enumerate);
- return 0;
-}
-
-static void test_hwdb(struct udev *udev, const char *modalias) {
- struct udev_hwdb *hwdb;
- struct udev_list_entry *entry;
-
- hwdb = udev_hwdb_new(udev);
-
- udev_list_entry_foreach(entry, udev_hwdb_get_properties_list_entry(hwdb, modalias, 0))
- printf("'%s'='%s'\n", udev_list_entry_get_name(entry), udev_list_entry_get_value(entry));
- printf("\n");
-
- hwdb = udev_hwdb_unref(hwdb);
- assert_se(hwdb == NULL);
-}
-
-int main(int argc, char *argv[]) {
- struct udev *udev = NULL;
- static const struct option options[] = {
- { "syspath", required_argument, NULL, 'p' },
- { "subsystem", required_argument, NULL, 's' },
- { "debug", no_argument, NULL, 'd' },
- { "help", no_argument, NULL, 'h' },
- { "version", no_argument, NULL, 'V' },
- {}
- };
- const char *syspath = "/devices/virtual/mem/null";
- const char *subsystem = NULL;
- char path[1024];
- int c;
-
- udev = udev_new();
- printf("context: %p\n", udev);
- if (udev == NULL) {
- printf("no context\n");
- return 1;
- }
-
- while ((c = getopt_long(argc, argv, "p:s:dhV", options, NULL)) >= 0)
- switch (c) {
-
- case 'p':
- syspath = optarg;
- break;
-
- case 's':
- subsystem = optarg;
- break;
-
- case 'd':
- if (log_get_max_level() < LOG_INFO)
- log_set_max_level(LOG_INFO);
- break;
-
- case 'h':
- printf("--debug --syspath= --subsystem= --help\n");
- goto out;
-
- case 'V':
- printf("%s\n", VERSION);
- goto out;
-
- case '?':
- goto out;
-
- default:
- assert_not_reached("Unhandled option code.");
- }
-
-
- /* add sys path if needed */
- if (!startswith(syspath, "/sys")) {
- snprintf(path, sizeof(path), "/sys/%s", syspath);
- syspath = path;
- }
-
- test_device(udev, syspath);
- test_device_devnum(udev);
- test_device_subsys_name(udev);
- test_device_parents(udev, syspath);
-
- test_enumerate(udev, subsystem);
-
- test_queue(udev);
-
- test_hwdb(udev, "usb:v0D50p0011*");
-
- test_monitor(udev);
-out:
- udev_unref(udev);
- return 0;
-}
diff --git a/src/test/test-list.c b/src/test/test-list.c
deleted file mode 100644
index f6da1a7053..0000000000
--- a/src/test/test-list.c
+++ /dev/null
@@ -1,154 +0,0 @@
-/***
- This file is part of systemd
-
- Copyright 2013 Jan Janssen
-
- 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 "list.h"
-#include "util.h"
-
-int main(int argc, const char *argv[]) {
- size_t i;
- typedef struct list_item {
- LIST_FIELDS(struct list_item, item);
- } list_item;
- LIST_HEAD(list_item, head);
- list_item items[4];
- list_item *cursor;
-
- LIST_HEAD_INIT(head);
- assert_se(head == NULL);
-
- for (i = 0; i < ELEMENTSOF(items); i++) {
- LIST_INIT(item, &items[i]);
- assert_se(LIST_JUST_US(item, &items[i]));
- LIST_PREPEND(item, head, &items[i]);
- }
-
- i = 0;
- LIST_FOREACH_OTHERS(item, cursor, &items[2]) {
- i++;
- assert_se(cursor != &items[2]);
- }
- assert_se(i == ELEMENTSOF(items)-1);
-
- i = 0;
- LIST_FOREACH_OTHERS(item, cursor, &items[0]) {
- i++;
- assert_se(cursor != &items[0]);
- }
- assert_se(i == ELEMENTSOF(items)-1);
-
- i = 0;
- LIST_FOREACH_OTHERS(item, cursor, &items[3]) {
- i++;
- assert_se(cursor != &items[3]);
- }
- assert_se(i == ELEMENTSOF(items)-1);
-
- assert_se(!LIST_JUST_US(item, head));
-
- assert_se(items[0].item_next == NULL);
- assert_se(items[1].item_next == &items[0]);
- assert_se(items[2].item_next == &items[1]);
- assert_se(items[3].item_next == &items[2]);
-
- assert_se(items[0].item_prev == &items[1]);
- assert_se(items[1].item_prev == &items[2]);
- assert_se(items[2].item_prev == &items[3]);
- assert_se(items[3].item_prev == NULL);
-
- LIST_FIND_HEAD(item, &items[0], cursor);
- assert_se(cursor == &items[3]);
-
- LIST_FIND_TAIL(item, &items[3], cursor);
- assert_se(cursor == &items[0]);
-
- LIST_REMOVE(item, head, &items[1]);
- assert_se(LIST_JUST_US(item, &items[1]));
-
- assert_se(items[0].item_next == NULL);
- assert_se(items[2].item_next == &items[0]);
- assert_se(items[3].item_next == &items[2]);
-
- assert_se(items[0].item_prev == &items[2]);
- assert_se(items[2].item_prev == &items[3]);
- assert_se(items[3].item_prev == NULL);
-
- LIST_INSERT_AFTER(item, head, &items[3], &items[1]);
- assert_se(items[0].item_next == NULL);
- assert_se(items[2].item_next == &items[0]);
- assert_se(items[1].item_next == &items[2]);
- assert_se(items[3].item_next == &items[1]);
-
- assert_se(items[0].item_prev == &items[2]);
- assert_se(items[2].item_prev == &items[1]);
- assert_se(items[1].item_prev == &items[3]);
- assert_se(items[3].item_prev == NULL);
-
- LIST_REMOVE(item, head, &items[0]);
- assert_se(LIST_JUST_US(item, &items[0]));
-
- assert_se(items[2].item_next == NULL);
- assert_se(items[1].item_next == &items[2]);
- assert_se(items[3].item_next == &items[1]);
-
- assert_se(items[2].item_prev == &items[1]);
- assert_se(items[1].item_prev == &items[3]);
- assert_se(items[3].item_prev == NULL);
-
- LIST_REMOVE(item, head, &items[1]);
- assert_se(LIST_JUST_US(item, &items[1]));
-
- assert_se(items[2].item_next == NULL);
- assert_se(items[3].item_next == &items[2]);
-
- assert_se(items[2].item_prev == &items[3]);
- assert_se(items[3].item_prev == NULL);
-
- LIST_REMOVE(item, head, &items[2]);
- assert_se(LIST_JUST_US(item, &items[2]));
- assert_se(LIST_JUST_US(item, head));
-
- LIST_REMOVE(item, head, &items[3]);
- assert_se(LIST_JUST_US(item, &items[3]));
-
- assert_se(head == NULL);
-
- for (i = 0; i < ELEMENTSOF(items); i++) {
- assert_se(LIST_JUST_US(item, &items[i]));
- LIST_APPEND(item, head, &items[i]);
- }
-
- assert_se(!LIST_JUST_US(item, head));
-
- assert_se(items[0].item_next == &items[1]);
- assert_se(items[1].item_next == &items[2]);
- assert_se(items[2].item_next == &items[3]);
- assert_se(items[3].item_next == NULL);
-
- assert_se(items[0].item_prev == NULL);
- assert_se(items[1].item_prev == &items[0]);
- assert_se(items[2].item_prev == &items[1]);
- assert_se(items[3].item_prev == &items[2]);
-
- for (i = 0; i < ELEMENTSOF(items); i++)
- LIST_REMOVE(item, head, &items[i]);
-
- assert_se(head == NULL);
-
- return 0;
-}
diff --git a/src/test/test-locale-util.c b/src/test/test-locale-util.c
deleted file mode 100644
index 9765075365..0000000000
--- a/src/test/test-locale-util.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/***
- This file is part of systemd
-
- Copyright 2014 Ronny Chevalier
-
- 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 "locale-util.h"
-#include "strv.h"
-#include "macro.h"
-
-static void test_get_locales(void) {
- _cleanup_strv_free_ char **locales = NULL;
- char **p;
- int r;
-
- r = get_locales(&locales);
- assert_se(r >= 0);
- assert_se(locales);
-
- STRV_FOREACH(p, locales) {
- puts(*p);
- assert_se(locale_is_valid(*p));
- }
-}
-
-static void test_locale_is_valid(void) {
- assert_se(locale_is_valid("en_EN.utf8"));
- assert_se(locale_is_valid("fr_FR.utf8"));
- assert_se(locale_is_valid("fr_FR@euro"));
- assert_se(locale_is_valid("fi_FI"));
- assert_se(locale_is_valid("POSIX"));
- assert_se(locale_is_valid("C"));
-
- assert_se(!locale_is_valid(""));
- assert_se(!locale_is_valid("/usr/bin/foo"));
- assert_se(!locale_is_valid("\x01gar\x02 bage\x03"));
-}
-
-int main(int argc, char *argv[]) {
- test_get_locales();
- test_locale_is_valid();
-
- return 0;
-}
diff --git a/src/test/test-log.c b/src/test/test-log.c
deleted file mode 100644
index ca64004b4c..0000000000
--- a/src/test/test-log.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2012 Lennart Poettering
-
- 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 <stddef.h>
-#include <unistd.h>
-
-#include "log.h"
-#include "util.h"
-
-int main(int argc, char* argv[]) {
-
- log_set_target(LOG_TARGET_CONSOLE);
- log_open();
-
- log_struct(LOG_INFO,
- "MESSAGE=Waldo PID="PID_FMT, getpid(),
- "SERVICE=piepapo",
- NULL);
-
- log_set_target(LOG_TARGET_JOURNAL);
- log_open();
-
- log_struct(LOG_INFO,
- "MESSAGE=Foobar PID="PID_FMT, getpid(),
- "SERVICE=foobar",
- NULL);
-
- log_struct(LOG_INFO,
- "MESSAGE=Foobar PID="PID_FMT, getpid(),
- "FORMAT_STR_TEST=1=%i A=%c 2=%hi 3=%li 4=%lli 1=%p foo=%s 2.5=%g 3.5=%g 4.5=%Lg",
- (int) 1, 'A', (short) 2, (long int) 3, (long long int) 4, (void*) 1, "foo", (float) 2.5f, (double) 3.5, (long double) 4.5,
- "SUFFIX=GOT IT",
- NULL);
-
- return 0;
-}
diff --git a/src/test/test-loopback.c b/src/test/test-loopback.c
deleted file mode 100644
index c03bda4382..0000000000
--- a/src/test/test-loopback.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2010 Lennart Poettering
-
- 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 <string.h>
-#include <stdio.h>
-
-#include "loopback-setup.h"
-#include "log.h"
-
-int main(int argc, char* argv[]) {
- int r;
-
- log_open();
- log_parse_environment();
-
- if ((r = loopback_setup()) < 0)
- fprintf(stderr, "loopback: %s\n", strerror(-r));
-
- return 0;
-}
diff --git a/src/test/test-namespace.c b/src/test/test-namespace.c
deleted file mode 100644
index 2397db5fff..0000000000
--- a/src/test/test-namespace.c
+++ /dev/null
@@ -1,144 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 Zbigniew Jędrzejewski-Szmek
-
- 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 <sys/socket.h>
-
-#include "namespace.h"
-#include "util.h"
-
-static void test_tmpdir(const char *id, const char *A, const char *B) {
- _cleanup_free_ char *a, *b;
- struct stat x, y;
- char *c, *d;
-
- assert_se(setup_tmp_dirs(id, &a, &b) == 0);
- assert_se(startswith(a, A));
- assert_se(startswith(b, B));
-
- assert_se(stat(a, &x) >= 0);
- assert_se(stat(b, &y) >= 0);
-
- assert_se(S_ISDIR(x.st_mode));
- assert_se(S_ISDIR(y.st_mode));
-
- assert_se((x.st_mode & 01777) == 0700);
- assert_se((y.st_mode & 01777) == 0700);
-
- c = strjoina(a, "/tmp");
- d = strjoina(b, "/tmp");
-
- assert_se(stat(c, &x) >= 0);
- assert_se(stat(d, &y) >= 0);
-
- assert_se(S_ISDIR(x.st_mode));
- assert_se(S_ISDIR(y.st_mode));
-
- assert_se((x.st_mode & 01777) == 01777);
- assert_se((y.st_mode & 01777) == 01777);
-
- assert_se(rmdir(c) >= 0);
- assert_se(rmdir(d) >= 0);
-
- assert_se(rmdir(a) >= 0);
- assert_se(rmdir(b) >= 0);
-}
-
-static void test_netns(void) {
- _cleanup_close_pair_ int s[2] = { -1, -1 };
- pid_t pid1, pid2, pid3;
- int r, n = 0;
- siginfo_t si;
-
- if (geteuid() > 0)
- return;
-
- assert_se(socketpair(AF_UNIX, SOCK_DGRAM, 0, s) >= 0);
-
- pid1 = fork();
- assert_se(pid1 >= 0);
-
- if (pid1 == 0) {
- r = setup_netns(s);
- assert_se(r >= 0);
- _exit(r);
- }
-
- pid2 = fork();
- assert_se(pid2 >= 0);
-
- if (pid2 == 0) {
- r = setup_netns(s);
- assert_se(r >= 0);
- exit(r);
- }
-
- pid3 = fork();
- assert_se(pid3 >= 0);
-
- if (pid3 == 0) {
- r = setup_netns(s);
- assert_se(r >= 0);
- exit(r);
- }
-
- r = wait_for_terminate(pid1, &si);
- assert_se(r >= 0);
- assert_se(si.si_code == CLD_EXITED);
- n += si.si_status;
-
- r = wait_for_terminate(pid2, &si);
- assert_se(r >= 0);
- assert_se(si.si_code == CLD_EXITED);
- n += si.si_status;
-
- r = wait_for_terminate(pid3, &si);
- assert_se(r >= 0);
- assert_se(si.si_code == CLD_EXITED);
- n += si.si_status;
-
- assert_se(n == 1);
-}
-
-int main(int argc, char *argv[]) {
- sd_id128_t bid;
- char boot_id[SD_ID128_STRING_MAX];
- _cleanup_free_ char *x = NULL, *y = NULL, *z = NULL, *zz = NULL;
-
- assert_se(sd_id128_get_boot(&bid) >= 0);
- sd_id128_to_string(bid, boot_id);
-
- x = strjoin("/tmp/systemd-private-", boot_id, "-abcd.service-", NULL);
- y = strjoin("/var/tmp/systemd-private-", boot_id, "-abcd.service-", NULL);
- assert_se(x && y);
-
- test_tmpdir("abcd.service", x, y);
-
- z = strjoin("/tmp/systemd-private-", boot_id, "-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-", NULL);
- zz = strjoin("/var/tmp/systemd-private-", boot_id, "-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-", NULL);
-
- assert_se(z && zz);
-
- test_tmpdir("sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device", z, zz);
-
- test_netns();
-
- return 0;
-}
diff --git a/src/test/test-ns.c b/src/test/test-ns.c
deleted file mode 100644
index 76b131c284..0000000000
--- a/src/test/test-ns.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2010 Lennart Poettering
-
- 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 <stdlib.h>
-#include <unistd.h>
-
-#include "namespace.h"
-#include "log.h"
-
-int main(int argc, char *argv[]) {
- const char * const writable[] = {
- "/home",
- NULL
- };
-
- const char * const readonly[] = {
- "/",
- "/usr",
- "/boot",
- NULL
- };
-
- const char * const inaccessible[] = {
- "/home/lennart/projects",
- NULL
- };
-
- int r;
- char tmp_dir[] = "/tmp/systemd-private-XXXXXX",
- var_tmp_dir[] = "/var/tmp/systemd-private-XXXXXX";
-
- assert_se(mkdtemp(tmp_dir));
- assert_se(mkdtemp(var_tmp_dir));
-
- r = setup_namespace((char **) writable,
- (char **) readonly,
- (char **) inaccessible,
- tmp_dir,
- var_tmp_dir,
- NULL,
- true,
- PROTECT_HOME_NO,
- PROTECT_SYSTEM_NO,
- 0);
- if (r < 0) {
- log_error_errno(r, "Failed to setup namespace: %m");
- return 1;
- }
-
- execl("/bin/sh", "/bin/sh", NULL);
- log_error_errno(errno, "execl(): %m");
-
- return 1;
-}
diff --git a/src/test/test-path-lookup.c b/src/test/test-path-lookup.c
deleted file mode 100644
index a951b01b97..0000000000
--- a/src/test/test-path-lookup.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2014 Zbigniew Jędrzejewski-Szmek
-
- 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 <sys/stat.h>
-
-#include "path-lookup.h"
-#include "log.h"
-#include "strv.h"
-
-static void test_paths(SystemdRunningAs running_as, bool personal) {
- char template[] = "/tmp/test-path-lookup.XXXXXXX";
-
- _cleanup_lookup_paths_free_ LookupPaths lp = {};
- char *exists, *not;
-
- assert_se(mkdtemp(template));
- exists = strjoina(template, "/exists");
- assert_se(mkdir(exists, 0755) == 0);
- not = strjoina(template, "/not");
-
- assert_se(lookup_paths_init(&lp, running_as, personal, NULL, exists, not, not) == 0);
-
- assert_se(!strv_isempty(lp.unit_path));
- assert_se(strv_contains(lp.unit_path, exists));
- assert_se(strv_contains(lp.unit_path, not));
-
- assert_se(rm_rf_dangerous(template, false, true, false) >= 0);
-}
-
-static void print_generator_paths(SystemdRunningAs running_as) {
- _cleanup_strv_free_ char **paths;
- char **dir;
-
- log_info("Generators dirs (%s):", running_as == SYSTEMD_SYSTEM ? "system" : "user");
-
- paths = generator_paths(running_as);
- STRV_FOREACH(dir, paths)
- log_info(" %s", *dir);
-}
-
-int main(int argc, char **argv) {
- log_set_max_level(LOG_DEBUG);
- log_parse_environment();
- log_open();
-
- test_paths(SYSTEMD_SYSTEM, false);
- test_paths(SYSTEMD_SYSTEM, true);
- test_paths(SYSTEMD_USER, false);
- test_paths(SYSTEMD_USER, true);
-
- print_generator_paths(SYSTEMD_SYSTEM);
- print_generator_paths(SYSTEMD_USER);
-
- return EXIT_SUCCESS;
-}
diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c
deleted file mode 100644
index 6396fcb398..0000000000
--- a/src/test/test-path-util.c
+++ /dev/null
@@ -1,293 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 Zbigniew Jędrzejewski-Szmek
-
- 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 <stdio.h>
-#include <unistd.h>
-
-#include "path-util.h"
-#include "util.h"
-#include "macro.h"
-#include "strv.h"
-
-#define test_path_compare(a, b, result) { \
- assert_se(path_compare(a, b) == result); \
- assert_se(path_compare(b, a) == -result); \
- assert_se(path_equal(a, b) == !result); \
- assert_se(path_equal(b, a) == !result); \
- }
-
-static void test_path(void) {
- test_path_compare("/goo", "/goo", 0);
- test_path_compare("/goo", "/goo", 0);
- test_path_compare("//goo", "/goo", 0);
- test_path_compare("//goo/////", "/goo", 0);
- test_path_compare("goo/////", "goo", 0);
-
- test_path_compare("/goo/boo", "/goo//boo", 0);
- test_path_compare("//goo/boo", "/goo/boo//", 0);
-
- test_path_compare("/", "///", 0);
-
- test_path_compare("/x", "x/", 1);
- test_path_compare("x/", "/", -1);
-
- test_path_compare("/x/./y", "x/y", 1);
- test_path_compare("x/.y", "x/y", -1);
-
- test_path_compare("foo", "/foo", -1);
- test_path_compare("/foo", "/foo/bar", -1);
- test_path_compare("/foo/aaa", "/foo/b", -1);
- test_path_compare("/foo/aaa", "/foo/b/a", -1);
- test_path_compare("/foo/a", "/foo/aaa", -1);
- test_path_compare("/foo/a/b", "/foo/aaa", -1);
-
- assert_se(path_is_absolute("/"));
- assert_se(!path_is_absolute("./"));
-
- assert_se(is_path("/dir"));
- assert_se(is_path("a/b"));
- assert_se(!is_path("."));
-
- assert_se(streq(basename("./aa/bb/../file.da."), "file.da."));
- assert_se(streq(basename("/aa///.file"), ".file"));
- assert_se(streq(basename("/aa///file..."), "file..."));
- assert_se(streq(basename("file.../"), ""));
-
-#define test_parent(x, y) { \
- _cleanup_free_ char *z = NULL; \
- int r = path_get_parent(x, &z); \
- printf("expected: %s\n", y ? y : "error"); \
- printf("actual: %s\n", r<0 ? "error" : z); \
- assert_se((y==NULL) ^ (r==0)); \
- assert_se(y==NULL || path_equal(z, y)); \
- }
-
- test_parent("./aa/bb/../file.da.", "./aa/bb/..");
- test_parent("/aa///.file", "/aa///");
- test_parent("/aa///file...", "/aa///");
- test_parent("file.../", NULL);
-
- assert_se(path_is_mount_point("/", true));
- assert_se(path_is_mount_point("/", false));
-
- {
- char p1[] = "aaa/bbb////ccc";
- char p2[] = "//aaa/.////ccc";
- char p3[] = "/./";
-
- assert_se(path_equal(path_kill_slashes(p1), "aaa/bbb/ccc"));
- assert_se(path_equal(path_kill_slashes(p2), "/aaa/./ccc"));
- assert_se(path_equal(path_kill_slashes(p3), "/./"));
- }
-}
-
-static void test_find_binary(const char *self, bool local) {
- char *p;
-
- assert_se(find_binary("/bin/sh", local, &p) == 0);
- puts(p);
- assert_se(streq(p, "/bin/sh"));
- free(p);
-
- assert_se(find_binary(self, local, &p) == 0);
- puts(p);
- assert_se(endswith(p, "/test-path-util"));
- assert_se(path_is_absolute(p));
- free(p);
-
- assert_se(find_binary("sh", local, &p) == 0);
- puts(p);
- assert_se(endswith(p, "/sh"));
- assert_se(path_is_absolute(p));
- free(p);
-
- assert_se(find_binary("xxxx-xxxx", local, &p) == -ENOENT);
-
- assert_se(find_binary("/some/dir/xxxx-xxxx", local, &p) ==
- (local ? -ENOENT : 0));
- if (!local)
- free(p);
-}
-
-static void test_prefixes(void) {
- static const char* values[] = { "/a/b/c/d", "/a/b/c", "/a/b", "/a", "", NULL};
- unsigned i;
- char s[PATH_MAX];
- bool b;
-
- i = 0;
- PATH_FOREACH_PREFIX_MORE(s, "/a/b/c/d") {
- log_error("---%s---", s);
- assert_se(streq(s, values[i++]));
- }
- assert_se(values[i] == NULL);
-
- i = 1;
- PATH_FOREACH_PREFIX(s, "/a/b/c/d") {
- log_error("---%s---", s);
- assert_se(streq(s, values[i++]));
- }
- assert_se(values[i] == NULL);
-
- i = 0;
- PATH_FOREACH_PREFIX_MORE(s, "////a////b////c///d///////")
- assert_se(streq(s, values[i++]));
- assert_se(values[i] == NULL);
-
- i = 1;
- PATH_FOREACH_PREFIX(s, "////a////b////c///d///////")
- assert_se(streq(s, values[i++]));
- assert_se(values[i] == NULL);
-
- PATH_FOREACH_PREFIX(s, "////")
- assert_not_reached("Wut?");
-
- b = false;
- PATH_FOREACH_PREFIX_MORE(s, "////") {
- assert_se(!b);
- assert_se(streq(s, ""));
- b = true;
- }
- assert_se(b);
-
- PATH_FOREACH_PREFIX(s, "")
- assert_not_reached("wut?");
-
- b = false;
- PATH_FOREACH_PREFIX_MORE(s, "") {
- assert_se(!b);
- assert_se(streq(s, ""));
- b = true;
- }
-}
-
-static void test_path_join(void) {
-
-#define test_join(root, path, rest, expected) { \
- _cleanup_free_ char *z = NULL; \
- z = path_join(root, path, rest); \
- assert_se(streq(z, expected)); \
- }
-
- test_join("/root", "/a/b", "/c", "/root/a/b/c");
- test_join("/root", "a/b", "c", "/root/a/b/c");
- test_join("/root", "/a/b", "c", "/root/a/b/c");
- test_join("/root", "/", "c", "/root/c");
- test_join("/root", "/", NULL, "/root/");
-
- test_join(NULL, "/a/b", "/c", "/a/b/c");
- test_join(NULL, "a/b", "c", "a/b/c");
- test_join(NULL, "/a/b", "c", "/a/b/c");
- test_join(NULL, "/", "c", "/c");
- test_join(NULL, "/", NULL, "/");
-}
-
-static void test_fsck_exists(void) {
- /* Ensure we use a sane default for PATH. */
- unsetenv("PATH");
-
- /* fsck.minix is provided by util-linux and will probably exist. */
- assert_se(fsck_exists("minix") == 0);
-
- assert_se(fsck_exists("AbCdE") == -ENOENT);
-}
-
-static void test_make_relative(void) {
- char *result;
-
- assert_se(path_make_relative("some/relative/path", "/some/path", &result) < 0);
- assert_se(path_make_relative("/some/path", "some/relative/path", &result) < 0);
-
-#define test(from_dir, to_path, expected) { \
- _cleanup_free_ char *z = NULL; \
- path_make_relative(from_dir, to_path, &z); \
- assert_se(streq(z, expected)); \
- }
-
- test("/", "/", ".");
- test("/", "/some/path", "some/path");
- test("/some/path", "/some/path", ".");
- test("/some/path", "/some/path/in/subdir", "in/subdir");
- test("/some/path", "/", "../..");
- test("/some/path", "/some/other/path", "../other/path");
- test("//extra/////slashes///won't////fool///anybody//", "////extra///slashes////are/just///fine///", "../../../are/just/fine");
-}
-
-static void test_strv_resolve(void) {
- char tmp_dir[] = "/tmp/test-path-util-XXXXXX";
- _cleanup_strv_free_ char **search_dirs = NULL;
- _cleanup_strv_free_ char **absolute_dirs = NULL;
- char **d;
-
- assert_se(mkdtemp(tmp_dir) != NULL);
-
- search_dirs = strv_new("/dir1", "/dir2", "/dir3", NULL);
- assert_se(search_dirs);
- STRV_FOREACH(d, search_dirs) {
- char *p = strappend(tmp_dir, *d);
- assert_se(p);
- assert_se(strv_push(&absolute_dirs, p) == 0);
- }
-
- assert_se(mkdir(absolute_dirs[0], 0700) == 0);
- assert_se(mkdir(absolute_dirs[1], 0700) == 0);
- assert_se(symlink("dir2", absolute_dirs[2]) == 0);
-
- path_strv_resolve(search_dirs, tmp_dir);
- assert_se(streq(search_dirs[0], "/dir1"));
- assert_se(streq(search_dirs[1], "/dir2"));
- assert_se(streq(search_dirs[2], "/dir2"));
-
- assert_se(rm_rf_dangerous(tmp_dir, false, true, false) == 0);
-}
-
-static void test_path_startswith(void) {
- assert_se(path_startswith("/foo/bar/barfoo/", "/foo"));
- assert_se(path_startswith("/foo/bar/barfoo/", "/foo/"));
- assert_se(path_startswith("/foo/bar/barfoo/", "/"));
- assert_se(path_startswith("/foo/bar/barfoo/", "////"));
- assert_se(path_startswith("/foo/bar/barfoo/", "/foo//bar/////barfoo///"));
- assert_se(path_startswith("/foo/bar/barfoo/", "/foo/bar/barfoo////"));
- assert_se(path_startswith("/foo/bar/barfoo/", "/foo/bar///barfoo/"));
- assert_se(path_startswith("/foo/bar/barfoo/", "/foo////bar/barfoo/"));
- assert_se(path_startswith("/foo/bar/barfoo/", "////foo/bar/barfoo/"));
- assert_se(path_startswith("/foo/bar/barfoo/", "/foo/bar/barfoo"));
-
- assert_se(!path_startswith("/foo/bar/barfoo/", "/foo/bar/barfooa/"));
- assert_se(!path_startswith("/foo/bar/barfoo/", "/foo/bar/barfooa"));
- assert_se(!path_startswith("/foo/bar/barfoo/", ""));
- assert_se(!path_startswith("/foo/bar/barfoo/", "/bar/foo"));
- assert_se(!path_startswith("/foo/bar/barfoo/", "/f/b/b/"));
-}
-
-int main(int argc, char **argv) {
- test_path();
- test_find_binary(argv[0], true);
- test_find_binary(argv[0], false);
- test_prefixes();
- test_path_join();
- test_fsck_exists();
- test_make_relative();
- test_strv_resolve();
- test_path_startswith();
-
- return 0;
-}
diff --git a/src/test/test-path.c b/src/test/test-path.c
deleted file mode 100644
index a3295aa997..0000000000
--- a/src/test/test-path.c
+++ /dev/null
@@ -1,267 +0,0 @@
-/***
- This file is part of systemd.
-
- Copyright 2014 Ronny Chevalier
-
- 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 <stdio.h>
-#include <stdbool.h>
-
-#include "unit.h"
-#include "manager.h"
-#include "util.h"
-#include "macro.h"
-#include "strv.h"
-#include "mkdir.h"
-
-typedef void (*test_function_t)(Manager *m);
-
-static int setup_test(Manager **m) {
- char **tests_path = STRV_MAKE("exists", "existsglobFOOBAR", "changed", "modified", "unit",
- "directorynotempty", "makedirectory");
- char **test_path;
- Manager *tmp = NULL;
- int r;
-
- assert_se(m);
-
- r = manager_new(SYSTEMD_USER, true, &tmp);
- if (IN_SET(r, -EPERM, -EACCES, -EADDRINUSE, -EHOSTDOWN, -ENOENT)) {
- printf("Skipping test: manager_new: %s", strerror(-r));
- return -EXIT_TEST_SKIP;
- }
- assert_se(r >= 0);
- assert_se(manager_startup(tmp, NULL, NULL) >= 0);
-
- STRV_FOREACH(test_path, tests_path) {
- rm_rf_dangerous(strjoina("/tmp/test-path_", *test_path), false, true, false);
- }
-
- *m = tmp;
-
- return 0;
-}
-
-static void shutdown_test(Manager *m) {
- assert_se(m);
-
- manager_free(m);
-}
-
-static void check_stop_unlink(Manager *m, Unit *unit, const char *test_path, const char *service_name) {
- _cleanup_free_ char *tmp = NULL;
- Unit *service_unit = NULL;
- Service *service = NULL;
- usec_t ts;
- usec_t timeout = 2 * USEC_PER_SEC;
-
- assert_se(m);
- assert_se(unit);
- assert_se(test_path);
-
- if (!service_name) {
- assert_se(tmp = strreplace(unit->id, ".path", ".service"));
- service_unit = manager_get_unit(m, tmp);
- } else
- service_unit = manager_get_unit(m, service_name);
- assert_se(service_unit);
- service = SERVICE(service_unit);
-
- ts = now(CLOCK_MONOTONIC);
- /* We process events until the service related to the path has been successfully started */
- while(service->result != SERVICE_SUCCESS || service->state != SERVICE_START) {
- usec_t n;
- int r;
-
- r = sd_event_run(m->event, 100 * USEC_PER_MSEC);
- assert_se(r >= 0);
-
- printf("%s: state = %s; result = %s \n",
- service_unit->id,
- service_state_to_string(service->state),
- service_result_to_string(service->result));
-
-
- /* But we timeout if the service has not been started in the allocated time */
- n = now(CLOCK_MONOTONIC);
- if (ts + timeout < n) {
- log_error("Test timeout when testing %s", unit->id);
- exit(EXIT_FAILURE);
- }
- }
-
- assert_se(UNIT_VTABLE(unit)->stop(unit) >= 0);
- rm_rf_dangerous(test_path, false, true, false);
-}
-
-static void test_path_exists(Manager *m) {
- const char *test_path = "/tmp/test-path_exists";
- Unit *unit = NULL;
-
- assert_se(m);
-
- assert_se(manager_load_unit(m, "path-exists.path", NULL, NULL, &unit) >= 0);
- assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
-
- assert_se(touch(test_path) >= 0);
-
- check_stop_unlink(m, unit, test_path, NULL);
-}
-
-static void test_path_existsglob(Manager *m) {
- const char *test_path = "/tmp/test-path_existsglobFOOBAR";
- Unit *unit = NULL;
-
- assert_se(m);
- assert_se(manager_load_unit(m, "path-existsglob.path", NULL, NULL, &unit) >= 0);
- assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
-
- assert_se(touch(test_path) >= 0);
-
- check_stop_unlink(m, unit, test_path, NULL);
-}
-
-static void test_path_changed(Manager *m) {
- const char *test_path = "/tmp/test-path_changed";
- FILE *f;
- Unit *unit = NULL;
-
- assert_se(m);
-
- assert_se(touch(test_path) >= 0);
-
- assert_se(manager_load_unit(m, "path-changed.path", NULL, NULL, &unit) >= 0);
- assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
-
- f = fopen(test_path, "w");
- assert_se(f);
- fclose(f);
-
- check_stop_unlink(m, unit, test_path, NULL);
-}
-
-static void test_path_modified(Manager *m) {
- _cleanup_fclose_ FILE *f = NULL;
- const char *test_path = "/tmp/test-path_modified";
- Unit *unit = NULL;
-
- assert_se(m);
-
- assert_se(touch(test_path) >= 0);
-
- assert_se(manager_load_unit(m, "path-modified.path", NULL, NULL, &unit) >= 0);
- assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
-
- f = fopen(test_path, "w");
- assert_se(f);
- fputs("test", f);
-
- check_stop_unlink(m, unit, test_path, NULL);
-}
-
-static void test_path_unit(Manager *m) {
- const char *test_path = "/tmp/test-path_unit";
- Unit *unit = NULL;
-
- assert_se(m);
-
- assert_se(manager_load_unit(m, "path-unit.path", NULL, NULL, &unit) >= 0);
- assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
-
- assert_se(touch(test_path) >= 0);
-
- check_stop_unlink(m, unit, test_path, "path-mycustomunit.service");
-}
-
-static void test_path_directorynotempty(Manager *m) {
- const char *test_path = "/tmp/test-path_directorynotempty/";
- Unit *unit = NULL;
-
- assert_se(m);
-
- assert_se(access(test_path, F_OK) < 0);
-
- assert_se(manager_load_unit(m, "path-directorynotempty.path", NULL, NULL, &unit) >= 0);
- assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
-
- /* MakeDirectory default to no */
- assert_se(access(test_path, F_OK) < 0);
-
- assert_se(mkdir_p(test_path, 0755) >= 0);
- assert_se(touch(strjoina(test_path, "test_file")) >= 0);
-
- check_stop_unlink(m, unit, test_path, NULL);
-}
-
-static void test_path_makedirectory_directorymode(Manager *m) {
- const char *test_path = "/tmp/test-path_makedirectory/";
- Unit *unit = NULL;
- struct stat s;
-
- assert_se(m);
-
- assert_se(access(test_path, F_OK) < 0);
-
- assert_se(manager_load_unit(m, "path-makedirectory.path", NULL, NULL, &unit) >= 0);
- assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
-
- /* Check if the directory has been created */
- assert_se(access(test_path, F_OK) >= 0);
-
- /* Check the mode we specified with DirectoryMode=0744 */
- assert_se(stat(test_path, &s) >= 0);
- assert_se((s.st_mode & S_IRWXU) == 0700);
- assert_se((s.st_mode & S_IRWXG) == 0040);
- assert_se((s.st_mode & S_IRWXO) == 0004);
-
- assert_se(UNIT_VTABLE(unit)->stop(unit) >= 0);
- rm_rf_dangerous(test_path, false, true, false);
-}
-
-int main(int argc, char *argv[]) {
- test_function_t tests[] = {
- test_path_exists,
- test_path_existsglob,
- test_path_changed,
- test_path_modified,
- test_path_unit,
- test_path_directorynotempty,
- test_path_makedirectory_directorymode,
- NULL,
- };
- test_function_t *test = NULL;
- Manager *m = NULL;
-
- log_parse_environment();
- log_open();
-
- assert_se(set_unit_path(TEST_DIR ":") >= 0);
-
- for (test = tests; test && *test; test++) {
- int r;
-
- /* We create a clean environment for each test */
- r = setup_test(&m);
- if (r < 0)
- return -r;
-
- (*test)(m);
-
- shutdown_test(m);
- }
-
- return 0;
-}
diff --git a/src/test/test-prioq.c b/src/test/test-prioq.c
deleted file mode 100644
index dfedc9b8dc..0000000000
--- a/src/test/test-prioq.c
+++ /dev/null
@@ -1,175 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 Lennart Poettering
-
- 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 <stdlib.h>
-
-#include "util.h"
-#include "set.h"
-#include "prioq.h"
-#include "siphash24.h"
-
-#define SET_SIZE 1024*4
-
-static int unsigned_compare(const void *a, const void *b) {
- const unsigned *x = a, *y = b;
-
- if (*x < *y)
- return -1;
-
- if (*x > *y)
- return 1;
-
- return 0;
-}
-
-static void test_unsigned(void) {
- unsigned buffer[SET_SIZE], i;
- Prioq *q;
-
- srand(0);
-
- q = prioq_new(trivial_compare_func);
- assert_se(q);
-
- for (i = 0; i < ELEMENTSOF(buffer); i++) {
- unsigned u;
-
- u = (unsigned) rand();
- buffer[i] = u;
- assert_se(prioq_put(q, UINT_TO_PTR(u), NULL) >= 0);
- }
-
- qsort(buffer, ELEMENTSOF(buffer), sizeof(buffer[0]), unsigned_compare);
-
- for (i = 0; i < ELEMENTSOF(buffer); i++) {
- unsigned u;
-
- assert_se(prioq_size(q) == ELEMENTSOF(buffer) - i);
-
- u = PTR_TO_UINT(prioq_pop(q));
- assert_se(buffer[i] == u);
- }
-
- assert_se(prioq_isempty(q));
- prioq_free(q);
-}
-
-struct test {
- unsigned value;
- unsigned idx;
-};
-
-static int test_compare(const void *a, const void *b) {
- const struct test *x = a, *y = b;
-
- if (x->value < y->value)
- return -1;
-
- if (x->value > y->value)
- return 1;
-
- return 0;
-}
-
-static unsigned long test_hash(const void *a, const uint8_t hash_key[HASH_KEY_SIZE]) {
- const struct test *x = a;
- uint64_t u;
-
- siphash24((uint8_t*) &u, &x->value, sizeof(x->value), hash_key);
-
- return (unsigned long) u;
-}
-
-static const struct hash_ops test_hash_ops = {
- .hash = test_hash,
- .compare = test_compare
-};
-
-static void test_struct(void) {
- Prioq *q;
- Set *s;
- unsigned previous = 0, i;
- int r;
-
- srand(0);
-
- q = prioq_new(test_compare);
- assert_se(q);
-
- s = set_new(&test_hash_ops);
- assert_se(s);
-
- for (i = 0; i < SET_SIZE; i++) {
- struct test *t;
-
- t = new0(struct test, 1);
- assert_se(t);
- t->value = (unsigned) rand();
-
- r = prioq_put(q, t, &t->idx);
- assert_se(r >= 0);
-
- if (i % 4 == 0) {
- r = set_consume(s, t);
- assert_se(r >= 0);
- }
- }
-
- for (;;) {
- struct test *t;
-
- t = set_steal_first(s);
- if (!t)
- break;
-
- r = prioq_remove(q, t, &t->idx);
- assert_se(r > 0);
-
- free(t);
- }
-
- for (i = 0; i < SET_SIZE * 3 / 4; i++) {
- struct test *t;
-
- assert_se(prioq_size(q) == (SET_SIZE * 3 / 4) - i);
-
- t = prioq_pop(q);
- assert_se(t);
-
- assert_se(previous <= t->value);
- previous = t->value;
- free(t);
- }
-
- assert_se(prioq_isempty(q));
- prioq_free(q);
-
- assert_se(set_isempty(s));
- set_free(s);
-}
-
-int main(int argc, char* argv[]) {
-
- test_unsigned();
- test_struct();
-
- return 0;
-}
diff --git a/src/test/test-pty.c b/src/test/test-pty.c
deleted file mode 100644
index b5f4d4f094..0000000000
--- a/src/test/test-pty.c
+++ /dev/null
@@ -1,141 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2014 David Herrmann <dh.herrmann@gmail.com>
-
- 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 <errno.h>
-#include <locale.h>
-#include <string.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-#include "pty.h"
-#include "util.h"
-
-static const char sndmsg[] = "message\n";
-static const char rcvmsg[] = "message\r\n";
-static char rcvbuf[128];
-static size_t rcvsiz = 0;
-static sd_event *event;
-
-static void run_child(Pty *pty) {
- ssize_t r, l;
- char buf[512];
-
- r = read(0, buf, sizeof(buf));
- assert_se((size_t)r == strlen(sndmsg));
- assert_se(!strncmp(buf, sndmsg, r));
-
- l = write(1, buf, r);
- assert_se(l == r);
-}
-
-static int pty_fn(Pty *pty, void *userdata, unsigned int ev, const void *ptr, size_t size) {
- switch (ev) {
- case PTY_DATA:
- assert_se(rcvsiz < strlen(rcvmsg) * 2);
- assert_se(rcvsiz + size < sizeof(rcvbuf));
-
- memcpy(&rcvbuf[rcvsiz], ptr, size);
- rcvsiz += size;
-
- if (rcvsiz >= strlen(rcvmsg) * 2) {
- assert_se(rcvsiz == strlen(rcvmsg) * 2);
- assert_se(!memcmp(rcvbuf, rcvmsg, strlen(rcvmsg)));
- assert_se(!memcmp(&rcvbuf[strlen(rcvmsg)], rcvmsg, strlen(rcvmsg)));
- }
-
- break;
- case PTY_HUP:
- /* This is guaranteed to appear _after_ the input queues are
- * drained! */
- assert_se(rcvsiz == strlen(rcvmsg) * 2);
- break;
- case PTY_CHILD:
- /* this may appear at any time */
- break;
- default:
- assert_se(0);
- break;
- }
-
- /* if we got HUP _and_ CHILD, exit */
- if (pty_get_fd(pty) < 0 && pty_get_child(pty) < 0)
- sd_event_exit(event, 0);
-
- return 0;
-}
-
-static void run_parent(Pty *pty) {
- int r;
-
- /* write message to pty, ECHO mode guarantees that we get it back
- * twice: once via ECHO, once from the run_child() fn */
- assert_se(pty_write(pty, sndmsg, strlen(sndmsg)) >= 0);
-
- r = sd_event_loop(event);
- assert_se(r >= 0);
-}
-
-static void test_pty(void) {
- pid_t pid;
- Pty *pty = NULL;
-
- rcvsiz = 0;
- zero(rcvbuf);
-
- assert_se(sd_event_default(&event) >= 0);
-
- pid = pty_fork(&pty, event, pty_fn, NULL, 80, 25);
- assert_se(pid >= 0);
-
- if (pid == 0) {
- /* child */
- run_child(pty);
- exit(0);
- }
-
- /* parent */
- run_parent(pty);
-
- /* Make sure the PTY recycled the child; yeah, this is racy if the
- * PID was already reused; but that seems fine for a test. */
- assert_se(waitpid(pid, NULL, WNOHANG) < 0 && errno == ECHILD);
-
- pty_unref(pty);
- sd_event_unref(event);
-}
-
-int main(int argc, char *argv[]) {
- unsigned int i;
-
- log_parse_environment();
- log_open();
-
- assert_se(sigprocmask_many(SIG_BLOCK, SIGCHLD, -1) >= 0);
-
- /* Oh, there're ugly races in the TTY layer regarding HUP vs IN. Turns
- * out they appear only 10% of the time. I fixed all of them and
- * don't see them, anymore. But lets be safe and run this 1000 times
- * so we catch any new ones, in case they appear again. */
- for (i = 0; i < 1000; ++i)
- test_pty();
-
- return 0;
-}
diff --git a/src/test/test-ratelimit.c b/src/test/test-ratelimit.c
deleted file mode 100644
index b7f6dfe246..0000000000
--- a/src/test/test-ratelimit.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/***
- This file is part of systemd
-
- Copyright 2014 Ronny Chevalier
-
- 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 <unistd.h>
-
-#include "ratelimit.h"
-#include "time-util.h"
-#include "macro.h"
-
-static void test_ratelimit_test(void) {
- int i;
- RATELIMIT_DEFINE(ratelimit, 1 * USEC_PER_SEC, 10);
-
- for (i = 0; i < 10; i++) {
- assert_se(ratelimit_test(&ratelimit));
- }
- assert_se(!ratelimit_test(&ratelimit));
- sleep(1);
- for (i = 0; i < 10; i++) {
- assert_se(ratelimit_test(&ratelimit));
- }
-
- RATELIMIT_INIT(ratelimit, 0, 10);
- for (i = 0; i < 10000; i++) {
- assert_se(ratelimit_test(&ratelimit));
- }
-}
-
-int main(int argc, char *argv[]) {
- test_ratelimit_test();
-
- return 0;
-}
diff --git a/src/test/test-replace-var.c b/src/test/test-replace-var.c
deleted file mode 100644
index b1d42d77fd..0000000000
--- a/src/test/test-replace-var.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2012 Lennart Poettering
-
- 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 <string.h>
-
-#include "util.h"
-#include "macro.h"
-#include "replace-var.h"
-
-static char *lookup(const char *variable, void *userdata) {
- return strjoin("<<<", variable, ">>>", NULL);
-}
-
-int main(int argc, char *argv[]) {
- char *r;
-
- assert_se(r = replace_var("@@@foobar@xyz@HALLO@foobar@test@@testtest@TEST@...@@@", lookup, NULL));
- puts(r);
- assert_se(streq(r, "@@@foobar@xyz<<<HALLO>>>foobar@test@@testtest<<<TEST>>>...@@@"));
- free(r);
-
- assert_se(r = strreplace("XYZFFFFXYZFFFFXYZ", "XYZ", "ABC"));
- puts(r);
- assert_se(streq(r, "ABCFFFFABCFFFFABC"));
- free(r);
-
- return 0;
-}
diff --git a/src/test/test-ring.c b/src/test/test-ring.c
deleted file mode 100644
index cb8a5d4e9e..0000000000
--- a/src/test/test-ring.c
+++ /dev/null
@@ -1,130 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2014 David Herrmann <dh.herrmann@gmail.com>
-
- 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 <string.h>
-
-#include "def.h"
-#include "ring.h"
-
-static void test_ring(void) {
- static const char buf[8192];
- Ring r;
- size_t l;
- struct iovec vec[2];
- int s;
-
- zero(r);
-
- l = ring_peek(&r, vec);
- assert_se(l == 0);
-
- s = ring_push(&r, buf, 2048);
- assert_se(!s);
- assert_se(ring_get_size(&r) == 2048);
-
- l = ring_peek(&r, vec);
- assert_se(l == 1);
- assert_se(vec[0].iov_len == 2048);
- assert_se(!memcmp(vec[0].iov_base, buf, vec[0].iov_len));
- assert_se(ring_get_size(&r) == 2048);
-
- ring_pull(&r, 2048);
- assert_se(ring_get_size(&r) == 0);
-
- l = ring_peek(&r, vec);
- assert_se(l == 0);
- assert_se(ring_get_size(&r) == 0);
-
- s = ring_push(&r, buf, 2048);
- assert_se(!s);
- assert_se(ring_get_size(&r) == 2048);
-
- l = ring_peek(&r, vec);
- assert_se(l == 1);
- assert_se(vec[0].iov_len == 2048);
- assert_se(!memcmp(vec[0].iov_base, buf, vec[0].iov_len));
- assert_se(ring_get_size(&r) == 2048);
-
- s = ring_push(&r, buf, 1);
- assert_se(!s);
- assert_se(ring_get_size(&r) == 2049);
-
- l = ring_peek(&r, vec);
- assert_se(l == 2);
- assert_se(vec[0].iov_len == 2048);
- assert_se(vec[1].iov_len == 1);
- assert_se(!memcmp(vec[0].iov_base, buf, vec[0].iov_len));
- assert_se(!memcmp(vec[1].iov_base, buf, vec[1].iov_len));
- assert_se(ring_get_size(&r) == 2049);
-
- ring_pull(&r, 2048);
- assert_se(ring_get_size(&r) == 1);
-
- l = ring_peek(&r, vec);
- assert_se(l == 1);
- assert_se(vec[0].iov_len == 1);
- assert_se(!memcmp(vec[0].iov_base, buf, vec[0].iov_len));
- assert_se(ring_get_size(&r) == 1);
-
- ring_pull(&r, 1);
- assert_se(ring_get_size(&r) == 0);
-
- s = ring_push(&r, buf, 2048);
- assert_se(!s);
- assert_se(ring_get_size(&r) == 2048);
-
- s = ring_push(&r, buf, 2049);
- assert_se(!s);
- assert_se(ring_get_size(&r) == 4097);
-
- l = ring_peek(&r, vec);
- assert_se(l == 1);
- assert_se(vec[0].iov_len == 4097);
- assert_se(!memcmp(vec[0].iov_base, buf, vec[0].iov_len));
- assert_se(ring_get_size(&r) == 4097);
-
- ring_pull(&r, 1);
- assert_se(ring_get_size(&r) == 4096);
-
- s = ring_push(&r, buf, 4096);
- assert_se(!s);
- assert_se(ring_get_size(&r) == 8192);
-
- l = ring_peek(&r, vec);
- assert_se(l == 2);
- assert_se(vec[0].iov_len == 8191);
- assert_se(vec[1].iov_len == 1);
- assert_se(!memcmp(vec[0].iov_base, buf, vec[0].iov_len));
- assert_se(!memcmp(vec[1].iov_base, buf, vec[1].iov_len));
- assert_se(ring_get_size(&r) == 8192);
-
- ring_clear(&r);
- assert_se(ring_get_size(&r) == 0);
-}
-
-int main(int argc, char *argv[]) {
- log_parse_environment();
- log_open();
-
- test_ring();
-
- return 0;
-}
diff --git a/src/test/test-rtnl-manual.c b/src/test/test-rtnl-manual.c
deleted file mode 100644
index c406454f77..0000000000
--- a/src/test/test-rtnl-manual.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2014 Susant Sahani
-
- 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 <arpa/inet.h>
-#include <net/if.h>
-#include <linux/ip.h>
-#include <linux/if_tunnel.h>
-#include <libkmod.h>
-
-#include "util.h"
-#include "macro.h"
-#include "sd-rtnl.h"
-
-static int load_module(const char *mod_name) {
- struct kmod_ctx *ctx;
- struct kmod_list *list = NULL, *l;
- int r;
-
- ctx = kmod_new(NULL, NULL);
- if (!ctx) {
- kmod_unref(ctx);
- return -ENOMEM;
- }
-
- r = kmod_module_new_from_lookup(ctx, mod_name, &list);
- if (r < 0)
- return -1;
-
- kmod_list_foreach(l, list) {
- struct kmod_module *mod = kmod_module_get_module(l);
-
- r = kmod_module_probe_insert_module(mod, 0, NULL, NULL, NULL, NULL);
- if (r >= 0)
- r = 0;
- else
- r = -1;
-
- kmod_module_unref(mod);
- }
-
- kmod_module_unref_list(list);
- kmod_unref(ctx);
-
- return r;
-}
-
-static int test_tunnel_configure(sd_rtnl *rtnl) {
- int r;
- sd_rtnl_message *m, *n;
- struct in_addr local, remote;
-
- /* skip test if module cannot be loaded */
- r = load_module("ipip");
- if(r < 0)
- return EXIT_TEST_SKIP;
-
- if(getuid() != 0)
- return EXIT_TEST_SKIP;
-
- /* IPIP tunnel */
- assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_NEWLINK, 0) >= 0);
- assert_se(m);
-
- assert_se(sd_rtnl_message_append_string(m, IFLA_IFNAME, "ipip-tunnel") >= 0);
- assert_se(sd_rtnl_message_append_u32(m, IFLA_MTU, 1234)>= 0);
-
- assert_se(sd_rtnl_message_open_container(m, IFLA_LINKINFO) >= 0);
-
- assert_se(sd_rtnl_message_open_container_union(m, IFLA_INFO_DATA, "ipip") >= 0);
-
- inet_pton(AF_INET, "192.168.21.1", &local.s_addr);
- assert_se(sd_rtnl_message_append_u32(m, IFLA_IPTUN_LOCAL, local.s_addr) >= 0);
-
- inet_pton(AF_INET, "192.168.21.2", &remote.s_addr);
- assert_se(sd_rtnl_message_append_u32(m, IFLA_IPTUN_REMOTE, remote.s_addr) >= 0);
-
- assert_se(sd_rtnl_message_close_container(m) >= 0);
- assert_se(sd_rtnl_message_close_container(m) >= 0);
-
- assert_se(sd_rtnl_call(rtnl, m, -1, 0) == 1);
-
- assert_se((m = sd_rtnl_message_unref(m)) == NULL);
-
- r = load_module("sit");
- if(r < 0)
- return EXIT_TEST_SKIP;
-
- /* sit */
- assert_se(sd_rtnl_message_new_link(rtnl, &n, RTM_NEWLINK, 0) >= 0);
- assert_se(n);
-
- assert_se(sd_rtnl_message_append_string(n, IFLA_IFNAME, "sit-tunnel") >= 0);
- assert_se(sd_rtnl_message_append_u32(n, IFLA_MTU, 1234)>= 0);
-
- assert_se(sd_rtnl_message_open_container(n, IFLA_LINKINFO) >= 0);
-
- assert_se(sd_rtnl_message_open_container_union(n, IFLA_INFO_DATA, "sit") >= 0);
-
- assert_se(sd_rtnl_message_append_u8(n, IFLA_IPTUN_PROTO, IPPROTO_IPIP) >= 0);
-
- inet_pton(AF_INET, "192.168.21.3", &local.s_addr);
- assert_se(sd_rtnl_message_append_u32(n, IFLA_IPTUN_LOCAL, local.s_addr) >= 0);
-
- inet_pton(AF_INET, "192.168.21.4", &remote.s_addr);
- assert_se(sd_rtnl_message_append_u32(n, IFLA_IPTUN_REMOTE, remote.s_addr) >= 0);
-
- assert_se(sd_rtnl_message_close_container(n) >= 0);
- assert_se(sd_rtnl_message_close_container(n) >= 0);
-
- assert_se(sd_rtnl_call(rtnl, n, -1, 0) == 1);
-
- assert_se((m = sd_rtnl_message_unref(n)) == NULL);
-
- return EXIT_SUCCESS;
-}
-
-int main(int argc, char *argv[]) {
- sd_rtnl *rtnl;
- int r;
-
- assert_se(sd_rtnl_open(&rtnl, 0) >= 0);
- assert_se(rtnl);
-
- r = test_tunnel_configure(rtnl);
-
- assert_se((rtnl = sd_rtnl_unref(rtnl)) == NULL);
-
- return r;
-}
diff --git a/src/test/test-sched-prio.c b/src/test/test-sched-prio.c
deleted file mode 100644
index 6b3128d3b7..0000000000
--- a/src/test/test-sched-prio.c
+++ /dev/null
@@ -1,94 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2012 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 <sched.h>
-
-#include "manager.h"
-#include "macro.h"
-
-int main(int argc, char *argv[]) {
- Manager *m = NULL;
- Unit *idle_ok, *idle_bad, *rr_ok, *rr_bad, *rr_sched;
- Service *ser;
- FILE *serial = NULL;
- FDSet *fdset = NULL;
- int r;
-
- /* prepare the test */
- assert_se(set_unit_path(TEST_DIR) >= 0);
- r = manager_new(SYSTEMD_USER, true, &m);
- if (IN_SET(r, -EPERM, -EACCES, -EADDRINUSE, -EHOSTDOWN, -ENOENT)) {
- printf("Skipping test: manager_new: %s", strerror(-r));
- return EXIT_TEST_SKIP;
- }
- assert_se(r >= 0);
- assert_se(manager_startup(m, serial, fdset) >= 0);
-
- /* load idle ok */
- assert_se(manager_load_unit(m, "sched_idle_ok.service", NULL, NULL, &idle_ok) >= 0);
- assert_se(idle_ok->load_state == UNIT_LOADED);
- ser = SERVICE(idle_ok);
- assert_se(ser->exec_context.cpu_sched_policy == SCHED_OTHER);
- assert_se(ser->exec_context.cpu_sched_priority == 0);
-
- /*
- * load idle bad. This should print a warning but we have no way to look at it.
- */
- assert_se(manager_load_unit(m, "sched_idle_bad.service", NULL, NULL, &idle_bad) >= 0);
- assert_se(idle_bad->load_state == UNIT_LOADED);
- ser = SERVICE(idle_ok);
- assert_se(ser->exec_context.cpu_sched_policy == SCHED_OTHER);
- assert_se(ser->exec_context.cpu_sched_priority == 0);
-
- /*
- * load rr ok.
- * Test that the default priority is moving from 0 to 1.
- */
- assert_se(manager_load_unit(m, "sched_rr_ok.service", NULL, NULL, &rr_ok) >= 0);
- assert_se(rr_ok->load_state == UNIT_LOADED);
- ser = SERVICE(rr_ok);
- assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
- assert_se(ser->exec_context.cpu_sched_priority == 1);
-
- /*
- * load rr bad.
- * Test that the value of 0 and 100 is ignored.
- */
- assert_se(manager_load_unit(m, "sched_rr_bad.service", NULL, NULL, &rr_bad) >= 0);
- assert_se(rr_bad->load_state == UNIT_LOADED);
- ser = SERVICE(rr_bad);
- assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
- assert_se(ser->exec_context.cpu_sched_priority == 1);
-
- /*
- * load rr change.
- * Test that anything between 1 and 99 can be set.
- */
- assert_se(manager_load_unit(m, "sched_rr_change.service", NULL, NULL, &rr_sched) >= 0);
- assert_se(rr_sched->load_state == UNIT_LOADED);
- ser = SERVICE(rr_sched);
- assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
- assert_se(ser->exec_context.cpu_sched_priority == 99);
-
- manager_free(m);
-
- return EXIT_SUCCESS;
-}
diff --git a/src/test/test-set.c b/src/test/test-set.c
deleted file mode 100644
index ac292ed680..0000000000
--- a/src/test/test-set.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/***
- This file is part of systemd
-
- Copyright 2014 Zbigniew Jędrzejewski-Szmek
-
- 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 "set.h"
-
-static void test_set_steal_first(void) {
- _cleanup_set_free_ Set *m = NULL;
- int seen[3] = {};
- char *val;
-
- m = set_new(&string_hash_ops);
- assert_se(m);
-
- assert_se(set_put(m, (void*) "1") == 1);
- assert_se(set_put(m, (void*) "22") == 1);
- assert_se(set_put(m, (void*) "333") == 1);
-
- while ((val = set_steal_first(m)))
- seen[strlen(val) - 1]++;
-
- assert_se(seen[0] == 1 && seen[1] == 1 && seen[2] == 1);
-
- assert_se(set_isempty(m));
-}
-
-int main(int argc, const char *argv[]) {
- test_set_steal_first();
-
- return 0;
-}
diff --git a/src/test/test-sigbus.c b/src/test/test-sigbus.c
deleted file mode 100644
index f5bae65bef..0000000000
--- a/src/test/test-sigbus.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2014 Lennart Poettering
-
- 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 <sys/mman.h>
-
-#include "util.h"
-#include "sigbus.h"
-
-int main(int argc, char *argv[]) {
- _cleanup_close_ int fd = -1;
- char template[] = "/tmp/sigbus-test-XXXXXX";
- void *addr = NULL;
- uint8_t *p;
-
- sigbus_install();
-
- assert_se(sigbus_pop(&addr) == 0);
-
- assert_se((fd = mkostemp(template, O_RDWR|O_CREAT|O_EXCL)) >= 0);
- assert_se(unlink(template) >= 0);
- assert_se(fallocate(fd, 0, 0, page_size() * 8) >= 0);
-
- p = mmap(NULL, page_size() * 16, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
- assert_se(p != MAP_FAILED);
-
- assert_se(sigbus_pop(&addr) == 0);
-
- p[0] = 0xFF;
- assert_se(sigbus_pop(&addr) == 0);
-
- p[page_size()] = 0xFF;
- assert_se(sigbus_pop(&addr) == 0);
-
- p[page_size()*8] = 0xFF;
- p[page_size()*8+1] = 0xFF;
- p[page_size()*10] = 0xFF;
- assert_se(sigbus_pop(&addr) > 0);
- assert_se(addr == p + page_size() * 8);
- assert_se(sigbus_pop(&addr) > 0);
- assert_se(addr == p + page_size() * 10);
- assert_se(sigbus_pop(&addr) == 0);
-
- sigbus_reset();
-}
diff --git a/src/test/test-sleep.c b/src/test/test-sleep.c
deleted file mode 100644
index 1d75d05a88..0000000000
--- a/src/test/test-sleep.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2012 Lennart Poettering
-
- 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 <stdio.h>
-
-#include "util.h"
-#include "log.h"
-#include "sleep-config.h"
-#include "strv.h"
-
-static void test_sleep(void) {
- _cleanup_strv_free_ char
- **standby = strv_new("standby", NULL),
- **mem = strv_new("mem", NULL),
- **disk = strv_new("disk", NULL),
- **suspend = strv_new("suspend", NULL),
- **reboot = strv_new("reboot", NULL),
- **platform = strv_new("platform", NULL),
- **shutdown = strv_new("shutdown", NULL),
- **freez = strv_new("freeze", NULL);
-
- log_info("Standby configured: %s", yes_no(can_sleep_state(standby) > 0));
- log_info("Suspend configured: %s", yes_no(can_sleep_state(mem) > 0));
- log_info("Hibernate configured: %s", yes_no(can_sleep_state(disk) > 0));
- log_info("Hibernate+Suspend (Hybrid-Sleep) configured: %s", yes_no(can_sleep_disk(suspend) > 0));
- log_info("Hibernate+Reboot configured: %s", yes_no(can_sleep_disk(reboot) > 0));
- log_info("Hibernate+Platform configured: %s", yes_no(can_sleep_disk(platform) > 0));
- log_info("Hibernate+Shutdown configured: %s", yes_no(can_sleep_disk(shutdown) > 0));
- log_info("Freeze configured: %s", yes_no(can_sleep_state(freez) > 0));
-
- log_info("Suspend configured and possible: %s", yes_no(can_sleep("suspend") > 0));
- log_info("Hibernation configured and possible: %s", yes_no(can_sleep("hibernate") > 0));
- log_info("Hybrid-sleep configured and possible: %s", yes_no(can_sleep("hybrid-sleep") > 0));
-}
-
-int main(int argc, char* argv[]) {
- log_parse_environment();
- log_open();
-
- if (getuid() != 0)
- log_warning("This program is unlikely to work for unpriviledged users");
-
- test_sleep();
-
- return 0;
-}
diff --git a/src/test/test-socket-util.c b/src/test/test-socket-util.c
deleted file mode 100644
index 6fb4a40944..0000000000
--- a/src/test/test-socket-util.c
+++ /dev/null
@@ -1,333 +0,0 @@
-/***
- This file is part of systemd
-
- Copyright 2014 Ronny Chevalier
-
- 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 "socket-util.h"
-#include "in-addr-util.h"
-#include "util.h"
-#include "macro.h"
-#include "log.h"
-#include "async.h"
-
-static void test_socket_address_parse(void) {
- SocketAddress a;
-
- assert_se(socket_address_parse(&a, "junk") < 0);
- assert_se(socket_address_parse(&a, "192.168.1.1") < 0);
- assert_se(socket_address_parse(&a, ".168.1.1") < 0);
- assert_se(socket_address_parse(&a, "989.168.1.1") < 0);
- assert_se(socket_address_parse(&a, "192.168.1.1:65536") < 0);
- assert_se(socket_address_parse(&a, "192.168.1.1:0") < 0);
- assert_se(socket_address_parse(&a, "0") < 0);
- assert_se(socket_address_parse(&a, "65536") < 0);
-
- assert_se(socket_address_parse(&a, "65535") >= 0);
-
- if (socket_ipv6_is_supported()) {
- assert_se(socket_address_parse(&a, "[::1]") < 0);
- assert_se(socket_address_parse(&a, "[::1]8888") < 0);
- assert_se(socket_address_parse(&a, "::1") < 0);
- assert_se(socket_address_parse(&a, "[::1]:0") < 0);
- assert_se(socket_address_parse(&a, "[::1]:65536") < 0);
- assert_se(socket_address_parse(&a, "[a:b:1]:8888") < 0);
-
- assert_se(socket_address_parse(&a, "8888") >= 0);
- assert_se(a.sockaddr.sa.sa_family == AF_INET6);
-
- assert_se(socket_address_parse(&a, "[2001:0db8:0000:85a3:0000:0000:ac1f:8001]:8888") >= 0);
- assert_se(a.sockaddr.sa.sa_family == AF_INET6);
-
- assert_se(socket_address_parse(&a, "[::1]:8888") >= 0);
- assert_se(a.sockaddr.sa.sa_family == AF_INET6);
- } else {
- assert_se(socket_address_parse(&a, "[::1]:8888") < 0);
-
- assert_se(socket_address_parse(&a, "8888") >= 0);
- assert_se(a.sockaddr.sa.sa_family == AF_INET);
- }
-
- assert_se(socket_address_parse(&a, "192.168.1.254:8888") >= 0);
- assert_se(a.sockaddr.sa.sa_family == AF_INET);
-
- assert_se(socket_address_parse(&a, "/foo/bar") >= 0);
- assert_se(a.sockaddr.sa.sa_family == AF_UNIX);
-
- assert_se(socket_address_parse(&a, "@abstract") >= 0);
- assert_se(a.sockaddr.sa.sa_family == AF_UNIX);
-}
-
-static void test_socket_address_parse_netlink(void) {
- SocketAddress a;
-
- assert_se(socket_address_parse_netlink(&a, "junk") < 0);
- assert_se(socket_address_parse_netlink(&a, "") < 0);
-
- assert_se(socket_address_parse_netlink(&a, "route") >= 0);
- assert_se(socket_address_parse_netlink(&a, "route 10") >= 0);
- assert_se(a.sockaddr.sa.sa_family == AF_NETLINK);
- assert_se(a.protocol == NETLINK_ROUTE);
-}
-
-static void test_socket_address_equal(void) {
- SocketAddress a;
- SocketAddress b;
-
- assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0);
- assert_se(socket_address_parse(&b, "192.168.1.1:888") >= 0);
- assert_se(!socket_address_equal(&a, &b));
-
- assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0);
- assert_se(socket_address_parse(&b, "192.16.1.1:8888") >= 0);
- assert_se(!socket_address_equal(&a, &b));
-
- assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0);
- assert_se(socket_address_parse(&b, "8888") >= 0);
- assert_se(!socket_address_equal(&a, &b));
-
- assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0);
- assert_se(socket_address_parse(&b, "/foo/bar/") >= 0);
- assert_se(!socket_address_equal(&a, &b));
-
- assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0);
- assert_se(socket_address_parse(&b, "192.168.1.1:8888") >= 0);
- assert_se(socket_address_equal(&a, &b));
-
- assert_se(socket_address_parse(&a, "/foo/bar") >= 0);
- assert_se(socket_address_parse(&b, "/foo/bar") >= 0);
- assert_se(socket_address_equal(&a, &b));
-
- assert_se(socket_address_parse(&a, "[::1]:8888") >= 0);
- assert_se(socket_address_parse(&b, "[::1]:8888") >= 0);
- assert_se(socket_address_equal(&a, &b));
-
- assert_se(socket_address_parse(&a, "@abstract") >= 0);
- assert_se(socket_address_parse(&b, "@abstract") >= 0);
- assert_se(socket_address_equal(&a, &b));
-
- assert_se(socket_address_parse_netlink(&a, "firewall") >= 0);
- assert_se(socket_address_parse_netlink(&b, "firewall") >= 0);
- assert_se(socket_address_equal(&a, &b));
-}
-
-static void test_socket_address_get_path(void) {
- SocketAddress a;
-
- assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0);
- assert_se(!socket_address_get_path(&a));
-
- assert_se(socket_address_parse(&a, "@abstract") >= 0);
- assert_se(!socket_address_get_path(&a));
-
- assert_se(socket_address_parse(&a, "[::1]:8888") >= 0);
- assert_se(!socket_address_get_path(&a));
-
- assert_se(socket_address_parse(&a, "/foo/bar") >= 0);
- assert_se(streq(socket_address_get_path(&a), "/foo/bar"));
-}
-
-static void test_socket_address_is(void) {
- SocketAddress a;
-
- assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0);
- assert_se(socket_address_is(&a, "192.168.1.1:8888", SOCK_STREAM));
- assert_se(!socket_address_is(&a, "route", SOCK_STREAM));
- assert_se(!socket_address_is(&a, "192.168.1.1:8888", SOCK_RAW));
-}
-
-static void test_socket_address_is_netlink(void) {
- SocketAddress a;
-
- assert_se(socket_address_parse_netlink(&a, "route 10") >= 0);
- assert_se(socket_address_is_netlink(&a, "route 10"));
- assert_se(!socket_address_is_netlink(&a, "192.168.1.1:8888"));
- assert_se(!socket_address_is_netlink(&a, "route 1"));
-}
-
-static void test_in_addr_prefix_intersect_one(unsigned f, const char *a, unsigned apl, const char *b, unsigned bpl, int result) {
- union in_addr_union ua, ub;
-
- assert_se(in_addr_from_string(f, a, &ua) >= 0);
- assert_se(in_addr_from_string(f, b, &ub) >= 0);
-
- assert_se(in_addr_prefix_intersect(f, &ua, apl, &ub, bpl) == result);
-}
-
-static void test_in_addr_prefix_intersect(void) {
-
- test_in_addr_prefix_intersect_one(AF_INET, "255.255.255.255", 32, "255.255.255.254", 32, 0);
- test_in_addr_prefix_intersect_one(AF_INET, "255.255.255.255", 0, "255.255.255.255", 32, 1);
- test_in_addr_prefix_intersect_one(AF_INET, "0.0.0.0", 0, "47.11.8.15", 32, 1);
-
- test_in_addr_prefix_intersect_one(AF_INET, "1.1.1.1", 24, "1.1.1.1", 24, 1);
- test_in_addr_prefix_intersect_one(AF_INET, "2.2.2.2", 24, "1.1.1.1", 24, 0);
-
- test_in_addr_prefix_intersect_one(AF_INET, "1.1.1.1", 24, "1.1.1.127", 25, 1);
- test_in_addr_prefix_intersect_one(AF_INET, "1.1.1.1", 24, "1.1.1.127", 26, 1);
- test_in_addr_prefix_intersect_one(AF_INET, "1.1.1.1", 25, "1.1.1.127", 25, 1);
- test_in_addr_prefix_intersect_one(AF_INET, "1.1.1.1", 25, "1.1.1.255", 25, 0);
-
- test_in_addr_prefix_intersect_one(AF_INET6, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 128, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe", 128, 0);
- test_in_addr_prefix_intersect_one(AF_INET6, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 0, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 128, 1);
- test_in_addr_prefix_intersect_one(AF_INET6, "::", 0, "beef:beef:beef:beef:beef:beef:beef:beef", 128, 1);
-
- test_in_addr_prefix_intersect_one(AF_INET6, "1::2", 64, "1::2", 64, 1);
- test_in_addr_prefix_intersect_one(AF_INET6, "2::2", 64, "1::2", 64, 0);
-
- test_in_addr_prefix_intersect_one(AF_INET6, "1::1", 120, "1::007f", 121, 1);
- test_in_addr_prefix_intersect_one(AF_INET6, "1::1", 120, "1::007f", 122, 1);
- test_in_addr_prefix_intersect_one(AF_INET6, "1::1", 121, "1::007f", 121, 1);
- test_in_addr_prefix_intersect_one(AF_INET6, "1::1", 121, "1::00ff", 121, 0);
-}
-
-static void test_in_addr_prefix_next_one(unsigned f, const char *before, unsigned pl, const char *after) {
- union in_addr_union ubefore, uafter, t;
-
- assert_se(in_addr_from_string(f, before, &ubefore) >= 0);
-
- t = ubefore;
- assert_se((in_addr_prefix_next(f, &t, pl) > 0) == !!after);
-
- if (after) {
- assert_se(in_addr_from_string(f, after, &uafter) >= 0);
- assert_se(in_addr_equal(f, &t, &uafter) > 0);
- }
-}
-
-static void test_in_addr_prefix_next(void) {
-
- test_in_addr_prefix_next_one(AF_INET, "192.168.0.0", 24, "192.168.1.0");
- test_in_addr_prefix_next_one(AF_INET, "192.168.0.0", 16, "192.169.0.0");
- test_in_addr_prefix_next_one(AF_INET, "192.168.0.0", 20, "192.168.16.0");
-
- test_in_addr_prefix_next_one(AF_INET, "0.0.0.0", 32, "0.0.0.1");
- test_in_addr_prefix_next_one(AF_INET, "255.255.255.255", 32, NULL);
- test_in_addr_prefix_next_one(AF_INET, "255.255.255.0", 24, NULL);
-
- test_in_addr_prefix_next_one(AF_INET6, "4400::", 128, "4400::0001");
- test_in_addr_prefix_next_one(AF_INET6, "4400::", 120, "4400::0100");
- test_in_addr_prefix_next_one(AF_INET6, "4400::", 127, "4400::0002");
- test_in_addr_prefix_next_one(AF_INET6, "4400::", 8, "4500::");
- test_in_addr_prefix_next_one(AF_INET6, "4400::", 7, "4600::");
-
- test_in_addr_prefix_next_one(AF_INET6, "::", 128, "::1");
-
- test_in_addr_prefix_next_one(AF_INET6, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 128, NULL);
- test_in_addr_prefix_next_one(AF_INET6, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00", 120, NULL);
-
-}
-
-static void *connect_thread(void *arg) {
- union sockaddr_union *sa = arg;
- _cleanup_close_ int fd = -1;
-
- fd = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
- assert_se(fd >= 0);
-
- assert_se(connect(fd, &sa->sa, sizeof(sa->in)) == 0);
-
- return NULL;
-}
-
-static void test_nameinfo_pretty(void) {
- _cleanup_free_ char *stdin_name = NULL, *localhost = NULL;
-
- union sockaddr_union s = {
- .in.sin_family = AF_INET,
- .in.sin_port = 0,
- .in.sin_addr.s_addr = htonl(INADDR_ANY),
- };
- int r;
-
- union sockaddr_union c = {};
- socklen_t slen = sizeof(c.in), clen = sizeof(c.in);
-
- _cleanup_close_ int sfd = -1, cfd = -1;
- r = getnameinfo_pretty(STDIN_FILENO, &stdin_name);
- log_info_errno(r, "No connection remote: %m");
-
- assert_se(r < 0);
-
- sfd = socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, 0);
- assert_se(sfd >= 0);
-
- assert_se(bind(sfd, &s.sa, sizeof(s.in)) == 0);
-
- /* find out the port number */
- assert_se(getsockname(sfd, &s.sa, &slen) == 0);
-
- assert_se(listen(sfd, 1) == 0);
-
- assert_se(asynchronous_job(connect_thread, &s) == 0);
-
- log_debug("Accepting new connection on fd:%d", sfd);
- cfd = accept4(sfd, &c.sa, &clen, SOCK_CLOEXEC);
- assert_se(cfd >= 0);
-
- r = getnameinfo_pretty(cfd, &localhost);
- log_info("Connection from %s", localhost);
- assert_se(r == 0);
-}
-
-static void test_sockaddr_equal(void) {
- union sockaddr_union a = {
- .in.sin_family = AF_INET,
- .in.sin_port = 0,
- .in.sin_addr.s_addr = htonl(INADDR_ANY),
- };
- union sockaddr_union b = {
- .in.sin_family = AF_INET,
- .in.sin_port = 0,
- .in.sin_addr.s_addr = htonl(INADDR_ANY),
- };
- union sockaddr_union c = {
- .in.sin_family = AF_INET,
- .in.sin_port = 0,
- .in.sin_addr.s_addr = htonl(1234),
- };
- union sockaddr_union d = {
- .in6.sin6_family = AF_INET6,
- .in6.sin6_port = 0,
- .in6.sin6_addr = IN6ADDR_ANY_INIT,
- };
- assert_se(sockaddr_equal(&a, &a));
- assert_se(sockaddr_equal(&a, &b));
- assert_se(sockaddr_equal(&d, &d));
- assert_se(!sockaddr_equal(&a, &c));
- assert_se(!sockaddr_equal(&b, &c));
-}
-
-int main(int argc, char *argv[]) {
-
- log_set_max_level(LOG_DEBUG);
-
- test_socket_address_parse();
- test_socket_address_parse_netlink();
- test_socket_address_equal();
- test_socket_address_get_path();
- test_socket_address_is();
- test_socket_address_is_netlink();
-
- test_in_addr_prefix_intersect();
- test_in_addr_prefix_next();
-
- test_nameinfo_pretty();
-
- test_sockaddr_equal();
-
- return 0;
-}
diff --git a/src/test/test-strbuf.c b/src/test/test-strbuf.c
deleted file mode 100644
index 4ec648ae66..0000000000
--- a/src/test/test-strbuf.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 Thomas H.P. Andersen
-
- 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 <stdlib.h>
-#include <string.h>
-
-#include "strbuf.h"
-#include "strv.h"
-#include "util.h"
-
-static ssize_t add_string(struct strbuf *sb, const char *s) {
- return strbuf_add_string(sb, s, strlen(s));
-}
-
-static void test_strbuf(void) {
- struct strbuf *sb;
- _cleanup_strv_free_ char **l;
- ssize_t a, b, c, d, e, f, g;
-
- sb = strbuf_new();
-
- a = add_string(sb, "waldo");
- b = add_string(sb, "foo");
- c = add_string(sb, "bar");
- d = add_string(sb, "waldo"); /* duplicate */
- e = add_string(sb, "aldo"); /* duplicate */
- f = add_string(sb, "do"); /* duplicate */
- g = add_string(sb, "waldorf"); /* not a duplicate: matches from tail */
-
- /* check the content of the buffer directly */
- l = strv_parse_nulstr(sb->buf, sb->len);
-
- assert_se(streq(l[0], "")); /* root */
- assert_se(streq(l[1], "waldo"));
- assert_se(streq(l[2], "foo"));
- assert_se(streq(l[3], "bar"));
- assert_se(streq(l[4], "waldorf"));
-
- assert_se(sb->nodes_count == 5); /* root + 4 non-duplicates */
- assert_se(sb->dedup_count == 3);
- assert_se(sb->in_count == 7);
-
- assert_se(sb->in_len == 29); /* length of all strings added */
- assert_se(sb->dedup_len == 11); /* length of all strings duplicated */
- assert_se(sb->len == 23); /* buffer length: in - dedup + \0 for each node */
-
- /* check the returned offsets and the respective content in the buffer */
- assert_se(a == 1);
- assert_se(b == 7);
- assert_se(c == 11);
- assert_se(d == 1);
- assert_se(e == 2);
- assert_se(f == 4);
- assert_se(g == 15);
-
- assert_se(streq(sb->buf + a, "waldo"));
- assert_se(streq(sb->buf + b, "foo"));
- assert_se(streq(sb->buf + c, "bar"));
- assert_se(streq(sb->buf + d, "waldo"));
- assert_se(streq(sb->buf + e, "aldo"));
- assert_se(streq(sb->buf + f, "do"));
- assert_se(streq(sb->buf + g, "waldorf"));
-
- strbuf_complete(sb);
- assert_se(sb->root == NULL);
-
- strbuf_cleanup(sb);
-}
-
-int main(int argc, const char *argv[]) {
- test_strbuf();
-
- return 0;
-}
diff --git a/src/test/test-strip-tab-ansi.c b/src/test/test-strip-tab-ansi.c
deleted file mode 100644
index 5016906ad0..0000000000
--- a/src/test/test-strip-tab-ansi.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2012 Lennart Poettering
-
- 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 <stdio.h>
-
-#include "util.h"
-
-int main(int argc, char *argv[]) {
- char *p;
-
- assert_se(p = strdup("\tFoobar\tbar\twaldo\t"));
- assert_se(strip_tab_ansi(&p, NULL));
- fprintf(stdout, "<%s>\n", p);
- assert_se(streq(p, " Foobar bar waldo "));
- free(p);
-
- assert_se(p = strdup(ANSI_HIGHLIGHT_ON "Hello" ANSI_HIGHLIGHT_OFF ANSI_HIGHLIGHT_RED_ON " world!" ANSI_HIGHLIGHT_OFF));
- assert_se(strip_tab_ansi(&p, NULL));
- fprintf(stdout, "<%s>\n", p);
- assert_se(streq(p, "Hello world!"));
- free(p);
-
- assert_se(p = strdup("\x1B[\x1B[\t\x1B[" ANSI_HIGHLIGHT_ON "\x1B[" "Hello" ANSI_HIGHLIGHT_OFF ANSI_HIGHLIGHT_RED_ON " world!" ANSI_HIGHLIGHT_OFF));
- assert_se(strip_tab_ansi(&p, NULL));
- assert_se(streq(p, "\x1B[\x1B[ \x1B[\x1B[Hello world!"));
- free(p);
-
- assert_se(p = strdup("\x1B[waldo"));
- assert_se(strip_tab_ansi(&p, NULL));
- assert_se(streq(p, "\x1B[waldo"));
- free(p);
-
- return 0;
-}
diff --git a/src/test/test-strv.c b/src/test/test-strv.c
deleted file mode 100644
index d5ea2b3fab..0000000000
--- a/src/test/test-strv.c
+++ /dev/null
@@ -1,603 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2010 Lennart Poettering
- Copyright 2013 Thomas H.P. Andersen
-
- 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 <string.h>
-
-#include "util.h"
-#include "specifier.h"
-#include "strv.h"
-
-static void test_specifier_printf(void) {
- static const Specifier table[] = {
- { 'a', specifier_string, (char*) "AAAA" },
- { 'b', specifier_string, (char*) "BBBB" },
- { 'm', specifier_machine_id, NULL },
- { 'B', specifier_boot_id, NULL },
- { 'H', specifier_host_name, NULL },
- { 'v', specifier_kernel_release, NULL },
- {}
- };
-
- _cleanup_free_ char *w = NULL;
- int r;
-
- r = specifier_printf("xxx a=%a b=%b yyy", table, NULL, &w);
- assert_se(r >= 0);
- assert_se(w);
-
- puts(w);
- assert_se(streq(w, "xxx a=AAAA b=BBBB yyy"));
-
- free(w);
- r = specifier_printf("machine=%m, boot=%B, host=%H, version=%v", table, NULL, &w);
- assert_se(r >= 0);
- assert_se(w);
- puts(w);
-}
-
-static const char* const input_table_multiple[] = {
- "one",
- "two",
- "three",
- NULL,
-};
-
-static const char* const input_table_one[] = {
- "one",
- NULL,
-};
-
-static const char* const input_table_none[] = {
- NULL,
-};
-
-static const char* const input_table_quotes[] = {
- "\"",
- "'",
- "\"\"",
- "\\",
- "\\\\",
- NULL,
-};
-#define QUOTES_STRING \
- "\"\\\"\" " \
- "\"\\\'\" " \
- "\"\\\"\\\"\" " \
- "\"\\\\\" " \
- "\"\\\\\\\\\""
-
-static const char * const input_table_spaces[] = {
- " ",
- "' '",
- "\" ",
- " \"",
- " \\\\ ",
- NULL,
-};
-#define SPACES_STRING \
- "\" \" " \
- "\"\\' \\'\" " \
- "\"\\\" \" " \
- "\" \\\"\" " \
- "\" \\\\\\\\ \""
-
-static void test_strv_find(void) {
- assert_se(strv_find((char **)input_table_multiple, "three"));
- assert_se(!strv_find((char **)input_table_multiple, "four"));
-}
-
-static void test_strv_find_prefix(void) {
- assert_se(strv_find_prefix((char **)input_table_multiple, "o"));
- assert_se(strv_find_prefix((char **)input_table_multiple, "one"));
- assert_se(strv_find_prefix((char **)input_table_multiple, ""));
- assert_se(!strv_find_prefix((char **)input_table_multiple, "xxx"));
- assert_se(!strv_find_prefix((char **)input_table_multiple, "onee"));
-}
-
-static void test_strv_find_startswith(void) {
- char *r;
-
- r = strv_find_startswith((char **)input_table_multiple, "o");
- assert_se(r && streq(r, "ne"));
-
- r = strv_find_startswith((char **)input_table_multiple, "one");
- assert_se(r && streq(r, ""));
-
- r = strv_find_startswith((char **)input_table_multiple, "");
- assert_se(r && streq(r, "one"));
-
- assert_se(!strv_find_startswith((char **)input_table_multiple, "xxx"));
- assert_se(!strv_find_startswith((char **)input_table_multiple, "onee"));
-}
-
-static void test_strv_join(void) {
- _cleanup_free_ char *p = NULL, *q = NULL, *r = NULL, *s = NULL, *t = NULL;
-
- p = strv_join((char **)input_table_multiple, ", ");
- assert_se(p);
- assert_se(streq(p, "one, two, three"));
-
- q = strv_join((char **)input_table_multiple, ";");
- assert_se(q);
- assert_se(streq(q, "one;two;three"));
-
- r = strv_join((char **)input_table_multiple, NULL);
- assert_se(r);
- assert_se(streq(r, "one two three"));
-
- s = strv_join((char **)input_table_one, ", ");
- assert_se(s);
- assert_se(streq(s, "one"));
-
- t = strv_join((char **)input_table_none, ", ");
- assert_se(t);
- assert_se(streq(t, ""));
-}
-
-static void test_strv_quote_unquote(const char* const *split, const char *quoted) {
- _cleanup_free_ char *p;
- _cleanup_strv_free_ char **s;
- char **t;
- int r;
-
- p = strv_join_quoted((char **)split);
- assert_se(p);
- printf("-%s- --- -%s-\n", p, quoted); /* fprintf deals with NULL, puts does not */
- assert_se(p);
- assert_se(streq(p, quoted));
-
- r = strv_split_quoted(&s, quoted, 0);
- assert_se(r == 0);
- assert_se(s);
- STRV_FOREACH(t, s) {
- assert_se(*t);
- assert_se(streq(*t, *split));
- split++;
- }
-}
-
-static void test_strv_unquote(const char *quoted, char **list) {
- _cleanup_strv_free_ char **s;
- _cleanup_free_ char *j;
- unsigned i = 0;
- char **t;
- int r;
-
- r = strv_split_quoted(&s, quoted, 0);
- assert_se(r == 0);
- assert_se(s);
- j = strv_join(s, " | ");
- assert_se(j);
- puts(j);
-
- STRV_FOREACH(t, s)
- assert_se(streq(list[i++], *t));
-
- assert_se(list[i] == NULL);
-}
-
-static void test_invalid_unquote(const char *quoted) {
- char **s = NULL;
- int r;
-
- r = strv_split_quoted(&s, quoted, 0);
- assert_se(s == NULL);
- assert_se(r == -EINVAL);
-}
-
-static void test_strv_split(void) {
- char **s;
- unsigned i = 0;
- _cleanup_strv_free_ char **l = NULL;
- const char str[] = "one,two,three";
-
- l = strv_split(str, ",");
-
- assert_se(l);
-
- STRV_FOREACH(s, l) {
- assert_se(streq(*s, input_table_multiple[i++]));
- }
-}
-
-static void test_strv_split_newlines(void) {
- unsigned i = 0;
- char **s;
- _cleanup_strv_free_ char **l = NULL;
- const char str[] = "one\ntwo\nthree";
-
- l = strv_split_newlines(str);
-
- assert_se(l);
-
- STRV_FOREACH(s, l) {
- assert_se(streq(*s, input_table_multiple[i++]));
- }
-}
-
-static void test_strv_split_nulstr(void) {
- _cleanup_strv_free_ char **l = NULL;
- const char nulstr[] = "str0\0str1\0str2\0str3\0";
-
- l = strv_split_nulstr (nulstr);
- assert_se(l);
-
- assert_se(streq(l[0], "str0"));
- assert_se(streq(l[1], "str1"));
- assert_se(streq(l[2], "str2"));
- assert_se(streq(l[3], "str3"));
-}
-
-static void test_strv_parse_nulstr(void) {
- _cleanup_strv_free_ char **l = NULL;
- const char nulstr[] = "fuck\0fuck2\0fuck3\0\0fuck5\0\0xxx";
-
- l = strv_parse_nulstr(nulstr, sizeof(nulstr)-1);
- assert_se(l);
- puts("Parse nulstr:");
- strv_print(l);
-
- assert_se(streq(l[0], "fuck"));
- assert_se(streq(l[1], "fuck2"));
- assert_se(streq(l[2], "fuck3"));
- assert_se(streq(l[3], ""));
- assert_se(streq(l[4], "fuck5"));
- assert_se(streq(l[5], ""));
- assert_se(streq(l[6], "xxx"));
-}
-
-static void test_strv_overlap(void) {
- const char * const input_table[] = {
- "one",
- "two",
- "three",
- NULL
- };
- const char * const input_table_overlap[] = {
- "two",
- NULL
- };
- const char * const input_table_unique[] = {
- "four",
- "five",
- "six",
- NULL
- };
-
- assert_se(strv_overlap((char **)input_table, (char**)input_table_overlap));
- assert_se(!strv_overlap((char **)input_table, (char**)input_table_unique));
-}
-
-static void test_strv_sort(void) {
- const char* input_table[] = {
- "durian",
- "apple",
- "citrus",
- "CAPITAL LETTERS FIRST",
- "banana",
- NULL
- };
-
- strv_sort((char **)input_table);
-
- assert_se(streq(input_table[0], "CAPITAL LETTERS FIRST"));
- assert_se(streq(input_table[1], "apple"));
- assert_se(streq(input_table[2], "banana"));
- assert_se(streq(input_table[3], "citrus"));
- assert_se(streq(input_table[4], "durian"));
-}
-
-static void test_strv_extend_strv_concat(void) {
- _cleanup_strv_free_ char **a = NULL, **b = NULL;
-
- a = strv_new("without", "suffix", NULL);
- b = strv_new("with", "suffix", NULL);
- assert_se(a);
- assert_se(b);
-
- assert_se(strv_extend_strv_concat(&a, b, "_suffix") >= 0);
-
- assert_se(streq(a[0], "without"));
- assert_se(streq(a[1], "suffix"));
- assert_se(streq(a[2], "with_suffix"));
- assert_se(streq(a[3], "suffix_suffix"));
-}
-
-static void test_strv_extend_strv(void) {
- _cleanup_strv_free_ char **a = NULL, **b = NULL;
-
- a = strv_new("abc", "def", "ghi", NULL);
- b = strv_new("jkl", "mno", "pqr", NULL);
- assert_se(a);
- assert_se(b);
-
- assert_se(strv_extend_strv(&a, b) >= 0);
-
- assert_se(streq(a[0], "abc"));
- assert_se(streq(a[1], "def"));
- assert_se(streq(a[2], "ghi"));
- assert_se(streq(a[3], "jkl"));
- assert_se(streq(a[4], "mno"));
- assert_se(streq(a[5], "pqr"));
-
- assert_se(strv_length(a) == 6);
-}
-
-static void test_strv_extend(void) {
- _cleanup_strv_free_ char **a = NULL, **b = NULL;
-
- a = strv_new("test", "test1", NULL);
- assert_se(a);
- assert_se(strv_extend(&a, "test2") >= 0);
- assert_se(strv_extend(&b, "test3") >= 0);
-
- assert_se(streq(a[0], "test"));
- assert_se(streq(a[1], "test1"));
- assert_se(streq(a[2], "test2"));
- assert_se(streq(b[0], "test3"));
-}
-
-static void test_strv_extendf(void) {
- _cleanup_strv_free_ char **a = NULL, **b = NULL;
-
- a = strv_new("test", "test1", NULL);
- assert_se(a);
- assert_se(strv_extendf(&a, "test2 %s %d %s", "foo", 128, "bar") >= 0);
- assert_se(strv_extendf(&b, "test3 %s %s %d", "bar", "foo", 128) >= 0);
-
- assert_se(streq(a[0], "test"));
- assert_se(streq(a[1], "test1"));
- assert_se(streq(a[2], "test2 foo 128 bar"));
- assert_se(streq(b[0], "test3 bar foo 128"));
-}
-
-static void test_strv_foreach(void) {
- _cleanup_strv_free_ char **a;
- unsigned i = 0;
- char **check;
-
- a = strv_new("one", "two", "three", NULL);
-
- assert_se(a);
-
- STRV_FOREACH(check, a) {
- assert_se(streq(*check, input_table_multiple[i++]));
- }
-}
-
-static void test_strv_foreach_backwards(void) {
- _cleanup_strv_free_ char **a;
- unsigned i = 2;
- char **check;
-
- a = strv_new("one", "two", "three", NULL);
-
- assert_se(a);
-
- STRV_FOREACH_BACKWARDS(check, a) {
- assert_se(streq_ptr(*check, input_table_multiple[i--]));
- }
-}
-
-static void test_strv_foreach_pair(void) {
- _cleanup_strv_free_ char **a = NULL;
- char **x, **y;
-
- a = strv_new("pair_one", "pair_one",
- "pair_two", "pair_two",
- "pair_three", "pair_three",
- NULL);
-
- STRV_FOREACH_PAIR(x, y, a) {
- assert_se(streq(*x, *y));
- }
-}
-
-static void test_strv_from_stdarg_alloca_one(char **l, const char *first, ...) {
- char **j;
- unsigned i;
-
- j = strv_from_stdarg_alloca(first);
-
- for (i = 0;; i++) {
- assert_se(streq_ptr(l[i], j[i]));
-
- if (!l[i])
- break;
- }
-}
-
-static void test_strv_from_stdarg_alloca(void) {
- test_strv_from_stdarg_alloca_one(STRV_MAKE("foo", "bar"), "foo", "bar", NULL);
- test_strv_from_stdarg_alloca_one(STRV_MAKE("foo"), "foo", NULL);
- test_strv_from_stdarg_alloca_one(STRV_MAKE_EMPTY, NULL);
-}
-
-static void test_strv_push_prepend(void) {
- _cleanup_strv_free_ char **a = NULL;
-
- a = strv_new("foo", "bar", "three", NULL);
-
- assert_se(strv_push_prepend(&a, strdup("first")) >= 0);
- assert_se(streq(a[0], "first"));
- assert_se(streq(a[1], "foo"));
- assert_se(streq(a[2], "bar"));
- assert_se(streq(a[3], "three"));
- assert_se(!a[4]);
-
- assert_se(strv_consume_prepend(&a, strdup("first2")) >= 0);
- assert_se(streq(a[0], "first2"));
- assert_se(streq(a[1], "first"));
- assert_se(streq(a[2], "foo"));
- assert_se(streq(a[3], "bar"));
- assert_se(streq(a[4], "three"));
- assert_se(!a[5]);
-}
-
-static void test_strv_push(void) {
- _cleanup_strv_free_ char **a = NULL;
- char *i, *j;
-
- assert_se(i = strdup("foo"));
- assert_se(strv_push(&a, i) >= 0);
-
- assert_se(i = strdup("a"));
- assert_se(j = strdup("b"));
- assert_se(strv_push_pair(&a, i, j) >= 0);
-
- assert_se(streq_ptr(a[0], "foo"));
- assert_se(streq_ptr(a[1], "a"));
- assert_se(streq_ptr(a[2], "b"));
- assert_se(streq_ptr(a[3], NULL));
-}
-
-static void test_strv_equal(void) {
- _cleanup_strv_free_ char **a = NULL;
- _cleanup_strv_free_ char **b = NULL;
- _cleanup_strv_free_ char **c = NULL;
-
- a = strv_new("one", "two", "three", NULL);
- assert_se(a);
- b = strv_new("one", "two", "three", NULL);
- assert_se(a);
- c = strv_new("one", "two", "three", "four", NULL);
- assert_se(a);
-
- assert_se(strv_equal(a, a));
- assert_se(strv_equal(a, b));
- assert_se(strv_equal(NULL, NULL));
-
- assert_se(!strv_equal(a, c));
- assert_se(!strv_equal(b, c));
- assert_se(!strv_equal(b, NULL));
-}
-
-static void test_strv_is_uniq(void) {
- _cleanup_strv_free_ char **a = NULL, **b = NULL, **c = NULL, **d = NULL;
-
- a = strv_new(NULL, NULL);
- assert_se(a);
- assert_se(strv_is_uniq(a));
-
- b = strv_new("foo", NULL);
- assert_se(b);
- assert_se(strv_is_uniq(b));
-
- c = strv_new("foo", "bar", NULL);
- assert_se(c);
- assert_se(strv_is_uniq(c));
-
- d = strv_new("foo", "bar", "waldo", "bar", "piep", NULL);
- assert_se(d);
- assert_se(!strv_is_uniq(d));
-}
-
-static void test_strv_reverse(void) {
- _cleanup_strv_free_ char **a = NULL, **b = NULL, **c = NULL, **d = NULL;
-
- a = strv_new(NULL, NULL);
- assert_se(a);
-
- strv_reverse(a);
- assert_se(strv_isempty(a));
-
- b = strv_new("foo", NULL);
- assert_se(b);
- strv_reverse(b);
- assert_se(streq_ptr(b[0], "foo"));
- assert_se(streq_ptr(b[1], NULL));
-
- c = strv_new("foo", "bar", NULL);
- assert_se(c);
- strv_reverse(c);
- assert_se(streq_ptr(c[0], "bar"));
- assert_se(streq_ptr(c[1], "foo"));
- assert_se(streq_ptr(c[2], NULL));
-
- d = strv_new("foo", "bar", "waldo", NULL);
- assert_se(d);
- strv_reverse(d);
- assert_se(streq_ptr(d[0], "waldo"));
- assert_se(streq_ptr(d[1], "bar"));
- assert_se(streq_ptr(d[2], "foo"));
- assert_se(streq_ptr(d[3], NULL));
-}
-
-int main(int argc, char *argv[]) {
- test_specifier_printf();
- test_strv_foreach();
- test_strv_foreach_backwards();
- test_strv_foreach_pair();
- test_strv_find();
- test_strv_find_prefix();
- test_strv_find_startswith();
- test_strv_join();
-
- test_strv_quote_unquote(input_table_multiple, "\"one\" \"two\" \"three\"");
- test_strv_quote_unquote(input_table_one, "\"one\"");
- test_strv_quote_unquote(input_table_none, "");
- test_strv_quote_unquote(input_table_quotes, QUOTES_STRING);
- test_strv_quote_unquote(input_table_spaces, SPACES_STRING);
-
- test_strv_unquote(" foo=bar \"waldo\" zzz ", STRV_MAKE("foo=bar", "waldo", "zzz"));
- test_strv_unquote("", STRV_MAKE_EMPTY);
- test_strv_unquote(" ", STRV_MAKE_EMPTY);
- test_strv_unquote(" ", STRV_MAKE_EMPTY);
- test_strv_unquote(" x", STRV_MAKE("x"));
- test_strv_unquote("x ", STRV_MAKE("x"));
- test_strv_unquote(" x ", STRV_MAKE("x"));
- test_strv_unquote(" \"x\" ", STRV_MAKE("x"));
- test_strv_unquote(" 'x' ", STRV_MAKE("x"));
- test_strv_unquote(" 'x\"' ", STRV_MAKE("x\""));
- test_strv_unquote(" \"x'\" ", STRV_MAKE("x'"));
- test_strv_unquote("a '--b=c \"d e\"'", STRV_MAKE("a", "--b=c \"d e\""));
-
- /* trailing backslashes */
- test_strv_unquote(" x\\\\", STRV_MAKE("x\\"));
- test_invalid_unquote(" x\\");
-
- test_invalid_unquote("a --b='c \"d e\"''");
- test_invalid_unquote("a --b='c \"d e\" '\"");
- test_invalid_unquote("a --b='c \"d e\"garbage");
- test_invalid_unquote("'");
- test_invalid_unquote("\"");
- test_invalid_unquote("'x'y'g");
-
- test_strv_split();
- test_strv_split_newlines();
- test_strv_split_nulstr();
- test_strv_parse_nulstr();
- test_strv_overlap();
- test_strv_sort();
- test_strv_extend_strv();
- test_strv_extend_strv_concat();
- test_strv_extend();
- test_strv_extendf();
- test_strv_from_stdarg_alloca();
- test_strv_push_prepend();
- test_strv_push();
- test_strv_equal();
- test_strv_is_uniq();
- test_strv_reverse();
-
- return 0;
-}
diff --git a/src/test/test-strxcpyx.c b/src/test/test-strxcpyx.c
deleted file mode 100644
index 858a4081da..0000000000
--- a/src/test/test-strxcpyx.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 Thomas H.P. Andersen
-
- 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 <string.h>
-
-#include "util.h"
-#include "strxcpyx.h"
-
-static void test_strpcpy(void) {
- char target[25];
- char *s = target;
- size_t space_left;
-
- space_left = sizeof(target);
- space_left = strpcpy(&s, space_left, "12345");
- space_left = strpcpy(&s, space_left, "hey hey hey");
- space_left = strpcpy(&s, space_left, "waldo");
- space_left = strpcpy(&s, space_left, "ba");
- space_left = strpcpy(&s, space_left, "r");
- space_left = strpcpy(&s, space_left, "foo");
-
- assert_se(streq(target, "12345hey hey heywaldobar"));
- assert_se(space_left == 0);
-}
-
-static void test_strpcpyf(void) {
- char target[25];
- char *s = target;
- size_t space_left;
-
- space_left = sizeof(target);
- space_left = strpcpyf(&s, space_left, "space left: %zu. ", space_left);
- space_left = strpcpyf(&s, space_left, "foo%s", "bar");
-
- assert_se(streq(target, "space left: 25. foobar"));
- assert_se(space_left == 3);
-}
-
-static void test_strpcpyl(void) {
- char target[25];
- char *s = target;
- size_t space_left;
-
- space_left = sizeof(target);
- space_left = strpcpyl(&s, space_left, "waldo", " test", " waldo. ", NULL);
- space_left = strpcpyl(&s, space_left, "Banana", NULL);
-
- assert_se(streq(target, "waldo test waldo. Banana"));
- assert_se(space_left == 1);
-}
-
-static void test_strscpy(void) {
- char target[25];
- size_t space_left;
-
- space_left = sizeof(target);
- space_left = strscpy(target, space_left, "12345");
-
- assert_se(streq(target, "12345"));
- assert_se(space_left == 20);
-}
-
-static void test_strscpyl(void) {
- char target[25];
- size_t space_left;
-
- space_left = sizeof(target);
- space_left = strscpyl(target, space_left, "12345", "waldo", "waldo", NULL);
-
- assert_se(streq(target, "12345waldowaldo"));
- assert_se(space_left == 10);
-}
-
-int main(int argc, char *argv[]) {
- test_strpcpy();
- test_strpcpyf();
- test_strpcpyl();
- test_strscpy();
- test_strscpyl();
-
- return 0;
-}
diff --git a/src/test/test-tables.c b/src/test/test-tables.c
deleted file mode 100644
index 0e5ab1645f..0000000000
--- a/src/test/test-tables.c
+++ /dev/null
@@ -1,126 +0,0 @@
-/***
- This file is part of systemd
-
- Copyright 2013 Zbigniew Jędrzejewski-Szmek
-
- 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 "automount.h"
-#include "cgroup.h"
-#include "compress.h"
-#include "condition.h"
-#include "device.h"
-#include "execute.h"
-#include "install.h"
-#include "job.h"
-#include "kill.h"
-#include "log.h"
-#include "logs-show.h"
-#include "mount.h"
-#include "path.h"
-#include "scope.h"
-#include "service.h"
-#include "slice.h"
-#include "snapshot.h"
-#include "socket-util.h"
-#include "socket.h"
-#include "swap.h"
-#include "target.h"
-#include "timer.h"
-#include "unit-name.h"
-#include "unit.h"
-#include "util.h"
-#include "architecture.h"
-#include "link-config.h"
-#include "bus-xml-policy.h"
-#include "busname.h"
-#include "journald-server.h"
-#include "locale-util.h"
-
-#include "test-tables.h"
-
-int main(int argc, char **argv) {
- test_table(architecture, ARCHITECTURE);
- test_table(automount_result, AUTOMOUNT_RESULT);
- test_table(automount_state, AUTOMOUNT_STATE);
- test_table(bus_policy_access, BUS_POLICY_ACCESS);
- test_table(busname_result, BUSNAME_RESULT);
- test_table(busname_state, BUSNAME_STATE);
- test_table(cgroup_device_policy, CGROUP_DEVICE_POLICY);
- test_table(condition_type, CONDITION_TYPE);
- test_table(assert_type, CONDITION_TYPE);
- test_table(condition_result, CONDITION_RESULT);
- test_table(device_state, DEVICE_STATE);
- test_table(exec_input, EXEC_INPUT);
- test_table(exec_output, EXEC_OUTPUT);
- test_table(failure_action, FAILURE_ACTION);
- test_table(job_mode, JOB_MODE);
- test_table(job_result, JOB_RESULT);
- test_table(job_state, JOB_STATE);
- test_table(job_type, JOB_TYPE);
- test_table(kill_mode, KILL_MODE);
- test_table(kill_who, KILL_WHO);
- test_table(log_target, LOG_TARGET);
- test_table(mac_policy, MACPOLICY);
- test_table(manager_state, MANAGER_STATE);
- test_table(mount_exec_command, MOUNT_EXEC_COMMAND);
- test_table(mount_result, MOUNT_RESULT);
- test_table(mount_state, MOUNT_STATE);
- test_table(name_policy, NAMEPOLICY);
- test_table(notify_access, NOTIFY_ACCESS);
- test_table(output_mode, OUTPUT_MODE);
- test_table(path_result, PATH_RESULT);
- test_table(path_state, PATH_STATE);
- test_table(path_type, PATH_TYPE);
- test_table(policy_item_class, POLICY_ITEM_CLASS);
- test_table(policy_item_type, POLICY_ITEM_TYPE);
- test_table(protect_home, PROTECT_HOME);
- test_table(protect_system, PROTECT_SYSTEM);
- test_table(rlimit, RLIMIT);
- test_table(scope_result, SCOPE_RESULT);
- test_table(scope_state, SCOPE_STATE);
- test_table(service_exec_command, SERVICE_EXEC_COMMAND);
- test_table(service_restart, SERVICE_RESTART);
- test_table(service_result, SERVICE_RESULT);
- test_table(service_state, SERVICE_STATE);
- test_table(service_type, SERVICE_TYPE);
- test_table(slice_state, SLICE_STATE);
- test_table(snapshot_state, SNAPSHOT_STATE);
- test_table(socket_address_bind_ipv6_only, SOCKET_ADDRESS_BIND_IPV6_ONLY);
- test_table(socket_exec_command, SOCKET_EXEC_COMMAND);
- test_table(socket_result, SOCKET_RESULT);
- test_table(socket_state, SOCKET_STATE);
- test_table(split_mode, SPLIT);
- test_table(storage, STORAGE);
- test_table(swap_exec_command, SWAP_EXEC_COMMAND);
- test_table(swap_result, SWAP_RESULT);
- test_table(swap_state, SWAP_STATE);
- test_table(target_state, TARGET_STATE);
- test_table(timer_base, TIMER_BASE);
- test_table(timer_result, TIMER_RESULT);
- test_table(timer_state, TIMER_STATE);
- test_table(unit_active_state, UNIT_ACTIVE_STATE);
- test_table(unit_dependency, UNIT_DEPENDENCY);
- test_table(unit_file_change_type, UNIT_FILE_CHANGE_TYPE);
- test_table(unit_file_preset_mode, UNIT_FILE_PRESET);
- test_table(unit_file_state, UNIT_FILE_STATE);
- test_table(unit_load_state, UNIT_LOAD_STATE);
- test_table(unit_type, UNIT_TYPE);
- test_table(locale_variable, VARIABLE_LC);
-
- test_table_sparse(object_compressed, OBJECT_COMPRESSED);
-
- return EXIT_SUCCESS;
-}
diff --git a/src/test/test-time.c b/src/test/test-time.c
deleted file mode 100644
index 3840fff061..0000000000
--- a/src/test/test-time.c
+++ /dev/null
@@ -1,172 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 Lennart Poettering
-
- 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 "time-util.h"
-#include "strv.h"
-
-static void test_parse_sec(void) {
- usec_t u;
-
- assert_se(parse_sec("5s", &u) >= 0);
- assert_se(u == 5 * USEC_PER_SEC);
- assert_se(parse_sec("5s500ms", &u) >= 0);
- assert_se(u == 5 * USEC_PER_SEC + 500 * USEC_PER_MSEC);
- assert_se(parse_sec(" 5s 500ms ", &u) >= 0);
- assert_se(u == 5 * USEC_PER_SEC + 500 * USEC_PER_MSEC);
- assert_se(parse_sec(" 5.5s ", &u) >= 0);
- assert_se(u == 5 * USEC_PER_SEC + 500 * USEC_PER_MSEC);
- assert_se(parse_sec(" 5.5s 0.5ms ", &u) >= 0);
- assert_se(u == 5 * USEC_PER_SEC + 500 * USEC_PER_MSEC + 500);
- assert_se(parse_sec(" .22s ", &u) >= 0);
- assert_se(u == 220 * USEC_PER_MSEC);
- assert_se(parse_sec(" .50y ", &u) >= 0);
- assert_se(u == USEC_PER_YEAR / 2);
- assert_se(parse_sec("2.5", &u) >= 0);
- assert_se(u == 2500 * USEC_PER_MSEC);
- assert_se(parse_sec(".7", &u) >= 0);
- assert_se(u == 700 * USEC_PER_MSEC);
- assert_se(parse_sec("infinity", &u) >= 0);
- assert_se(u == USEC_INFINITY);
- assert_se(parse_sec(" infinity ", &u) >= 0);
- assert_se(u == USEC_INFINITY);
-
- assert_se(parse_sec(" xyz ", &u) < 0);
- assert_se(parse_sec("", &u) < 0);
- assert_se(parse_sec(" . ", &u) < 0);
- assert_se(parse_sec(" 5. ", &u) < 0);
- assert_se(parse_sec(".s ", &u) < 0);
- assert_se(parse_sec(" infinity .7", &u) < 0);
- assert_se(parse_sec(".3 infinity", &u) < 0);
-}
-
-static void test_parse_nsec(void) {
- nsec_t u;
-
- assert_se(parse_nsec("5s", &u) >= 0);
- assert_se(u == 5 * NSEC_PER_SEC);
- assert_se(parse_nsec("5s500ms", &u) >= 0);
- assert_se(u == 5 * NSEC_PER_SEC + 500 * NSEC_PER_MSEC);
- assert_se(parse_nsec(" 5s 500ms ", &u) >= 0);
- assert_se(u == 5 * NSEC_PER_SEC + 500 * NSEC_PER_MSEC);
- assert_se(parse_nsec(" 5.5s ", &u) >= 0);
- assert_se(u == 5 * NSEC_PER_SEC + 500 * NSEC_PER_MSEC);
- assert_se(parse_nsec(" 5.5s 0.5ms ", &u) >= 0);
- assert_se(u == 5 * NSEC_PER_SEC + 500 * NSEC_PER_MSEC + 500 * NSEC_PER_USEC);
- assert_se(parse_nsec(" .22s ", &u) >= 0);
- assert_se(u == 220 * NSEC_PER_MSEC);
- assert_se(parse_nsec(" .50y ", &u) >= 0);
- assert_se(u == NSEC_PER_YEAR / 2);
- assert_se(parse_nsec("2.5", &u) >= 0);
- assert_se(u == 2);
- assert_se(parse_nsec(".7", &u) >= 0);
- assert_se(u == 0);
- assert_se(parse_nsec("infinity", &u) >= 0);
- assert_se(u == NSEC_INFINITY);
- assert_se(parse_nsec(" infinity ", &u) >= 0);
- assert_se(u == NSEC_INFINITY);
-
- assert_se(parse_nsec(" xyz ", &u) < 0);
- assert_se(parse_nsec("", &u) < 0);
- assert_se(parse_nsec(" . ", &u) < 0);
- assert_se(parse_nsec(" 5. ", &u) < 0);
- assert_se(parse_nsec(".s ", &u) < 0);
- assert_se(parse_nsec(" infinity .7", &u) < 0);
- assert_se(parse_nsec(".3 infinity", &u) < 0);
-}
-
-static void test_format_timespan_one(usec_t x, usec_t accuracy) {
- char *r;
- char l[FORMAT_TIMESPAN_MAX];
- usec_t y;
-
- log_info(USEC_FMT" (at accuracy "USEC_FMT")", x, accuracy);
-
- r = format_timespan(l, sizeof(l), x, accuracy);
- assert_se(r);
-
- log_info(" = <%s>", l);
-
- assert_se(parse_sec(l, &y) >= 0);
-
- log_info(" = "USEC_FMT, y);
-
- if (accuracy <= 0)
- accuracy = 1;
-
- assert_se(x / accuracy == y / accuracy);
-}
-
-static void test_format_timespan(usec_t accuracy) {
- test_format_timespan_one(0, accuracy);
- test_format_timespan_one(1, accuracy);
- test_format_timespan_one(1*USEC_PER_SEC, accuracy);
- test_format_timespan_one(999*USEC_PER_MSEC, accuracy);
- test_format_timespan_one(1234567, accuracy);
- test_format_timespan_one(12, accuracy);
- test_format_timespan_one(123, accuracy);
- test_format_timespan_one(1234, accuracy);
- test_format_timespan_one(12345, accuracy);
- test_format_timespan_one(123456, accuracy);
- test_format_timespan_one(1234567, accuracy);
- test_format_timespan_one(12345678, accuracy);
- test_format_timespan_one(1200000, accuracy);
- test_format_timespan_one(1230000, accuracy);
- test_format_timespan_one(1230000, accuracy);
- test_format_timespan_one(1234000, accuracy);
- test_format_timespan_one(1234500, accuracy);
- test_format_timespan_one(1234560, accuracy);
- test_format_timespan_one(1234567, accuracy);
- test_format_timespan_one(986087, accuracy);
- test_format_timespan_one(500 * USEC_PER_MSEC, accuracy);
- test_format_timespan_one(9*USEC_PER_YEAR/5 - 23, accuracy);
- test_format_timespan_one(USEC_INFINITY, accuracy);
-}
-
-static void test_timezone_is_valid(void) {
- assert_se(timezone_is_valid("Europe/Berlin"));
- assert_se(timezone_is_valid("Australia/Sydney"));
- assert_se(!timezone_is_valid("Europe/Do not exist"));
-}
-
-static void test_get_timezones(void) {
- _cleanup_strv_free_ char **zones = NULL;
- int r;
- char **zone;
-
- r = get_timezones(&zones);
- assert_se(r == 0);
-
- STRV_FOREACH(zone, zones) {
- assert_se(timezone_is_valid(*zone));
- }
-}
-
-int main(int argc, char *argv[]) {
- test_parse_sec();
- test_parse_nsec();
- test_format_timespan(1);
- test_format_timespan(USEC_PER_MSEC);
- test_format_timespan(USEC_PER_SEC);
- test_timezone_is_valid();
- test_get_timezones();
-
- return 0;
-}
diff --git a/src/test/test-tmpfiles.c b/src/test/test-tmpfiles.c
deleted file mode 100644
index 90e49d4542..0000000000
--- a/src/test/test-tmpfiles.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2014 Zbigniew Jędrzejewski-Szmek
-
- 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 <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "util.h"
-
-int main(int argc, char** argv) {
- const char *p = argv[1] ?: "/tmp";
- char *pattern = strjoina(p, "/systemd-test-XXXXXX");
- _cleanup_close_ int fd, fd2;
- _cleanup_free_ char *cmd, *cmd2;
-
- fd = open_tmpfile(p, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
-
- assert_se(asprintf(&cmd, "ls -l /proc/"PID_FMT"/fd/%d", getpid(), fd) > 0);
- system(cmd);
-
- fd2 = mkostemp_safe(pattern, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- assert_se(unlink(pattern) == 0);
-
- assert_se(asprintf(&cmd2, "ls -l /proc/"PID_FMT"/fd/%d", getpid(), fd2) > 0);
- system(cmd2);
-
- return 0;
-}
diff --git a/src/test/test-udev.c b/src/test/test-udev.c
deleted file mode 100644
index 23b7faa939..0000000000
--- a/src/test/test-udev.c
+++ /dev/null
@@ -1,161 +0,0 @@
-/***
- This file is part of systemd.
-
- Copyright 2003-2004 Greg Kroah-Hartman <greg@kroah.com>
- Copyright 2004-2012 Kay Sievers <kay@vrfy.org>
-
- 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 <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sched.h>
-#include <sys/mount.h>
-#include <sys/signalfd.h>
-
-#include "missing.h"
-#include "selinux-util.h"
-#include "udev.h"
-#include "udev-util.h"
-
-static int fake_filesystems(void) {
- static const struct fakefs {
- const char *src;
- const char *target;
- const char *error;
- } fakefss[] = {
- { "test/sys", "/sys", "failed to mount test /sys" },
- { "test/dev", "/dev", "failed to mount test /dev" },
- { "test/run", "/run", "failed to mount test /run" },
- { "test/run", "/etc/udev/rules.d", "failed to mount empty /etc/udev/rules.d" },
- { "test/run", "/usr/lib/udev/rules.d", "failed to mount empty /usr/lib/udev/rules.d" },
- };
- unsigned int i;
- int err;
-
- err = unshare(CLONE_NEWNS);
- if (err < 0) {
- err = -errno;
- fprintf(stderr, "failed to call unshare(): %m\n");
- goto out;
- }
-
- if (mount(NULL, "/", NULL, MS_PRIVATE|MS_REC, NULL) < 0) {
- err = -errno;
- fprintf(stderr, "failed to mount / as private: %m\n");
- goto out;
- }
-
- for (i = 0; i < ELEMENTSOF(fakefss); i++) {
- err = mount(fakefss[i].src, fakefss[i].target, NULL, MS_BIND, NULL);
- if (err < 0) {
- err = -errno;
- fprintf(stderr, "%s %m", fakefss[i].error);
- return err;
- }
- }
-out:
- return err;
-}
-
-int main(int argc, char *argv[]) {
- _cleanup_udev_unref_ struct udev *udev = NULL;
- _cleanup_udev_event_unref_ struct udev_event *event = NULL;
- _cleanup_udev_device_unref_ struct udev_device *dev = NULL;
- _cleanup_udev_rules_unref_ struct udev_rules *rules = NULL;
- char syspath[UTIL_PATH_SIZE];
- const char *devpath;
- const char *action;
- sigset_t mask, sigmask_orig;
- int err;
-
- err = fake_filesystems();
- if (err < 0)
- return EXIT_FAILURE;
-
- udev = udev_new();
- if (udev == NULL)
- return EXIT_FAILURE;
-
- log_debug("version %s", VERSION);
- mac_selinux_init("/dev");
-
- sigprocmask(SIG_SETMASK, NULL, &sigmask_orig);
-
- action = argv[1];
- if (action == NULL) {
- log_error("action missing");
- goto out;
- }
-
- devpath = argv[2];
- if (devpath == NULL) {
- log_error("devpath missing");
- goto out;
- }
-
- rules = udev_rules_new(udev, 1);
-
- strscpyl(syspath, sizeof(syspath), "/sys", devpath, NULL);
- dev = udev_device_new_from_synthetic_event(udev, syspath, action);
- if (dev == NULL) {
- log_debug("unknown device '%s'", devpath);
- goto out;
- }
-
- event = udev_event_new(dev);
-
- sigfillset(&mask);
- sigprocmask(SIG_SETMASK, &mask, &sigmask_orig);
- event->fd_signal = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC);
- if (event->fd_signal < 0) {
- fprintf(stderr, "error creating signalfd\n");
- goto out;
- }
-
- /* do what devtmpfs usually provides us */
- if (udev_device_get_devnode(dev) != NULL) {
- mode_t mode = 0600;
-
- if (streq(udev_device_get_subsystem(dev), "block"))
- mode |= S_IFBLK;
- else
- mode |= S_IFCHR;
-
- if (!streq(action, "remove")) {
- mkdir_parents_label(udev_device_get_devnode(dev), 0755);
- mknod(udev_device_get_devnode(dev), mode, udev_device_get_devnum(dev));
- } else {
- unlink(udev_device_get_devnode(dev));
- rmdir_parents(udev_device_get_devnode(dev), "/");
- }
- }
-
- udev_event_execute_rules(event,
- 3 * USEC_PER_SEC, USEC_PER_SEC,
- NULL,
- rules,
- &sigmask_orig);
- udev_event_execute_run(event,
- 3 * USEC_PER_SEC, USEC_PER_SEC,
- NULL);
-out:
- if (event != NULL && event->fd_signal >= 0)
- close(event->fd_signal);
- mac_selinux_finish();
-
- return err ? EXIT_FAILURE : EXIT_SUCCESS;
-}
diff --git a/src/test/test-uid-range.c b/src/test/test-uid-range.c
deleted file mode 100644
index bc5baa2fcb..0000000000
--- a/src/test/test-uid-range.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2014 Lennart Poettering
-
- 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 <stddef.h>
-
-#include "util.h"
-#include "uid-range.h"
-
-int main(int argc, char *argv[]) {
- _cleanup_free_ UidRange *p = NULL;
- unsigned n = 0;
- uid_t search;
-
- assert_se(uid_range_add_str(&p, &n, "500-999") >= 0);
- assert_se(n == 1);
- assert_se(p[0].start == 500);
- assert_se(p[0].nr == 500);
-
- assert_se(!uid_range_contains(p, n, 499));
- assert_se(uid_range_contains(p, n, 500));
- assert_se(uid_range_contains(p, n, 999));
- assert_se(!uid_range_contains(p, n, 1000));
-
- search = UID_INVALID;
- assert_se(uid_range_next_lower(p, n, &search));
- assert_se(search == 999);
- assert_se(uid_range_next_lower(p, n, &search));
- assert_se(search == 998);
- search = 501;
- assert_se(uid_range_next_lower(p, n, &search));
- assert_se(search == 500);
- assert_se(uid_range_next_lower(p, n, &search) == -EBUSY);
-
- assert_se(uid_range_add_str(&p, &n, "1000") >= 0);
- assert_se(n == 1);
- assert_se(p[0].start == 500);
- assert_se(p[0].nr == 501);
-
- assert_se(uid_range_add_str(&p, &n, "30-40") >= 0);
- assert_se(n == 2);
- assert_se(p[0].start == 30);
- assert_se(p[0].nr == 11);
- assert_se(p[1].start == 500);
- assert_se(p[1].nr == 501);
-
- assert_se(uid_range_add_str(&p, &n, "60-70") >= 0);
- assert_se(n == 3);
- assert_se(p[0].start == 30);
- assert_se(p[0].nr == 11);
- assert_se(p[1].start == 60);
- assert_se(p[1].nr == 11);
- assert_se(p[2].start == 500);
- assert_se(p[2].nr == 501);
-
- assert_se(uid_range_add_str(&p, &n, "20-2000") >= 0);
- assert_se(n == 1);
- assert_se(p[0].start == 20);
- assert_se(p[0].nr == 1981);
-
- assert_se(uid_range_add_str(&p, &n, "2002") >= 0);
- assert_se(n == 2);
- assert_se(p[0].start == 20);
- assert_se(p[0].nr == 1981);
- assert_se(p[1].start == 2002);
- assert_se(p[1].nr == 1);
-
- assert_se(uid_range_add_str(&p, &n, "2001") >= 0);
- assert_se(n == 1);
- assert_se(p[0].start == 20);
- assert_se(p[0].nr == 1983);
-
- return 0;
-}
diff --git a/src/test/test-unaligned.c b/src/test/test-unaligned.c
deleted file mode 100644
index 1754d06b2d..0000000000
--- a/src/test/test-unaligned.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/***
- This file is part of systemd
-
- Copyright 2014 Tom Gundersen
-
- 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 "unaligned.h"
-#include "sparse-endian.h"
-#include "util.h"
-
-static uint8_t data[] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
-};
-
-int main(int argc, const char *argv[]) {
- uint8_t scratch[16];
-
- assert_se(unaligned_read_be16(&data[0]) == 0x0001);
- assert_se(unaligned_read_be16(&data[1]) == 0x0102);
-
- assert_se(unaligned_read_be32(&data[0]) == 0x00010203);
- assert_se(unaligned_read_be32(&data[1]) == 0x01020304);
- assert_se(unaligned_read_be32(&data[2]) == 0x02030405);
- assert_se(unaligned_read_be32(&data[3]) == 0x03040506);
-
- assert_se(unaligned_read_be64(&data[0]) == 0x0001020304050607);
- assert_se(unaligned_read_be64(&data[1]) == 0x0102030405060708);
- assert_se(unaligned_read_be64(&data[2]) == 0x0203040506070809);
- assert_se(unaligned_read_be64(&data[3]) == 0x030405060708090a);
- assert_se(unaligned_read_be64(&data[4]) == 0x0405060708090a0b);
- assert_se(unaligned_read_be64(&data[5]) == 0x05060708090a0b0c);
- assert_se(unaligned_read_be64(&data[6]) == 0x060708090a0b0c0d);
- assert_se(unaligned_read_be64(&data[7]) == 0x0708090a0b0c0d0e);
-
- zero(scratch);
- unaligned_write_be16(&scratch[0], 0x0001);
- assert_se(memcmp(&scratch[0], &data[0], sizeof(uint16_t)) == 0);
- zero(scratch);
- unaligned_write_be16(&scratch[1], 0x0102);
- assert_se(memcmp(&scratch[1], &data[1], sizeof(uint16_t)) == 0);
-
- zero(scratch);
- unaligned_write_be32(&scratch[0], 0x00010203);
- assert_se(memcmp(&scratch[0], &data[0], sizeof(uint32_t)) == 0);
- zero(scratch);
- unaligned_write_be32(&scratch[1], 0x01020304);
- assert_se(memcmp(&scratch[1], &data[1], sizeof(uint32_t)) == 0);
- zero(scratch);
- unaligned_write_be32(&scratch[2], 0x02030405);
- assert_se(memcmp(&scratch[2], &data[2], sizeof(uint32_t)) == 0);
- zero(scratch);
- unaligned_write_be32(&scratch[3], 0x03040506);
- assert_se(memcmp(&scratch[3], &data[3], sizeof(uint32_t)) == 0);
-
- zero(scratch);
- unaligned_write_be64(&scratch[0], 0x0001020304050607);
- assert_se(memcmp(&scratch[0], &data[0], sizeof(uint64_t)) == 0);
- zero(scratch);
- unaligned_write_be64(&scratch[1], 0x0102030405060708);
- assert_se(memcmp(&scratch[1], &data[1], sizeof(uint64_t)) == 0);
- zero(scratch);
- unaligned_write_be64(&scratch[2], 0x0203040506070809);
- assert_se(memcmp(&scratch[2], &data[2], sizeof(uint64_t)) == 0);
- zero(scratch);
- unaligned_write_be64(&scratch[3], 0x030405060708090a);
- assert_se(memcmp(&scratch[3], &data[3], sizeof(uint64_t)) == 0);
- zero(scratch);
- unaligned_write_be64(&scratch[4], 0x0405060708090a0b);
- assert_se(memcmp(&scratch[4], &data[4], sizeof(uint64_t)) == 0);
- zero(scratch);
- unaligned_write_be64(&scratch[5], 0x05060708090a0b0c);
- assert_se(memcmp(&scratch[5], &data[5], sizeof(uint64_t)) == 0);
- zero(scratch);
- unaligned_write_be64(&scratch[6], 0x060708090a0b0c0d);
- assert_se(memcmp(&scratch[6], &data[6], sizeof(uint64_t)) == 0);
- zero(scratch);
- unaligned_write_be64(&scratch[7], 0x0708090a0b0c0d0e);
- assert_se(memcmp(&scratch[7], &data[7], sizeof(uint64_t)) == 0);
-}
diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c
deleted file mode 100644
index 22ac76de56..0000000000
--- a/src/test/test-unit-file.c
+++ /dev/null
@@ -1,527 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2012 Lennart Poettering
- Copyright 2013 Zbigniew Jędrzejewski-Szmek
-
- 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 <stdio.h>
-#include <stddef.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#include "install.h"
-#include "install-printf.h"
-#include "specifier.h"
-#include "util.h"
-#include "macro.h"
-#include "hashmap.h"
-#include "load-fragment.h"
-#include "strv.h"
-#include "fileio.h"
-#include "test-helper.h"
-
-static int test_unit_file_get_set(void) {
- int r;
- Hashmap *h;
- Iterator i;
- UnitFileList *p;
-
- h = hashmap_new(&string_hash_ops);
- assert_se(h);
-
- r = unit_file_get_list(UNIT_FILE_SYSTEM, NULL, h);
-
- if (r == -EPERM || r == -EACCES) {
- printf("Skipping test: unit_file_get_list: %s", strerror(-r));
- return EXIT_TEST_SKIP;
- }
-
- log_full(r == 0 ? LOG_INFO : LOG_ERR,
- "unit_file_get_list: %s", strerror(-r));
- if (r < 0)
- return EXIT_FAILURE;
-
- HASHMAP_FOREACH(p, h, i)
- printf("%s = %s\n", p->path, unit_file_state_to_string(p->state));
-
- unit_file_list_free(h);
-
- return 0;
-}
-
-static void check_execcommand(ExecCommand *c,
- const char* path,
- const char* argv0,
- const char* argv1,
- const char* argv2,
- bool ignore) {
- size_t n;
-
- assert_se(c);
- log_info("expect: \"%s\" [\"%s\" \"%s\" \"%s\"]",
- path, argv0 ?: path, argv1, argv2);
- n = strv_length(c->argv);
- log_info("actual: \"%s\" [\"%s\" \"%s\" \"%s\"]",
- c->path, c->argv[0], n > 0 ? c->argv[1] : NULL, n > 1 ? c->argv[2] : NULL);
- assert_se(streq(c->path, path));
- assert_se(streq(c->argv[0], argv0 ?: path));
- if (n > 0)
- assert_se(streq_ptr(c->argv[1], argv1));
- if (n > 1)
- assert_se(streq_ptr(c->argv[2], argv2));
- assert_se(c->ignore == ignore);
-}
-
-static void test_config_parse_exec(void) {
- /* int config_parse_exec(
- const char *filename,
- unsigned line,
- const char *section,
- unsigned section_line,
- const char *lvalue,
- int ltype,
- const char *rvalue,
- void *data,
- void *userdata) */
- int r;
-
- ExecCommand *c = NULL, *c1;
- const char *ccc;
-
- log_info("/* basic test */");
- r = config_parse_exec(NULL, "fake", 1, "section", 1,
- "LValue", 0, "/RValue r1",
- &c, NULL);
- assert_se(r >= 0);
- check_execcommand(c, "/RValue", "/RValue", "r1", NULL, false);
-
- r = config_parse_exec(NULL, "fake", 2, "section", 1,
- "LValue", 0, "/RValue///slashes r1///",
- &c, NULL);
-
- log_info("/* test slashes */");
- assert_se(r >= 0);
- c1 = c->command_next;
- check_execcommand(c1, "/RValue/slashes", "/RValue///slashes", "r1///", NULL, false);
-
- log_info("/* trailing slash */");
- r = config_parse_exec(NULL, "fake", 4, "section", 1,
- "LValue", 0, "/RValue/ argv0 r1",
- &c, NULL);
- assert_se(r == 0);
- assert_se(c1->command_next == NULL);
-
- log_info("/* honour_argv0 */");
- r = config_parse_exec(NULL, "fake", 3, "section", 1,
- "LValue", 0, "@/RValue///slashes2 ///argv0 r1",
- &c, NULL);
- assert_se(r >= 0);
- c1 = c1->command_next;
- check_execcommand(c1, "/RValue/slashes2", "///argv0", "r1", NULL, false);
-
- log_info("/* honour_argv0, no args */");
- r = config_parse_exec(NULL, "fake", 3, "section", 1,
- "LValue", 0, "@/RValue",
- &c, NULL);
- assert_se(r == 0);
- assert_se(c1->command_next == NULL);
-
- log_info("/* no command, check for bad memory access */");
- r = config_parse_exec(NULL, "fake", 3, "section", 1,
- "LValue", 0, " ",
- &c, NULL);
- assert_se(r == 0);
- assert_se(c1->command_next == NULL);
-
- log_info("/* ignore && honour_argv0 */");
- r = config_parse_exec(NULL, "fake", 4, "section", 1,
- "LValue", 0, "-@/RValue///slashes3 argv0a r1",
- &c, NULL);
- assert_se(r >= 0);
- c1 = c1->command_next;
- check_execcommand(c1, "/RValue/slashes3", "argv0a", "r1", NULL, true);
-
- log_info("/* ignore && honour_argv0 */");
- r = config_parse_exec(NULL, "fake", 4, "section", 1,
- "LValue", 0, "@-/RValue///slashes4 argv0b r1",
- &c, NULL);
- assert_se(r >= 0);
- c1 = c1->command_next;
- check_execcommand(c1, "/RValue/slashes4", "argv0b", "r1", NULL, true);
-
- log_info("/* ignore && ignore */");
- r = config_parse_exec(NULL, "fake", 4, "section", 1,
- "LValue", 0, "--/RValue argv0 r1",
- &c, NULL);
- assert_se(r == 0);
- assert_se(c1->command_next == NULL);
-
- log_info("/* ignore && ignore (2) */");
- r = config_parse_exec(NULL, "fake", 4, "section", 1,
- "LValue", 0, "-@-/RValue argv0 r1",
- &c, NULL);
- assert_se(r == 0);
- assert_se(c1->command_next == NULL);
-
- log_info("/* semicolon */");
- r = config_parse_exec(NULL, "fake", 5, "section", 1,
- "LValue", 0,
- "-@/RValue argv0 r1 ; "
- "/goo/goo boo",
- &c, NULL);
- assert_se(r >= 0);
- c1 = c1->command_next;
- check_execcommand(c1, "/RValue", "argv0", "r1", NULL, true);
-
- c1 = c1->command_next;
- check_execcommand(c1, "/goo/goo", NULL, "boo", NULL, false);
-
- log_info("/* trailing semicolon */");
- r = config_parse_exec(NULL, "fake", 5, "section", 1,
- "LValue", 0,
- "-@/RValue argv0 r1 ; ",
- &c, NULL);
- assert_se(r >= 0);
- c1 = c1->command_next;
- check_execcommand(c1, "/RValue", "argv0", "r1", NULL, true);
-
- assert_se(c1->command_next == NULL);
-
- log_info("/* escaped semicolon */");
- r = config_parse_exec(NULL, "fake", 5, "section", 1,
- "LValue", 0,
- "/bin/find \\;",
- &c, NULL);
- assert_se(r >= 0);
- c1 = c1->command_next;
- check_execcommand(c1, "/bin/find", NULL, ";", NULL, false);
-
- log_info("/* escaped semicolon with following arg */");
- r = config_parse_exec(NULL, "fake", 5, "section", 1,
- "LValue", 0,
- "/sbin/find \\; x",
- &c, NULL);
- assert_se(r >= 0);
- c1 = c1->command_next;
- check_execcommand(c1,
- "/sbin/find", NULL, ";", "x", false);
-
- log_info("/* spaces in the filename */");
- r = config_parse_exec(NULL, "fake", 5, "section", 1,
- "LValue", 0,
- "\"/PATH WITH SPACES/daemon\" -1 -2",
- &c, NULL);
- assert_se(r >= 0);
- c1 = c1->command_next;
- check_execcommand(c1,
- "/PATH WITH SPACES/daemon", NULL, "-1", "-2", false);
-
- log_info("/* spaces in the filename, no args */");
- r = config_parse_exec(NULL, "fake", 5, "section", 1,
- "LValue", 0,
- "\"/PATH WITH SPACES/daemon -1 -2\"",
- &c, NULL);
- assert_se(r >= 0);
- c1 = c1->command_next;
- check_execcommand(c1,
- "/PATH WITH SPACES/daemon -1 -2", NULL, NULL, NULL, false);
-
- log_info("/* spaces in the filename, everything quoted */");
- r = config_parse_exec(NULL, "fake", 5, "section", 1,
- "LValue", 0,
- "\"/PATH WITH SPACES/daemon\" \"-1\" '-2'",
- &c, NULL);
- assert_se(r >= 0);
- c1 = c1->command_next;
- check_execcommand(c1,
- "/PATH WITH SPACES/daemon", NULL, "-1", "-2", false);
-
- log_info("/* escaped spaces in the filename */");
- r = config_parse_exec(NULL, "fake", 5, "section", 1,
- "LValue", 0,
- "\"/PATH\\sWITH\\sSPACES/daemon\" '-1 -2'",
- &c, NULL);
- assert_se(r >= 0);
- c1 = c1->command_next;
- check_execcommand(c1,
- "/PATH WITH SPACES/daemon", NULL, "-1 -2", NULL, false);
-
- log_info("/* escaped spaces in the filename (2) */");
- r = config_parse_exec(NULL, "fake", 5, "section", 1,
- "LValue", 0,
- "\"/PATH\\x20WITH\\x20SPACES/daemon\" \"-1 -2\"",
- &c, NULL);
- assert_se(r >= 0);
- c1 = c1->command_next;
- check_execcommand(c1,
- "/PATH WITH SPACES/daemon", NULL, "-1 -2", NULL, false);
-
- for (ccc = "abfnrtv\\\'\"x"; *ccc; ccc++) {
- /* \\x is an incomplete hexadecimal sequence, invalid because of the slash */
- char path[] = "/path\\X";
- path[sizeof(path) - 2] = *ccc;
-
- log_info("/* invalid character: \\%c */", *ccc);
- r = config_parse_exec(NULL, "fake", 4, "section", 1,
- "LValue", 0, path,
- &c, NULL);
- assert_se(r == 0);
- assert_se(c1->command_next == NULL);
- }
-
- log_info("/* valid character: \\s */");
- r = config_parse_exec(NULL, "fake", 4, "section", 1,
- "LValue", 0, "/path\\s",
- &c, NULL);
- assert_se(r >= 0);
- c1 = c1->command_next;
- check_execcommand(c1, "/path ", NULL, NULL, NULL, false);
-
- log_info("/* trailing backslash: \\ */");
- /* backslash is invalid */
- r = config_parse_exec(NULL, "fake", 4, "section", 1,
- "LValue", 0, "/path\\",
- &c, NULL);
- assert_se(r == 0);
- assert_se(c1->command_next == NULL);
-
- exec_command_free_list(c);
-}
-
-#define env_file_1 \
- "a=a\n" \
- "b=b\\\n" \
- "c\n" \
- "d=d\\\n" \
- "e\\\n" \
- "f\n" \
- "g=g\\ \n" \
- "h=h\n" \
- "i=i\\"
-
-#define env_file_2 \
- "a=a\\\n"
-
-#define env_file_3 \
- "#SPAMD_ARGS=\"-d --socketpath=/var/lib/bulwark/spamd \\\n" \
- "#--nouser-config \\\n" \
- "normal=line"
-
-#define env_file_4 \
- "# Generated\n" \
- "\n" \
- "HWMON_MODULES=\"coretemp f71882fg\"\n" \
- "\n" \
- "# For compatibility reasons\n" \
- "\n" \
- "MODULE_0=coretemp\n" \
- "MODULE_1=f71882fg"
-
-#define env_file_5 \
- "a=\n" \
- "b="
-
-static void test_load_env_file_1(void) {
- _cleanup_strv_free_ char **data = NULL;
- int r;
-
- char name[] = "/tmp/test-load-env-file.XXXXXX";
- _cleanup_close_ int fd;
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- assert_se(write(fd, env_file_1, sizeof(env_file_1)) == sizeof(env_file_1));
-
- r = load_env_file(NULL, name, NULL, &data);
- assert_se(r == 0);
- assert_se(streq(data[0], "a=a"));
- assert_se(streq(data[1], "b=bc"));
- assert_se(streq(data[2], "d=def"));
- assert_se(streq(data[3], "g=g "));
- assert_se(streq(data[4], "h=h"));
- assert_se(streq(data[5], "i=i"));
- assert_se(data[6] == NULL);
- unlink(name);
-}
-
-static void test_load_env_file_2(void) {
- _cleanup_strv_free_ char **data = NULL;
- int r;
-
- char name[] = "/tmp/test-load-env-file.XXXXXX";
- _cleanup_close_ int fd;
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- assert_se(write(fd, env_file_2, sizeof(env_file_2)) == sizeof(env_file_2));
-
- r = load_env_file(NULL, name, NULL, &data);
- assert_se(r == 0);
- assert_se(streq(data[0], "a=a"));
- assert_se(data[1] == NULL);
- unlink(name);
-}
-
-static void test_load_env_file_3(void) {
- _cleanup_strv_free_ char **data = NULL;
- int r;
-
- char name[] = "/tmp/test-load-env-file.XXXXXX";
- _cleanup_close_ int fd;
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- assert_se(write(fd, env_file_3, sizeof(env_file_3)) == sizeof(env_file_3));
-
- r = load_env_file(NULL, name, NULL, &data);
- assert_se(r == 0);
- assert_se(data == NULL);
- unlink(name);
-}
-
-static void test_load_env_file_4(void) {
- _cleanup_strv_free_ char **data = NULL;
- char name[] = "/tmp/test-load-env-file.XXXXXX";
- _cleanup_close_ int fd;
- int r;
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- assert_se(write(fd, env_file_4, sizeof(env_file_4)) == sizeof(env_file_4));
-
- r = load_env_file(NULL, name, NULL, &data);
- assert_se(r == 0);
- assert_se(streq(data[0], "HWMON_MODULES=coretemp f71882fg"));
- assert_se(streq(data[1], "MODULE_0=coretemp"));
- assert_se(streq(data[2], "MODULE_1=f71882fg"));
- assert_se(data[3] == NULL);
- unlink(name);
-}
-
-static void test_load_env_file_5(void) {
- _cleanup_strv_free_ char **data = NULL;
- int r;
-
- char name[] = "/tmp/test-load-env-file.XXXXXX";
- _cleanup_close_ int fd;
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- assert_se(write(fd, env_file_5, sizeof(env_file_5)) == sizeof(env_file_5));
-
- r = load_env_file(NULL, name, NULL, &data);
- assert_se(r == 0);
- assert_se(streq(data[0], "a="));
- assert_se(streq(data[1], "b="));
- assert_se(data[2] == NULL);
- unlink(name);
-}
-
-static void test_install_printf(void) {
- char name[] = "name.service",
- path[] = "/run/systemd/system/name.service",
- user[] = "xxxx-no-such-user";
- InstallInfo i = {name, path, user};
- InstallInfo i2 = {name, path, NULL};
- char name3[] = "name@inst.service",
- path3[] = "/run/systemd/system/name.service";
- InstallInfo i3 = {name3, path3, user};
- InstallInfo i4 = {name3, path3, NULL};
-
- _cleanup_free_ char *mid, *bid, *host;
-
- assert_se(specifier_machine_id('m', NULL, NULL, &mid) >= 0 && mid);
- assert_se(specifier_boot_id('b', NULL, NULL, &bid) >= 0 && bid);
- assert_se((host = gethostname_malloc()));
-
-#define expect(src, pattern, result) \
- do { \
- _cleanup_free_ char *t = NULL; \
- _cleanup_free_ char \
- *d1 = strdup(i.name), \
- *d2 = strdup(i.path), \
- *d3 = strdup(i.user); \
- assert_se(install_full_printf(&src, pattern, &t) >= 0 || !result); \
- memzero(i.name, strlen(i.name)); \
- memzero(i.path, strlen(i.path)); \
- memzero(i.user, strlen(i.user)); \
- assert_se(d1 && d2 && d3); \
- if (result) { \
- printf("%s\n", t); \
- assert_se(streq(t, result)); \
- } else assert_se(t == NULL); \
- strcpy(i.name, d1); \
- strcpy(i.path, d2); \
- strcpy(i.user, d3); \
- } while(false)
-
- assert_se(setenv("USER", "root", 1) == 0);
-
- expect(i, "%n", "name.service");
- expect(i, "%N", "name");
- expect(i, "%p", "name");
- expect(i, "%i", "");
- expect(i, "%u", "xxxx-no-such-user");
-
- DISABLE_WARNING_NONNULL;
- expect(i, "%U", NULL);
- REENABLE_WARNING;
-
- expect(i, "%m", mid);
- expect(i, "%b", bid);
- expect(i, "%H", host);
-
- expect(i2, "%u", "root");
- expect(i2, "%U", "0");
-
- expect(i3, "%n", "name@inst.service");
- expect(i3, "%N", "name@inst");
- expect(i3, "%p", "name");
- expect(i3, "%u", "xxxx-no-such-user");
-
- DISABLE_WARNING_NONNULL;
- expect(i3, "%U", NULL);
- REENABLE_WARNING;
-
- expect(i3, "%m", mid);
- expect(i3, "%b", bid);
- expect(i3, "%H", host);
-
- expect(i4, "%u", "root");
- expect(i4, "%U", "0");
-}
-
-int main(int argc, char *argv[]) {
- int r;
-
- log_parse_environment();
- log_open();
-
- r = test_unit_file_get_set();
- test_config_parse_exec();
- test_load_env_file_1();
- test_load_env_file_2();
- test_load_env_file_3();
- test_load_env_file_4();
- test_load_env_file_5();
- 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
deleted file mode 100644
index 7d882aebd6..0000000000
--- a/src/test/test-unit-name.c
+++ /dev/null
@@ -1,364 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2012 Lennart Poettering
- Copyright 2013 Zbigniew Jędrzejewski-Szmek
- Copyright 2014 Ronny Chevalier
-
- 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <pwd.h>
-
-#include "manager.h"
-#include "unit.h"
-#include "unit-name.h"
-#include "unit-printf.h"
-#include "specifier.h"
-#include "util.h"
-#include "macro.h"
-#include "test-helper.h"
-
-static void test_replacements(void) {
-#define expect(pattern, repl, expected) \
- { \
- _cleanup_free_ char *t = \
- unit_name_replace_instance(pattern, repl); \
- puts(t); \
- assert_se(streq(t, expected)); \
- }
-
- expect("foo@.service", "waldo", "foo@waldo.service");
- expect("foo@xyz.service", "waldo", "foo@waldo.service");
- expect("xyz", "waldo", "xyz");
- expect("", "waldo", "");
- expect("foo.service", "waldo", "foo.service");
- expect(".service", "waldo", ".service");
- expect("foo@", "waldo", "foo@waldo");
- expect("@bar", "waldo", "@waldo");
-
- puts("-------------------------------------------------");
-#undef expect
-#define expect(path, suffix, expected) \
- { \
- _cleanup_free_ char *k, *t = \
- unit_name_from_path(path, suffix); \
- puts(t); \
- k = unit_name_to_path(t); \
- puts(k); \
- assert_se(streq(k, expected ? expected : path)); \
- }
-
- expect("/waldo", ".mount", NULL);
- expect("/waldo/quuix", ".mount", NULL);
- expect("/waldo/quuix/", ".mount", "/waldo/quuix");
- expect("/", ".mount", NULL);
- expect("///", ".mount", "/");
-
- puts("-------------------------------------------------");
-#undef expect
-#define expect(pattern, path, suffix, expected) \
- { \
- _cleanup_free_ char *t = \
- unit_name_from_path_instance(pattern, path, suffix); \
- puts(t); \
- assert_se(streq(t, expected)); \
- }
-
- expect("waldo", "/waldo", ".mount", "waldo@waldo.mount");
- expect("waldo", "/waldo////quuix////", ".mount", "waldo@waldo-quuix.mount");
- expect("waldo", "/", ".mount", "waldo@-.mount");
- expect("wa--ldo", "/--", ".mount", "wa--ldo@\\x2d\\x2d.mount");
-
- puts("-------------------------------------------------");
-#undef expect
-#define expect(pattern) \
- { \
- _cleanup_free_ char *k, *t; \
- assert_se(t = unit_name_mangle(pattern, MANGLE_NOGLOB)); \
- assert_se(k = unit_name_mangle(t, MANGLE_NOGLOB)); \
- puts(t); \
- assert_se(streq(t, k)); \
- }
-
- expect("/home");
- expect("/dev/sda");
- expect("üxknürz.service");
- expect("foobar-meh...waldi.service");
- expect("_____####----.....service");
- expect("_____##@;;;,,,##----.....service");
- expect("xxx@@@@/////\\\\\\\\\\yyy.service");
-
-#undef expect
-}
-
-static int test_unit_printf(void) {
- Manager *m = NULL;
- Unit *u, *u2;
- int r;
-
- _cleanup_free_ char *mid, *bid, *host, *root_uid;
- struct passwd *root;
-
- assert_se(specifier_machine_id('m', NULL, NULL, &mid) >= 0 && mid);
- assert_se(specifier_boot_id('b', NULL, NULL, &bid) >= 0 && bid);
- assert_se((host = gethostname_malloc()));
-
- assert_se((root = getpwnam("root")));
- assert_se(asprintf(&root_uid, "%d", (int) root->pw_uid) > 0);
-
- r = manager_new(SYSTEMD_USER, true, &m);
- if (r == -EPERM || r == -EACCES || r == -EADDRINUSE) {
- puts("manager_new: Permission denied. Skipping test.");
- return EXIT_TEST_SKIP;
- }
- assert_se(r == 0);
-
-#define expect(unit, pattern, expected) \
- { \
- char *e; \
- _cleanup_free_ char *t = NULL; \
- assert_se(unit_full_printf(unit, pattern, &t) >= 0); \
- printf("result: %s\nexpect: %s\n", t, expected); \
- if ((e = endswith(expected, "*"))) \
- assert_se(strncmp(t, e, e-expected)); \
- else \
- assert_se(streq(t, expected)); \
- }
-
- assert_se(setenv("USER", "root", 1) == 0);
- assert_se(setenv("HOME", "/root", 1) == 0);
- assert_se(setenv("XDG_RUNTIME_DIR", "/run/user/1/", 1) == 0);
-
- assert_se(u = unit_new(m, sizeof(Service)));
- assert_se(unit_add_name(u, "blah.service") == 0);
- assert_se(unit_add_name(u, "blah.service") == 0);
-
- /* general tests */
- expect(u, "%%", "%");
- expect(u, "%%s", "%s");
- expect(u, "%", ""); // REALLY?
-
- /* normal unit */
- expect(u, "%n", "blah.service");
- expect(u, "%f", "/blah");
- expect(u, "%N", "blah");
- expect(u, "%p", "blah");
- expect(u, "%P", "blah");
- expect(u, "%i", "");
- expect(u, "%u", root->pw_name);
- expect(u, "%U", root_uid);
- expect(u, "%h", root->pw_dir);
- expect(u, "%m", mid);
- expect(u, "%b", bid);
- expect(u, "%H", host);
- expect(u, "%t", "/run/user/*");
-
- /* templated */
- assert_se(u2 = unit_new(m, sizeof(Service)));
- assert_se(unit_add_name(u2, "blah@foo-foo.service") == 0);
- assert_se(unit_add_name(u2, "blah@foo-foo.service") == 0);
-
- expect(u2, "%n", "blah@foo-foo.service");
- expect(u2, "%N", "blah@foo-foo");
- expect(u2, "%f", "/foo/foo");
- expect(u2, "%p", "blah");
- expect(u2, "%P", "blah");
- expect(u2, "%i", "foo-foo");
- expect(u2, "%I", "foo/foo");
- expect(u2, "%u", root->pw_name);
- expect(u2, "%U", root_uid);
- expect(u2, "%h", root->pw_dir);
- expect(u2, "%m", mid);
- expect(u2, "%b", bid);
- expect(u2, "%H", host);
- expect(u2, "%t", "/run/user/*");
-
- manager_free(m);
-#undef expect
-
- return 0;
-}
-
-static void test_unit_instance_is_valid(void) {
- assert_se(unit_instance_is_valid("fooBar"));
- assert_se(unit_instance_is_valid("foo-bar"));
- assert_se(unit_instance_is_valid("foo.stUff"));
- assert_se(unit_instance_is_valid("fOo123.stuff"));
- assert_se(unit_instance_is_valid("@f_oo123.Stuff"));
-
- assert_se(!unit_instance_is_valid("$¢£"));
- assert_se(!unit_instance_is_valid(""));
- assert_se(!unit_instance_is_valid("foo bar"));
- assert_se(!unit_instance_is_valid("foo/bar"));
-}
-
-static void test_unit_prefix_is_valid(void) {
- assert_se(unit_prefix_is_valid("fooBar"));
- assert_se(unit_prefix_is_valid("foo-bar"));
- assert_se(unit_prefix_is_valid("foo.stUff"));
- assert_se(unit_prefix_is_valid("fOo123.stuff"));
- assert_se(unit_prefix_is_valid("foo123.Stuff"));
-
- assert_se(!unit_prefix_is_valid("$¢£"));
- assert_se(!unit_prefix_is_valid(""));
- assert_se(!unit_prefix_is_valid("foo bar"));
- assert_se(!unit_prefix_is_valid("foo/bar"));
- assert_se(!unit_prefix_is_valid("@foo-bar"));
-}
-
-static void test_unit_name_change_suffix(void) {
- char *r;
-
- r = unit_name_change_suffix("foo.bar", ".service");
- assert_se(r);
- assert_se(streq(r, "foo.service"));
- free(r);
-
- r = unit_name_change_suffix("foo@stuff.bar", ".boo");
- assert_se(r);
- assert_se(streq(r, "foo@stuff.boo"));
- free(r);
-}
-
-static void test_unit_name_build(void) {
- char *r;
-
- r = unit_name_build("foo", "bar", ".service");
- assert_se(r);
- assert_se(streq(r, "foo@bar.service"));
- free(r);
-
- r = unit_name_build("fo0-stUff_b", "bar", ".mount");
- assert_se(r);
- assert_se(streq(r, "fo0-stUff_b@bar.mount"));
- free(r);
-
- r = unit_name_build("foo", NULL, ".service");
- assert_se(r);
- assert_se(streq(r, "foo.service"));
- free(r);
-}
-
-static void test_unit_name_is_instance(void) {
- assert_se(unit_name_is_instance("a@b.service"));
- assert_se(unit_name_is_instance("a-c_c01Aj@b05Dii_-oioi.service"));
-
- assert_se(!unit_name_is_instance("a.service"));
- assert_se(!unit_name_is_instance("a@.service"));
- assert_se(!unit_name_is_instance("junk"));
- assert_se(!unit_name_is_instance(""));
-}
-
-static void test_build_subslice(void) {
- char *a;
- char *b;
-
- assert_se(build_subslice("-.slice", "foo", &a) >= 0);
- assert_se(build_subslice(a, "bar", &b) >= 0);
- free(a);
- assert_se(build_subslice(b, "barfoo", &a) >= 0);
- free(b);
- assert_se(build_subslice(a, "foobar", &b) >= 0);
- free(a);
- assert_se(streq(b, "foo-bar-barfoo-foobar.slice"));
- free(b);
-
- assert_se(build_subslice("foo.service", "bar", &a) < 0);
- assert_se(build_subslice("foo", "bar", &a) < 0);
-}
-
-static void test_unit_name_to_instance(void) {
- char *instance;
- int r;
-
- r = unit_name_to_instance("foo@bar.service", &instance);
- assert_se(r >= 0);
- assert_se(streq(instance, "bar"));
- free(instance);
-
- r = unit_name_to_instance("foo@.service", &instance);
- assert_se(r >= 0);
- assert_se(streq(instance, ""));
- free(instance);
-
- r = unit_name_to_instance("fo0-stUff_b@b.e", &instance);
- assert_se(r >= 0);
- assert_se(streq(instance, "b"));
- free(instance);
-
- r = unit_name_to_instance("foo.bar", &instance);
- assert_se(r >= 0);
- assert_se(!instance);
-
- r = unit_name_to_instance("fooj@unk", &instance);
- assert_se(r < 0);
-
- r = unit_name_to_instance("foo@", &instance);
- assert_se(r < 0);
-}
-
-static void test_unit_name_escape(void) {
- _cleanup_free_ char *r;
-
- r = unit_name_escape("ab+-c.a/bc@foo.service");
- assert_se(r);
- assert_se(streq(r, "ab\\x2b\\x2dc.a-bc\\x40foo.service"));
-}
-
-static void test_unit_name_template(void) {
-#define expect(name, expected) \
- { \
- _cleanup_free_ char *f = NULL; \
- f = unit_name_template(name); \
- assert_se(f); \
- printf("got: %s, expected: %s\n", f, expected); \
- assert_se(streq(f, expected)); \
- }
- expect("foo@bar.service", "foo@.service")
- expect("foo.mount", "foo.mount")
-#undef expect
-}
-
-static void test_unit_name_is_template(void) {
- assert_se(unit_name_is_template("foo@.service"));
- assert_se(unit_name_is_template("bar@.path"));
-
- assert_se(!unit_name_is_template("bar@i.mount"));
- assert_se(!unit_name_is_template("bar@foobbbb.service"));
- assert_se(!unit_name_is_template("barfoo.service"));
-}
-
-int main(int argc, char* argv[]) {
- int rc = 0;
- test_replacements();
- TEST_REQ_RUNNING_SYSTEMD(rc = test_unit_printf());
- test_unit_instance_is_valid();
- test_unit_prefix_is_valid();
- test_unit_name_change_suffix();
- test_unit_name_build();
- test_unit_name_is_instance();
- test_build_subslice();
- test_unit_name_to_instance();
- test_unit_name_escape();
- test_unit_name_template();
- test_unit_name_is_template();
-
- return rc;
-}
diff --git a/src/test/test-utf8.c b/src/test/test-utf8.c
deleted file mode 100644
index 346f8524c6..0000000000
--- a/src/test/test-utf8.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 Dave Reisner
-
- 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 "utf8.h"
-#include "util.h"
-
-static void test_utf8_is_printable(void) {
- assert_se(utf8_is_printable("ascii is valid\tunicode", 22));
- assert_se(utf8_is_printable("\342\204\242", 3));
- assert_se(!utf8_is_printable("\341\204", 2));
- assert_se(utf8_is_printable("ąę", 4));
-}
-
-static void test_utf8_is_valid(void) {
- assert_se(utf8_is_valid("ascii is valid unicode"));
- assert_se(utf8_is_valid("\342\204\242"));
- assert_se(!utf8_is_valid("\341\204"));
-}
-
-static void test_ascii_is_valid(void) {
- assert_se(ascii_is_valid("alsdjf\t\vbarr\nba z"));
- assert_se(!ascii_is_valid("\342\204\242"));
- assert_se(!ascii_is_valid("\341\204"));
-}
-
-static void test_utf8_encoded_valid_unichar(void) {
- assert_se(utf8_encoded_valid_unichar("\342\204\242") == 3);
- assert_se(utf8_encoded_valid_unichar("\302\256") == 2);
- assert_se(utf8_encoded_valid_unichar("a") == 1);
- assert_se(utf8_encoded_valid_unichar("\341\204") < 0);
- assert_se(utf8_encoded_valid_unichar("\341\204\341\204") < 0);
-}
-
-static void test_utf8_escaping(void) {
- _cleanup_free_ char *p1, *p2, *p3;
-
- p1 = utf8_escape_invalid("goo goo goo");
- puts(p1);
- assert_se(utf8_is_valid(p1));
-
- p2 = utf8_escape_invalid("\341\204\341\204");
- puts(p2);
- assert_se(utf8_is_valid(p2));
-
- p3 = utf8_escape_invalid("\341\204");
- puts(p3);
- assert_se(utf8_is_valid(p3));
-}
-
-static void test_utf8_escaping_printable(void) {
- _cleanup_free_ char *p1, *p2, *p3, *p4, *p5, *p6;
-
- p1 = utf8_escape_non_printable("goo goo goo");
- puts(p1);
- assert_se(utf8_is_valid(p1));
-
- p2 = utf8_escape_non_printable("\341\204\341\204");
- puts(p2);
- assert_se(utf8_is_valid(p2));
-
- p3 = utf8_escape_non_printable("\341\204");
- puts(p3);
- assert_se(utf8_is_valid(p3));
-
- p4 = utf8_escape_non_printable("ąę\n가너도루\n1234\n\341\204\341\204\n\001 \019\20\a");
- puts(p4);
- assert_se(utf8_is_valid(p4));
-
- p5 = utf8_escape_non_printable("\001 \019\20\a");
- puts(p5);
- assert_se(utf8_is_valid(p5));
-
- p6 = utf8_escape_non_printable("\xef\xbf\x30\x13");
- puts(p6);
- assert_se(utf8_is_valid(p6));
-}
-
-static void test_utf16_to_utf8(void) {
- char *a = NULL;
- const uint16_t utf16[] = { htole16('a'), htole16(0xd800), htole16('b'), htole16(0xdc00), htole16('c'), htole16(0xd801), htole16(0xdc37) };
- const char utf8[] = { 'a', 'b', 'c', 0xf0, 0x90, 0x90, 0xb7, 0 };
-
- a = utf16_to_utf8(utf16, 14);
- assert_se(a);
- assert_se(streq(a, utf8));
-
- free(a);
-}
-
-int main(int argc, char *argv[]) {
- test_utf8_is_valid();
- test_utf8_is_printable();
- test_ascii_is_valid();
- test_utf8_encoded_valid_unichar();
- test_utf8_escaping();
- test_utf8_escaping_printable();
- test_utf16_to_utf8();
-
- return 0;
-}
diff --git a/src/test/test-util.c b/src/test/test-util.c
deleted file mode 100644
index d32ddd3a68..0000000000
--- a/src/test/test-util.c
+++ /dev/null
@@ -1,1606 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2010 Lennart Poettering
- Copyright 2013 Thomas H.P. Andersen
-
- 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 <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <locale.h>
-#include <errno.h>
-#include <signal.h>
-#include <math.h>
-#include <sys/wait.h>
-
-#include "util.h"
-#include "mkdir.h"
-#include "strv.h"
-#include "def.h"
-#include "fileio.h"
-#include "conf-parser.h"
-#include "virt.h"
-
-static void test_streq_ptr(void) {
- assert_se(streq_ptr(NULL, NULL));
- assert_se(!streq_ptr("abc", "cdef"));
-}
-
-static void test_align_power2(void) {
- unsigned long i, p2;
-
- assert_se(ALIGN_POWER2(0) == 0);
- assert_se(ALIGN_POWER2(1) == 1);
- assert_se(ALIGN_POWER2(2) == 2);
- assert_se(ALIGN_POWER2(3) == 4);
- assert_se(ALIGN_POWER2(12) == 16);
-
- assert_se(ALIGN_POWER2(ULONG_MAX) == 0);
- assert_se(ALIGN_POWER2(ULONG_MAX - 1) == 0);
- assert_se(ALIGN_POWER2(ULONG_MAX - 1024) == 0);
- assert_se(ALIGN_POWER2(ULONG_MAX / 2) == ULONG_MAX / 2 + 1);
- assert_se(ALIGN_POWER2(ULONG_MAX + 1) == 0);
-
- for (i = 1; i < 131071; ++i) {
- for (p2 = 1; p2 < i; p2 <<= 1)
- /* empty */ ;
-
- assert_se(ALIGN_POWER2(i) == p2);
- }
-
- for (i = ULONG_MAX - 1024; i < ULONG_MAX; ++i) {
- for (p2 = 1; p2 && p2 < i; p2 <<= 1)
- /* empty */ ;
-
- assert_se(ALIGN_POWER2(i) == p2);
- }
-}
-
-static void test_max(void) {
- static const struct {
- int a;
- int b[CONST_MAX(10, 100)];
- } val1 = {
- .a = CONST_MAX(10, 100),
- };
- int d = 0;
-
- assert_cc(sizeof(val1.b) == sizeof(int) * 100);
-
- /* CONST_MAX returns (void) instead of a value if the passed arguments
- * are not of the same type or not constant expressions. */
- assert_cc(__builtin_types_compatible_p(typeof(CONST_MAX(1, 10)), int));
- assert_cc(__builtin_types_compatible_p(typeof(CONST_MAX(1, 1U)), void));
-
- assert_se(val1.a == 100);
- assert_se(MAX(++d, 0) == 1);
- assert_se(d == 1);
-
- assert_cc(MAXSIZE(char[3], uint16_t) == 3);
- assert_cc(MAXSIZE(char[3], uint32_t) == 4);
- assert_cc(MAXSIZE(char, long) == sizeof(long));
-
- assert_se(MAX(-5, 5) == 5);
- assert_se(MAX(5, 5) == 5);
- assert_se(MAX(MAX(1, MAX(2, MAX(3, 4))), 5) == 5);
- assert_se(MAX(MAX(1, MAX(2, MAX(3, 2))), 1) == 3);
- assert_se(MAX(MIN(1, MIN(2, MIN(3, 4))), 5) == 5);
- assert_se(MAX(MAX(1, MIN(2, MIN(3, 2))), 1) == 2);
- assert_se(LESS_BY(8, 4) == 4);
- assert_se(LESS_BY(8, 8) == 0);
- assert_se(LESS_BY(4, 8) == 0);
- assert_se(LESS_BY(16, LESS_BY(8, 4)) == 12);
- assert_se(LESS_BY(4, LESS_BY(8, 4)) == 0);
- assert_se(CLAMP(-5, 0, 1) == 0);
- assert_se(CLAMP(5, 0, 1) == 1);
- assert_se(CLAMP(5, -10, 1) == 1);
- assert_se(CLAMP(5, -10, 10) == 5);
- assert_se(CLAMP(CLAMP(0, -10, 10), CLAMP(-5, 10, 20), CLAMP(100, -5, 20)) == 10);
-}
-
-static void test_container_of(void) {
- struct mytype {
- uint8_t pad1[3];
- uint64_t v1;
- uint8_t pad2[2];
- uint32_t v2;
- } _packed_ myval = { };
-
- assert_cc(sizeof(myval) == 17);
- assert_se(container_of(&myval.v1, struct mytype, v1) == &myval);
- assert_se(container_of(&myval.v2, struct mytype, v2) == &myval);
- assert_se(container_of(&container_of(&myval.v2,
- struct mytype,
- v2)->v1,
- struct mytype,
- v1) == &myval);
-}
-
-static void test_alloca(void) {
- static const uint8_t zero[997] = { };
- char *t;
-
- t = alloca_align(17, 512);
- assert_se(!((uintptr_t)t & 0xff));
- memzero(t, 17);
-
- t = alloca0_align(997, 1024);
- assert_se(!((uintptr_t)t & 0x1ff));
- assert_se(!memcmp(t, zero, 997));
-}
-
-static void test_div_round_up(void) {
- int div;
-
- /* basic tests */
- assert_se(DIV_ROUND_UP(0, 8) == 0);
- assert_se(DIV_ROUND_UP(1, 8) == 1);
- assert_se(DIV_ROUND_UP(8, 8) == 1);
- assert_se(DIV_ROUND_UP(12, 8) == 2);
- assert_se(DIV_ROUND_UP(16, 8) == 2);
-
- /* test multiple evaluation */
- div = 0;
- assert_se(DIV_ROUND_UP(div++, 8) == 0 && div == 1);
- assert_se(DIV_ROUND_UP(++div, 8) == 1 && div == 2);
- assert_se(DIV_ROUND_UP(8, div++) == 4 && div == 3);
- assert_se(DIV_ROUND_UP(8, ++div) == 2 && div == 4);
-
- /* overflow test with exact division */
- assert_se(sizeof(0U) == 4);
- assert_se(0xfffffffaU % 10U == 0U);
- assert_se(0xfffffffaU / 10U == 429496729U);
- assert_se(DIV_ROUND_UP(0xfffffffaU, 10U) == 429496729U);
- assert_se((0xfffffffaU + 10U - 1U) / 10U == 0U);
- assert_se(0xfffffffaU / 10U + !!(0xfffffffaU % 10U) == 429496729U);
-
- /* overflow test with rounded division */
- assert_se(0xfffffffdU % 10U == 3U);
- assert_se(0xfffffffdU / 10U == 429496729U);
- assert_se(DIV_ROUND_UP(0xfffffffdU, 10U) == 429496730U);
- assert_se((0xfffffffdU + 10U - 1U) / 10U == 0U);
- assert_se(0xfffffffdU / 10U + !!(0xfffffffdU % 10U) == 429496730U);
-}
-
-static void test_first_word(void) {
- assert_se(first_word("Hello", ""));
- assert_se(first_word("Hello", "Hello"));
- assert_se(first_word("Hello world", "Hello"));
- assert_se(first_word("Hello\tworld", "Hello"));
- assert_se(first_word("Hello\nworld", "Hello"));
- assert_se(first_word("Hello\rworld", "Hello"));
- assert_se(first_word("Hello ", "Hello"));
-
- assert_se(!first_word("Hello", "Hellooo"));
- assert_se(!first_word("Hello", "xxxxx"));
- assert_se(!first_word("Hellooo", "Hello"));
-}
-
-static void test_close_many(void) {
- int fds[3];
- char name0[] = "/tmp/test-close-many.XXXXXX";
- char name1[] = "/tmp/test-close-many.XXXXXX";
- char name2[] = "/tmp/test-close-many.XXXXXX";
-
- fds[0] = mkostemp_safe(name0, O_RDWR|O_CLOEXEC);
- fds[1] = mkostemp_safe(name1, O_RDWR|O_CLOEXEC);
- fds[2] = mkostemp_safe(name2, O_RDWR|O_CLOEXEC);
-
- close_many(fds, 2);
-
- assert_se(fcntl(fds[0], F_GETFD) == -1);
- assert_se(fcntl(fds[1], F_GETFD) == -1);
- assert_se(fcntl(fds[2], F_GETFD) >= 0);
-
- safe_close(fds[2]);
-
- unlink(name0);
- unlink(name1);
- unlink(name2);
-}
-
-static void test_parse_boolean(void) {
- assert_se(parse_boolean("1") == 1);
- assert_se(parse_boolean("y") == 1);
- assert_se(parse_boolean("Y") == 1);
- assert_se(parse_boolean("yes") == 1);
- assert_se(parse_boolean("YES") == 1);
- assert_se(parse_boolean("true") == 1);
- assert_se(parse_boolean("TRUE") == 1);
- assert_se(parse_boolean("on") == 1);
- assert_se(parse_boolean("ON") == 1);
-
- assert_se(parse_boolean("0") == 0);
- assert_se(parse_boolean("n") == 0);
- assert_se(parse_boolean("N") == 0);
- assert_se(parse_boolean("no") == 0);
- assert_se(parse_boolean("NO") == 0);
- assert_se(parse_boolean("false") == 0);
- assert_se(parse_boolean("FALSE") == 0);
- assert_se(parse_boolean("off") == 0);
- assert_se(parse_boolean("OFF") == 0);
-
- assert_se(parse_boolean("garbage") < 0);
- assert_se(parse_boolean("") < 0);
- assert_se(parse_boolean("full") < 0);
-}
-
-static void test_parse_pid(void) {
- int r;
- pid_t pid;
-
- r = parse_pid("100", &pid);
- assert_se(r == 0);
- assert_se(pid == 100);
-
- r = parse_pid("0x7FFFFFFF", &pid);
- assert_se(r == 0);
- assert_se(pid == 2147483647);
-
- pid = 65; /* pid is left unchanged on ERANGE. Set to known arbitrary value. */
- r = parse_pid("0", &pid);
- assert_se(r == -ERANGE);
- assert_se(pid == 65);
-
- pid = 65; /* pid is left unchanged on ERANGE. Set to known arbitrary value. */
- r = parse_pid("-100", &pid);
- assert_se(r == -ERANGE);
- assert_se(pid == 65);
-
- pid = 65; /* pid is left unchanged on ERANGE. Set to known arbitrary value. */
- r = parse_pid("0xFFFFFFFFFFFFFFFFF", &pid);
- assert_se(r == -ERANGE);
- assert_se(pid == 65);
-}
-
-static void test_parse_uid(void) {
- int r;
- uid_t uid;
-
- r = parse_uid("100", &uid);
- assert_se(r == 0);
- assert_se(uid == 100);
-}
-
-static void test_safe_atolli(void) {
- int r;
- long long l;
-
- r = safe_atolli("12345", &l);
- assert_se(r == 0);
- assert_se(l == 12345);
-
- r = safe_atolli("junk", &l);
- assert_se(r == -EINVAL);
-}
-
-static void test_safe_atod(void) {
- int r;
- double d;
- char *e;
-
- r = safe_atod("junk", &d);
- assert_se(r == -EINVAL);
-
- r = safe_atod("0.2244", &d);
- assert_se(r == 0);
- assert_se(fabs(d - 0.2244) < 0.000001);
-
- r = safe_atod("0,5", &d);
- assert_se(r == -EINVAL);
-
- errno = 0;
- strtod("0,5", &e);
- assert_se(*e == ',');
-
- /* Check if this really is locale independent */
- if (setlocale(LC_NUMERIC, "de_DE.utf8")) {
-
- r = safe_atod("0.2244", &d);
- assert_se(r == 0);
- assert_se(fabs(d - 0.2244) < 0.000001);
-
- r = safe_atod("0,5", &d);
- assert_se(r == -EINVAL);
-
- errno = 0;
- assert_se(fabs(strtod("0,5", &e) - 0.5) < 0.00001);
- }
-
- /* And check again, reset */
- assert_se(setlocale(LC_NUMERIC, "C"));
-
- r = safe_atod("0.2244", &d);
- assert_se(r == 0);
- assert_se(fabs(d - 0.2244) < 0.000001);
-
- r = safe_atod("0,5", &d);
- assert_se(r == -EINVAL);
-
- errno = 0;
- strtod("0,5", &e);
- assert_se(*e == ',');
-}
-
-static void test_strappend(void) {
- _cleanup_free_ char *t1, *t2, *t3, *t4;
-
- t1 = strappend(NULL, NULL);
- assert_se(streq(t1, ""));
-
- t2 = strappend(NULL, "suf");
- assert_se(streq(t2, "suf"));
-
- t3 = strappend("pre", NULL);
- assert_se(streq(t3, "pre"));
-
- 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."));
-}
-
-static void test_delete_chars(void) {
- char *r;
- char input[] = " 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"));
-}
-
-static void test_hexchar(void) {
- assert_se(hexchar(0xa) == 'a');
- assert_se(hexchar(0x0) == '0');
-}
-
-static void test_unhexchar(void) {
- assert_se(unhexchar('a') == 0xA);
- assert_se(unhexchar('A') == 0xA);
- assert_se(unhexchar('0') == 0x0);
-}
-
-static void test_octchar(void) {
- assert_se(octchar(00) == '0');
- assert_se(octchar(07) == '7');
-}
-
-static void test_unoctchar(void) {
- assert_se(unoctchar('0') == 00);
- assert_se(unoctchar('7') == 07);
-}
-
-static void test_decchar(void) {
- assert_se(decchar(0) == '0');
- assert_se(decchar(9) == '9');
-}
-
-static void test_undecchar(void) {
- assert_se(undecchar('0') == 0);
- assert_se(undecchar('9') == 9);
-}
-
-static void test_cescape(void) {
- _cleanup_free_ char *escaped;
-
- assert_se(escaped = cescape("abc\\\"\b\f\n\r\t\v\a\003\177\234\313"));
- assert_se(streq(escaped, "abc\\\\\\\"\\b\\f\\n\\r\\t\\v\\a\\003\\177\\234\\313"));
-}
-
-static void test_cunescape(void) {
- _cleanup_free_ char *unescaped;
-
- unescaped = cunescape("abc\\\\\\\"\\b\\f\\a\\n\\r\\t\\v\\003\\177\\234\\313\\000\\x00");
- assert_se(streq_ptr(unescaped, "abc\\\"\b\f\a\n\r\t\v\003\177\234\313\\000\\x00"));
-
- /* incomplete sequences */
- unescaped = cunescape("\\x0");
- assert_se(streq_ptr(unescaped, "\\x0"));
-
- unescaped = cunescape("\\x");
- assert_se(streq_ptr(unescaped, "\\x"));
-
- unescaped = cunescape("\\");
- assert_se(streq_ptr(unescaped, "\\"));
-
- unescaped = cunescape("\\11");
- assert_se(streq_ptr(unescaped, "\\11"));
-
- unescaped = cunescape("\\1");
- assert_se(streq_ptr(unescaped, "\\1"));
-}
-
-static void test_foreach_word(void) {
- const char *word, *state;
- size_t l;
- int i = 0;
- const char test[] = "test abc d\te f ";
- const char * const expected[] = {
- "test",
- "abc",
- "d",
- "e",
- "f",
- "",
- NULL
- };
-
- FOREACH_WORD(word, l, test, state)
- assert_se(strneq(expected[i++], word, l));
-}
-
-static void check(const char *test, char** expected, bool trailing) {
- const char *word, *state;
- size_t l;
- int i = 0;
-
- printf("<<<%s>>>\n", test);
- FOREACH_WORD_QUOTED(word, l, test, state) {
- _cleanup_free_ char *t = NULL;
-
- assert_se(t = strndup(word, l));
- assert_se(strneq(expected[i++], word, l));
- printf("<%s>\n", t);
- }
- printf("<<<%s>>>\n", state);
- assert_se(expected[i] == NULL);
- assert_se(isempty(state) == !trailing);
-}
-
-static void test_foreach_word_quoted(void) {
- check("test a b c 'd' e '' '' hhh '' '' \"a b c\"",
- STRV_MAKE("test",
- "a",
- "b",
- "c",
- "d",
- "e",
- "",
- "",
- "hhh",
- "",
- "",
- "a b c"),
- false);
-
- check("test \"xxx",
- STRV_MAKE("test"),
- true);
-
- check("test\\",
- STRV_MAKE_EMPTY,
- true);
-}
-
-static void test_default_term_for_tty(void) {
- puts(default_term_for_tty("/dev/tty23"));
- puts(default_term_for_tty("/dev/ttyS23"));
- puts(default_term_for_tty("/dev/tty0"));
- puts(default_term_for_tty("/dev/pty0"));
- puts(default_term_for_tty("/dev/pts/0"));
- puts(default_term_for_tty("/dev/console"));
- puts(default_term_for_tty("tty23"));
- puts(default_term_for_tty("ttyS23"));
- puts(default_term_for_tty("tty0"));
- puts(default_term_for_tty("pty0"));
- puts(default_term_for_tty("pts/0"));
- puts(default_term_for_tty("console"));
-}
-
-static void test_memdup_multiply(void) {
- int org[] = {1, 2, 3};
- int *dup;
-
- dup = (int*)memdup_multiply(org, sizeof(int), 3);
-
- assert_se(dup);
- assert_se(dup[0] == 1);
- assert_se(dup[1] == 2);
- assert_se(dup[2] == 3);
- free(dup);
-}
-
-static void test_hostname_is_valid(void) {
- assert_se(hostname_is_valid("foobar"));
- assert_se(hostname_is_valid("foobar.com"));
- assert_se(!hostname_is_valid("fööbar"));
- assert_se(!hostname_is_valid(""));
- assert_se(!hostname_is_valid("."));
- assert_se(!hostname_is_valid(".."));
- assert_se(!hostname_is_valid("foobar."));
- assert_se(!hostname_is_valid(".foobar"));
- assert_se(!hostname_is_valid("foo..bar"));
- assert_se(!hostname_is_valid("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
-}
-
-static void test_u64log2(void) {
- assert_se(u64log2(0) == 0);
- assert_se(u64log2(8) == 3);
- assert_se(u64log2(9) == 3);
- assert_se(u64log2(15) == 3);
- assert_se(u64log2(16) == 4);
- assert_se(u64log2(1024*1024) == 20);
- assert_se(u64log2(1024*1024+5) == 20);
-}
-
-static void test_get_process_comm(void) {
- struct stat st;
- _cleanup_free_ char *a = NULL, *c = NULL, *d = NULL, *f = NULL, *i = NULL, *cwd = NULL, *root = NULL;
- _cleanup_free_ char *env = NULL;
- pid_t e;
- uid_t u;
- gid_t g;
- dev_t h;
- int r;
- pid_t me;
-
- 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_process_cmdline(1, 0, true, &c) >= 0);
- log_info("pid1 cmdline: '%s'", c);
-
- assert_se(get_process_cmdline(1, 8, false, &d) >= 0);
- log_info("pid1 cmdline truncated: '%s'", d);
-
- assert_se(get_parent_of_pid(1, &e) >= 0);
- log_info("pid1 ppid: "PID_FMT, e);
- assert_se(e == 0);
-
- assert_se(is_kernel_thread(1) == 0);
-
- r = get_process_exe(1, &f);
- assert_se(r >= 0 || r == -EACCES);
- log_info("pid1 exe: '%s'", strna(f));
-
- assert_se(get_process_uid(1, &u) == 0);
- log_info("pid1 uid: "UID_FMT, u);
- assert_se(u == 0);
-
- assert_se(get_process_gid(1, &g) == 0);
- log_info("pid1 gid: "GID_FMT, g);
- assert_se(g == 0);
-
- me = getpid();
-
- r = get_process_cwd(me, &cwd);
- assert_se(r >= 0 || r == -EACCES);
- log_info("pid1 cwd: '%s'", cwd);
-
- r = get_process_root(me, &root);
- assert_se(r >= 0 || r == -EACCES);
- log_info("pid1 root: '%s'", root);
-
- r = get_process_environ(me, &env);
- assert_se(r >= 0 || r == -EACCES);
- log_info("self strlen(environ): '%zu'", strlen(env));
-
- if (!detect_container(NULL))
- assert_se(get_ctty_devnr(1, &h) == -ENOENT);
-
- getenv_for_pid(1, "PATH", &i);
- log_info("pid1 $PATH: '%s'", strna(i));
-}
-
-static void test_protect_errno(void) {
- errno = 12;
- {
- PROTECT_ERRNO;
- errno = 11;
- }
- assert_se(errno == 12);
-}
-
-static void test_parse_size(void) {
- off_t bytes;
-
- assert_se(parse_size("111", 1024, &bytes) == 0);
- assert_se(bytes == 111);
-
- assert_se(parse_size("111.4", 1024, &bytes) == 0);
- assert_se(bytes == 111);
-
- assert_se(parse_size(" 112 B", 1024, &bytes) == 0);
- assert_se(bytes == 112);
-
- assert_se(parse_size(" 112.6 B", 1024, &bytes) == 0);
- assert_se(bytes == 112);
-
- assert_se(parse_size("3.5 K", 1024, &bytes) == 0);
- assert_se(bytes == 3*1024 + 512);
-
- assert_se(parse_size("3. K", 1024, &bytes) == 0);
- assert_se(bytes == 3*1024);
-
- assert_se(parse_size("3.0 K", 1024, &bytes) == 0);
- assert_se(bytes == 3*1024);
-
- assert_se(parse_size("3. 0 K", 1024, &bytes) == -EINVAL);
-
- assert_se(parse_size(" 4 M 11.5K", 1024, &bytes) == 0);
- assert_se(bytes == 4*1024*1024 + 11 * 1024 + 512);
-
- assert_se(parse_size("3B3.5G", 1024, &bytes) == -EINVAL);
-
- assert_se(parse_size("3.5G3B", 1024, &bytes) == 0);
- assert_se(bytes == 3ULL*1024*1024*1024 + 512*1024*1024 + 3);
-
- assert_se(parse_size("3.5G 4B", 1024, &bytes) == 0);
- assert_se(bytes == 3ULL*1024*1024*1024 + 512*1024*1024 + 4);
-
- assert_se(parse_size("3B3G4T", 1024, &bytes) == -EINVAL);
-
- assert_se(parse_size("4T3G3B", 1024, &bytes) == 0);
- assert_se(bytes == (4ULL*1024 + 3)*1024*1024*1024 + 3);
-
- assert_se(parse_size(" 4 T 3 G 3 B", 1024, &bytes) == 0);
- assert_se(bytes == (4ULL*1024 + 3)*1024*1024*1024 + 3);
-
- assert_se(parse_size("12P", 1024, &bytes) == 0);
- assert_se(bytes == 12ULL * 1024*1024*1024*1024*1024);
-
- assert_se(parse_size("12P12P", 1024, &bytes) == -EINVAL);
-
- assert_se(parse_size("3E 2P", 1024, &bytes) == 0);
- assert_se(bytes == (3 * 1024 + 2ULL) * 1024*1024*1024*1024*1024);
-
- assert_se(parse_size("12X", 1024, &bytes) == -EINVAL);
-
- assert_se(parse_size("12.5X", 1024, &bytes) == -EINVAL);
-
- assert_se(parse_size("12.5e3", 1024, &bytes) == -EINVAL);
-
- assert_se(parse_size("1024E", 1024, &bytes) == -ERANGE);
- assert_se(parse_size("-1", 1024, &bytes) == -ERANGE);
- assert_se(parse_size("-1024E", 1024, &bytes) == -ERANGE);
-
- assert_se(parse_size("-1024P", 1024, &bytes) == -ERANGE);
-
- assert_se(parse_size("-10B 20K", 1024, &bytes) == -ERANGE);
-}
-
-static void test_config_parse_iec_off(void) {
- off_t offset = 0;
- assert_se(config_parse_iec_off(NULL, "/this/file", 11, "Section", 22, "Size", 0, "4M", &offset, NULL) == 0);
- assert_se(offset == 4 * 1024 * 1024);
-
- assert_se(config_parse_iec_off(NULL, "/this/file", 11, "Section", 22, "Size", 0, "4.5M", &offset, NULL) == 0);
-}
-
-static void test_strextend(void) {
- _cleanup_free_ char *str = strdup("0123");
- strextend(&str, "456", "78", "9", NULL);
- assert_se(streq(str, "0123456789"));
-}
-
-static void test_strrep(void) {
- _cleanup_free_ char *one, *three, *zero;
- one = strrep("waldo", 1);
- three = strrep("waldo", 3);
- zero = strrep("waldo", 0);
-
- assert_se(streq(one, "waldo"));
- assert_se(streq(three, "waldowaldowaldo"));
- assert_se(streq(zero, ""));
-}
-
-static void test_split_pair(void) {
- _cleanup_free_ char *a = NULL, *b = NULL;
-
- assert_se(split_pair("", "", &a, &b) == -EINVAL);
- assert_se(split_pair("foo=bar", "", &a, &b) == -EINVAL);
- assert_se(split_pair("", "=", &a, &b) == -EINVAL);
- assert_se(split_pair("foo=bar", "=", &a, &b) >= 0);
- assert_se(streq(a, "foo"));
- assert_se(streq(b, "bar"));
- free(a);
- free(b);
- assert_se(split_pair("==", "==", &a, &b) >= 0);
- assert_se(streq(a, ""));
- assert_se(streq(b, ""));
- free(a);
- free(b);
-
- assert_se(split_pair("===", "==", &a, &b) >= 0);
- assert_se(streq(a, ""));
- assert_se(streq(b, "="));
-}
-
-static void test_fstab_node_to_udev_node(void) {
- char *n;
-
- n = fstab_node_to_udev_node("LABEL=applé/jack");
- puts(n);
- assert_se(streq(n, "/dev/disk/by-label/applé\\x2fjack"));
- free(n);
-
- n = fstab_node_to_udev_node("PARTLABEL=pinkié pie");
- puts(n);
- assert_se(streq(n, "/dev/disk/by-partlabel/pinkié\\x20pie"));
- free(n);
-
- n = fstab_node_to_udev_node("UUID=037b9d94-148e-4ee4-8d38-67bfe15bb535");
- puts(n);
- assert_se(streq(n, "/dev/disk/by-uuid/037b9d94-148e-4ee4-8d38-67bfe15bb535"));
- free(n);
-
- n = fstab_node_to_udev_node("PARTUUID=037b9d94-148e-4ee4-8d38-67bfe15bb535");
- puts(n);
- assert_se(streq(n, "/dev/disk/by-partuuid/037b9d94-148e-4ee4-8d38-67bfe15bb535"));
- free(n);
-
- n = fstab_node_to_udev_node("PONIES=awesome");
- puts(n);
- assert_se(streq(n, "PONIES=awesome"));
- free(n);
-
- n = fstab_node_to_udev_node("/dev/xda1");
- puts(n);
- assert_se(streq(n, "/dev/xda1"));
- free(n);
-}
-
-static void test_get_files_in_directory(void) {
- _cleanup_strv_free_ char **l = NULL, **t = NULL;
-
- assert_se(get_files_in_directory("/tmp", &l) >= 0);
- assert_se(get_files_in_directory(".", &t) >= 0);
- assert_se(get_files_in_directory(".", NULL) >= 0);
-}
-
-static void test_in_set(void) {
- assert_se(IN_SET(1, 1));
- assert_se(IN_SET(1, 1, 2, 3, 4));
- assert_se(IN_SET(2, 1, 2, 3, 4));
- assert_se(IN_SET(3, 1, 2, 3, 4));
- assert_se(IN_SET(4, 1, 2, 3, 4));
- assert_se(!IN_SET(0, 1));
- assert_se(!IN_SET(0, 1, 2, 3, 4));
-}
-
-static void test_writing_tmpfile(void) {
- char name[] = "/tmp/test-systemd_writing_tmpfile.XXXXXX";
- _cleanup_free_ char *contents = NULL;
- size_t size;
- int fd, r;
- struct iovec iov[3];
-
- IOVEC_SET_STRING(iov[0], "abc\n");
- IOVEC_SET_STRING(iov[1], ALPHANUMERICAL "\n");
- IOVEC_SET_STRING(iov[2], "");
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- printf("tmpfile: %s", name);
-
- r = writev(fd, iov, 3);
- assert_se(r >= 0);
-
- r = read_full_file(name, &contents, &size);
- assert_se(r == 0);
- printf("contents: %s", contents);
- assert_se(streq(contents, "abc\n" ALPHANUMERICAL "\n"));
-
- unlink(name);
-}
-
-static void test_hexdump(void) {
- uint8_t data[146];
- unsigned i;
-
- hexdump(stdout, NULL, 0);
- hexdump(stdout, "", 0);
- hexdump(stdout, "", 1);
- hexdump(stdout, "x", 1);
- hexdump(stdout, "x", 2);
- hexdump(stdout, "foobar", 7);
- hexdump(stdout, "f\nobar", 7);
- hexdump(stdout, "xxxxxxxxxxxxxxxxxxxxyz", 23);
-
- for (i = 0; i < ELEMENTSOF(data); i++)
- data[i] = i*2;
-
- hexdump(stdout, data, sizeof(data));
-}
-
-static void test_log2i(void) {
- assert_se(log2i(1) == 0);
- assert_se(log2i(2) == 1);
- assert_se(log2i(3) == 1);
- assert_se(log2i(4) == 2);
- assert_se(log2i(32) == 5);
- assert_se(log2i(33) == 5);
- assert_se(log2i(63) == 5);
- assert_se(log2i(INT_MAX) == sizeof(int)*8-2);
-}
-
-static void test_foreach_string(void) {
- const char * const t[] = {
- "foo",
- "bar",
- "waldo",
- NULL
- };
- const char *x;
- unsigned i = 0;
-
- FOREACH_STRING(x, "foo", "bar", "waldo")
- assert_se(streq_ptr(t[i++], x));
-
- assert_se(i == 3);
-
- FOREACH_STRING(x, "zzz")
- assert_se(streq(x, "zzz"));
-}
-
-static void test_filename_is_valid(void) {
- char foo[FILENAME_MAX+2];
- int i;
-
- assert_se(!filename_is_valid(""));
- assert_se(!filename_is_valid("/bar/foo"));
- assert_se(!filename_is_valid("/"));
- assert_se(!filename_is_valid("."));
- assert_se(!filename_is_valid(".."));
-
- for (i=0; i<FILENAME_MAX+1; i++)
- foo[i] = 'a';
- foo[FILENAME_MAX+1] = '\0';
-
- assert_se(!filename_is_valid(foo));
-
- assert_se(filename_is_valid("foo_bar-333"));
- assert_se(filename_is_valid("o.o"));
-}
-
-static void test_string_has_cc(void) {
- assert_se(string_has_cc("abc\1", NULL));
- assert_se(string_has_cc("abc\x7f", NULL));
- assert_se(string_has_cc("abc\x7f", NULL));
- assert_se(string_has_cc("abc\t\x7f", "\t"));
- assert_se(string_has_cc("abc\t\x7f", "\t"));
- assert_se(string_has_cc("\x7f", "\t"));
- assert_se(string_has_cc("\x7f", "\t\a"));
-
- assert_se(!string_has_cc("abc\t\t", "\t"));
- assert_se(!string_has_cc("abc\t\t\a", "\t\a"));
- assert_se(!string_has_cc("a\ab\tc", "\t\a"));
-}
-
-static void test_ascii_strlower(void) {
- char a[] = "AabBcC Jk Ii Od LKJJJ kkd LK";
- assert_se(streq(ascii_strlower(a), "aabbcc jk ii od lkjjj kkd lk"));
-}
-
-static void test_files_same(void) {
- _cleanup_close_ int fd = -1;
- char name[] = "/tmp/test-files_same.XXXXXX";
- char name_alias[] = "/tmp/test-files_same.alias";
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- assert_se(symlink(name, name_alias) >= 0);
-
- assert_se(files_same(name, name));
- assert_se(files_same(name, name_alias));
-
- unlink(name);
- unlink(name_alias);
-}
-
-static void test_is_valid_documentation_url(void) {
- assert_se(documentation_url_is_valid("http://www.freedesktop.org/wiki/Software/systemd"));
- assert_se(documentation_url_is_valid("https://www.kernel.org/doc/Documentation/binfmt_misc.txt"));
- assert_se(documentation_url_is_valid("file:/foo/foo"));
- assert_se(documentation_url_is_valid("man:systemd.special(7)"));
- assert_se(documentation_url_is_valid("info:bar"));
-
- assert_se(!documentation_url_is_valid("foo:"));
- assert_se(!documentation_url_is_valid("info:"));
- assert_se(!documentation_url_is_valid(""));
-}
-
-static void test_file_in_same_dir(void) {
- char *t;
-
- t = file_in_same_dir("/", "a");
- assert_se(streq(t, "/a"));
- free(t);
-
- t = file_in_same_dir("/", "/a");
- assert_se(streq(t, "/a"));
- free(t);
-
- t = file_in_same_dir("", "a");
- assert_se(streq(t, "a"));
- free(t);
-
- t = file_in_same_dir("a/", "a");
- assert_se(streq(t, "a/a"));
- free(t);
-
- t = file_in_same_dir("bar/foo", "bar");
- assert_se(streq(t, "bar/bar"));
- free(t);
-}
-
-static void test_endswith(void) {
- assert_se(endswith("foobar", "bar"));
- assert_se(endswith("foobar", ""));
- assert_se(endswith("foobar", "foobar"));
- assert_se(endswith("", ""));
-
- assert_se(!endswith("foobar", "foo"));
- assert_se(!endswith("foobar", "foobarfoofoo"));
-}
-
-static void test_close_nointr(void) {
- char name[] = "/tmp/test-test-close_nointr.XXXXXX";
- int fd;
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- assert_se(close_nointr(fd) >= 0);
- assert_se(close_nointr(fd) < 0);
-
- unlink(name);
-}
-
-
-static void test_unlink_noerrno(void) {
- char name[] = "/tmp/test-close_nointr.XXXXXX";
- int fd;
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- assert_se(close_nointr(fd) >= 0);
-
- {
- PROTECT_ERRNO;
- errno = -42;
- assert_se(unlink_noerrno(name) >= 0);
- assert_se(errno == -42);
- assert_se(unlink_noerrno(name) < 0);
- assert_se(errno == -42);
- }
-}
-
-static void test_readlink_and_make_absolute(void) {
- char tempdir[] = "/tmp/test-readlink_and_make_absolute";
- char name[] = "/tmp/test-readlink_and_make_absolute/original";
- char name2[] = "test-readlink_and_make_absolute/original";
- char name_alias[] = "/tmp/test-readlink_and_make_absolute-alias";
- char *r = NULL;
-
- assert_se(mkdir_safe(tempdir, 0755, getuid(), getgid()) >= 0);
- assert_se(touch(name) >= 0);
-
- assert_se(symlink(name, name_alias) >= 0);
- assert_se(readlink_and_make_absolute(name_alias, &r) >= 0);
- assert_se(streq(r, name));
- free(r);
- assert_se(unlink(name_alias) >= 0);
-
- assert_se(chdir(tempdir) >= 0);
- assert_se(symlink(name2, name_alias) >= 0);
- assert_se(readlink_and_make_absolute(name_alias, &r) >= 0);
- assert_se(streq(r, name));
- free(r);
- assert_se(unlink(name_alias) >= 0);
-
- assert_se(rm_rf_dangerous(tempdir, false, true, false) >= 0);
-}
-
-static void test_read_one_char(void) {
- _cleanup_fclose_ FILE *file = NULL;
- char r;
- bool need_nl;
- char name[] = "/tmp/test-read_one_char.XXXXXX";
- int fd;
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- file = fdopen(fd, "r+");
- assert_se(file);
- assert_se(fputs("c\n", file) >= 0);
- rewind(file);
-
- assert_se(read_one_char(file, &r, 1000000, &need_nl) >= 0);
- assert_se(!need_nl);
- assert_se(r == 'c');
- assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0);
-
- rewind(file);
- assert_se(fputs("foobar\n", file) >= 0);
- rewind(file);
- assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0);
-
- rewind(file);
- assert_se(fputs("\n", file) >= 0);
- rewind(file);
- assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0);
-
- unlink(name);
-}
-
-static void test_ignore_signals(void) {
- assert_se(ignore_signals(SIGINT, -1) >= 0);
- assert_se(kill(getpid(), SIGINT) >= 0);
- assert_se(ignore_signals(SIGUSR1, SIGUSR2, SIGTERM, SIGPIPE, -1) >= 0);
- assert_se(kill(getpid(), SIGUSR1) >= 0);
- assert_se(kill(getpid(), SIGUSR2) >= 0);
- assert_se(kill(getpid(), SIGTERM) >= 0);
- assert_se(kill(getpid(), SIGPIPE) >= 0);
- assert_se(default_signals(SIGINT, SIGUSR1, SIGUSR2, SIGTERM, SIGPIPE, -1) >= 0);
-}
-
-static void test_strshorten(void) {
- char s[] = "foobar";
-
- assert_se(strlen(strshorten(s, 6)) == 6);
- assert_se(strlen(strshorten(s, 12)) == 6);
- assert_se(strlen(strshorten(s, 2)) == 2);
- assert_se(strlen(strshorten(s, 0)) == 0);
-}
-
-static void test_strjoina(void) {
- char *actual;
-
- actual = strjoina("", "foo", "bar");
- assert_se(streq(actual, "foobar"));
-
- actual = strjoina("foo", "bar", "baz");
- assert_se(streq(actual, "foobarbaz"));
-
- actual = strjoina("foo", "", "bar", "baz");
- assert_se(streq(actual, "foobarbaz"));
-
- actual = strjoina("foo");
- assert_se(streq(actual, "foo"));
-
- actual = strjoina(NULL);
- assert_se(streq(actual, ""));
-
- actual = strjoina(NULL, "foo");
- assert_se(streq(actual, ""));
-
- actual = strjoina("foo", NULL, "bar");
- assert_se(streq(actual, "foo"));
-}
-
-static void test_is_symlink(void) {
- char name[] = "/tmp/test-is_symlink.XXXXXX";
- char name_link[] = "/tmp/test-is_symlink.link";
- _cleanup_close_ int fd = -1;
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- assert_se(symlink(name, name_link) >= 0);
-
- assert_se(is_symlink(name) == 0);
- assert_se(is_symlink(name_link) == 1);
- assert_se(is_symlink("/a/file/which/does/not/exist/i/guess") < 0);
-
-
- unlink(name);
- unlink(name_link);
-}
-
-static void test_pid_is_unwaited(void) {
- pid_t pid;
-
- pid = fork();
- assert_se(pid >= 0);
- if (pid == 0) {
- _exit(EXIT_SUCCESS);
- } else {
- int status;
-
- waitpid(pid, &status, 0);
- assert_se(!pid_is_unwaited(pid));
- }
- assert_se(pid_is_unwaited(getpid()));
- assert_se(!pid_is_unwaited(-1));
-}
-
-static void test_pid_is_alive(void) {
- pid_t pid;
-
- pid = fork();
- assert_se(pid >= 0);
- if (pid == 0) {
- _exit(EXIT_SUCCESS);
- } else {
- int status;
-
- waitpid(pid, &status, 0);
- assert_se(!pid_is_alive(pid));
- }
- assert_se(pid_is_alive(getpid()));
- assert_se(!pid_is_alive(-1));
-}
-
-static void test_search_and_fopen(void) {
- const char *dirs[] = {"/tmp/foo/bar", "/tmp", NULL};
- char name[] = "/tmp/test-search_and_fopen.XXXXXX";
- int fd = -1;
- int r;
- FILE *f;
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- close(fd);
-
- r = search_and_fopen(basename(name), "r", NULL, dirs, &f);
- assert_se(r >= 0);
- fclose(f);
-
- r = search_and_fopen(name, "r", NULL, dirs, &f);
- assert_se(r >= 0);
- fclose(f);
-
- r = search_and_fopen(basename(name), "r", "/", dirs, &f);
- assert_se(r >= 0);
- fclose(f);
-
- r = search_and_fopen("/a/file/which/does/not/exist/i/guess", "r", NULL, dirs, &f);
- assert_se(r < 0);
- r = search_and_fopen("afilewhichdoesnotexistiguess", "r", NULL, dirs, &f);
- assert_se(r < 0);
-
- r = unlink(name);
- assert_se(r == 0);
-
- r = search_and_fopen(basename(name), "r", NULL, dirs, &f);
- assert_se(r < 0);
-}
-
-
-static void test_search_and_fopen_nulstr(void) {
- const char dirs[] = "/tmp/foo/bar\0/tmp\0";
- char name[] = "/tmp/test-search_and_fopen.XXXXXX";
- int fd = -1;
- int r;
- FILE *f;
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- close(fd);
-
- r = search_and_fopen_nulstr(basename(name), "r", NULL, dirs, &f);
- assert_se(r >= 0);
- fclose(f);
-
- r = search_and_fopen_nulstr(name, "r", NULL, dirs, &f);
- assert_se(r >= 0);
- fclose(f);
-
- r = search_and_fopen_nulstr("/a/file/which/does/not/exist/i/guess", "r", NULL, dirs, &f);
- assert_se(r < 0);
- r = search_and_fopen_nulstr("afilewhichdoesnotexistiguess", "r", NULL, dirs, &f);
- assert_se(r < 0);
-
- r = unlink(name);
- assert_se(r == 0);
-
- r = search_and_fopen_nulstr(basename(name), "r", NULL, dirs, &f);
- assert_se(r < 0);
-}
-
-static void test_glob_exists(void) {
- char name[] = "/tmp/test-glob_exists.XXXXXX";
- int fd = -1;
- int r;
-
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- close(fd);
-
- r = glob_exists("/tmp/test-glob_exists*");
- assert_se(r == 1);
-
- r = unlink(name);
- assert_se(r == 0);
- r = glob_exists("/tmp/test-glob_exists*");
- assert_se(r == 0);
-}
-
-static void test_execute_directory(void) {
- char template_lo[] = "/tmp/test-readlink_and_make_absolute-lo.XXXXXXX";
- char template_hi[] = "/tmp/test-readlink_and_make_absolute-hi.XXXXXXX";
- const char * dirs[] = {template_hi, template_lo, NULL};
- const char *name, *name2, *name3, *overridden, *override, *masked, *mask;
-
- assert_se(mkdtemp(template_lo));
- assert_se(mkdtemp(template_hi));
-
- name = strjoina(template_lo, "/script");
- name2 = strjoina(template_hi, "/script2");
- name3 = strjoina(template_lo, "/useless");
- overridden = strjoina(template_lo, "/overridden");
- override = strjoina(template_hi, "/overridden");
- masked = strjoina(template_lo, "/masked");
- mask = strjoina(template_hi, "/masked");
-
- assert_se(write_string_file(name, "#!/bin/sh\necho 'Executing '$0\ntouch $(dirname $0)/it_works") == 0);
- assert_se(write_string_file(name2, "#!/bin/sh\necho 'Executing '$0\ntouch $(dirname $0)/it_works2") == 0);
- assert_se(write_string_file(overridden, "#!/bin/sh\necho 'Executing '$0\ntouch $(dirname $0)/failed") == 0);
- assert_se(write_string_file(override, "#!/bin/sh\necho 'Executing '$0") == 0);
- assert_se(write_string_file(masked, "#!/bin/sh\necho 'Executing '$0\ntouch $(dirname $0)/failed") == 0);
- assert_se(symlink("/dev/null", mask) == 0);
- assert_se(chmod(name, 0755) == 0);
- assert_se(chmod(name2, 0755) == 0);
- assert_se(chmod(overridden, 0755) == 0);
- assert_se(chmod(override, 0755) == 0);
- assert_se(chmod(masked, 0755) == 0);
- assert_se(touch(name3) >= 0);
-
- execute_directories(dirs, DEFAULT_TIMEOUT_USEC, NULL);
-
- assert_se(chdir(template_lo) == 0);
- assert_se(access("it_works", F_OK) >= 0);
- assert_se(access("failed", F_OK) < 0);
-
- assert_se(chdir(template_hi) == 0);
- assert_se(access("it_works2", F_OK) >= 0);
- assert_se(access("failed", F_OK) < 0);
-
- rm_rf_dangerous(template_lo, false, true, false);
- rm_rf_dangerous(template_hi, false, true, false);
-}
-
-static void test_unquote_first_word(void) {
- const char *p, *original;
- char *t;
-
- p = original = "foobar waldo";
- assert_se(unquote_first_word(&p, &t, 0) > 0);
- assert_se(streq(t, "foobar"));
- free(t);
- assert_se(p == original + 7);
-
- assert_se(unquote_first_word(&p, &t, 0) > 0);
- assert_se(streq(t, "waldo"));
- free(t);
- assert_se(p == original + 12);
-
- assert_se(unquote_first_word(&p, &t, 0) == 0);
- assert_se(!t);
- assert_se(p == original + 12);
-
- p = original = "\"foobar\" \'waldo\'";
- assert_se(unquote_first_word(&p, &t, 0) > 0);
- assert_se(streq(t, "foobar"));
- free(t);
- assert_se(p == original + 9);
-
- assert_se(unquote_first_word(&p, &t, 0) > 0);
- assert_se(streq(t, "waldo"));
- free(t);
- assert_se(p == original + 16);
-
- assert_se(unquote_first_word(&p, &t, 0) == 0);
- assert_se(!t);
- assert_se(p == original + 16);
-
- p = original = "\"";
- assert_se(unquote_first_word(&p, &t, 0) == -EINVAL);
- assert_se(p == original + 1);
-
- p = original = "\'";
- assert_se(unquote_first_word(&p, &t, 0) == -EINVAL);
- assert_se(p == original + 1);
-
- p = original = "\'fooo";
- assert_se(unquote_first_word(&p, &t, 0) == -EINVAL);
- assert_se(p == original + 5);
-
- p = original = "\'fooo";
- assert_se(unquote_first_word(&p, &t, UNQUOTE_RELAX) > 0);
- assert_se(streq(t, "fooo"));
- free(t);
- assert_se(p == original + 5);
-
- p = original = "yay\'foo\'bar";
- assert_se(unquote_first_word(&p, &t, 0) > 0);
- assert_se(streq(t, "yayfoobar"));
- free(t);
- assert_se(p == original + 11);
-
- p = original = " foobar ";
- assert_se(unquote_first_word(&p, &t, 0) > 0);
- assert_se(streq(t, "foobar"));
- free(t);
- assert_se(p == original + 12);
-
- p = original = " foo\\ba\\x6ar ";
- assert_se(unquote_first_word(&p, &t, UNQUOTE_CUNESCAPE) > 0);
- assert_se(streq(t, "foo\ba\x6ar"));
- free(t);
- assert_se(p == original + 13);
-
- p = original = " foo\\ba\\x6ar ";
- assert_se(unquote_first_word(&p, &t, 0) > 0);
- assert_se(streq(t, "foobax6ar"));
- free(t);
- assert_se(p == original + 13);
-}
-
-static void test_unquote_many_words(void) {
- const char *p, *original;
- char *a, *b, *c;
-
- p = original = "foobar waldi piep";
- assert_se(unquote_many_words(&p, 0, &a, &b, &c, NULL) == 3);
- assert_se(p == original + 17);
- assert_se(streq_ptr(a, "foobar"));
- assert_se(streq_ptr(b, "waldi"));
- assert_se(streq_ptr(c, "piep"));
- free(a);
- free(b);
- free(c);
-
- p = original = "'foobar' wa\"ld\"i ";
- assert_se(unquote_many_words(&p, 0, &a, &b, &c, NULL) == 2);
- assert_se(p == original + 19);
- assert_se(streq_ptr(a, "foobar"));
- assert_se(streq_ptr(b, "waldi"));
- assert_se(streq_ptr(c, NULL));
- free(a);
- free(b);
-
- p = original = "";
- assert_se(unquote_many_words(&p, 0, &a, &b, &c, NULL) == 0);
- assert_se(p == original);
- assert_se(streq_ptr(a, NULL));
- assert_se(streq_ptr(b, NULL));
- assert_se(streq_ptr(c, NULL));
-
- p = original = " ";
- assert_se(unquote_many_words(&p, 0, &a, &b, &c, NULL) == 0);
- assert_se(p == original+2);
- assert_se(streq_ptr(a, NULL));
- assert_se(streq_ptr(b, NULL));
- assert_se(streq_ptr(c, NULL));
-
- p = original = "foobar";
- assert_se(unquote_many_words(&p, 0, NULL) == 0);
- assert_se(p == original);
-
- p = original = "foobar waldi";
- assert_se(unquote_many_words(&p, 0, &a, NULL) == 1);
- assert_se(p == original+7);
- assert_se(streq_ptr(a, "foobar"));
- free(a);
-
- p = original = " foobar ";
- assert_se(unquote_many_words(&p, 0, &a, NULL) == 1);
- assert_se(p == original+15);
- assert_se(streq_ptr(a, "foobar"));
- free(a);
-}
-
-static int parse_item(const char *key, const char *value) {
- assert_se(key);
-
- log_info("kernel cmdline option <%s> = <%s>", key, strna(value));
- return 0;
-}
-
-static void test_parse_proc_cmdline(void) {
- assert_se(parse_proc_cmdline(parse_item) >= 0);
-}
-
-static void test_raw_clone(void) {
- pid_t parent, pid, pid2;
-
- parent = getpid();
- log_info("before clone: getpid()→"PID_FMT, parent);
- assert_se(raw_getpid() == parent);
-
- pid = raw_clone(0, NULL);
- assert_se(pid >= 0);
-
- pid2 = raw_getpid();
- log_info("raw_clone: "PID_FMT" getpid()→"PID_FMT" raw_getpid()→"PID_FMT,
- pid, getpid(), pid2);
- if (pid == 0) {
- assert_se(pid2 != parent);
- _exit(EXIT_SUCCESS);
- } else {
- int status;
-
- assert_se(pid2 == parent);
- waitpid(pid, &status, __WCLONE);
- assert_se(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS);
- }
-}
-
-static void test_same_fd(void) {
- _cleanup_close_pair_ int p[2] = { -1, -1 };
- _cleanup_close_ int a = -1, b = -1, c = -1;
-
- assert_se(pipe2(p, O_CLOEXEC) >= 0);
- assert_se((a = dup(p[0])) >= 0);
- assert_se((b = open("/dev/null", O_RDONLY|O_CLOEXEC)) >= 0);
- assert_se((c = dup(a)) >= 0);
-
- assert_se(same_fd(p[0], p[0]) > 0);
- assert_se(same_fd(p[1], p[1]) > 0);
- assert_se(same_fd(a, a) > 0);
- assert_se(same_fd(b, b) > 0);
-
- assert_se(same_fd(a, p[0]) > 0);
- assert_se(same_fd(p[0], a) > 0);
- assert_se(same_fd(c, p[0]) > 0);
- assert_se(same_fd(p[0], c) > 0);
- assert_se(same_fd(a, c) > 0);
- assert_se(same_fd(c, a) > 0);
-
- assert_se(same_fd(p[0], p[1]) == 0);
- assert_se(same_fd(p[1], p[0]) == 0);
- assert_se(same_fd(p[0], b) == 0);
- assert_se(same_fd(b, p[0]) == 0);
- assert_se(same_fd(p[1], a) == 0);
- assert_se(same_fd(a, p[1]) == 0);
- assert_se(same_fd(p[1], b) == 0);
- assert_se(same_fd(b, p[1]) == 0);
-
- assert_se(same_fd(a, b) == 0);
- assert_se(same_fd(b, a) == 0);
-}
-
-static void test_uid_ptr(void) {
-
- assert_se(UID_TO_PTR(0) != NULL);
- assert_se(UID_TO_PTR(1000) != NULL);
-
- assert_se(PTR_TO_UID(UID_TO_PTR(0)) == 0);
- assert_se(PTR_TO_UID(UID_TO_PTR(1000)) == 1000);
-}
-
-static void test_sparse_write_one(int fd, const char *buffer, size_t n) {
- char check[n];
-
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(ftruncate(fd, 0) >= 0);
- assert_se(sparse_write(fd, buffer, n, 4) == (ssize_t) n);
-
- assert_se(lseek(fd, 0, SEEK_CUR) == (off_t) n);
- assert_se(ftruncate(fd, n) >= 0);
-
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(read(fd, check, n) == (ssize_t) n);
-
- assert_se(memcmp(buffer, check, n) == 0);
-}
-
-static void test_sparse_write(void) {
- const char test_a[] = "test";
- const char test_b[] = "\0\0\0\0test\0\0\0\0";
- const char test_c[] = "\0\0test\0\0\0\0";
- const char test_d[] = "\0\0test\0\0\0test\0\0\0\0test\0\0\0\0\0test\0\0\0test\0\0\0\0test\0\0\0\0\0\0\0\0";
- const char test_e[] = "test\0\0\0\0test";
- _cleanup_close_ int fd = -1;
- char fn[] = "/tmp/sparseXXXXXX";
-
- fd = mkostemp(fn, O_CLOEXEC);
- assert_se(fd >= 0);
- unlink(fn);
-
- test_sparse_write_one(fd, test_a, sizeof(test_a));
- test_sparse_write_one(fd, test_b, sizeof(test_b));
- test_sparse_write_one(fd, test_c, sizeof(test_c));
- test_sparse_write_one(fd, test_d, sizeof(test_d));
- test_sparse_write_one(fd, test_e, sizeof(test_e));
-}
-
-int main(int argc, char *argv[]) {
- log_parse_environment();
- log_open();
-
- test_streq_ptr();
- test_align_power2();
- test_max();
- test_container_of();
- test_alloca();
- test_div_round_up();
- test_first_word();
- test_close_many();
- test_parse_boolean();
- test_parse_pid();
- test_parse_uid();
- test_safe_atolli();
- test_safe_atod();
- test_strappend();
- test_strstrip();
- test_delete_chars();
- test_in_charset();
- test_hexchar();
- test_unhexchar();
- test_octchar();
- test_unoctchar();
- test_decchar();
- test_undecchar();
- test_cescape();
- test_cunescape();
- test_foreach_word();
- test_foreach_word_quoted();
- test_default_term_for_tty();
- test_memdup_multiply();
- test_hostname_is_valid();
- test_u64log2();
- test_get_process_comm();
- test_protect_errno();
- test_parse_size();
- test_config_parse_iec_off();
- test_strextend();
- test_strrep();
- test_split_pair();
- test_fstab_node_to_udev_node();
- test_get_files_in_directory();
- test_in_set();
- test_writing_tmpfile();
- test_hexdump();
- test_log2i();
- test_foreach_string();
- test_filename_is_valid();
- test_string_has_cc();
- test_ascii_strlower();
- test_files_same();
- test_is_valid_documentation_url();
- test_file_in_same_dir();
- test_endswith();
- test_close_nointr();
- test_unlink_noerrno();
- test_readlink_and_make_absolute();
- test_read_one_char();
- test_ignore_signals();
- test_strshorten();
- test_strjoina();
- test_is_symlink();
- test_pid_is_unwaited();
- test_pid_is_alive();
- test_search_and_fopen();
- test_search_and_fopen_nulstr();
- test_glob_exists();
- test_execute_directory();
- test_unquote_first_word();
- test_unquote_many_words();
- test_parse_proc_cmdline();
- test_raw_clone();
- test_same_fd();
- test_uid_ptr();
- test_sparse_write();
-
- return 0;
-}
diff --git a/src/test/test-verbs.c b/src/test/test-verbs.c
deleted file mode 100644
index 0fcdd9e78d..0000000000
--- a/src/test/test-verbs.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/***
- This file is part of systemd.
-
- Copyright 2014 systemd developers
-
- 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 "macro.h"
-#include "strv.h"
-#include "verbs.h"
-
-static int noop_dispatcher(int argc, char *argv[], void *userdata) {
- return 0;
-}
-
-#define test_dispatch_one(argv, verbs, expected) \
- optind = 0; \
- assert_se(dispatch_verb(strv_length(argv), argv, verbs, NULL) == expected);
-
-static void test_verbs(void) {
- static const Verb verbs[] = {
- { "help", VERB_ANY, VERB_ANY, 0, noop_dispatcher },
- { "list-images", VERB_ANY, 1, 0, noop_dispatcher },
- { "list", VERB_ANY, 2, VERB_DEFAULT, noop_dispatcher },
- { "status", 2, VERB_ANY, 0, noop_dispatcher },
- { "show", VERB_ANY, VERB_ANY, 0, noop_dispatcher },
- { "terminate", 2, VERB_ANY, 0, noop_dispatcher },
- { "login", 2, 2, 0, noop_dispatcher },
- { "copy-to", 3, 4, 0, noop_dispatcher },
- {}
- };
-
- /* not found */
- test_dispatch_one(STRV_MAKE("command-not-found"), verbs, -EINVAL);
-
- /* found */
- test_dispatch_one(STRV_MAKE("show"), verbs, 0);
-
- /* found, too few args */
- test_dispatch_one(STRV_MAKE("copy-to", "foo"), verbs, -EINVAL);
-
- /* found, meets min args */
- test_dispatch_one(STRV_MAKE("status", "foo", "bar"), verbs, 0);
-
- /* found, too many args */
- test_dispatch_one(STRV_MAKE("copy-to", "foo", "bar", "baz", "quux", "qaax"), verbs, -EINVAL);
-
- /* no verb, but a default is set */
- test_dispatch_one(STRV_MAKE_EMPTY, verbs, 0);
-}
-
-static void test_verbs_no_default(void) {
- static const Verb verbs[] = {
- { "help", VERB_ANY, VERB_ANY, 0, noop_dispatcher },
- {},
- };
-
- test_dispatch_one(STRV_MAKE(NULL), verbs, -EINVAL);
-}
-
-int main(int argc, char *argv[]) {
- test_verbs();
- test_verbs_no_default();
-
- return 0;
-}
diff --git a/src/test/test-watchdog.c b/src/test/test-watchdog.c
deleted file mode 100644
index 2e5d0c3aae..0000000000
--- a/src/test/test-watchdog.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2012 Lennart Poettering
-
- 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 <unistd.h>
-
-#include "watchdog.h"
-#include "log.h"
-
-int main(int argc, char *argv[]) {
- usec_t t = 10 * USEC_PER_SEC;
- unsigned i;
- int r;
-
- log_set_max_level(LOG_DEBUG);
- log_parse_environment();
-
- r = watchdog_set_timeout(&t);
- if (r < 0)
- log_warning_errno(r, "Failed to open watchdog: %m");
-
- for (i = 0; i < 5; i++) {
- log_info("Pinging...");
- r = watchdog_ping();
- if (r < 0)
- log_warning_errno(r, "Failed to ping watchdog: %m");
-
- usleep(t/2);
- }
-
- watchdog_close(true);
- return 0;
-}
diff --git a/src/test/test-xml.c b/src/test/test-xml.c
deleted file mode 100644
index ea109fbde0..0000000000
--- a/src/test/test-xml.c
+++ /dev/null
@@ -1,83 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 Lennart Poettering
-
- 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 <stdarg.h>
-
-#include "xml.h"
-#include "util.h"
-
-static void test_one(const char *data, ...) {
- void *state = NULL;
- va_list ap;
-
- va_start(ap, data);
-
- for (;;) {
- _cleanup_free_ char *name = NULL;
- int t, tt;
- const char *nn;
-
- t = xml_tokenize(&data, &name, &state, NULL);
- assert_se(t >= 0);
-
- tt = va_arg(ap, int);
- assert_se(tt >= 0);
-
- assert_se(t == tt);
- if (t == XML_END)
- break;
-
- nn = va_arg(ap, const char *);
- assert_se(streq_ptr(nn, name));
- }
-
- va_end(ap);
-}
-
-int main(int argc, char *argv[]) {
-
- test_one("", XML_END);
-
- test_one("<foo></foo>",
- XML_TAG_OPEN, "foo",
- XML_TAG_CLOSE, "foo",
- XML_END);
-
- test_one("<foo waldo=piep meh=\"huhu\"/>",
- XML_TAG_OPEN, "foo",
- XML_ATTRIBUTE_NAME, "waldo",
- XML_ATTRIBUTE_VALUE, "piep",
- XML_ATTRIBUTE_NAME, "meh",
- XML_ATTRIBUTE_VALUE, "huhu",
- XML_TAG_CLOSE_EMPTY, NULL,
- XML_END);
-
- test_one("xxxx\n"
- "<foo><?xml foo?> <!-- zzzz --> </foo>",
- XML_TEXT, "xxxx\n",
- XML_TAG_OPEN, "foo",
- XML_TEXT, " ",
- XML_TEXT, " ",
- XML_TAG_CLOSE, "foo",
- XML_END);
-
- return 0;
-}