From 5e2c93666f2590614214a33027002b431ebafebc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 31 Dec 2011 13:48:35 +0100 Subject: test: rename test directory --- test/Makefile | 7 +++++++ test/a.service | 7 +++++++ test/b.service | 6 ++++++ test/c.service | 6 ++++++ test/d.service | 8 ++++++++ test/e.service | 8 ++++++++ test/f.service | 5 +++++ test/g.service | 6 ++++++ test/h.service | 6 ++++++ 9 files changed, 59 insertions(+) create mode 100644 test/Makefile create mode 100644 test/a.service create mode 100644 test/b.service create mode 100644 test/c.service create mode 100644 test/d.service create mode 100644 test/e.service create mode 100644 test/f.service create mode 100644 test/g.service create mode 100644 test/h.service (limited to 'test') diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000000..9aa46b4eb6 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,7 @@ +# Just a little hook script to easy building when in this directory + +all: + $(MAKE) -C .. + +clean: + $(MAKE) -C .. clean diff --git a/test/a.service b/test/a.service new file mode 100644 index 0000000000..4168d2d051 --- /dev/null +++ b/test/a.service @@ -0,0 +1,7 @@ +[Unit] +Description=A +Requires=b.service +Before=b.service + +[Service] +ExecStart=/bin/true diff --git a/test/b.service b/test/b.service new file mode 100644 index 0000000000..e03bae36be --- /dev/null +++ b/test/b.service @@ -0,0 +1,6 @@ +[Unit] +Description=B +Wants=f.service + +[Service] +ExecStart=/bin/true diff --git a/test/c.service b/test/c.service new file mode 100644 index 0000000000..e2f60a8fbf --- /dev/null +++ b/test/c.service @@ -0,0 +1,6 @@ +[Unit] +Description=C +Requires=a.service + +[Service] +ExecStart=/bin/true diff --git a/test/d.service b/test/d.service new file mode 100644 index 0000000000..921fd2ee1b --- /dev/null +++ b/test/d.service @@ -0,0 +1,8 @@ +[Unit] +Description=D:Cyclic +After=b.service +Before=a.service +Requires=a.service + +[Service] +ExecStart=/bin/true diff --git a/test/e.service b/test/e.service new file mode 100644 index 0000000000..5ba98c7c43 --- /dev/null +++ b/test/e.service @@ -0,0 +1,8 @@ +[Unit] +Description=E:Cyclic +After=b.service +Before=a.service +Wants=a.service + +[Service] +ExecStart=/bin/true diff --git a/test/f.service b/test/f.service new file mode 100644 index 0000000000..7dde681c17 --- /dev/null +++ b/test/f.service @@ -0,0 +1,5 @@ +[Unit] +Description=F + +[Service] +ExecStart=/bin/true diff --git a/test/g.service b/test/g.service new file mode 100644 index 0000000000..cbfa82a454 --- /dev/null +++ b/test/g.service @@ -0,0 +1,6 @@ +[Unit] +Description=G +Conflicts=e.service + +[Service] +ExecStart=/bin/true diff --git a/test/h.service b/test/h.service new file mode 100644 index 0000000000..74a7751cad --- /dev/null +++ b/test/h.service @@ -0,0 +1,6 @@ +[Unit] +Description=H +Wants=g.service + +[Service] +ExecStart=/bin/true -- cgit v1.2.3-54-g00ecf From 6af684ee5cf49f3d0fef16369c3c2782c8a73357 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Thu, 12 Apr 2012 13:17:41 +0200 Subject: move a couple of test-*.c to test/ --- Makefile.am | 24 ++--- src/test-cgroup.c | 104 ------------------- src/test-daemon.c | 37 ------- src/test-engine.c | 99 ------------------ src/test-env-replace.c | 127 ----------------------- src/test-hostname.c | 37 ------- src/test-id128.c | 52 ---------- src/test-install.c | 264 ------------------------------------------------ src/test-job-type.c | 84 --------------- src/test-loopback.c | 37 ------- src/test-ns.c | 60 ----------- src/test-strv.c | 66 ------------ src/test-watchdog.c | 51 ---------- test/test-cgroup.c | 104 +++++++++++++++++++ test/test-daemon.c | 37 +++++++ test/test-engine.c | 99 ++++++++++++++++++ test/test-env-replace.c | 127 +++++++++++++++++++++++ test/test-hostname.c | 37 +++++++ test/test-id128.c | 52 ++++++++++ test/test-install.c | 264 ++++++++++++++++++++++++++++++++++++++++++++++++ test/test-job-type.c | 84 +++++++++++++++ test/test-loopback.c | 37 +++++++ test/test-ns.c | 60 +++++++++++ test/test-strv.c | 66 ++++++++++++ test/test-watchdog.c | 51 ++++++++++ 25 files changed, 1030 insertions(+), 1030 deletions(-) delete mode 100644 src/test-cgroup.c delete mode 100644 src/test-daemon.c delete mode 100644 src/test-engine.c delete mode 100644 src/test-env-replace.c delete mode 100644 src/test-hostname.c delete mode 100644 src/test-id128.c delete mode 100644 src/test-install.c delete mode 100644 src/test-job-type.c delete mode 100644 src/test-loopback.c delete mode 100644 src/test-ns.c delete mode 100644 src/test-strv.c delete mode 100644 src/test-watchdog.c create mode 100644 test/test-cgroup.c create mode 100644 test/test-daemon.c create mode 100644 test/test-engine.c create mode 100644 test/test-env-replace.c create mode 100644 test/test-hostname.c create mode 100644 test/test-id128.c create mode 100644 test/test-install.c create mode 100644 test/test-job-type.c create mode 100644 test/test-loopback.c create mode 100644 test/test-ns.c create mode 100644 test/test-strv.c create mode 100644 test/test-watchdog.c (limited to 'test') diff --git a/Makefile.am b/Makefile.am index 3a1e0422e7..4a12d89b5e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -828,7 +828,7 @@ systemd_LDADD = \ # ------------------------------------------------------------------------------ test_engine_SOURCES = \ - src/test-engine.c + test/test-engine.c test_engine_CFLAGS = \ $(AM_CFLAGS) \ @@ -839,7 +839,7 @@ test_engine_LDADD = \ libsystemd-daemon.la test_job_type_SOURCES = \ - src/test-job-type.c + test/test-job-type.c test_job_type_CFLAGS = \ $(AM_CFLAGS) \ @@ -849,51 +849,51 @@ test_job_type_LDADD = \ libsystemd-core.la test_ns_SOURCES = \ - src/test-ns.c + test/test-ns.c test_ns_LDADD = \ libsystemd-core.la test_loopback_SOURCES = \ - src/test-loopback.c + test/test-loopback.c test_loopback_LDADD = \ libsystemd-shared.la test_hostname_SOURCES = \ - src/test-hostname.c + test/test-hostname.c test_hostname_LDADD = \ libsystemd-shared.la test_daemon_SOURCES = \ - src/test-daemon.c + test/test-daemon.c test_daemon_LDADD = \ libsystemd-shared.la \ libsystemd-daemon.la test_cgroup_SOURCES = \ - src/test-cgroup.c + test/test-cgroup.c test_cgroup_LDADD = \ libsystemd-label.la \ libsystemd-shared.la test_env_replace_SOURCES = \ - src/test-env-replace.c + test/test-env-replace.c test_env_replace_LDADD = \ libsystemd-shared.la test_strv_SOURCES = \ - src/test-strv.c + test/test-strv.c test_strv_LDADD = \ libsystemd-shared.la test_install_SOURCES = \ - src/test-install.c + test/test-install.c test_install_CFLAGS = \ $(AM_CFLAGS) \ @@ -904,7 +904,7 @@ test_install_LDADD = \ libsystemd-shared.la test_watchdog_SOURCES = \ - src/test-watchdog.c + test/test-watchdog.c test_watchdog_LDADD = \ libsystemd-shared.la @@ -1863,7 +1863,7 @@ libsystemd_id128_la_LIBADD = \ libsystemd-shared.la test_id128_SOURCES = \ - src/test-id128.c + test/test-id128.c test_id128_LDADD = \ libsystemd-shared.la \ diff --git a/src/test-cgroup.c b/src/test-cgroup.c deleted file mode 100644 index e742632032..0000000000 --- a/src/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 . -***/ - -#include -#include - -#include "cgroup-util.h" -#include "util.h" -#include "log.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_get_by_pid(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_get_by_pid(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_get_by_pid(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", "/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(streq(c, "foobar")); - assert(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(c == NULL); - assert(streq(p, "/")); - free(p); - - assert_se(cg_split_spec("foo", &c, &p) >= 0); - assert(streq(c, "foo")); - assert(p == NULL); - free(c); - - return 0; -} diff --git a/src/test-daemon.c b/src/test-daemon.c deleted file mode 100644 index 3215f0c560..0000000000 --- a/src/test-daemon.c +++ /dev/null @@ -1,37 +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 . -***/ - -#include - -#include - -int main(int argc, char*argv[]) { - - sd_notify(0, "STATUS=Starting up"); - sleep(5); - sd_notify(0, - "STATUS=Running\n" - "READY=1"); - sleep(10); - sd_notify(0, "STATUS=Quitting"); - - return 0; -} diff --git a/src/test-engine.c b/src/test-engine.c deleted file mode 100644 index 11389a5ac7..0000000000 --- a/src/test-engine.c +++ /dev/null @@ -1,99 +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 . -***/ - -#include -#include -#include -#include - -#include "manager.h" - -int main(int argc, char *argv[]) { - Manager *m = NULL; - Unit *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL, *g = NULL, *h = NULL; - Job *j; - - assert_se(set_unit_path("test") >= 0); - - assert_se(manager_new(MANAGER_SYSTEM, &m) >= 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"); - assert_se(manager_add_job(m, JOB_START, c, JOB_REPLACE, false, NULL, &j) == 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) == -ENOEXEC); - 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) == -EEXIST); - - 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) == -EEXIST); - - 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-env-replace.c b/src/test-env-replace.c deleted file mode 100644 index 4b6b884779..0000000000 --- a/src/test-env-replace.c +++ /dev/null @@ -1,127 +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 . -***/ - -#include -#include - -#include "util.h" -#include "log.h" -#include "strv.h" - -int main(int argc, char *argv[]) { - - 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 - }; - - char **i, **r, *t, **a, **b; - const char nulstr[] = "fuck\0fuck2\0fuck3\0\0fuck5\0\0xxx"; - - a = strv_parse_nulstr(nulstr, sizeof(nulstr)-1); - - STRV_FOREACH(i, a) - printf("nulstr--%s\n", *i); - - strv_free(a); - - r = replace_env_argv((char**) line, (char**) env); - - STRV_FOREACH(i, r) - printf("%s\n", *i); - - strv_free(r); - - t = normalize_env_assignment("foo=bar"); - printf("%s\n", t); - free(t); - - t = normalize_env_assignment("=bar"); - printf("%s\n", t); - free(t); - - t = normalize_env_assignment("foo="); - printf("%s\n", t); - free(t); - - t = normalize_env_assignment("="); - printf("%s\n", t); - free(t); - - t = normalize_env_assignment(""); - printf("%s\n", t); - free(t); - - t = normalize_env_assignment("a=\"waldo\""); - printf("%s\n", t); - free(t); - - t = normalize_env_assignment("a=\"waldo"); - printf("%s\n", t); - free(t); - - t = normalize_env_assignment("a=waldo\""); - printf("%s\n", t); - free(t); - - t = normalize_env_assignment("a=\'"); - printf("%s\n", t); - free(t); - - t = normalize_env_assignment("a=\'\'"); - printf("%s\n", t); - free(t); - - a = strv_new("FOO=BAR", "WALDO=WALDO", "WALDO=", "PIEP", "SCHLUMPF=SMURF", NULL); - b = strv_new("FOO=KKK", "FOO=", "PIEP=", "SCHLUMPF=SMURFF", "NANANANA=YES", NULL); - - r = strv_env_merge(2, a, b); - strv_free(a); - strv_free(b); - - STRV_FOREACH(i, r) - printf("%s\n", *i); - - printf("CLEANED UP:\n"); - - r = strv_env_clean(r); - - STRV_FOREACH(i, r) - printf("%s\n", *i); - - strv_free(r); - - return 0; -} diff --git a/src/test-hostname.c b/src/test-hostname.c deleted file mode 100644 index 8c1a60f940..0000000000 --- a/src/test-hostname.c +++ /dev/null @@ -1,37 +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 . -***/ - -#include -#include -#include -#include - -#include "hostname-setup.h" -#include "util.h" - -int main(int argc, char* argv[]) { - int r; - - if ((r = hostname_setup()) < 0) - fprintf(stderr, "hostname: %s\n", strerror(-r)); - - return 0; -} diff --git a/src/test-id128.c b/src/test-id128.c deleted file mode 100644 index bfd743eca3..0000000000 --- a/src/test-id128.c +++ /dev/null @@ -1,52 +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 . -***/ - -#include - -#include - -#include "util.h" -#include "macro.h" - -#define ID128_WALDI SD_ID128_MAKE(01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 10) - -int main(int argc, char *argv[]) { - sd_id128_t id, id2; - char t[33]; - - 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)); - - 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)); - - printf("waldi2: " SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(ID128_WALDI)); - - return 0; -} diff --git a/src/test-install.c b/src/test-install.c deleted file mode 100644 index 709974f9e5..0000000000 --- a/src/test-install.c +++ /dev/null @@ -1,264 +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 . -***/ - -#include -#include -#include -#include - -#include "util.h" -#include "install.h" - -static void dump_changes(UnitFileChange *c, unsigned n) { - unsigned i; - - assert(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_func, string_compare_func); - 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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, 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, file_name_from_path(files[0])) == UNIT_FILE_ENABLED); - - return 0; -} diff --git a/src/test-job-type.c b/src/test-job-type.c deleted file mode 100644 index ba8b307dd3..0000000000 --- a/src/test-job-type.c +++ /dev/null @@ -1,84 +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 . -***/ - -#include -#include -#include -#include - -#include "job.h" - -int main(int argc, char*argv[]) { - JobType a, b, c, d, e, f, g; - - for (a = 0; a < _JOB_TYPE_MAX; a++) - for (b = 0; b < _JOB_TYPE_MAX; b++) { - - if (!job_type_is_mergeable(a, b)) - printf("Not mergeable: %s + %s\n", job_type_to_string(a), job_type_to_string(b)); - - for (c = 0; c < _JOB_TYPE_MAX; c++) { - - /* Verify transitivity of mergeability - * of job types */ - assert(!job_type_is_mergeable(a, b) || - !job_type_is_mergeable(b, c) || - job_type_is_mergeable(a, c)); - - d = a; - if (job_type_merge(&d, b) >= 0) { - - printf("%s + %s = %s\n", job_type_to_string(a), job_type_to_string(b), job_type_to_string(d)); - - /* Verify that merged entries can be - * merged with the same entries they - * can be merged with separately */ - assert(!job_type_is_mergeable(a, c) || job_type_is_mergeable(d, c)); - assert(!job_type_is_mergeable(b, c) || job_type_is_mergeable(d, 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(job_type_is_mergeable(d, c) || !job_type_is_mergeable(a, c) || !job_type_is_mergeable(b, c)); - - e = b; - if (job_type_merge(&e, c) >= 0) { - - /* Verify associativity */ - - f = d; - assert(job_type_merge(&f, c) == 0); - - g = e; - assert(job_type_merge(&g, a) == 0); - - assert(f == g); - - 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(d)); - } - } - } - } - - - return 0; -} diff --git a/src/test-loopback.c b/src/test-loopback.c deleted file mode 100644 index ab330ac840..0000000000 --- a/src/test-loopback.c +++ /dev/null @@ -1,37 +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 . -***/ - -#include -#include -#include -#include - -#include "loopback-setup.h" -#include "util.h" - -int main(int argc, char* argv[]) { - int r; - - if ((r = loopback_setup()) < 0) - fprintf(stderr, "loopback: %s\n", strerror(-r)); - - return 0; -} diff --git a/src/test-ns.c b/src/test-ns.c deleted file mode 100644 index 102b005880..0000000000 --- a/src/test-ns.c +++ /dev/null @@ -1,60 +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 . -***/ - -#include -#include -#include -#include -#include - -#include "namespace.h" -#include "log.h" - -int main(int argc, char *argv[]) { - const char * const writable[] = { - "/home", - NULL - }; - - const char * const readable[] = { - "/", - "/usr", - "/boot", - NULL - }; - - const char * const inaccessible[] = { - "/home/lennart/projects", - NULL - }; - - int r; - - if ((r = setup_namespace((char**) writable, (char**) readable, (char**) inaccessible, true, MS_SHARED)) < 0) { - log_error("Failed to setup namespace: %s", strerror(-r)); - return 1; - } - - execl("/bin/sh", "/bin/sh", NULL); - log_error("execl(): %m"); - - return 1; -} diff --git a/src/test-strv.c b/src/test-strv.c deleted file mode 100644 index 5ee4447669..0000000000 --- a/src/test-strv.c +++ /dev/null @@ -1,66 +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 . -***/ - -#include - -#include "util.h" -#include "specifier.h" - -int main(int argc, char *argv[]) { - const Specifier table[] = { - { 'a', specifier_string, (char*) "AAAA" }, - { 'b', specifier_string, (char*) "BBBB" }, - { 0, NULL, NULL } - }; - - char *w, *state; - size_t l; - const char test[] = "test a b c 'd' e '' '' hhh '' ''"; - - printf("<%s>\n", test); - - FOREACH_WORD_QUOTED(w, l, test, state) { - char *t; - - assert_se(t = strndup(w, l)); - printf("<%s>\n", t); - free(t); - } - - printf("%s\n", default_term_for_tty("/dev/tty23")); - printf("%s\n", default_term_for_tty("/dev/ttyS23")); - printf("%s\n", default_term_for_tty("/dev/tty0")); - printf("%s\n", default_term_for_tty("/dev/pty0")); - printf("%s\n", default_term_for_tty("/dev/pts/0")); - printf("%s\n", default_term_for_tty("/dev/console")); - printf("%s\n", default_term_for_tty("tty23")); - printf("%s\n", default_term_for_tty("ttyS23")); - printf("%s\n", default_term_for_tty("tty0")); - printf("%s\n", default_term_for_tty("pty0")); - printf("%s\n", default_term_for_tty("pts/0")); - printf("%s\n", default_term_for_tty("console")); - - w = specifier_printf("xxx a=%a b=%b yyy", table, NULL); - printf("<%s>\n", w); - free(w); - - return 0; -} diff --git a/src/test-watchdog.c b/src/test-watchdog.c deleted file mode 100644 index ccb1854708..0000000000 --- a/src/test-watchdog.c +++ /dev/null @@ -1,51 +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 . -***/ - -#include -#include - -#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("Failed to open watchdog: %s", strerror(-r)); - - for (i = 0; i < 5; i++) { - log_info("Pinging..."); - r = watchdog_ping(); - if (r < 0) - log_warning("Failed to ping watchdog: %s", strerror(-r)); - - usleep(t/2); - } - - watchdog_close(true); - return 0; -} diff --git a/test/test-cgroup.c b/test/test-cgroup.c new file mode 100644 index 0000000000..e742632032 --- /dev/null +++ b/test/test-cgroup.c @@ -0,0 +1,104 @@ +/*-*- 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 . +***/ + +#include +#include + +#include "cgroup-util.h" +#include "util.h" +#include "log.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_get_by_pid(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_get_by_pid(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_get_by_pid(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", "/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(streq(c, "foobar")); + assert(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(c == NULL); + assert(streq(p, "/")); + free(p); + + assert_se(cg_split_spec("foo", &c, &p) >= 0); + assert(streq(c, "foo")); + assert(p == NULL); + free(c); + + return 0; +} diff --git a/test/test-daemon.c b/test/test-daemon.c new file mode 100644 index 0000000000..3215f0c560 --- /dev/null +++ b/test/test-daemon.c @@ -0,0 +1,37 @@ +/*-*- 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 . +***/ + +#include + +#include + +int main(int argc, char*argv[]) { + + sd_notify(0, "STATUS=Starting up"); + sleep(5); + sd_notify(0, + "STATUS=Running\n" + "READY=1"); + sleep(10); + sd_notify(0, "STATUS=Quitting"); + + return 0; +} diff --git a/test/test-engine.c b/test/test-engine.c new file mode 100644 index 0000000000..11389a5ac7 --- /dev/null +++ b/test/test-engine.c @@ -0,0 +1,99 @@ +/*-*- 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 . +***/ + +#include +#include +#include +#include + +#include "manager.h" + +int main(int argc, char *argv[]) { + Manager *m = NULL; + Unit *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL, *g = NULL, *h = NULL; + Job *j; + + assert_se(set_unit_path("test") >= 0); + + assert_se(manager_new(MANAGER_SYSTEM, &m) >= 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"); + assert_se(manager_add_job(m, JOB_START, c, JOB_REPLACE, false, NULL, &j) == 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) == -ENOEXEC); + 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) == -EEXIST); + + 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) == -EEXIST); + + 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/test/test-env-replace.c b/test/test-env-replace.c new file mode 100644 index 0000000000..4b6b884779 --- /dev/null +++ b/test/test-env-replace.c @@ -0,0 +1,127 @@ +/*-*- 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 . +***/ + +#include +#include + +#include "util.h" +#include "log.h" +#include "strv.h" + +int main(int argc, char *argv[]) { + + 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 + }; + + char **i, **r, *t, **a, **b; + const char nulstr[] = "fuck\0fuck2\0fuck3\0\0fuck5\0\0xxx"; + + a = strv_parse_nulstr(nulstr, sizeof(nulstr)-1); + + STRV_FOREACH(i, a) + printf("nulstr--%s\n", *i); + + strv_free(a); + + r = replace_env_argv((char**) line, (char**) env); + + STRV_FOREACH(i, r) + printf("%s\n", *i); + + strv_free(r); + + t = normalize_env_assignment("foo=bar"); + printf("%s\n", t); + free(t); + + t = normalize_env_assignment("=bar"); + printf("%s\n", t); + free(t); + + t = normalize_env_assignment("foo="); + printf("%s\n", t); + free(t); + + t = normalize_env_assignment("="); + printf("%s\n", t); + free(t); + + t = normalize_env_assignment(""); + printf("%s\n", t); + free(t); + + t = normalize_env_assignment("a=\"waldo\""); + printf("%s\n", t); + free(t); + + t = normalize_env_assignment("a=\"waldo"); + printf("%s\n", t); + free(t); + + t = normalize_env_assignment("a=waldo\""); + printf("%s\n", t); + free(t); + + t = normalize_env_assignment("a=\'"); + printf("%s\n", t); + free(t); + + t = normalize_env_assignment("a=\'\'"); + printf("%s\n", t); + free(t); + + a = strv_new("FOO=BAR", "WALDO=WALDO", "WALDO=", "PIEP", "SCHLUMPF=SMURF", NULL); + b = strv_new("FOO=KKK", "FOO=", "PIEP=", "SCHLUMPF=SMURFF", "NANANANA=YES", NULL); + + r = strv_env_merge(2, a, b); + strv_free(a); + strv_free(b); + + STRV_FOREACH(i, r) + printf("%s\n", *i); + + printf("CLEANED UP:\n"); + + r = strv_env_clean(r); + + STRV_FOREACH(i, r) + printf("%s\n", *i); + + strv_free(r); + + return 0; +} diff --git a/test/test-hostname.c b/test/test-hostname.c new file mode 100644 index 0000000000..8c1a60f940 --- /dev/null +++ b/test/test-hostname.c @@ -0,0 +1,37 @@ +/*-*- 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 . +***/ + +#include +#include +#include +#include + +#include "hostname-setup.h" +#include "util.h" + +int main(int argc, char* argv[]) { + int r; + + if ((r = hostname_setup()) < 0) + fprintf(stderr, "hostname: %s\n", strerror(-r)); + + return 0; +} diff --git a/test/test-id128.c b/test/test-id128.c new file mode 100644 index 0000000000..bfd743eca3 --- /dev/null +++ b/test/test-id128.c @@ -0,0 +1,52 @@ +/*-*- 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 . +***/ + +#include + +#include + +#include "util.h" +#include "macro.h" + +#define ID128_WALDI SD_ID128_MAKE(01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 10) + +int main(int argc, char *argv[]) { + sd_id128_t id, id2; + char t[33]; + + 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)); + + 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)); + + printf("waldi2: " SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(ID128_WALDI)); + + return 0; +} diff --git a/test/test-install.c b/test/test-install.c new file mode 100644 index 0000000000..709974f9e5 --- /dev/null +++ b/test/test-install.c @@ -0,0 +1,264 @@ +/*-*- 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 . +***/ + +#include +#include +#include +#include + +#include "util.h" +#include "install.h" + +static void dump_changes(UnitFileChange *c, unsigned n) { + unsigned i; + + assert(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_func, string_compare_func); + 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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, 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, file_name_from_path(files[0])) == UNIT_FILE_ENABLED); + + return 0; +} diff --git a/test/test-job-type.c b/test/test-job-type.c new file mode 100644 index 0000000000..ba8b307dd3 --- /dev/null +++ b/test/test-job-type.c @@ -0,0 +1,84 @@ +/*-*- 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 . +***/ + +#include +#include +#include +#include + +#include "job.h" + +int main(int argc, char*argv[]) { + JobType a, b, c, d, e, f, g; + + for (a = 0; a < _JOB_TYPE_MAX; a++) + for (b = 0; b < _JOB_TYPE_MAX; b++) { + + if (!job_type_is_mergeable(a, b)) + printf("Not mergeable: %s + %s\n", job_type_to_string(a), job_type_to_string(b)); + + for (c = 0; c < _JOB_TYPE_MAX; c++) { + + /* Verify transitivity of mergeability + * of job types */ + assert(!job_type_is_mergeable(a, b) || + !job_type_is_mergeable(b, c) || + job_type_is_mergeable(a, c)); + + d = a; + if (job_type_merge(&d, b) >= 0) { + + printf("%s + %s = %s\n", job_type_to_string(a), job_type_to_string(b), job_type_to_string(d)); + + /* Verify that merged entries can be + * merged with the same entries they + * can be merged with separately */ + assert(!job_type_is_mergeable(a, c) || job_type_is_mergeable(d, c)); + assert(!job_type_is_mergeable(b, c) || job_type_is_mergeable(d, 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(job_type_is_mergeable(d, c) || !job_type_is_mergeable(a, c) || !job_type_is_mergeable(b, c)); + + e = b; + if (job_type_merge(&e, c) >= 0) { + + /* Verify associativity */ + + f = d; + assert(job_type_merge(&f, c) == 0); + + g = e; + assert(job_type_merge(&g, a) == 0); + + assert(f == g); + + 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(d)); + } + } + } + } + + + return 0; +} diff --git a/test/test-loopback.c b/test/test-loopback.c new file mode 100644 index 0000000000..ab330ac840 --- /dev/null +++ b/test/test-loopback.c @@ -0,0 +1,37 @@ +/*-*- 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 . +***/ + +#include +#include +#include +#include + +#include "loopback-setup.h" +#include "util.h" + +int main(int argc, char* argv[]) { + int r; + + if ((r = loopback_setup()) < 0) + fprintf(stderr, "loopback: %s\n", strerror(-r)); + + return 0; +} diff --git a/test/test-ns.c b/test/test-ns.c new file mode 100644 index 0000000000..102b005880 --- /dev/null +++ b/test/test-ns.c @@ -0,0 +1,60 @@ +/*-*- 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 . +***/ + +#include +#include +#include +#include +#include + +#include "namespace.h" +#include "log.h" + +int main(int argc, char *argv[]) { + const char * const writable[] = { + "/home", + NULL + }; + + const char * const readable[] = { + "/", + "/usr", + "/boot", + NULL + }; + + const char * const inaccessible[] = { + "/home/lennart/projects", + NULL + }; + + int r; + + if ((r = setup_namespace((char**) writable, (char**) readable, (char**) inaccessible, true, MS_SHARED)) < 0) { + log_error("Failed to setup namespace: %s", strerror(-r)); + return 1; + } + + execl("/bin/sh", "/bin/sh", NULL); + log_error("execl(): %m"); + + return 1; +} diff --git a/test/test-strv.c b/test/test-strv.c new file mode 100644 index 0000000000..5ee4447669 --- /dev/null +++ b/test/test-strv.c @@ -0,0 +1,66 @@ +/*-*- 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 . +***/ + +#include + +#include "util.h" +#include "specifier.h" + +int main(int argc, char *argv[]) { + const Specifier table[] = { + { 'a', specifier_string, (char*) "AAAA" }, + { 'b', specifier_string, (char*) "BBBB" }, + { 0, NULL, NULL } + }; + + char *w, *state; + size_t l; + const char test[] = "test a b c 'd' e '' '' hhh '' ''"; + + printf("<%s>\n", test); + + FOREACH_WORD_QUOTED(w, l, test, state) { + char *t; + + assert_se(t = strndup(w, l)); + printf("<%s>\n", t); + free(t); + } + + printf("%s\n", default_term_for_tty("/dev/tty23")); + printf("%s\n", default_term_for_tty("/dev/ttyS23")); + printf("%s\n", default_term_for_tty("/dev/tty0")); + printf("%s\n", default_term_for_tty("/dev/pty0")); + printf("%s\n", default_term_for_tty("/dev/pts/0")); + printf("%s\n", default_term_for_tty("/dev/console")); + printf("%s\n", default_term_for_tty("tty23")); + printf("%s\n", default_term_for_tty("ttyS23")); + printf("%s\n", default_term_for_tty("tty0")); + printf("%s\n", default_term_for_tty("pty0")); + printf("%s\n", default_term_for_tty("pts/0")); + printf("%s\n", default_term_for_tty("console")); + + w = specifier_printf("xxx a=%a b=%b yyy", table, NULL); + printf("<%s>\n", w); + free(w); + + return 0; +} diff --git a/test/test-watchdog.c b/test/test-watchdog.c new file mode 100644 index 0000000000..ccb1854708 --- /dev/null +++ b/test/test-watchdog.c @@ -0,0 +1,51 @@ +/*-*- 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 . +***/ + +#include +#include + +#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("Failed to open watchdog: %s", strerror(-r)); + + for (i = 0; i < 5; i++) { + log_info("Pinging..."); + r = watchdog_ping(); + if (r < 0) + log_warning("Failed to ping watchdog: %s", strerror(-r)); + + usleep(t/2); + } + + watchdog_close(true); + return 0; +} -- cgit v1.2.3-54-g00ecf From 379079ba6b06e82de9a8f0025456308a34b4b115 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 12 Apr 2012 13:48:01 +0200 Subject: test: test tools should still be in the src/ directory --- Makefile.am | 24 ++-- src/test/Makefile | 1 + src/test/test-cgroup.c | 104 +++++++++++++++++ src/test/test-daemon.c | 37 +++++++ src/test/test-engine.c | 99 +++++++++++++++++ src/test/test-env-replace.c | 127 +++++++++++++++++++++ src/test/test-hostname.c | 37 +++++++ src/test/test-id128.c | 52 +++++++++ src/test/test-install.c | 264 ++++++++++++++++++++++++++++++++++++++++++++ src/test/test-job-type.c | 84 ++++++++++++++ src/test/test-loopback.c | 37 +++++++ src/test/test-ns.c | 60 ++++++++++ src/test/test-strv.c | 66 +++++++++++ src/test/test-watchdog.c | 51 +++++++++ test/test-cgroup.c | 104 ----------------- test/test-daemon.c | 37 ------- test/test-engine.c | 99 ----------------- test/test-env-replace.c | 127 --------------------- test/test-hostname.c | 37 ------- test/test-id128.c | 52 --------- test/test-install.c | 264 -------------------------------------------- test/test-job-type.c | 84 -------------- test/test-loopback.c | 37 ------- test/test-ns.c | 60 ---------- test/test-strv.c | 66 ----------- test/test-watchdog.c | 51 --------- 26 files changed, 1031 insertions(+), 1030 deletions(-) create mode 120000 src/test/Makefile create mode 100644 src/test/test-cgroup.c create mode 100644 src/test/test-daemon.c create mode 100644 src/test/test-engine.c create mode 100644 src/test/test-env-replace.c create mode 100644 src/test/test-hostname.c create mode 100644 src/test/test-id128.c create mode 100644 src/test/test-install.c create mode 100644 src/test/test-job-type.c create mode 100644 src/test/test-loopback.c create mode 100644 src/test/test-ns.c create mode 100644 src/test/test-strv.c create mode 100644 src/test/test-watchdog.c delete mode 100644 test/test-cgroup.c delete mode 100644 test/test-daemon.c delete mode 100644 test/test-engine.c delete mode 100644 test/test-env-replace.c delete mode 100644 test/test-hostname.c delete mode 100644 test/test-id128.c delete mode 100644 test/test-install.c delete mode 100644 test/test-job-type.c delete mode 100644 test/test-loopback.c delete mode 100644 test/test-ns.c delete mode 100644 test/test-strv.c delete mode 100644 test/test-watchdog.c (limited to 'test') diff --git a/Makefile.am b/Makefile.am index 13e1af6776..829db7e9ef 100644 --- a/Makefile.am +++ b/Makefile.am @@ -824,7 +824,7 @@ systemd_LDADD = \ # ------------------------------------------------------------------------------ test_engine_SOURCES = \ - test/test-engine.c + src/test/test-engine.c test_engine_CFLAGS = \ $(AM_CFLAGS) \ @@ -835,7 +835,7 @@ test_engine_LDADD = \ libsystemd-daemon.la test_job_type_SOURCES = \ - test/test-job-type.c + src/test/test-job-type.c test_job_type_CFLAGS = \ $(AM_CFLAGS) \ @@ -845,51 +845,51 @@ test_job_type_LDADD = \ libsystemd-core.la test_ns_SOURCES = \ - test/test-ns.c + src/test/test-ns.c test_ns_LDADD = \ libsystemd-core.la test_loopback_SOURCES = \ - test/test-loopback.c + src/test/test-loopback.c test_loopback_LDADD = \ libsystemd-shared.la test_hostname_SOURCES = \ - test/test-hostname.c + src/test/test-hostname.c test_hostname_LDADD = \ libsystemd-shared.la test_daemon_SOURCES = \ - test/test-daemon.c + src/test/test-daemon.c test_daemon_LDADD = \ libsystemd-shared.la \ libsystemd-daemon.la test_cgroup_SOURCES = \ - test/test-cgroup.c + src/test/test-cgroup.c test_cgroup_LDADD = \ libsystemd-label.la \ libsystemd-shared.la test_env_replace_SOURCES = \ - test/test-env-replace.c + src/test/test-env-replace.c test_env_replace_LDADD = \ libsystemd-shared.la test_strv_SOURCES = \ - test/test-strv.c + src/test/test-strv.c test_strv_LDADD = \ libsystemd-shared.la test_install_SOURCES = \ - test/test-install.c + src/test/test-install.c test_install_CFLAGS = \ $(AM_CFLAGS) \ @@ -900,7 +900,7 @@ test_install_LDADD = \ libsystemd-shared.la test_watchdog_SOURCES = \ - test/test-watchdog.c + src/test/test-watchdog.c test_watchdog_LDADD = \ libsystemd-shared.la @@ -1861,7 +1861,7 @@ libsystemd_id128_la_LIBADD = \ libsystemd-shared.la test_id128_SOURCES = \ - test/test-id128.c + src/test/test-id128.c test_id128_LDADD = \ libsystemd-shared.la \ diff --git a/src/test/Makefile b/src/test/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/test/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/test/test-cgroup.c b/src/test/test-cgroup.c new file mode 100644 index 0000000000..e742632032 --- /dev/null +++ b/src/test/test-cgroup.c @@ -0,0 +1,104 @@ +/*-*- 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 . +***/ + +#include +#include + +#include "cgroup-util.h" +#include "util.h" +#include "log.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_get_by_pid(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_get_by_pid(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_get_by_pid(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", "/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(streq(c, "foobar")); + assert(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(c == NULL); + assert(streq(p, "/")); + free(p); + + assert_se(cg_split_spec("foo", &c, &p) >= 0); + assert(streq(c, "foo")); + assert(p == NULL); + free(c); + + return 0; +} diff --git a/src/test/test-daemon.c b/src/test/test-daemon.c new file mode 100644 index 0000000000..3215f0c560 --- /dev/null +++ b/src/test/test-daemon.c @@ -0,0 +1,37 @@ +/*-*- 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 . +***/ + +#include + +#include + +int main(int argc, char*argv[]) { + + sd_notify(0, "STATUS=Starting up"); + sleep(5); + sd_notify(0, + "STATUS=Running\n" + "READY=1"); + sleep(10); + sd_notify(0, "STATUS=Quitting"); + + return 0; +} diff --git a/src/test/test-engine.c b/src/test/test-engine.c new file mode 100644 index 0000000000..11389a5ac7 --- /dev/null +++ b/src/test/test-engine.c @@ -0,0 +1,99 @@ +/*-*- 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 . +***/ + +#include +#include +#include +#include + +#include "manager.h" + +int main(int argc, char *argv[]) { + Manager *m = NULL; + Unit *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL, *g = NULL, *h = NULL; + Job *j; + + assert_se(set_unit_path("test") >= 0); + + assert_se(manager_new(MANAGER_SYSTEM, &m) >= 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"); + assert_se(manager_add_job(m, JOB_START, c, JOB_REPLACE, false, NULL, &j) == 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) == -ENOEXEC); + 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) == -EEXIST); + + 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) == -EEXIST); + + 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 new file mode 100644 index 0000000000..4b6b884779 --- /dev/null +++ b/src/test/test-env-replace.c @@ -0,0 +1,127 @@ +/*-*- 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 . +***/ + +#include +#include + +#include "util.h" +#include "log.h" +#include "strv.h" + +int main(int argc, char *argv[]) { + + 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 + }; + + char **i, **r, *t, **a, **b; + const char nulstr[] = "fuck\0fuck2\0fuck3\0\0fuck5\0\0xxx"; + + a = strv_parse_nulstr(nulstr, sizeof(nulstr)-1); + + STRV_FOREACH(i, a) + printf("nulstr--%s\n", *i); + + strv_free(a); + + r = replace_env_argv((char**) line, (char**) env); + + STRV_FOREACH(i, r) + printf("%s\n", *i); + + strv_free(r); + + t = normalize_env_assignment("foo=bar"); + printf("%s\n", t); + free(t); + + t = normalize_env_assignment("=bar"); + printf("%s\n", t); + free(t); + + t = normalize_env_assignment("foo="); + printf("%s\n", t); + free(t); + + t = normalize_env_assignment("="); + printf("%s\n", t); + free(t); + + t = normalize_env_assignment(""); + printf("%s\n", t); + free(t); + + t = normalize_env_assignment("a=\"waldo\""); + printf("%s\n", t); + free(t); + + t = normalize_env_assignment("a=\"waldo"); + printf("%s\n", t); + free(t); + + t = normalize_env_assignment("a=waldo\""); + printf("%s\n", t); + free(t); + + t = normalize_env_assignment("a=\'"); + printf("%s\n", t); + free(t); + + t = normalize_env_assignment("a=\'\'"); + printf("%s\n", t); + free(t); + + a = strv_new("FOO=BAR", "WALDO=WALDO", "WALDO=", "PIEP", "SCHLUMPF=SMURF", NULL); + b = strv_new("FOO=KKK", "FOO=", "PIEP=", "SCHLUMPF=SMURFF", "NANANANA=YES", NULL); + + r = strv_env_merge(2, a, b); + strv_free(a); + strv_free(b); + + STRV_FOREACH(i, r) + printf("%s\n", *i); + + printf("CLEANED UP:\n"); + + r = strv_env_clean(r); + + STRV_FOREACH(i, r) + printf("%s\n", *i); + + strv_free(r); + + return 0; +} diff --git a/src/test/test-hostname.c b/src/test/test-hostname.c new file mode 100644 index 0000000000..8c1a60f940 --- /dev/null +++ b/src/test/test-hostname.c @@ -0,0 +1,37 @@ +/*-*- 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 . +***/ + +#include +#include +#include +#include + +#include "hostname-setup.h" +#include "util.h" + +int main(int argc, char* argv[]) { + int r; + + if ((r = hostname_setup()) < 0) + fprintf(stderr, "hostname: %s\n", strerror(-r)); + + return 0; +} diff --git a/src/test/test-id128.c b/src/test/test-id128.c new file mode 100644 index 0000000000..bfd743eca3 --- /dev/null +++ b/src/test/test-id128.c @@ -0,0 +1,52 @@ +/*-*- 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 . +***/ + +#include + +#include + +#include "util.h" +#include "macro.h" + +#define ID128_WALDI SD_ID128_MAKE(01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 10) + +int main(int argc, char *argv[]) { + sd_id128_t id, id2; + char t[33]; + + 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)); + + 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)); + + printf("waldi2: " SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(ID128_WALDI)); + + return 0; +} diff --git a/src/test/test-install.c b/src/test/test-install.c new file mode 100644 index 0000000000..709974f9e5 --- /dev/null +++ b/src/test/test-install.c @@ -0,0 +1,264 @@ +/*-*- 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 . +***/ + +#include +#include +#include +#include + +#include "util.h" +#include "install.h" + +static void dump_changes(UnitFileChange *c, unsigned n) { + unsigned i; + + assert(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_func, string_compare_func); + 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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, 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, file_name_from_path(files[0])) == UNIT_FILE_ENABLED); + + return 0; +} diff --git a/src/test/test-job-type.c b/src/test/test-job-type.c new file mode 100644 index 0000000000..ba8b307dd3 --- /dev/null +++ b/src/test/test-job-type.c @@ -0,0 +1,84 @@ +/*-*- 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 . +***/ + +#include +#include +#include +#include + +#include "job.h" + +int main(int argc, char*argv[]) { + JobType a, b, c, d, e, f, g; + + for (a = 0; a < _JOB_TYPE_MAX; a++) + for (b = 0; b < _JOB_TYPE_MAX; b++) { + + if (!job_type_is_mergeable(a, b)) + printf("Not mergeable: %s + %s\n", job_type_to_string(a), job_type_to_string(b)); + + for (c = 0; c < _JOB_TYPE_MAX; c++) { + + /* Verify transitivity of mergeability + * of job types */ + assert(!job_type_is_mergeable(a, b) || + !job_type_is_mergeable(b, c) || + job_type_is_mergeable(a, c)); + + d = a; + if (job_type_merge(&d, b) >= 0) { + + printf("%s + %s = %s\n", job_type_to_string(a), job_type_to_string(b), job_type_to_string(d)); + + /* Verify that merged entries can be + * merged with the same entries they + * can be merged with separately */ + assert(!job_type_is_mergeable(a, c) || job_type_is_mergeable(d, c)); + assert(!job_type_is_mergeable(b, c) || job_type_is_mergeable(d, 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(job_type_is_mergeable(d, c) || !job_type_is_mergeable(a, c) || !job_type_is_mergeable(b, c)); + + e = b; + if (job_type_merge(&e, c) >= 0) { + + /* Verify associativity */ + + f = d; + assert(job_type_merge(&f, c) == 0); + + g = e; + assert(job_type_merge(&g, a) == 0); + + assert(f == g); + + 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(d)); + } + } + } + } + + + return 0; +} diff --git a/src/test/test-loopback.c b/src/test/test-loopback.c new file mode 100644 index 0000000000..ab330ac840 --- /dev/null +++ b/src/test/test-loopback.c @@ -0,0 +1,37 @@ +/*-*- 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 . +***/ + +#include +#include +#include +#include + +#include "loopback-setup.h" +#include "util.h" + +int main(int argc, char* argv[]) { + int r; + + if ((r = loopback_setup()) < 0) + fprintf(stderr, "loopback: %s\n", strerror(-r)); + + return 0; +} diff --git a/src/test/test-ns.c b/src/test/test-ns.c new file mode 100644 index 0000000000..102b005880 --- /dev/null +++ b/src/test/test-ns.c @@ -0,0 +1,60 @@ +/*-*- 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 . +***/ + +#include +#include +#include +#include +#include + +#include "namespace.h" +#include "log.h" + +int main(int argc, char *argv[]) { + const char * const writable[] = { + "/home", + NULL + }; + + const char * const readable[] = { + "/", + "/usr", + "/boot", + NULL + }; + + const char * const inaccessible[] = { + "/home/lennart/projects", + NULL + }; + + int r; + + if ((r = setup_namespace((char**) writable, (char**) readable, (char**) inaccessible, true, MS_SHARED)) < 0) { + log_error("Failed to setup namespace: %s", strerror(-r)); + return 1; + } + + execl("/bin/sh", "/bin/sh", NULL); + log_error("execl(): %m"); + + return 1; +} diff --git a/src/test/test-strv.c b/src/test/test-strv.c new file mode 100644 index 0000000000..5ee4447669 --- /dev/null +++ b/src/test/test-strv.c @@ -0,0 +1,66 @@ +/*-*- 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 . +***/ + +#include + +#include "util.h" +#include "specifier.h" + +int main(int argc, char *argv[]) { + const Specifier table[] = { + { 'a', specifier_string, (char*) "AAAA" }, + { 'b', specifier_string, (char*) "BBBB" }, + { 0, NULL, NULL } + }; + + char *w, *state; + size_t l; + const char test[] = "test a b c 'd' e '' '' hhh '' ''"; + + printf("<%s>\n", test); + + FOREACH_WORD_QUOTED(w, l, test, state) { + char *t; + + assert_se(t = strndup(w, l)); + printf("<%s>\n", t); + free(t); + } + + printf("%s\n", default_term_for_tty("/dev/tty23")); + printf("%s\n", default_term_for_tty("/dev/ttyS23")); + printf("%s\n", default_term_for_tty("/dev/tty0")); + printf("%s\n", default_term_for_tty("/dev/pty0")); + printf("%s\n", default_term_for_tty("/dev/pts/0")); + printf("%s\n", default_term_for_tty("/dev/console")); + printf("%s\n", default_term_for_tty("tty23")); + printf("%s\n", default_term_for_tty("ttyS23")); + printf("%s\n", default_term_for_tty("tty0")); + printf("%s\n", default_term_for_tty("pty0")); + printf("%s\n", default_term_for_tty("pts/0")); + printf("%s\n", default_term_for_tty("console")); + + w = specifier_printf("xxx a=%a b=%b yyy", table, NULL); + printf("<%s>\n", w); + free(w); + + return 0; +} diff --git a/src/test/test-watchdog.c b/src/test/test-watchdog.c new file mode 100644 index 0000000000..ccb1854708 --- /dev/null +++ b/src/test/test-watchdog.c @@ -0,0 +1,51 @@ +/*-*- 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 . +***/ + +#include +#include + +#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("Failed to open watchdog: %s", strerror(-r)); + + for (i = 0; i < 5; i++) { + log_info("Pinging..."); + r = watchdog_ping(); + if (r < 0) + log_warning("Failed to ping watchdog: %s", strerror(-r)); + + usleep(t/2); + } + + watchdog_close(true); + return 0; +} diff --git a/test/test-cgroup.c b/test/test-cgroup.c deleted file mode 100644 index e742632032..0000000000 --- a/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 . -***/ - -#include -#include - -#include "cgroup-util.h" -#include "util.h" -#include "log.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_get_by_pid(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_get_by_pid(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_get_by_pid(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", "/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(streq(c, "foobar")); - assert(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(c == NULL); - assert(streq(p, "/")); - free(p); - - assert_se(cg_split_spec("foo", &c, &p) >= 0); - assert(streq(c, "foo")); - assert(p == NULL); - free(c); - - return 0; -} diff --git a/test/test-daemon.c b/test/test-daemon.c deleted file mode 100644 index 3215f0c560..0000000000 --- a/test/test-daemon.c +++ /dev/null @@ -1,37 +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 . -***/ - -#include - -#include - -int main(int argc, char*argv[]) { - - sd_notify(0, "STATUS=Starting up"); - sleep(5); - sd_notify(0, - "STATUS=Running\n" - "READY=1"); - sleep(10); - sd_notify(0, "STATUS=Quitting"); - - return 0; -} diff --git a/test/test-engine.c b/test/test-engine.c deleted file mode 100644 index 11389a5ac7..0000000000 --- a/test/test-engine.c +++ /dev/null @@ -1,99 +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 . -***/ - -#include -#include -#include -#include - -#include "manager.h" - -int main(int argc, char *argv[]) { - Manager *m = NULL; - Unit *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL, *g = NULL, *h = NULL; - Job *j; - - assert_se(set_unit_path("test") >= 0); - - assert_se(manager_new(MANAGER_SYSTEM, &m) >= 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"); - assert_se(manager_add_job(m, JOB_START, c, JOB_REPLACE, false, NULL, &j) == 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) == -ENOEXEC); - 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) == -EEXIST); - - 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) == -EEXIST); - - 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/test/test-env-replace.c b/test/test-env-replace.c deleted file mode 100644 index 4b6b884779..0000000000 --- a/test/test-env-replace.c +++ /dev/null @@ -1,127 +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 . -***/ - -#include -#include - -#include "util.h" -#include "log.h" -#include "strv.h" - -int main(int argc, char *argv[]) { - - 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 - }; - - char **i, **r, *t, **a, **b; - const char nulstr[] = "fuck\0fuck2\0fuck3\0\0fuck5\0\0xxx"; - - a = strv_parse_nulstr(nulstr, sizeof(nulstr)-1); - - STRV_FOREACH(i, a) - printf("nulstr--%s\n", *i); - - strv_free(a); - - r = replace_env_argv((char**) line, (char**) env); - - STRV_FOREACH(i, r) - printf("%s\n", *i); - - strv_free(r); - - t = normalize_env_assignment("foo=bar"); - printf("%s\n", t); - free(t); - - t = normalize_env_assignment("=bar"); - printf("%s\n", t); - free(t); - - t = normalize_env_assignment("foo="); - printf("%s\n", t); - free(t); - - t = normalize_env_assignment("="); - printf("%s\n", t); - free(t); - - t = normalize_env_assignment(""); - printf("%s\n", t); - free(t); - - t = normalize_env_assignment("a=\"waldo\""); - printf("%s\n", t); - free(t); - - t = normalize_env_assignment("a=\"waldo"); - printf("%s\n", t); - free(t); - - t = normalize_env_assignment("a=waldo\""); - printf("%s\n", t); - free(t); - - t = normalize_env_assignment("a=\'"); - printf("%s\n", t); - free(t); - - t = normalize_env_assignment("a=\'\'"); - printf("%s\n", t); - free(t); - - a = strv_new("FOO=BAR", "WALDO=WALDO", "WALDO=", "PIEP", "SCHLUMPF=SMURF", NULL); - b = strv_new("FOO=KKK", "FOO=", "PIEP=", "SCHLUMPF=SMURFF", "NANANANA=YES", NULL); - - r = strv_env_merge(2, a, b); - strv_free(a); - strv_free(b); - - STRV_FOREACH(i, r) - printf("%s\n", *i); - - printf("CLEANED UP:\n"); - - r = strv_env_clean(r); - - STRV_FOREACH(i, r) - printf("%s\n", *i); - - strv_free(r); - - return 0; -} diff --git a/test/test-hostname.c b/test/test-hostname.c deleted file mode 100644 index 8c1a60f940..0000000000 --- a/test/test-hostname.c +++ /dev/null @@ -1,37 +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 . -***/ - -#include -#include -#include -#include - -#include "hostname-setup.h" -#include "util.h" - -int main(int argc, char* argv[]) { - int r; - - if ((r = hostname_setup()) < 0) - fprintf(stderr, "hostname: %s\n", strerror(-r)); - - return 0; -} diff --git a/test/test-id128.c b/test/test-id128.c deleted file mode 100644 index bfd743eca3..0000000000 --- a/test/test-id128.c +++ /dev/null @@ -1,52 +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 . -***/ - -#include - -#include - -#include "util.h" -#include "macro.h" - -#define ID128_WALDI SD_ID128_MAKE(01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 10) - -int main(int argc, char *argv[]) { - sd_id128_t id, id2; - char t[33]; - - 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)); - - 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)); - - printf("waldi2: " SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(ID128_WALDI)); - - return 0; -} diff --git a/test/test-install.c b/test/test-install.c deleted file mode 100644 index 709974f9e5..0000000000 --- a/test/test-install.c +++ /dev/null @@ -1,264 +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 . -***/ - -#include -#include -#include -#include - -#include "util.h" -#include "install.h" - -static void dump_changes(UnitFileChange *c, unsigned n) { - unsigned i; - - assert(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_func, string_compare_func); - 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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, file_name_from_path(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, 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, file_name_from_path(files[0])) == UNIT_FILE_ENABLED); - - return 0; -} diff --git a/test/test-job-type.c b/test/test-job-type.c deleted file mode 100644 index ba8b307dd3..0000000000 --- a/test/test-job-type.c +++ /dev/null @@ -1,84 +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 . -***/ - -#include -#include -#include -#include - -#include "job.h" - -int main(int argc, char*argv[]) { - JobType a, b, c, d, e, f, g; - - for (a = 0; a < _JOB_TYPE_MAX; a++) - for (b = 0; b < _JOB_TYPE_MAX; b++) { - - if (!job_type_is_mergeable(a, b)) - printf("Not mergeable: %s + %s\n", job_type_to_string(a), job_type_to_string(b)); - - for (c = 0; c < _JOB_TYPE_MAX; c++) { - - /* Verify transitivity of mergeability - * of job types */ - assert(!job_type_is_mergeable(a, b) || - !job_type_is_mergeable(b, c) || - job_type_is_mergeable(a, c)); - - d = a; - if (job_type_merge(&d, b) >= 0) { - - printf("%s + %s = %s\n", job_type_to_string(a), job_type_to_string(b), job_type_to_string(d)); - - /* Verify that merged entries can be - * merged with the same entries they - * can be merged with separately */ - assert(!job_type_is_mergeable(a, c) || job_type_is_mergeable(d, c)); - assert(!job_type_is_mergeable(b, c) || job_type_is_mergeable(d, 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(job_type_is_mergeable(d, c) || !job_type_is_mergeable(a, c) || !job_type_is_mergeable(b, c)); - - e = b; - if (job_type_merge(&e, c) >= 0) { - - /* Verify associativity */ - - f = d; - assert(job_type_merge(&f, c) == 0); - - g = e; - assert(job_type_merge(&g, a) == 0); - - assert(f == g); - - 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(d)); - } - } - } - } - - - return 0; -} diff --git a/test/test-loopback.c b/test/test-loopback.c deleted file mode 100644 index ab330ac840..0000000000 --- a/test/test-loopback.c +++ /dev/null @@ -1,37 +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 . -***/ - -#include -#include -#include -#include - -#include "loopback-setup.h" -#include "util.h" - -int main(int argc, char* argv[]) { - int r; - - if ((r = loopback_setup()) < 0) - fprintf(stderr, "loopback: %s\n", strerror(-r)); - - return 0; -} diff --git a/test/test-ns.c b/test/test-ns.c deleted file mode 100644 index 102b005880..0000000000 --- a/test/test-ns.c +++ /dev/null @@ -1,60 +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 . -***/ - -#include -#include -#include -#include -#include - -#include "namespace.h" -#include "log.h" - -int main(int argc, char *argv[]) { - const char * const writable[] = { - "/home", - NULL - }; - - const char * const readable[] = { - "/", - "/usr", - "/boot", - NULL - }; - - const char * const inaccessible[] = { - "/home/lennart/projects", - NULL - }; - - int r; - - if ((r = setup_namespace((char**) writable, (char**) readable, (char**) inaccessible, true, MS_SHARED)) < 0) { - log_error("Failed to setup namespace: %s", strerror(-r)); - return 1; - } - - execl("/bin/sh", "/bin/sh", NULL); - log_error("execl(): %m"); - - return 1; -} diff --git a/test/test-strv.c b/test/test-strv.c deleted file mode 100644 index 5ee4447669..0000000000 --- a/test/test-strv.c +++ /dev/null @@ -1,66 +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 . -***/ - -#include - -#include "util.h" -#include "specifier.h" - -int main(int argc, char *argv[]) { - const Specifier table[] = { - { 'a', specifier_string, (char*) "AAAA" }, - { 'b', specifier_string, (char*) "BBBB" }, - { 0, NULL, NULL } - }; - - char *w, *state; - size_t l; - const char test[] = "test a b c 'd' e '' '' hhh '' ''"; - - printf("<%s>\n", test); - - FOREACH_WORD_QUOTED(w, l, test, state) { - char *t; - - assert_se(t = strndup(w, l)); - printf("<%s>\n", t); - free(t); - } - - printf("%s\n", default_term_for_tty("/dev/tty23")); - printf("%s\n", default_term_for_tty("/dev/ttyS23")); - printf("%s\n", default_term_for_tty("/dev/tty0")); - printf("%s\n", default_term_for_tty("/dev/pty0")); - printf("%s\n", default_term_for_tty("/dev/pts/0")); - printf("%s\n", default_term_for_tty("/dev/console")); - printf("%s\n", default_term_for_tty("tty23")); - printf("%s\n", default_term_for_tty("ttyS23")); - printf("%s\n", default_term_for_tty("tty0")); - printf("%s\n", default_term_for_tty("pty0")); - printf("%s\n", default_term_for_tty("pts/0")); - printf("%s\n", default_term_for_tty("console")); - - w = specifier_printf("xxx a=%a b=%b yyy", table, NULL); - printf("<%s>\n", w); - free(w); - - return 0; -} diff --git a/test/test-watchdog.c b/test/test-watchdog.c deleted file mode 100644 index ccb1854708..0000000000 --- a/test/test-watchdog.c +++ /dev/null @@ -1,51 +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 . -***/ - -#include -#include - -#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("Failed to open watchdog: %s", strerror(-r)); - - for (i = 0; i < 5; i++) { - log_info("Pinging..."); - r = watchdog_ping(); - if (r < 0) - log_warning("Failed to ping watchdog: %s", strerror(-r)); - - usleep(t/2); - } - - watchdog_close(true); - return 0; -} -- cgit v1.2.3-54-g00ecf From 0b87a07761dcad31583142a3a454c42833e65a09 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sat, 14 Apr 2012 19:31:18 +0200 Subject: udev: test - move test/ and src/test/ --- Makefile.am | 27 +- src/test/test-libudev.c | 501 ++++++++++++ src/test/test-udev.c | 121 +++ src/udev/test-libudev.c | 501 ------------ src/udev/test-udev.c | 121 --- src/udev/test/.gitignore | 1 - src/udev/test/rule-syntax-check.py | 64 -- src/udev/test/rules-test.sh | 15 - src/udev/test/sys.tar.xz | Bin 165116 -> 0 bytes src/udev/test/udev-test.pl | 1560 ------------------------------------ test/.gitignore | 1 + test/rule-syntax-check.py | 64 ++ test/rules-test.sh | 15 + test/sys.tar.xz | Bin 0 -> 165116 bytes test/udev-test.pl | 1560 ++++++++++++++++++++++++++++++++++++ 15 files changed, 2276 insertions(+), 2275 deletions(-) create mode 100644 src/test/test-libudev.c create mode 100644 src/test/test-udev.c delete mode 100644 src/udev/test-libudev.c delete mode 100644 src/udev/test-udev.c delete mode 100644 src/udev/test/.gitignore delete mode 100755 src/udev/test/rule-syntax-check.py delete mode 100755 src/udev/test/rules-test.sh delete mode 100644 src/udev/test/sys.tar.xz delete mode 100755 src/udev/test/udev-test.pl create mode 100644 test/.gitignore create mode 100755 test/rule-syntax-check.py create mode 100755 test/rules-test.sh create mode 100644 test/sys.tar.xz create mode 100755 test/udev-test.pl (limited to 'test') diff --git a/Makefile.am b/Makefile.am index 33b51d8e30..fcc3bc6ba0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -136,7 +136,8 @@ AM_CPPFLAGS = \ -I $(top_srcdir)/src/journal \ -I $(top_srcdir)/src/systemd \ -I $(top_srcdir)/src/core \ - -I $(top_srcdir)/src/libudev + -I $(top_srcdir)/src/libudev \ + -I $(top_srcdir)/src/udev AM_CFLAGS = $(WARNINGFLAGS) AM_LDFLAGS = $(GCLDFLAGS) @@ -1486,21 +1487,21 @@ udevadm_LDADD = \ # ------------------------------------------------------------------------------ TESTS += \ - src/udev/test/udev-test.pl \ - src/udev/test/rules-test.sh + test/udev-test.pl \ + test/rules-test.sh noinst_PROGRAMS += \ test-libudev \ test-udev test_libudev_SOURCES = \ - src/udev/test-libudev.c + src/test/test-libudev.c test_libudev_LDADD = \ libudev.la test_udev_SOURCES = \ - src/udev/test-udev.c + src/test/test-udev.c test_udev_LDADD = \ libudev-core.la \ @@ -1508,21 +1509,21 @@ test_udev_LDADD = \ libsystemd-shared.la check_DATA += \ - src/udev/test/sys + test/sys # packed sysfs test tree -src/udev/test/sys: - $(AM_V_GEN)mkdir -p src/udev/test && tar -C src/udev/test/ -xJf $(top_srcdir)/src/udev/test/sys.tar.xz +test/sys: + $(AM_V_GEN)mkdir -p test && tar -C test/ -xJf $(top_srcdir)/test/sys.tar.xz test-sys-distclean: - -rm -rf src/udev/test/sys + -rm -rf test/sys DISTCLEAN_LOCAL_HOOKS += test-sys-distclean EXTRA_DIST += \ - src/udev/test/sys.tar.xz \ - src/udev/test/udev-test.pl \ - src/udev/test/rules-test.sh \ - src/udev/test/rule-syntax-check.py + test/sys.tar.xz \ + test/udev-test.pl \ + test/rules-test.sh \ + test/rule-syntax-check.py # ------------------------------------------------------------------------------ ata_id_SOURCES = \ diff --git a/src/test/test-libudev.c b/src/test/test-libudev.c new file mode 100644 index 0000000000..6161fb3e31 --- /dev/null +++ b/src/test/test-libudev.c @@ -0,0 +1,501 @@ +/* + * test-libudev + * + * Copyright (C) 2008 Kay Sievers + * + * This library 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libudev.h" + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +static void log_fn(struct udev *udev, + int priority, const char *file, int line, const char *fn, + const char *format, va_list args) +{ + printf("test-libudev: %s %s:%d ", fn, file, line); + vprintf(format, args); +} + +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) +{ + 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); + udev_device_unref(device); + return 0; +} + +static int test_device_parents(struct udev *udev, const char *syspath) +{ + 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); + udev_device_unref(device); + + 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; + } + + memset(&ep_udev, 0, 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; + } + + memset(&ep_stdin, 0, 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; + unsigned long long int seqnum; + struct udev_list_entry *list_entry; + + udev_queue = udev_queue_new(udev); + if (udev_queue == NULL) + return -1; + seqnum = udev_queue_get_kernel_seqnum(udev_queue); + printf("seqnum kernel: %llu\n", seqnum); + seqnum = udev_queue_get_udev_seqnum(udev_queue); + printf("seqnum udev : %llu\n", seqnum); + + if (udev_queue_get_queue_is_empty(udev_queue)) + printf("queue is empty\n"); + printf("get queue list\n"); + udev_list_entry_foreach(list_entry, udev_queue_get_queued_list_entry(udev_queue)) + printf("queued: '%s' [%s]\n", udev_list_entry_get_name(list_entry), udev_list_entry_get_value(list_entry)); + printf("\n"); + printf("get queue list again\n"); + udev_list_entry_foreach(list_entry, udev_queue_get_queued_list_entry(udev_queue)) + printf("queued: '%s' [%s]\n", udev_list_entry_get_name(list_entry), udev_list_entry_get_value(list_entry)); + printf("\n"); + + list_entry = udev_queue_get_queued_list_entry(udev_queue); + if (list_entry != NULL) { + printf("event [%llu] is queued\n", seqnum); + seqnum = strtoull(udev_list_entry_get_value(list_entry), NULL, 10); + if (udev_queue_get_seqnum_is_finished(udev_queue, seqnum)) + printf("event [%llu] is not finished\n", seqnum); + else + printf("event [%llu] is finished\n", seqnum); + } + printf("\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 ? "" : 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; +} + +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]; + const char *str; + + udev = udev_new(); + printf("context: %p\n", udev); + if (udev == NULL) { + printf("no context\n"); + return 1; + } + udev_set_log_fn(udev, log_fn); + printf("set log: %p\n", log_fn); + + for (;;) { + int option; + + option = getopt_long(argc, argv, "+p:s:dhV", options, NULL); + if (option == -1) + break; + + switch (option) { + case 'p': + syspath = optarg; + break; + case 's': + subsystem = optarg; + break; + case 'd': + if (udev_get_log_priority(udev) < LOG_INFO) + udev_set_log_priority(udev, LOG_INFO); + break; + case 'h': + printf("--debug --syspath= --subsystem= --help\n"); + goto out; + case 'V': + printf("%s\n", VERSION); + goto out; + default: + goto out; + } + } + + str = udev_get_sys_path(udev); + printf("sys_path: '%s'\n", str); + str = udev_get_dev_path(udev); + printf("dev_path: '%s'\n", str); + + /* add sys path if needed */ + if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) { + snprintf(path, sizeof(path), "%s%s", udev_get_sys_path(udev), 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_monitor(udev); +out: + udev_unref(udev); + return 0; +} diff --git a/src/test/test-udev.c b/src/test/test-udev.c new file mode 100644 index 0000000000..150cb16a31 --- /dev/null +++ b/src/test/test-udev.c @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2003-2004 Greg Kroah-Hartman + * Copyright (C) 2004-2008 Kay Sievers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "udev.h" + +void udev_main_log(struct udev *udev, int priority, + const char *file, int line, const char *fn, + const char *format, va_list args) {} + +int main(int argc, char *argv[]) +{ + struct udev *udev; + struct udev_event *event = NULL; + struct udev_device *dev = NULL; + struct udev_rules *rules = NULL; + char syspath[UTIL_PATH_SIZE]; + const char *devpath; + const char *action; + sigset_t mask, sigmask_orig; + int err = -EINVAL; + + udev = udev_new(); + if (udev == NULL) + exit(EXIT_FAILURE); + log_debug("version %s\n", VERSION); + udev_selinux_init(udev); + + sigprocmask(SIG_SETMASK, NULL, &sigmask_orig); + + action = argv[1]; + if (action == NULL) { + log_error("action missing\n"); + goto out; + } + + devpath = argv[2]; + if (devpath == NULL) { + log_error("devpath missing\n"); + goto out; + } + + rules = udev_rules_new(udev, 1); + + util_strscpyl(syspath, sizeof(syspath), udev_get_sys_path(udev), devpath, NULL); + dev = udev_device_new_from_syspath(udev, syspath); + if (dev == NULL) { + log_debug("unknown device '%s'\n", devpath); + goto out; + } + + udev_device_set_action(dev, action); + 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 (strcmp(udev_device_get_subsystem(dev), "block") == 0) + mode |= S_IFBLK; + else + mode |= S_IFCHR; + + if (strcmp(action, "remove") != 0) { + util_create_path(udev, udev_device_get_devnode(dev)); + mknod(udev_device_get_devnode(dev), mode, udev_device_get_devnum(dev)); + } else { + unlink(udev_device_get_devnode(dev)); + util_delete_path(udev, udev_device_get_devnode(dev)); + } + } + + err = udev_event_execute_rules(event, rules, &sigmask_orig); + if (err == 0) + udev_event_execute_run(event, NULL); +out: + if (event != NULL && event->fd_signal >= 0) + close(event->fd_signal); + udev_event_unref(event); + udev_device_unref(dev); + udev_rules_unref(rules); + udev_selinux_exit(udev); + udev_unref(udev); + if (err != 0) + return EXIT_FAILURE; + return EXIT_SUCCESS; +} diff --git a/src/udev/test-libudev.c b/src/udev/test-libudev.c deleted file mode 100644 index 6161fb3e31..0000000000 --- a/src/udev/test-libudev.c +++ /dev/null @@ -1,501 +0,0 @@ -/* - * test-libudev - * - * Copyright (C) 2008 Kay Sievers - * - * This library 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. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "libudev.h" - -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) - -static void log_fn(struct udev *udev, - int priority, const char *file, int line, const char *fn, - const char *format, va_list args) -{ - printf("test-libudev: %s %s:%d ", fn, file, line); - vprintf(format, args); -} - -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) -{ - 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); - udev_device_unref(device); - return 0; -} - -static int test_device_parents(struct udev *udev, const char *syspath) -{ - 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); - udev_device_unref(device); - - 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; - } - - memset(&ep_udev, 0, 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; - } - - memset(&ep_stdin, 0, 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; - unsigned long long int seqnum; - struct udev_list_entry *list_entry; - - udev_queue = udev_queue_new(udev); - if (udev_queue == NULL) - return -1; - seqnum = udev_queue_get_kernel_seqnum(udev_queue); - printf("seqnum kernel: %llu\n", seqnum); - seqnum = udev_queue_get_udev_seqnum(udev_queue); - printf("seqnum udev : %llu\n", seqnum); - - if (udev_queue_get_queue_is_empty(udev_queue)) - printf("queue is empty\n"); - printf("get queue list\n"); - udev_list_entry_foreach(list_entry, udev_queue_get_queued_list_entry(udev_queue)) - printf("queued: '%s' [%s]\n", udev_list_entry_get_name(list_entry), udev_list_entry_get_value(list_entry)); - printf("\n"); - printf("get queue list again\n"); - udev_list_entry_foreach(list_entry, udev_queue_get_queued_list_entry(udev_queue)) - printf("queued: '%s' [%s]\n", udev_list_entry_get_name(list_entry), udev_list_entry_get_value(list_entry)); - printf("\n"); - - list_entry = udev_queue_get_queued_list_entry(udev_queue); - if (list_entry != NULL) { - printf("event [%llu] is queued\n", seqnum); - seqnum = strtoull(udev_list_entry_get_value(list_entry), NULL, 10); - if (udev_queue_get_seqnum_is_finished(udev_queue, seqnum)) - printf("event [%llu] is not finished\n", seqnum); - else - printf("event [%llu] is finished\n", seqnum); - } - printf("\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 ? "" : 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; -} - -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]; - const char *str; - - udev = udev_new(); - printf("context: %p\n", udev); - if (udev == NULL) { - printf("no context\n"); - return 1; - } - udev_set_log_fn(udev, log_fn); - printf("set log: %p\n", log_fn); - - for (;;) { - int option; - - option = getopt_long(argc, argv, "+p:s:dhV", options, NULL); - if (option == -1) - break; - - switch (option) { - case 'p': - syspath = optarg; - break; - case 's': - subsystem = optarg; - break; - case 'd': - if (udev_get_log_priority(udev) < LOG_INFO) - udev_set_log_priority(udev, LOG_INFO); - break; - case 'h': - printf("--debug --syspath= --subsystem= --help\n"); - goto out; - case 'V': - printf("%s\n", VERSION); - goto out; - default: - goto out; - } - } - - str = udev_get_sys_path(udev); - printf("sys_path: '%s'\n", str); - str = udev_get_dev_path(udev); - printf("dev_path: '%s'\n", str); - - /* add sys path if needed */ - if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) { - snprintf(path, sizeof(path), "%s%s", udev_get_sys_path(udev), 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_monitor(udev); -out: - udev_unref(udev); - return 0; -} diff --git a/src/udev/test-udev.c b/src/udev/test-udev.c deleted file mode 100644 index 150cb16a31..0000000000 --- a/src/udev/test-udev.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2003-2004 Greg Kroah-Hartman - * Copyright (C) 2004-2008 Kay Sievers - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "udev.h" - -void udev_main_log(struct udev *udev, int priority, - const char *file, int line, const char *fn, - const char *format, va_list args) {} - -int main(int argc, char *argv[]) -{ - struct udev *udev; - struct udev_event *event = NULL; - struct udev_device *dev = NULL; - struct udev_rules *rules = NULL; - char syspath[UTIL_PATH_SIZE]; - const char *devpath; - const char *action; - sigset_t mask, sigmask_orig; - int err = -EINVAL; - - udev = udev_new(); - if (udev == NULL) - exit(EXIT_FAILURE); - log_debug("version %s\n", VERSION); - udev_selinux_init(udev); - - sigprocmask(SIG_SETMASK, NULL, &sigmask_orig); - - action = argv[1]; - if (action == NULL) { - log_error("action missing\n"); - goto out; - } - - devpath = argv[2]; - if (devpath == NULL) { - log_error("devpath missing\n"); - goto out; - } - - rules = udev_rules_new(udev, 1); - - util_strscpyl(syspath, sizeof(syspath), udev_get_sys_path(udev), devpath, NULL); - dev = udev_device_new_from_syspath(udev, syspath); - if (dev == NULL) { - log_debug("unknown device '%s'\n", devpath); - goto out; - } - - udev_device_set_action(dev, action); - 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 (strcmp(udev_device_get_subsystem(dev), "block") == 0) - mode |= S_IFBLK; - else - mode |= S_IFCHR; - - if (strcmp(action, "remove") != 0) { - util_create_path(udev, udev_device_get_devnode(dev)); - mknod(udev_device_get_devnode(dev), mode, udev_device_get_devnum(dev)); - } else { - unlink(udev_device_get_devnode(dev)); - util_delete_path(udev, udev_device_get_devnode(dev)); - } - } - - err = udev_event_execute_rules(event, rules, &sigmask_orig); - if (err == 0) - udev_event_execute_run(event, NULL); -out: - if (event != NULL && event->fd_signal >= 0) - close(event->fd_signal); - udev_event_unref(event); - udev_device_unref(dev); - udev_rules_unref(rules); - udev_selinux_exit(udev); - udev_unref(udev); - if (err != 0) - return EXIT_FAILURE; - return EXIT_SUCCESS; -} diff --git a/src/udev/test/.gitignore b/src/udev/test/.gitignore deleted file mode 100644 index 98fa886530..0000000000 --- a/src/udev/test/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/sys diff --git a/src/udev/test/rule-syntax-check.py b/src/udev/test/rule-syntax-check.py deleted file mode 100755 index 4fa3042d4f..0000000000 --- a/src/udev/test/rule-syntax-check.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/python -# Simple udev rules syntax checker -# -# (C) 2010 Canonical Ltd. -# Author: Martin Pitt -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program 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 -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - -import re -import sys - -if len(sys.argv) < 2: - print >> sys.stderr, 'Usage: %s [...]' % sys.argv[0] - sys.exit(2) - -no_args_tests = re.compile('(ACTION|DEVPATH|KERNELS?|NAME|SYMLINK|SUBSYSTEMS?|DRIVERS?|TAG|RESULT|TEST)\s*(?:=|!)=\s*"([^"]*)"$') -args_tests = re.compile('(ATTRS?|ENV|TEST){([a-zA-Z0-9/_.*%-]+)}\s*(?:=|!)=\s*"([^"]*)"$') -no_args_assign = re.compile('(NAME|SYMLINK|OWNER|GROUP|MODE|TAG|PROGRAM|RUN|LABEL|GOTO|WAIT_FOR|OPTIONS|IMPORT)\s*(?:\+=|:=|=)\s*"([^"]*)"$') -args_assign = re.compile('(ATTR|ENV|IMPORT|RUN){([a-zA-Z0-9/_.*%-]+)}\s*=\s*"([^"]*)"$') - -result = 0 -buffer = '' -for path in sys.argv[1:]: - lineno = 0 - for line in open(path): - lineno += 1 - - # handle line continuation - if line.endswith('\\\n'): - buffer += line[:-2] - continue - else: - line = buffer + line - buffer = '' - - # filter out comments and empty lines - line = line.strip() - if not line or line.startswith('#'): - continue - - for clause in line.split(','): - clause = clause.strip() - if not (no_args_tests.match(clause) or args_tests.match(clause) or - no_args_assign.match(clause) or args_assign.match(clause)): - - print('Invalid line %s:%i: %s' % (path, lineno, line)) - print(' clause:', clause) - print() - result = 1 - break - -sys.exit(result) diff --git a/src/udev/test/rules-test.sh b/src/udev/test/rules-test.sh deleted file mode 100755 index 5b3acea31f..0000000000 --- a/src/udev/test/rules-test.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -# Call the udev rule syntax checker on all rules that we ship -# -# (C) 2010 Canonical Ltd. -# Author: Martin Pitt - -[ -n "$srcdir" ] || srcdir=`dirname $0`/.. - -# skip if we don't have python -type python >/dev/null 2>&1 || { - echo "$0: No python installed, skipping udev rule syntax check" - exit 0 -} - -$srcdir/src/udev/test/rule-syntax-check.py `find $srcdir/rules -name '*.rules'` diff --git a/src/udev/test/sys.tar.xz b/src/udev/test/sys.tar.xz deleted file mode 100644 index 49ee8027b2..0000000000 Binary files a/src/udev/test/sys.tar.xz and /dev/null differ diff --git a/src/udev/test/udev-test.pl b/src/udev/test/udev-test.pl deleted file mode 100755 index a09e1b5fe2..0000000000 --- a/src/udev/test/udev-test.pl +++ /dev/null @@ -1,1560 +0,0 @@ -#!/usr/bin/perl - -# udev test -# -# Provides automated testing of the udev binary. -# The whole test is self contained in this file, except the matching sysfs tree. -# Simply extend the @tests array, to add a new test variant. -# -# Every test is driven by its own temporary config file. -# This program prepares the environment, creates the config and calls udev. -# -# udev parses the rules, looks at the provided sysfs and -# first creates and then removes the device node. -# After creation and removal the result is checked against the -# expected value and the result is printed. -# -# Copyright (C) 2004-2011 Kay Sievers -# Copyright (C) 2004 Leann Ogasawara - -use warnings; -use strict; - -my $PWD = $ENV{PWD}; -my $sysfs = "src/udev/test/sys"; -my $udev_bin = "./test-udev"; -my $valgrind = 0; -my $udev_bin_valgrind = "valgrind --tool=memcheck --leak-check=yes --quiet $udev_bin"; -my $udev_root = "udev-root"; -my $udev_conf = "udev-test.conf"; -my $udev_rules = "udev-test.rules"; - -my @tests = ( - { - desc => "no rules", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "sda" , - exp_rem_error => "yes", - rules => < "label test of scsi disc", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "boot_disk" , - rules => < "label test of scsi disc", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "boot_disk" , - rules => < "label test of scsi disc", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "boot_disk" , - rules => < "label test of scsi partition", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "boot_disk1" , - rules => < "label test of pattern match", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "boot_disk1" , - rules => < "label test of multiple sysfs files", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "boot_disk1" , - rules => < "label test of max sysfs files (skip invalid rule)", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "boot_disk1" , - rules => < "catch device by *", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "modem/0" , - rules => < "catch device by * - take 2", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "modem/0" , - rules => < "catch device by ?", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "modem/0" , - rules => < "catch device by character class", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "modem/0" , - rules => < "replace kernel name", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "modem" , - rules => < "Handle comment lines in config file (and replace kernel name)", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "modem" , - rules => < "Handle comment lines in config file with whitespace (and replace kernel name)", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "modem" , - rules => < "Handle whitespace only lines (and replace kernel name)", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "whitespace" , - rules => < "Handle empty lines in config file (and replace kernel name)", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "modem" , - rules => < "Handle backslashed multi lines in config file (and replace kernel name)", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "modem" , - rules => < "preserve backslashes, if they are not for a newline", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "aaa", - rules => < "Handle stupid backslashed multi lines in config file (and replace kernel name)", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "modem" , - rules => < "subdirectory handling", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "sub/direct/ory/modem" , - rules => < "parent device name match of scsi partition", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", - exp_name => "first_disk5" , - rules => < "test substitution chars", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", - exp_name => "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" , - rules => < "import of shell-value file", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "subdir/err/node" , - rules => < "import of shell-value returned from program", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "node12345678", - rules => < "sustitution of sysfs value (%s{file})", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "disk-ATA-sda" , - rules => < "program result substitution", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", - exp_name => "special-device-5" , - not_exp_name => "not" , - rules => < "program result substitution (newline removal)", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", - exp_name => "newline_removed" , - rules => < "program result substitution", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", - exp_name => "test-0:0:0:0" , - rules => < "program with lots of arguments", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", - exp_name => "foo9" , - rules => < "program with subshell", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", - exp_name => "bar9" , - rules => < "program arguments combined with apostrophes", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", - exp_name => "foo7" , - rules => < "characters before the %c{N} substitution", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", - exp_name => "my-foo9" , - rules => < "substitute the second to last argument", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", - exp_name => "my-foo8" , - rules => < "test substitution by variable name", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", - exp_name => "Major:8-minor:5-kernelnumber:5-id:0:0:0:0", - rules => < "test substitution by variable name 2", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", - exp_name => "Major:8-minor:5-kernelnumber:5-id:0:0:0:0", - rules => < "test substitution by variable name 3", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", - exp_name => "850:0:0:05" , - rules => < "test substitution by variable name 4", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", - exp_name => "855" , - rules => < "test substitution by variable name 5", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", - exp_name => "8550:0:0:0" , - rules => < "non matching SUBSYSTEMS for device with no parent", - devpath => "/devices/virtual/tty/console", - exp_name => "TTY", - rules => < "non matching SUBSYSTEMS", - devpath => "/devices/virtual/tty/console", - exp_name => "TTY" , - rules => < "ATTRS match", - devpath => "/devices/virtual/tty/console", - exp_name => "foo" , - rules => < "ATTR (empty file)", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "empty" , - rules => < "ATTR (non-existent file)", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "non-existent" , - rules => < "program and bus type match", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "scsi-0:0:0:0" , - rules => < "sysfs parent hierarchy", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "modem" , - rules => < "name test with ! in the name", - devpath => "/devices/virtual/block/fake!blockdev0", - exp_name => "is/a/fake/blockdev0" , - rules => < "name test with ! in the name, but no matching rule", - devpath => "/devices/virtual/block/fake!blockdev0", - exp_name => "fake/blockdev0" , - exp_rem_error => "yes", - rules => < "KERNELS rule", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "scsi-0:0:0:0", - rules => < "KERNELS wildcard all", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "scsi-0:0:0:0", - rules => < "KERNELS wildcard partial", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "scsi-0:0:0:0", - rules => < "KERNELS wildcard partial 2", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "scsi-0:0:0:0", - rules => < "substitute attr with link target value (first match)", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "driver-is-sd", - rules => < "substitute attr with link target value (currently selected device)", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "driver-is-ahci", - rules => < "ignore ATTRS attribute whitespace", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "ignored", - rules => < "do not ignore ATTRS attribute whitespace", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "matched-with-space", - rules => < "permissions USER=bad GROUP=name", - devpath => "/devices/virtual/tty/tty33", - exp_name => "tty33", - exp_perms => "0:0:0600", - rules => < "permissions OWNER=5000", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "node", - exp_perms => "5000::0600", - rules => < "permissions GROUP=100", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "node", - exp_perms => ":100:0660", - rules => < "textual user id", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "node", - exp_perms => "nobody::0600", - rules => < "textual group id", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "node", - exp_perms => ":daemon:0660", - rules => < "textual user/group id", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "node", - exp_perms => "root:mail:0660", - rules => < "permissions MODE=0777", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "node", - exp_perms => "::0777", - rules => < "permissions OWNER=5000 GROUP=100 MODE=0777", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "node", - exp_perms => "5000:100:0777", - rules => < "permissions OWNER to 5000", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "ttyACM0", - exp_perms => "5000::", - rules => < "permissions GROUP to 100", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "ttyACM0", - exp_perms => ":100:0660", - rules => < "permissions MODE to 0060", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "ttyACM0", - exp_perms => "::0060", - rules => < "permissions OWNER, GROUP, MODE", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "ttyACM0", - exp_perms => "5000:100:0777", - rules => < "permissions only rule", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "ttyACM0", - exp_perms => "5000:100:0777", - rules => < "multiple permissions only rule", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "ttyACM0", - exp_perms => "3000:4000:0777", - rules => < "permissions only rule with override at SYMLINK+ rule", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "ttyACM0", - exp_perms => "3000:8000:0777", - rules => < "major/minor number test", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "node", - exp_majorminor => "8:0", - rules => < "big major number test", - devpath => "/devices/virtual/misc/misc-fake1", - exp_name => "node", - exp_majorminor => "4095:1", - rules => < "big major and big minor number test", - devpath => "/devices/virtual/misc/misc-fake89999", - exp_name => "node", - exp_majorminor => "4095:89999", - rules => < "multiple symlinks with format char", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "symlink2-ttyACM0", - rules => < "multiple symlinks with a lot of s p a c e s", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "one", - not_exp_name => " ", - rules => < "symlink creation (same directory)", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "modem0", - rules => < "multiple symlinks", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "second-0" , - rules => < "symlink name '.'", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => ".", - exp_add_error => "yes", - exp_rem_error => "yes", - rules => < "symlink node to itself", - devpath => "/devices/virtual/tty/tty0", - exp_name => "link", - exp_add_error => "yes", - exp_rem_error => "yes", - option => "clean", - rules => < "symlink %n substitution", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "symlink0", - rules => < "symlink %k substitution", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "symlink-ttyACM0", - rules => < "symlink %M:%m substitution", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "major-166:0", - rules => < "symlink %b substitution", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "symlink-0:0:0:0", - rules => < "symlink %c substitution", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "test", - rules => < "symlink %c{N} substitution", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "test", - rules => < "symlink %c{N+} substitution", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "this", - rules => < "symlink only rule with %c{N+}", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "test", - rules => < "symlink %s{filename} substitution", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "166:0", - rules => < "program result substitution (numbered part of)", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", - exp_name => "link1", - rules => < "program result substitution (numbered part of+)", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", - exp_name => "link4", - rules => < "SUBSYSTEM match test", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "node", - rules => < "DRIVERS match test", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "node", - rules => < "devnode substitution test", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "node", - rules => < "parent node name substitution test", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "sda-part-1", - rules => < "udev_root substitution", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "start-udev-root-end", - rules => < "last_rule option", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "last", - rules => < "negation KERNEL!=", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "match", - rules => < "negation SUBSYSTEM!=", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "not-anything", - rules => < "negation PROGRAM!= exit code", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "nonzero-program", - rules => < "test for whitespace between the operator", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "true", - rules => < "ENV{} test", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "true", - rules => < "ENV{} test", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "true", - rules => < "ENV{} test (assign)", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "true", - rules => < "ENV{} test (assign 2 times)", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "true", - rules => < "ENV{} test (assign2)", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "part", - rules => < "untrusted string sanitize", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "sane", - rules => < "untrusted string sanitize (don't replace utf8)", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "uber", - rules => < "untrusted string sanitize (replace invalid utf8)", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "replaced", - rules => < "read sysfs value from parent device", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "serial-354172020305000", - rules => < "match against empty key string", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "ok", - rules => < "check ACTION value", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "ok", - rules => < "final assignment", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "ok", - exp_perms => "root:tty:0640", - rules => < "final assignment 2", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "ok", - exp_perms => "root:tty:0640", - rules => < "env substitution", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "node-add-me", - rules => < "reset list to current value", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "three", - not_exp_name => "two", - rules => < "test empty SYMLINK+ (empty override)", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "right", - not_exp_name => "wrong", - rules => < "test multi matches", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "right", - rules => < "test multi matches 2", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "right", - rules => < "test multi matches 3", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "right", - rules => < "test multi matches 4", - devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", - exp_name => "right", - rules => < "IMPORT parent test sequence 1/2 (keep)", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "parent", - option => "keep", - rules => < "IMPORT parent test sequence 2/2 (keep)", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "parentenv-parent_right", - option => "clean", - rules => < "GOTO test", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "right", - rules => < "GOTO label does not exist", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "right", - rules => < "SYMLINK+ compare test", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "right", - not_exp_name => "wrong", - rules => < "invalid key operation", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "yes", - rules => < "operator chars in attribute", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "yes", - rules => < "overlong comment line", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "yes", - rules => < "magic subsys/kernel lookup", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "00:16:41:e2:8d:ff", - rules => < "TEST absolute path", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "there", - rules => < "TEST subsys/kernel lookup", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "yes", - rules => < "TEST relative path", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "relative", - rules => < "TEST wildcard substitution (find queue/nr_requests)", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "found-subdir", - rules => < "TEST MODE=0000", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "sda", - exp_perms => "0:0:0000", - exp_rem_error => "yes", - rules => < "TEST PROGRAM feeds OWNER, GROUP, MODE", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "sda", - exp_perms => "5000:100:0400", - exp_rem_error => "yes", - rules => < "TEST PROGRAM feeds MODE with overflow", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "sda", - exp_perms => "0:0:0440", - exp_rem_error => "yes", - rules => < "magic [subsys/sysname] attribute substitution", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "sda-8741C4G-end", - exp_perms => "0:0:0600", - rules => < "builtin path_id", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0", - rules => <$udev_rules" || die "unable to create rules file: $udev_rules"; - print CONF $$rules; - close CONF; - - if ($valgrind > 0) { - system("$udev_bin_valgrind $action $devpath"); - } else { - system("$udev_bin", "$action", "$devpath"); - } -} - -my $error = 0; - -sub permissions_test { - my($rules, $uid, $gid, $mode) = @_; - - my $wrong = 0; - my $userid; - my $groupid; - - $rules->{exp_perms} =~ m/^(.*):(.*):(.*)$/; - if ($1 ne "") { - if (defined(getpwnam($1))) { - $userid = int(getpwnam($1)); - } else { - $userid = $1; - } - if ($uid != $userid) { $wrong = 1; } - } - if ($2 ne "") { - if (defined(getgrnam($2))) { - $groupid = int(getgrnam($2)); - } else { - $groupid = $2; - } - if ($gid != $groupid) { $wrong = 1; } - } - if ($3 ne "") { - if (($mode & 07777) != oct($3)) { $wrong = 1; }; - } - if ($wrong == 0) { - print "permissions: ok\n"; - } else { - printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3); - printf " created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777; - print "permissions: error\n"; - $error++; - sleep(1); - } -} - -sub major_minor_test { - my($rules, $rdev) = @_; - - my $major = ($rdev >> 8) & 0xfff; - my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00); - my $wrong = 0; - - $rules->{exp_majorminor} =~ m/^(.*):(.*)$/; - if ($1 ne "") { - if ($major != $1) { $wrong = 1; }; - } - if ($2 ne "") { - if ($minor != $2) { $wrong = 1; }; - } - if ($wrong == 0) { - print "major:minor: ok\n"; - } else { - printf " expected major:minor is: %i:%i\n", $1, $2; - printf " created major:minor is : %i:%i\n", $major, $minor; - print "major:minor: error\n"; - $error++; - sleep(1); - } -} - -sub make_udev_root { - system("rm -rf $udev_root"); - mkdir($udev_root) || die "unable to create udev_root: $udev_root\n"; - # setting group and mode of udev_root ensures the tests work - # even if the parent directory has setgid bit enabled. - chown (0, 0, $udev_root) || die "unable to chown $udev_root\n"; - chmod (0755, $udev_root) || die "unable to chmod $udev_root\n"; -} - -sub run_test { - my ($rules, $number) = @_; - - print "TEST $number: $rules->{desc}\n"; - print "device \'$rules->{devpath}\' expecting node/link \'$rules->{exp_name}\'\n"; - - udev("add", $rules->{devpath}, \$rules->{rules}); - if (defined($rules->{not_exp_name})) { - if ((-e "$PWD/$udev_root/$rules->{not_exp_name}") || - (-l "$PWD/$udev_root/$rules->{not_exp_name}")) { - print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n"; - $error++; - sleep(1); - } - } - - if ((-e "$PWD/$udev_root/$rules->{exp_name}") || - (-l "$PWD/$udev_root/$rules->{exp_name}")) { - - my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, - $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root/$rules->{exp_name}"); - - if (defined($rules->{exp_perms})) { - permissions_test($rules, $uid, $gid, $mode); - } - if (defined($rules->{exp_majorminor})) { - major_minor_test($rules, $rdev); - } - print "add: ok\n"; - } else { - print "add: error"; - if ($rules->{exp_add_error}) { - print " as expected\n"; - } else { - print "\n"; - system("tree $udev_root"); - print "\n"; - $error++; - sleep(1); - } - } - - if (defined($rules->{option}) && $rules->{option} eq "keep") { - print "\n\n"; - return; - } - - udev("remove", $rules->{devpath}, \$rules->{rules}); - if ((-e "$PWD/$udev_root/$rules->{exp_name}") || - (-l "$PWD/$udev_root/$rules->{exp_name}")) { - print "remove: error"; - if ($rules->{exp_rem_error}) { - print " as expected\n"; - } else { - print "\n"; - system("tree $udev_root"); - print "\n"; - $error++; - sleep(1); - } - } else { - print "remove: ok\n"; - } - - print "\n"; - - if (defined($rules->{option}) && $rules->{option} eq "clean") { - make_udev_root(); - } - -} - -# only run if we have root permissions -# due to mknod restrictions -if (!($<==0)) { - print "Must have root permissions to run properly.\n"; - exit; -} - -# prepare -make_udev_root(); - -# create config file -open CONF, ">$udev_conf" || die "unable to create config file: $udev_conf"; -print CONF "udev_root=\"$udev_root\"\n"; -print CONF "udev_run=\"$udev_root/.udev\"\n"; -print CONF "udev_sys=\"$sysfs\"\n"; -print CONF "udev_rules=\"$PWD\"\n"; -print CONF "udev_log=\"err\"\n"; -close CONF; - -my $test_num = 1; -my @list; - -foreach my $arg (@ARGV) { - if ($arg =~ m/--valgrind/) { - $valgrind = 1; - printf("using valgrind\n"); - } else { - push(@list, $arg); - } -} - -if ($list[0]) { - foreach my $arg (@list) { - if (defined($tests[$arg-1]->{desc})) { - print "udev-test will run test number $arg:\n\n"; - run_test($tests[$arg-1], $arg); - } else { - print "test does not exist.\n"; - } - } -} else { - # test all - print "\nudev-test will run ".($#tests + 1)." tests:\n\n"; - - foreach my $rules (@tests) { - run_test($rules, $test_num); - $test_num++; - } -} - -print "$error errors occured\n\n"; - -# cleanup -system("rm -rf $udev_root"); -unlink($udev_rules); -unlink($udev_conf); - -if ($error > 0) { - exit(1); -} -exit(0); diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000000..98fa886530 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1 @@ +/sys diff --git a/test/rule-syntax-check.py b/test/rule-syntax-check.py new file mode 100755 index 0000000000..4fa3042d4f --- /dev/null +++ b/test/rule-syntax-check.py @@ -0,0 +1,64 @@ +#!/usr/bin/python +# Simple udev rules syntax checker +# +# (C) 2010 Canonical Ltd. +# Author: Martin Pitt +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + +import re +import sys + +if len(sys.argv) < 2: + print >> sys.stderr, 'Usage: %s [...]' % sys.argv[0] + sys.exit(2) + +no_args_tests = re.compile('(ACTION|DEVPATH|KERNELS?|NAME|SYMLINK|SUBSYSTEMS?|DRIVERS?|TAG|RESULT|TEST)\s*(?:=|!)=\s*"([^"]*)"$') +args_tests = re.compile('(ATTRS?|ENV|TEST){([a-zA-Z0-9/_.*%-]+)}\s*(?:=|!)=\s*"([^"]*)"$') +no_args_assign = re.compile('(NAME|SYMLINK|OWNER|GROUP|MODE|TAG|PROGRAM|RUN|LABEL|GOTO|WAIT_FOR|OPTIONS|IMPORT)\s*(?:\+=|:=|=)\s*"([^"]*)"$') +args_assign = re.compile('(ATTR|ENV|IMPORT|RUN){([a-zA-Z0-9/_.*%-]+)}\s*=\s*"([^"]*)"$') + +result = 0 +buffer = '' +for path in sys.argv[1:]: + lineno = 0 + for line in open(path): + lineno += 1 + + # handle line continuation + if line.endswith('\\\n'): + buffer += line[:-2] + continue + else: + line = buffer + line + buffer = '' + + # filter out comments and empty lines + line = line.strip() + if not line or line.startswith('#'): + continue + + for clause in line.split(','): + clause = clause.strip() + if not (no_args_tests.match(clause) or args_tests.match(clause) or + no_args_assign.match(clause) or args_assign.match(clause)): + + print('Invalid line %s:%i: %s' % (path, lineno, line)) + print(' clause:', clause) + print() + result = 1 + break + +sys.exit(result) diff --git a/test/rules-test.sh b/test/rules-test.sh new file mode 100755 index 0000000000..1e224ff8b5 --- /dev/null +++ b/test/rules-test.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# Call the udev rule syntax checker on all rules that we ship +# +# (C) 2010 Canonical Ltd. +# Author: Martin Pitt + +[ -n "$srcdir" ] || srcdir=`dirname $0`/.. + +# skip if we don't have python +type python >/dev/null 2>&1 || { + echo "$0: No python installed, skipping udev rule syntax check" + exit 0 +} + +$srcdir/test/rule-syntax-check.py `find $srcdir/rules -name '*.rules'` diff --git a/test/sys.tar.xz b/test/sys.tar.xz new file mode 100644 index 0000000000..49ee8027b2 Binary files /dev/null and b/test/sys.tar.xz differ diff --git a/test/udev-test.pl b/test/udev-test.pl new file mode 100755 index 0000000000..0a2571a1d5 --- /dev/null +++ b/test/udev-test.pl @@ -0,0 +1,1560 @@ +#!/usr/bin/perl + +# udev test +# +# Provides automated testing of the udev binary. +# The whole test is self contained in this file, except the matching sysfs tree. +# Simply extend the @tests array, to add a new test variant. +# +# Every test is driven by its own temporary config file. +# This program prepares the environment, creates the config and calls udev. +# +# udev parses the rules, looks at the provided sysfs and +# first creates and then removes the device node. +# After creation and removal the result is checked against the +# expected value and the result is printed. +# +# Copyright (C) 2004-2011 Kay Sievers +# Copyright (C) 2004 Leann Ogasawara + +use warnings; +use strict; + +my $PWD = $ENV{PWD}; +my $sysfs = "test/sys"; +my $udev_bin = "./test-udev"; +my $valgrind = 0; +my $udev_bin_valgrind = "valgrind --tool=memcheck --leak-check=yes --quiet $udev_bin"; +my $udev_root = "udev-root"; +my $udev_conf = "udev-test.conf"; +my $udev_rules = "udev-test.rules"; + +my @tests = ( + { + desc => "no rules", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "sda" , + exp_rem_error => "yes", + rules => < "label test of scsi disc", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "boot_disk" , + rules => < "label test of scsi disc", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "boot_disk" , + rules => < "label test of scsi disc", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "boot_disk" , + rules => < "label test of scsi partition", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "boot_disk1" , + rules => < "label test of pattern match", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "boot_disk1" , + rules => < "label test of multiple sysfs files", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "boot_disk1" , + rules => < "label test of max sysfs files (skip invalid rule)", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "boot_disk1" , + rules => < "catch device by *", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "modem/0" , + rules => < "catch device by * - take 2", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "modem/0" , + rules => < "catch device by ?", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "modem/0" , + rules => < "catch device by character class", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "modem/0" , + rules => < "replace kernel name", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "modem" , + rules => < "Handle comment lines in config file (and replace kernel name)", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "modem" , + rules => < "Handle comment lines in config file with whitespace (and replace kernel name)", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "modem" , + rules => < "Handle whitespace only lines (and replace kernel name)", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "whitespace" , + rules => < "Handle empty lines in config file (and replace kernel name)", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "modem" , + rules => < "Handle backslashed multi lines in config file (and replace kernel name)", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "modem" , + rules => < "preserve backslashes, if they are not for a newline", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "aaa", + rules => < "Handle stupid backslashed multi lines in config file (and replace kernel name)", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "modem" , + rules => < "subdirectory handling", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "sub/direct/ory/modem" , + rules => < "parent device name match of scsi partition", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "first_disk5" , + rules => < "test substitution chars", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" , + rules => < "import of shell-value file", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "subdir/err/node" , + rules => < "import of shell-value returned from program", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "node12345678", + rules => < "sustitution of sysfs value (%s{file})", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "disk-ATA-sda" , + rules => < "program result substitution", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "special-device-5" , + not_exp_name => "not" , + rules => < "program result substitution (newline removal)", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "newline_removed" , + rules => < "program result substitution", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "test-0:0:0:0" , + rules => < "program with lots of arguments", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "foo9" , + rules => < "program with subshell", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "bar9" , + rules => < "program arguments combined with apostrophes", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "foo7" , + rules => < "characters before the %c{N} substitution", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "my-foo9" , + rules => < "substitute the second to last argument", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "my-foo8" , + rules => < "test substitution by variable name", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "Major:8-minor:5-kernelnumber:5-id:0:0:0:0", + rules => < "test substitution by variable name 2", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "Major:8-minor:5-kernelnumber:5-id:0:0:0:0", + rules => < "test substitution by variable name 3", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "850:0:0:05" , + rules => < "test substitution by variable name 4", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "855" , + rules => < "test substitution by variable name 5", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "8550:0:0:0" , + rules => < "non matching SUBSYSTEMS for device with no parent", + devpath => "/devices/virtual/tty/console", + exp_name => "TTY", + rules => < "non matching SUBSYSTEMS", + devpath => "/devices/virtual/tty/console", + exp_name => "TTY" , + rules => < "ATTRS match", + devpath => "/devices/virtual/tty/console", + exp_name => "foo" , + rules => < "ATTR (empty file)", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "empty" , + rules => < "ATTR (non-existent file)", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "non-existent" , + rules => < "program and bus type match", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "scsi-0:0:0:0" , + rules => < "sysfs parent hierarchy", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "modem" , + rules => < "name test with ! in the name", + devpath => "/devices/virtual/block/fake!blockdev0", + exp_name => "is/a/fake/blockdev0" , + rules => < "name test with ! in the name, but no matching rule", + devpath => "/devices/virtual/block/fake!blockdev0", + exp_name => "fake/blockdev0" , + exp_rem_error => "yes", + rules => < "KERNELS rule", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "scsi-0:0:0:0", + rules => < "KERNELS wildcard all", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "scsi-0:0:0:0", + rules => < "KERNELS wildcard partial", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "scsi-0:0:0:0", + rules => < "KERNELS wildcard partial 2", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "scsi-0:0:0:0", + rules => < "substitute attr with link target value (first match)", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "driver-is-sd", + rules => < "substitute attr with link target value (currently selected device)", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "driver-is-ahci", + rules => < "ignore ATTRS attribute whitespace", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "ignored", + rules => < "do not ignore ATTRS attribute whitespace", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "matched-with-space", + rules => < "permissions USER=bad GROUP=name", + devpath => "/devices/virtual/tty/tty33", + exp_name => "tty33", + exp_perms => "0:0:0600", + rules => < "permissions OWNER=5000", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "node", + exp_perms => "5000::0600", + rules => < "permissions GROUP=100", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "node", + exp_perms => ":100:0660", + rules => < "textual user id", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "node", + exp_perms => "nobody::0600", + rules => < "textual group id", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "node", + exp_perms => ":daemon:0660", + rules => < "textual user/group id", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "node", + exp_perms => "root:mail:0660", + rules => < "permissions MODE=0777", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "node", + exp_perms => "::0777", + rules => < "permissions OWNER=5000 GROUP=100 MODE=0777", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "node", + exp_perms => "5000:100:0777", + rules => < "permissions OWNER to 5000", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "ttyACM0", + exp_perms => "5000::", + rules => < "permissions GROUP to 100", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "ttyACM0", + exp_perms => ":100:0660", + rules => < "permissions MODE to 0060", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "ttyACM0", + exp_perms => "::0060", + rules => < "permissions OWNER, GROUP, MODE", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "ttyACM0", + exp_perms => "5000:100:0777", + rules => < "permissions only rule", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "ttyACM0", + exp_perms => "5000:100:0777", + rules => < "multiple permissions only rule", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "ttyACM0", + exp_perms => "3000:4000:0777", + rules => < "permissions only rule with override at SYMLINK+ rule", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "ttyACM0", + exp_perms => "3000:8000:0777", + rules => < "major/minor number test", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "node", + exp_majorminor => "8:0", + rules => < "big major number test", + devpath => "/devices/virtual/misc/misc-fake1", + exp_name => "node", + exp_majorminor => "4095:1", + rules => < "big major and big minor number test", + devpath => "/devices/virtual/misc/misc-fake89999", + exp_name => "node", + exp_majorminor => "4095:89999", + rules => < "multiple symlinks with format char", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "symlink2-ttyACM0", + rules => < "multiple symlinks with a lot of s p a c e s", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "one", + not_exp_name => " ", + rules => < "symlink creation (same directory)", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "modem0", + rules => < "multiple symlinks", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "second-0" , + rules => < "symlink name '.'", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => ".", + exp_add_error => "yes", + exp_rem_error => "yes", + rules => < "symlink node to itself", + devpath => "/devices/virtual/tty/tty0", + exp_name => "link", + exp_add_error => "yes", + exp_rem_error => "yes", + option => "clean", + rules => < "symlink %n substitution", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "symlink0", + rules => < "symlink %k substitution", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "symlink-ttyACM0", + rules => < "symlink %M:%m substitution", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "major-166:0", + rules => < "symlink %b substitution", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "symlink-0:0:0:0", + rules => < "symlink %c substitution", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "test", + rules => < "symlink %c{N} substitution", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "test", + rules => < "symlink %c{N+} substitution", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "this", + rules => < "symlink only rule with %c{N+}", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "test", + rules => < "symlink %s{filename} substitution", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "166:0", + rules => < "program result substitution (numbered part of)", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "link1", + rules => < "program result substitution (numbered part of+)", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", + exp_name => "link4", + rules => < "SUBSYSTEM match test", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "node", + rules => < "DRIVERS match test", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "node", + rules => < "devnode substitution test", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "node", + rules => < "parent node name substitution test", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "sda-part-1", + rules => < "udev_root substitution", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "start-udev-root-end", + rules => < "last_rule option", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "last", + rules => < "negation KERNEL!=", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "match", + rules => < "negation SUBSYSTEM!=", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "not-anything", + rules => < "negation PROGRAM!= exit code", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "nonzero-program", + rules => < "test for whitespace between the operator", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "true", + rules => < "ENV{} test", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "true", + rules => < "ENV{} test", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "true", + rules => < "ENV{} test (assign)", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "true", + rules => < "ENV{} test (assign 2 times)", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "true", + rules => < "ENV{} test (assign2)", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "part", + rules => < "untrusted string sanitize", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "sane", + rules => < "untrusted string sanitize (don't replace utf8)", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "uber", + rules => < "untrusted string sanitize (replace invalid utf8)", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "replaced", + rules => < "read sysfs value from parent device", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "serial-354172020305000", + rules => < "match against empty key string", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "ok", + rules => < "check ACTION value", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "ok", + rules => < "final assignment", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "ok", + exp_perms => "root:tty:0640", + rules => < "final assignment 2", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "ok", + exp_perms => "root:tty:0640", + rules => < "env substitution", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "node-add-me", + rules => < "reset list to current value", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "three", + not_exp_name => "two", + rules => < "test empty SYMLINK+ (empty override)", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "right", + not_exp_name => "wrong", + rules => < "test multi matches", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "right", + rules => < "test multi matches 2", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "right", + rules => < "test multi matches 3", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "right", + rules => < "test multi matches 4", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "right", + rules => < "IMPORT parent test sequence 1/2 (keep)", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "parent", + option => "keep", + rules => < "IMPORT parent test sequence 2/2 (keep)", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "parentenv-parent_right", + option => "clean", + rules => < "GOTO test", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "right", + rules => < "GOTO label does not exist", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "right", + rules => < "SYMLINK+ compare test", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "right", + not_exp_name => "wrong", + rules => < "invalid key operation", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "yes", + rules => < "operator chars in attribute", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "yes", + rules => < "overlong comment line", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", + exp_name => "yes", + rules => < "magic subsys/kernel lookup", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "00:16:41:e2:8d:ff", + rules => < "TEST absolute path", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "there", + rules => < "TEST subsys/kernel lookup", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "yes", + rules => < "TEST relative path", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "relative", + rules => < "TEST wildcard substitution (find queue/nr_requests)", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "found-subdir", + rules => < "TEST MODE=0000", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "sda", + exp_perms => "0:0:0000", + exp_rem_error => "yes", + rules => < "TEST PROGRAM feeds OWNER, GROUP, MODE", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "sda", + exp_perms => "5000:100:0400", + exp_rem_error => "yes", + rules => < "TEST PROGRAM feeds MODE with overflow", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "sda", + exp_perms => "0:0:0440", + exp_rem_error => "yes", + rules => < "magic [subsys/sysname] attribute substitution", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "sda-8741C4G-end", + exp_perms => "0:0:0600", + rules => < "builtin path_id", + devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", + exp_name => "disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0", + rules => <$udev_rules" || die "unable to create rules file: $udev_rules"; + print CONF $$rules; + close CONF; + + if ($valgrind > 0) { + system("$udev_bin_valgrind $action $devpath"); + } else { + system("$udev_bin", "$action", "$devpath"); + } +} + +my $error = 0; + +sub permissions_test { + my($rules, $uid, $gid, $mode) = @_; + + my $wrong = 0; + my $userid; + my $groupid; + + $rules->{exp_perms} =~ m/^(.*):(.*):(.*)$/; + if ($1 ne "") { + if (defined(getpwnam($1))) { + $userid = int(getpwnam($1)); + } else { + $userid = $1; + } + if ($uid != $userid) { $wrong = 1; } + } + if ($2 ne "") { + if (defined(getgrnam($2))) { + $groupid = int(getgrnam($2)); + } else { + $groupid = $2; + } + if ($gid != $groupid) { $wrong = 1; } + } + if ($3 ne "") { + if (($mode & 07777) != oct($3)) { $wrong = 1; }; + } + if ($wrong == 0) { + print "permissions: ok\n"; + } else { + printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3); + printf " created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777; + print "permissions: error\n"; + $error++; + sleep(1); + } +} + +sub major_minor_test { + my($rules, $rdev) = @_; + + my $major = ($rdev >> 8) & 0xfff; + my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00); + my $wrong = 0; + + $rules->{exp_majorminor} =~ m/^(.*):(.*)$/; + if ($1 ne "") { + if ($major != $1) { $wrong = 1; }; + } + if ($2 ne "") { + if ($minor != $2) { $wrong = 1; }; + } + if ($wrong == 0) { + print "major:minor: ok\n"; + } else { + printf " expected major:minor is: %i:%i\n", $1, $2; + printf " created major:minor is : %i:%i\n", $major, $minor; + print "major:minor: error\n"; + $error++; + sleep(1); + } +} + +sub make_udev_root { + system("rm -rf $udev_root"); + mkdir($udev_root) || die "unable to create udev_root: $udev_root\n"; + # setting group and mode of udev_root ensures the tests work + # even if the parent directory has setgid bit enabled. + chown (0, 0, $udev_root) || die "unable to chown $udev_root\n"; + chmod (0755, $udev_root) || die "unable to chmod $udev_root\n"; +} + +sub run_test { + my ($rules, $number) = @_; + + print "TEST $number: $rules->{desc}\n"; + print "device \'$rules->{devpath}\' expecting node/link \'$rules->{exp_name}\'\n"; + + udev("add", $rules->{devpath}, \$rules->{rules}); + if (defined($rules->{not_exp_name})) { + if ((-e "$PWD/$udev_root/$rules->{not_exp_name}") || + (-l "$PWD/$udev_root/$rules->{not_exp_name}")) { + print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n"; + $error++; + sleep(1); + } + } + + if ((-e "$PWD/$udev_root/$rules->{exp_name}") || + (-l "$PWD/$udev_root/$rules->{exp_name}")) { + + my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, + $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root/$rules->{exp_name}"); + + if (defined($rules->{exp_perms})) { + permissions_test($rules, $uid, $gid, $mode); + } + if (defined($rules->{exp_majorminor})) { + major_minor_test($rules, $rdev); + } + print "add: ok\n"; + } else { + print "add: error"; + if ($rules->{exp_add_error}) { + print " as expected\n"; + } else { + print "\n"; + system("tree $udev_root"); + print "\n"; + $error++; + sleep(1); + } + } + + if (defined($rules->{option}) && $rules->{option} eq "keep") { + print "\n\n"; + return; + } + + udev("remove", $rules->{devpath}, \$rules->{rules}); + if ((-e "$PWD/$udev_root/$rules->{exp_name}") || + (-l "$PWD/$udev_root/$rules->{exp_name}")) { + print "remove: error"; + if ($rules->{exp_rem_error}) { + print " as expected\n"; + } else { + print "\n"; + system("tree $udev_root"); + print "\n"; + $error++; + sleep(1); + } + } else { + print "remove: ok\n"; + } + + print "\n"; + + if (defined($rules->{option}) && $rules->{option} eq "clean") { + make_udev_root(); + } + +} + +# only run if we have root permissions +# due to mknod restrictions +if (!($<==0)) { + print "Must have root permissions to run properly.\n"; + exit; +} + +# prepare +make_udev_root(); + +# create config file +open CONF, ">$udev_conf" || die "unable to create config file: $udev_conf"; +print CONF "udev_root=\"$udev_root\"\n"; +print CONF "udev_run=\"$udev_root/.udev\"\n"; +print CONF "udev_sys=\"$sysfs\"\n"; +print CONF "udev_rules=\"$PWD\"\n"; +print CONF "udev_log=\"err\"\n"; +close CONF; + +my $test_num = 1; +my @list; + +foreach my $arg (@ARGV) { + if ($arg =~ m/--valgrind/) { + $valgrind = 1; + printf("using valgrind\n"); + } else { + push(@list, $arg); + } +} + +if ($list[0]) { + foreach my $arg (@list) { + if (defined($tests[$arg-1]->{desc})) { + print "udev-test will run test number $arg:\n\n"; + run_test($tests[$arg-1], $arg); + } else { + print "test does not exist.\n"; + } + } +} else { + # test all + print "\nudev-test will run ".($#tests + 1)." tests:\n\n"; + + foreach my $rules (@tests) { + run_test($rules, $test_num); + $test_num++; + } +} + +print "$error errors occured\n\n"; + +# cleanup +system("rm -rf $udev_root"); +unlink($udev_rules); +unlink($udev_conf); + +if ($error > 0) { + exit(1); +} +exit(0); -- cgit v1.2.3-54-g00ecf From 6ada823a9a0979ea145fd70add1007c21caa45c0 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Mon, 16 Apr 2012 17:21:22 +0200 Subject: udev: remove configuration options for /dev, /sys, /run directories --- Makefile.am | 26 +++++-- TODO | 5 +- docs/libudev/libudev-sections.txt | 4 +- man/udev.xml | 8 --- src/libudev/libudev-device-private.c | 11 ++- src/libudev/libudev-device.c | 69 +++++++++---------- src/libudev/libudev-enumerate.c | 25 ++----- src/libudev/libudev-private.h | 6 +- src/libudev/libudev-queue-private.c | 16 ++--- src/libudev/libudev-queue.c | 8 +-- src/libudev/libudev-selinux-private.c | 2 +- src/libudev/libudev.c | 119 +++------------------------------ src/test/test-libudev.c | 10 +-- src/test/test-udev.c | 2 +- src/udev/accelerometer/accelerometer.c | 7 +- src/udev/collect/collect.c | 2 +- src/udev/udev-builtin-firmware.c | 2 +- src/udev/udev-ctrl.c | 3 +- src/udev/udev-event.c | 30 +++------ src/udev/udev-node.c | 11 ++- src/udev/udev-rules.c | 72 ++++++++++++++------ src/udev/udev-watch.c | 46 +++++-------- src/udev/udev.h | 1 + src/udev/udevadm-info.c | 62 ++++++----------- src/udev/udevadm-settle.c | 4 +- src/udev/udevadm-test-builtin.c | 4 +- src/udev/udevadm-test.c | 4 +- src/udev/udevadm-trigger.c | 4 +- src/udev/udevadm.c | 2 - src/udev/udevd.c | 55 +++------------ test/udev-test.pl | 79 ++++++++-------------- 31 files changed, 253 insertions(+), 446 deletions(-) (limited to 'test') diff --git a/Makefile.am b/Makefile.am index 0d2cb70349..7df3915b75 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1501,12 +1501,30 @@ test_libudev_LDADD = \ libudev.la test_udev_SOURCES = \ - src/test/test-udev.c + src/test/test-udev.c \ + $(libudev_core_la_SOURCES) \ + $(libudev_private_la_SOURCES) + +# The test-udev program needs everything compiled with relative path +# names for /sys, /dev, /run prefixed, pointing to our test/ directory. +test_udev_CFLAGS = \ + -DTEST_PREFIX=\"test\" \ + $(libudev_core_la_CFLAGS) \ + $(libudev_private_la_CFLAGS) + +test_udev_CPPFLAGS =\ + $(libudev_core_la_CPPFLAGS) test_udev_LDADD = \ - libudev-core.la \ - libudev-private.la \ - libsystemd-shared.la + libsystemd-shared.la \ + $(BLKID_LIBS) \ + $(KMOD_LIBS) \ + $(SELINUX_LIBS) + +if HAVE_ACL +test_udev_LDADD += \ + libsystemd-acl.la +endif check_DATA += \ test/sys diff --git a/TODO b/TODO index 292ee21708..d2145f99d1 100644 --- a/TODO +++ b/TODO @@ -17,7 +17,9 @@ Features: * suspend/hibernate/hybrid support, auto-suspend logic with idle hint -* udev: remove /sys and /dev configurability +* udev: unify selinux stuff with systemd + +* udev: move udev's recursive mkdir to shared/ * udev: find a way to tell udev to not cancel firmware requests when running in initramfs @@ -31,6 +33,7 @@ Features: - return object with *_unref() - kill: udev_monitor_from_socket() - kill: udev_queue_get_failed_list_entry() + - kill: udev_get_{dev,sys,run}_path() * allow configuration of console width/height in vconsole.conf diff --git a/docs/libudev/libudev-sections.txt b/docs/libudev/libudev-sections.txt index 83b2b79ee2..31f356f295 100644 --- a/docs/libudev/libudev-sections.txt +++ b/docs/libudev/libudev-sections.txt @@ -8,11 +8,11 @@ udev_new udev_set_log_fn udev_get_log_priority udev_set_log_priority +udev_get_userdata +udev_set_userdata udev_get_sys_path udev_get_dev_path udev_get_run_path -udev_get_userdata -udev_set_userdata
diff --git a/man/udev.xml b/man/udev.xml index 417fb11ebc..458d351658 100644 --- a/man/udev.xml +++ b/man/udev.xml @@ -64,14 +64,6 @@ It consists of a set of variables allowing the user to override default udev values. The following variables can be set: - - - - Specifies where to place the device nodes in the filesystem. - The default value is /dev. - - - diff --git a/src/libudev/libudev-device-private.c b/src/libudev/libudev-device-private.c index 91fd06c025..c58cde2ff6 100644 --- a/src/libudev/libudev-device-private.c +++ b/src/libudev/libudev-device-private.c @@ -31,7 +31,7 @@ static void udev_device_tag(struct udev_device *dev, const char *tag, bool add) id = udev_device_get_id_filename(dev); if (id == NULL) return; - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/tags/", tag, "/", id, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/tags/", tag, "/", id, NULL); if (add) { int fd; @@ -108,7 +108,7 @@ int udev_device_update_db(struct udev_device *udev_device) return -1; has_info = device_has_info(udev_device); - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data/", id, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/data/", id, NULL); /* do not store anything for otherwise empty devices */ if (!has_info && @@ -138,10 +138,8 @@ int udev_device_update_db(struct udev_device *udev_device) struct udev_list_entry *list_entry; if (major(udev_device_get_devnum(udev_device)) > 0) { - size_t devlen = strlen(udev_get_dev_path(udev))+1; - udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(udev_device)) - fprintf(f, "S:%s\n", &udev_list_entry_get_name(list_entry)[devlen]); + fprintf(f, "S:%s\n", udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/")); if (udev_device_get_devlink_priority(udev_device) != 0) fprintf(f, "L:%i\n", udev_device_get_devlink_priority(udev_device)); if (udev_device_get_watch_handle(udev_device) >= 0) @@ -173,13 +171,12 @@ int udev_device_update_db(struct udev_device *udev_device) int udev_device_delete_db(struct udev_device *udev_device) { const char *id; - struct udev *udev = udev_device_get_udev(udev_device); char filename[UTIL_PATH_SIZE]; id = udev_device_get_id_filename(udev_device); if (id == NULL) return -1; - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data/", id, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/data/", id, NULL); unlink(filename); return 0; } diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index 257d6355fe..212163bb92 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -356,7 +356,7 @@ void udev_device_add_property_from_string_parse(struct udev_device *udev_device, if (strncmp(property, "DEVPATH=", 8) == 0) { char path[UTIL_PATH_SIZE]; - util_strscpyl(path, sizeof(path), udev_get_sys_path(udev_device->udev), &property[8], NULL); + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys", &property[8], NULL); udev_device_set_syspath(udev_device, path); } else if (strncmp(property, "SUBSYSTEM=", 10) == 0) { udev_device_set_subsystem(udev_device, &property[10]); @@ -473,7 +473,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile) id = udev_device_get_id_filename(udev_device); if (id == NULL) return -1; - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_device->udev), "/data/", id, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/data/", id, NULL); dbfile = filename; } @@ -496,7 +496,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile) val = &line[2]; switch(line[0]) { case 'S': - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/", val, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/", val, NULL); udev_device_add_devlink(udev_device, filename, 0); break; case 'L': @@ -624,7 +624,6 @@ struct udev_device *udev_device_new(struct udev *udev) **/ _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath) { - size_t len; const char *subdir; char path[UTIL_PATH_SIZE]; char *pos; @@ -637,14 +636,13 @@ _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, con return NULL; /* path starts in sys */ - len = strlen(udev_get_sys_path(udev)); - if (strncmp(syspath, udev_get_sys_path(udev), len) != 0) { + if (strncmp(syspath, TEST_PREFIX "/sys", strlen(TEST_PREFIX "/sys")) != 0) { dbg(udev, "not in sys :%s\n", syspath); return NULL; } /* path is not a root directory */ - subdir = &syspath[len+1]; + subdir = syspath + strlen(TEST_PREFIX "/sys"); pos = strrchr(subdir, '/'); if (pos == NULL || pos[1] == '\0' || pos < &subdir[2]) return NULL; @@ -653,7 +651,7 @@ _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, con util_strscpy(path, sizeof(path), syspath); util_resolve_sys_link(udev, path, sizeof(path)); - if (strncmp(&path[len], "/devices/", 9) == 0) { + if (strncmp(path + strlen(TEST_PREFIX "/sys"), "/devices/", 9) == 0) { char file[UTIL_PATH_SIZE]; /* all "devices" require a "uevent" file */ @@ -705,8 +703,8 @@ _public_ struct udev_device *udev_device_new_from_devnum(struct udev *udev, char return NULL; /* use /sys/dev/{block,char}/: link */ - snprintf(path, sizeof(path), "%s/dev/%s/%u:%u", - udev_get_sys_path(udev), type_str, major(devnum), minor(devnum)); + snprintf(path, sizeof(path), TEST_PREFIX "/sys/dev/%s/%u:%u", + type_str, major(devnum), minor(devnum)); return udev_device_new_from_syspath(udev, path); } @@ -782,32 +780,27 @@ struct udev_device *udev_device_new_from_id_filename(struct udev *udev, char *id **/ _public_ struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname) { - char path_full[UTIL_PATH_SIZE]; - char *path; - size_t l; + char path[UTIL_PATH_SIZE]; struct stat statbuf; - path = path_full; - l = util_strpcpyl(&path, sizeof(path_full), udev_get_sys_path(udev), NULL); - if (strcmp(subsystem, "subsystem") == 0) { - util_strscpyl(path, l, "/subsystem/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/subsystem/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, l, "/bus/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/bus/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, l, "/class/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/class/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; goto out; } if (strcmp(subsystem, "module") == 0) { - util_strscpyl(path, l, "/module/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/module/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; goto out; } @@ -822,32 +815,32 @@ _public_ struct udev_device *udev_device_new_from_subsystem_sysname(struct udev driver[0] = '\0'; driver = &driver[1]; - util_strscpyl(path, l, "/subsystem/", subsys, "/drivers/", driver, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/subsystem/", subsys, "/drivers/", driver, NULL); + if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, l, "/bus/", subsys, "/drivers/", driver, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/bus/", subsys, "/drivers/", driver, NULL); + if (stat(path, &statbuf) == 0) goto found; } goto out; } - util_strscpyl(path, l, "/subsystem/", subsystem, "/devices/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/subsystem/", subsystem, "/devices/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, l, "/bus/", subsystem, "/devices/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/bus/", subsystem, "/devices/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, l, "/class/", subsystem, "/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/class/", subsystem, "/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; out: return NULL; found: - return udev_device_new_from_syspath(udev, path_full); + return udev_device_new_from_syspath(udev, path); } /** @@ -893,7 +886,7 @@ static struct udev_device *device_new_from_parent(struct udev_device *udev_devic const char *subdir; util_strscpy(path, sizeof(path), udev_device->syspath); - subdir = &path[strlen(udev_get_sys_path(udev_device->udev))+1]; + subdir = path + strlen(TEST_PREFIX "/sys/"); for (;;) { char *pos; @@ -1438,7 +1431,7 @@ int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath udev_device->syspath = strdup(syspath); if (udev_device->syspath == NULL) return -ENOMEM; - udev_device->devpath = &udev_device->syspath[strlen(udev_get_sys_path(udev_device->udev))]; + udev_device->devpath = udev_device->syspath + strlen(TEST_PREFIX "/sys"); udev_device_add_property(udev_device, "DEVPATH", udev_device->devpath); pos = strrchr(udev_device->syspath, '/'); @@ -1471,7 +1464,7 @@ int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode { free(udev_device->devnode); if (devnode[0] != '/') { - if (asprintf(&udev_device->devnode, "%s/%s", udev_get_dev_path(udev_device->udev), devnode) < 0) + if (asprintf(&udev_device->devnode, TEST_PREFIX "/dev/%s", devnode) < 0) udev_device->devnode = NULL; } else { udev_device->devnode = strdup(devnode); diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c index 7b9a732ce6..ed4f62c66c 100644 --- a/src/libudev/libudev-enumerate.c +++ b/src/libudev/libudev-enumerate.c @@ -204,12 +204,10 @@ static bool devices_delay_end(struct udev *udev, const char *syspath) "/block/dm-", NULL }; - size_t len; int i; - len = strlen(udev_get_sys_path(udev)); for (i = 0; delay_device_list[i] != NULL; i++) { - if (strstr(&syspath[len], delay_device_list[i]) != NULL) + if (strstr(syspath + strlen("/sys"), delay_device_list[i]) != NULL) return true; } return false; @@ -624,7 +622,6 @@ static bool match_sysname(struct udev_enumerate *udev_enumerate, const char *sys static int scan_dir_and_add_devices(struct udev_enumerate *udev_enumerate, const char *basedir, const char *subdir1, const char *subdir2) { - struct udev *udev = udev_enumerate_get_udev(udev_enumerate); char path[UTIL_PATH_SIZE]; size_t l; char *s; @@ -632,7 +629,7 @@ static int scan_dir_and_add_devices(struct udev_enumerate *udev_enumerate, struct dirent *dent; s = path; - l = util_strpcpyl(&s, sizeof(path), udev_get_sys_path(udev), "/", basedir, NULL); + l = util_strpcpyl(&s, sizeof(path), "/sys/", basedir, NULL); if (subdir1 != NULL) l = util_strpcpyl(&s, l, "/", subdir1, NULL); if (subdir2 != NULL) @@ -707,13 +704,11 @@ static bool match_subsystem(struct udev_enumerate *udev_enumerate, const char *s static int scan_dir(struct udev_enumerate *udev_enumerate, const char *basedir, const char *subdir, const char *subsystem) { - struct udev *udev = udev_enumerate_get_udev(udev_enumerate); - char path[UTIL_PATH_SIZE]; DIR *dir; struct dirent *dent; - util_strscpyl(path, sizeof(path), udev_get_sys_path(udev), "/", basedir, NULL); + util_strscpyl(path, sizeof(path), "/sys/", basedir, NULL); dir = opendir(path); if (dir == NULL) return -1; @@ -756,7 +751,6 @@ _public_ int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, c static int scan_devices_tags(struct udev_enumerate *udev_enumerate) { - struct udev *udev = udev_enumerate_get_udev(udev_enumerate); struct udev_list_entry *list_entry; /* scan only tagged devices, use tags reverse-index, instead of searching all devices in /sys */ @@ -765,8 +759,7 @@ static int scan_devices_tags(struct udev_enumerate *udev_enumerate) struct dirent *dent; char path[UTIL_PATH_SIZE]; - util_strscpyl(path, sizeof(path), udev_get_run_path(udev), "/tags/", - udev_list_entry_get_name(list_entry), NULL); + util_strscpyl(path, sizeof(path), "/run/udev/tags/", udev_list_entry_get_name(list_entry), NULL); dir = opendir(path); if (dir == NULL) continue; @@ -861,12 +854,9 @@ static int scan_devices_children(struct udev_enumerate *enumerate) static int scan_devices_all(struct udev_enumerate *udev_enumerate) { - struct udev *udev = udev_enumerate_get_udev(udev_enumerate); - char base[UTIL_PATH_SIZE]; struct stat statbuf; - util_strscpyl(base, sizeof(base), udev_get_sys_path(udev), "/subsystem", NULL); - if (stat(base, &statbuf) == 0) { + if (stat("/sys/subsystem", &statbuf) == 0) { /* we have /subsystem/, forget all the old stuff */ scan_dir(udev_enumerate, "subsystem", "devices", NULL); } else { @@ -907,8 +897,6 @@ _public_ int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate) **/ _public_ int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate) { - struct udev *udev = udev_enumerate_get_udev(udev_enumerate); - char base[UTIL_PATH_SIZE]; struct stat statbuf; const char *subsysdir; @@ -919,8 +907,7 @@ _public_ int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerat if (match_subsystem(udev_enumerate, "module")) scan_dir_and_add_devices(udev_enumerate, "module", NULL, NULL); - util_strscpyl(base, sizeof(base), udev_get_sys_path(udev), "/subsystem", NULL); - if (stat(base, &statbuf) == 0) + if (stat("/sys/subsystem", &statbuf) == 0) subsysdir = "subsystem"; else subsysdir = "bus"; diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h index 91f92264dd..986c40c91e 100644 --- a/src/libudev/libudev-private.h +++ b/src/libudev/libudev-private.h @@ -19,9 +19,13 @@ #include "macro.h" #include "libudev.h" -#define READ_END 0 +#define READ_END 0 #define WRITE_END 1 +#ifndef TEST_PREFIX +#define TEST_PREFIX "" +#endif + /* avoid (sometimes expensive) calculations of parameters for debug output */ #define udev_log_cond(udev, prio, arg...) \ do { \ diff --git a/src/libudev/libudev-queue-private.c b/src/libudev/libudev-queue-private.c index ca6d229a2c..f653e6db4c 100644 --- a/src/libudev/libudev-queue-private.c +++ b/src/libudev/libudev-queue-private.c @@ -101,14 +101,10 @@ struct udev_queue_export *udev_queue_export_unref(struct udev_queue_export *udev void udev_queue_export_cleanup(struct udev_queue_export *udev_queue_export) { - char filename[UTIL_PATH_SIZE]; - if (udev_queue_export == NULL) return; - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue_export->udev), "/queue.tmp", NULL); - unlink(filename); - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue_export->udev), "/queue.bin", NULL); - unlink(filename); + unlink("/run/udev/queue.tmp"); + unlink("/run/udev/queue.bin"); } static int skip_to(FILE *file, long offset) @@ -201,8 +197,6 @@ static int rebuild_queue_file(struct udev_queue_export *udev_queue_export) { unsigned long long int seqnum; struct queue_devpaths *devpaths = NULL; - char filename[UTIL_PATH_SIZE]; - char filename_tmp[UTIL_PATH_SIZE]; FILE *new_queue_file = NULL; unsigned int i; @@ -218,8 +212,7 @@ static int rebuild_queue_file(struct udev_queue_export *udev_queue_export) } /* create new queue file */ - util_strscpyl(filename_tmp, sizeof(filename_tmp), udev_get_run_path(udev_queue_export->udev), "/queue.tmp", NULL); - new_queue_file = fopen(filename_tmp, "w+"); + new_queue_file = fopen("/run/udev/queue.tmp", "w+"); if (new_queue_file == NULL) goto error; seqnum = udev_queue_export->seqnum_max; @@ -252,8 +245,7 @@ static int rebuild_queue_file(struct udev_queue_export *udev_queue_export) goto error; /* rename the new file on top of the old one */ - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue_export->udev), "/queue.bin", NULL); - if (rename(filename_tmp, filename) != 0) + if (rename("/run/udev/queue.tmp", "/run/udev/queue.bin") != 0) goto error; if (udev_queue_export->queue_file != NULL) diff --git a/src/libudev/libudev-queue.c b/src/libudev/libudev-queue.c index 0e0df8597d..ca23002307 100644 --- a/src/libudev/libudev-queue.c +++ b/src/libudev/libudev-queue.c @@ -121,14 +121,12 @@ _public_ struct udev *udev_queue_get_udev(struct udev_queue *udev_queue) unsigned long long int udev_get_kernel_seqnum(struct udev *udev) { - char filename[UTIL_PATH_SIZE]; unsigned long long int seqnum; int fd; char buf[32]; ssize_t len; - util_strscpyl(filename, sizeof(filename), udev_get_sys_path(udev), "/kernel/uevent_seqnum", NULL); - fd = open(filename, O_RDONLY|O_CLOEXEC); + fd = open("/sys/kernel/uevent_seqnum", O_RDONLY|O_CLOEXEC); if (fd < 0) return 0; len = read(fd, buf, sizeof(buf)); @@ -210,7 +208,7 @@ static FILE *open_queue_file(struct udev_queue *udev_queue, unsigned long long i char filename[UTIL_PATH_SIZE]; FILE *queue_file; - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue->udev), "/queue.bin", NULL); + util_strscpyl(filename, sizeof(filename), "/run/udev/queue.bin", NULL); queue_file = fopen(filename, "re"); if (queue_file == NULL) return NULL; @@ -437,7 +435,7 @@ _public_ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_qu snprintf(seqnum_str, sizeof(seqnum_str), "%llu", seqnum); s = syspath; - l = util_strpcpyl(&s, sizeof(syspath), udev_get_sys_path(udev_queue->udev), NULL); + l = util_strpcpy(&s, sizeof(syspath), "/sys"); len = udev_queue_read_devpath(queue_file, s, l); if (len < 0) break; diff --git a/src/libudev/libudev-selinux-private.c b/src/libudev/libudev-selinux-private.c index d68097f991..e9e65ad41d 100644 --- a/src/libudev/libudev-selinux-private.c +++ b/src/libudev/libudev-selinux-private.c @@ -29,7 +29,7 @@ void udev_selinux_init(struct udev *udev) dbg(udev, "selinux=%i\n", selinux_enabled); if (!selinux_enabled) return; - matchpathcon_init_prefix(NULL, udev_get_dev_path(udev)); + matchpathcon_init_prefix(NULL, TEST_PREFIX "/dev"); if (getfscreatecon(&selinux_prev_scontext) < 0) { err(udev, "getfscreatecon failed\n"); selinux_prev_scontext = NULL; diff --git a/src/libudev/libudev.c b/src/libudev/libudev.c index 74b53cbf1b..212c5fdd75 100644 --- a/src/libudev/libudev.c +++ b/src/libudev/libudev.c @@ -41,12 +41,6 @@ struct udev { int priority, const char *file, int line, const char *fn, const char *format, va_list args); void *userdata; - char *sys_path; - char *dev_path; - char *rules_path[4]; - unsigned long long rules_path_ts[4]; - int rules_path_count; - char *run_path; struct udev_list properties_list; int log_priority; }; @@ -100,14 +94,6 @@ _public_ void udev_set_userdata(struct udev *udev, void *userdata) udev->userdata = userdata; } -static char *set_value(char **s, const char *v) -{ - free(*s); - *s = strdup(v); - util_remove_trailing_chars(*s, '/'); - return *s; -} - /** * udev_new: * @@ -123,7 +109,6 @@ _public_ struct udev *udev_new(void) { struct udev *udev; const char *env; - char *config_file = NULL; FILE *f; udev = calloc(1, sizeof(struct udev)); @@ -134,21 +119,7 @@ _public_ struct udev *udev_new(void) udev->log_priority = LOG_ERR; udev_list_init(udev, &udev->properties_list, true); - /* custom config file */ - env = getenv("UDEV_CONFIG_FILE"); - if (env != NULL) { - if (set_value(&config_file, env) == NULL) - goto err; - udev_add_property(udev, "UDEV_CONFIG_FILE", config_file); - } - - /* default config file */ - if (config_file == NULL) - config_file = strdup(SYSCONFDIR "/udev/udev.conf"); - if (config_file == NULL) - goto err; - - f = fopen(config_file, "re"); + f = fopen(SYSCONFDIR "/udev/udev.conf", "re"); if (f != NULL) { char line[UTIL_LINE_SIZE]; int line_nr = 0; @@ -172,7 +143,7 @@ _public_ struct udev *udev_new(void) /* split key/value */ val = strchr(key, '='); if (val == NULL) { - err(udev, "missing = in '%s'[%i], skip line\n", config_file, line_nr); + err(udev, "missing = in " SYSCONFDIR "/udev/udev.conf[%i]; skip line\n", line_nr); continue; } val[0] = '\0'; @@ -204,7 +175,7 @@ _public_ struct udev *udev_new(void) /* unquote */ if (val[0] == '"' || val[0] == '\'') { if (val[len-1] != val[0]) { - err(udev, "inconsistent quoting in '%s'[%i], skip line\n", config_file, line_nr); + err(udev, "inconsistent quoting in " SYSCONFDIR "/udev/udev.conf[%i]; skip line\n", line_nr); continue; } val[len-1] = '\0'; @@ -215,23 +186,6 @@ _public_ struct udev *udev_new(void) udev_set_log_priority(udev, util_log_priority(val)); continue; } - if (strcmp(key, "udev_root") == 0) { - set_value(&udev->dev_path, val); - continue; - } - if (strcmp(key, "udev_run") == 0) { - set_value(&udev->run_path, val); - continue; - } - if (strcmp(key, "udev_sys") == 0) { - set_value(&udev->sys_path, val); - continue; - } - if (strcmp(key, "udev_rules") == 0) { - set_value(&udev->rules_path[0], val); - udev->rules_path_count = 1; - continue; - } } fclose(f); } @@ -241,44 +195,7 @@ _public_ struct udev *udev_new(void) if (env != NULL) udev_set_log_priority(udev, util_log_priority(env)); - /* set defaults */ - if (udev->dev_path == NULL) - if (set_value(&udev->dev_path, "/dev") == NULL) - goto err; - - if (udev->sys_path == NULL) - if (set_value(&udev->sys_path, "/sys") == NULL) - goto err; - - if (udev->run_path == NULL) - if (set_value(&udev->run_path, "/run/udev") == NULL) - goto err; - - if (udev->rules_path[0] == NULL) { - /* /usr/lib/udev -- system rules */ - udev->rules_path[0] = strdup(UDEVLIBEXECDIR "/rules.d"); - if (!udev->rules_path[0]) - goto err; - - /* /run/udev -- runtime rules */ - if (asprintf(&udev->rules_path[1], "%s/rules.d", udev->run_path) < 0) - goto err; - - /* /etc/udev -- local administration rules */ - udev->rules_path[2] = strdup(SYSCONFDIR "/udev/rules.d"); - if (!udev->rules_path[2]) - goto err; - - udev->rules_path_count = 3; - } - - free(config_file); return udev; -err: - free(config_file); - err(udev, "context creation failed\n"); - udev_unref(udev); - return NULL; } /** @@ -313,12 +230,6 @@ _public_ void udev_unref(struct udev *udev) if (udev->refcount > 0) return; udev_list_cleanup(&udev->properties_list); - free(udev->dev_path); - free(udev->sys_path); - free(udev->rules_path[0]); - free(udev->rules_path[1]); - free(udev->rules_path[2]); - free(udev->run_path); free(udev); } @@ -372,21 +283,11 @@ _public_ void udev_set_log_priority(struct udev *udev, int priority) udev_add_property(udev, "UDEV_LOG", num); } -int udev_get_rules_path(struct udev *udev, char **path[], unsigned long long *stamp_usec[]) -{ - *path = udev->rules_path; - if (stamp_usec) - *stamp_usec = udev->rules_path_ts; - return udev->rules_path_count; -} - /** * udev_get_sys_path: * @udev: udev library context * - * Retrieve the sysfs mount point. The default is "/sys". For - * testing purposes, it can be overridden with udev_sys= - * in the udev configuration file. + * Returns always "/sys"; deprecated, will be removed in a future version. * * Returns: the sys mount point **/ @@ -394,16 +295,14 @@ _public_ const char *udev_get_sys_path(struct udev *udev) { if (udev == NULL) return NULL; - return udev->sys_path; + return "/sys"; } /** * udev_get_dev_path: * @udev: udev library context * - * Retrieve the device directory path. The default value is "/dev", - * the actual value may be overridden in the udev configuration - * file. + * Returns always "/dev"; deprecated, will be removed in a future version. * * Returns: the device directory path **/ @@ -411,14 +310,14 @@ _public_ const char *udev_get_dev_path(struct udev *udev) { if (udev == NULL) return NULL; - return udev->dev_path; + return "/dev"; } /** * udev_get_run_path: * @udev: udev library context * - * Retrieve the udev runtime directory path. The default is "/run/udev". + * Returns always "/run/udev"; deprecated, will be removed in a future version. * * Returns: the runtime directory path **/ @@ -426,7 +325,7 @@ _public_ const char *udev_get_run_path(struct udev *udev) { if (udev == NULL) return NULL; - return udev->run_path; + return "/run/udev"; } struct udev_list_entry *udev_add_property(struct udev *udev, const char *key, const char *value) diff --git a/src/test/test-libudev.c b/src/test/test-libudev.c index 6161fb3e31..f5c7ae2c30 100644 --- a/src/test/test-libudev.c +++ b/src/test/test-libudev.c @@ -434,7 +434,6 @@ int main(int argc, char *argv[]) const char *syspath = "/devices/virtual/mem/null"; const char *subsystem = NULL; char path[1024]; - const char *str; udev = udev_new(); printf("context: %p\n", udev); @@ -474,14 +473,9 @@ int main(int argc, char *argv[]) } } - str = udev_get_sys_path(udev); - printf("sys_path: '%s'\n", str); - str = udev_get_dev_path(udev); - printf("dev_path: '%s'\n", str); - /* add sys path if needed */ - if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) { - snprintf(path, sizeof(path), "%s%s", udev_get_sys_path(udev), syspath); + if (strncmp(syspath, "/sys", strlen("/sys")) != 0) { + snprintf(path, sizeof(path), "/sys/%s", syspath); syspath = path; } diff --git a/src/test/test-udev.c b/src/test/test-udev.c index 150cb16a31..b843e5f648 100644 --- a/src/test/test-udev.c +++ b/src/test/test-udev.c @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) rules = udev_rules_new(udev, 1); - util_strscpyl(syspath, sizeof(syspath), udev_get_sys_path(udev), devpath, NULL); + util_strscpyl(syspath, sizeof(syspath), TEST_PREFIX "/sys", devpath, NULL); dev = udev_device_new_from_syspath(udev, syspath); if (dev == NULL) { log_debug("unknown device '%s'\n", devpath); diff --git a/src/udev/accelerometer/accelerometer.c b/src/udev/accelerometer/accelerometer.c index 4c5e47d0b7..08be363370 100644 --- a/src/udev/accelerometer/accelerometer.c +++ b/src/udev/accelerometer/accelerometer.c @@ -294,7 +294,7 @@ int main (int argc, char** argv) } /* get the device */ - snprintf(devpath, sizeof(devpath), "%s/%s", udev_get_sys_path(udev), argv[optind]); + snprintf(devpath, sizeof(devpath), "/sys/%s", argv[optind]); dev = udev_device_new_from_syspath(udev, devpath); if (dev == NULL) { fprintf(stderr, "unable to access '%s'\n", devpath); @@ -307,9 +307,8 @@ int main (int argc, char** argv) return 0; } - /* Get the children devices and find the devnode - * FIXME: use udev_enumerate_add_match_children() instead - * when it's available */ + /* Get the children devices and find the devnode */ + /* FIXME: use udev_enumerate_add_match_parent() instead */ devnode = NULL; enumerate = udev_enumerate_new(udev); udev_enumerate_add_match_property(enumerate, "ID_PATH", id_path); diff --git a/src/udev/collect/collect.c b/src/udev/collect/collect.c index 076fe479e2..882564a5f5 100644 --- a/src/udev/collect/collect.c +++ b/src/udev/collect/collect.c @@ -405,7 +405,7 @@ int main(int argc, char **argv) if (debug) fprintf(stderr, "Using checkpoint '%s'\n", checkpoint); - util_strscpyl(tmpdir, sizeof(tmpdir), udev_get_run_path(udev), "/collect", NULL); + util_strscpyl(tmpdir, sizeof(tmpdir), "/run/udev/collect", NULL); fd = prepare(tmpdir, checkpoint); if (fd < 0) { ret = 3; diff --git a/src/udev/udev-builtin-firmware.c b/src/udev/udev-builtin-firmware.c index 5ba712c89d..bd2716fdc8 100644 --- a/src/udev/udev-builtin-firmware.c +++ b/src/udev/udev-builtin-firmware.c @@ -112,7 +112,7 @@ static int builtin_firmware(struct udev_device *dev, int argc, char *argv[], boo } util_path_encode(firmware, fwencpath, sizeof(fwencpath)); - util_strscpyl(misspath, sizeof(misspath), udev_get_run_path(udev), "/firmware-missing/", fwencpath, NULL); + util_strscpyl(misspath, sizeof(misspath), "/run/udev/firmware-missing/", fwencpath, NULL); util_strscpyl(loadpath, sizeof(loadpath), udev_device_get_syspath(dev), "/loading", NULL); if (fwfile == NULL) { diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c index 71c330f6f9..fcb0cd48a6 100644 --- a/src/udev/udev-ctrl.c +++ b/src/udev/udev-ctrl.c @@ -93,8 +93,7 @@ struct udev_ctrl *udev_ctrl_new_from_fd(struct udev *udev, int fd) } uctrl->saddr.sun_family = AF_LOCAL; - util_strscpyl(uctrl->saddr.sun_path, sizeof(uctrl->saddr.sun_path), - udev_get_run_path(udev), "/control", NULL); + util_strscpy(uctrl->saddr.sun_path, sizeof(uctrl->saddr.sun_path), "/run/udev/control"); uctrl->addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(uctrl->saddr.sun_path); return uctrl; } diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index eab1bae27f..d330062ebf 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -318,46 +318,38 @@ subst: if (dev_parent == NULL) break; devnode = udev_device_get_devnode(dev_parent); - if (devnode != NULL) { - size_t devlen = strlen(udev_get_dev_path(event->udev))+1; - - l = util_strpcpy(&s, l, &devnode[devlen]); - } + if (devnode != NULL) + l = util_strpcpy(&s, l, devnode + strlen(TEST_PREFIX "/dev/")); break; } case SUBST_DEVNODE: if (udev_device_get_devnode(dev) != NULL) l = util_strpcpy(&s, l, udev_device_get_devnode(dev)); break; - case SUBST_NAME: { - if (event->name != NULL) { + case SUBST_NAME: + if (event->name != NULL) l = util_strpcpy(&s, l, event->name); - } else if (udev_device_get_devnode(dev) != NULL) { - size_t devlen = strlen(udev_get_dev_path(event->udev))+1; - - l = util_strpcpy(&s, l, &udev_device_get_devnode(dev)[devlen]); - } else { + else if (udev_device_get_devnode(dev) != NULL) + l = util_strpcpy(&s, l, udev_device_get_devnode(dev) + strlen(TEST_PREFIX "/dev/")); + else l = util_strpcpy(&s, l, udev_device_get_sysname(dev)); - } break; - } case SUBST_LINKS: { - size_t devlen = strlen(udev_get_dev_path(event->udev))+1; struct udev_list_entry *list_entry; list_entry = udev_device_get_devlinks_list_entry(dev); if (list_entry == NULL) break; - l = util_strpcpy(&s, l, &udev_list_entry_get_name(list_entry)[devlen]); + l = util_strpcpy(&s, l, udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/")); udev_list_entry_foreach(list_entry, udev_list_entry_get_next(list_entry)) - l = util_strpcpyl(&s, l, " ", &udev_list_entry_get_name(list_entry)[devlen], NULL); + l = util_strpcpyl(&s, l, " ", udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/"), NULL); break; } case SUBST_ROOT: - l = util_strpcpy(&s, l, udev_get_dev_path(event->udev)); + l = util_strpcpy(&s, l, TEST_PREFIX "/dev"); break; case SUBST_SYS: - l = util_strpcpy(&s, l, udev_get_sys_path(event->udev)); + l = util_strpcpy(&s, l, TEST_PREFIX "/sys"); break; case SUBST_ENV: if (attr == NULL) { diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 8e1318872a..26a43e9623 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -203,8 +203,8 @@ static void link_update(struct udev_device *dev, const char *slink, bool add) const char *target; char buf[UTIL_PATH_SIZE]; - util_path_encode(&slink[strlen(udev_get_dev_path(udev))+1], name_enc, sizeof(name_enc)); - util_strscpyl(dirname, sizeof(dirname), udev_get_run_path(udev), "/links/", name_enc, NULL); + util_path_encode(slink + strlen(TEST_PREFIX "/dev"), name_enc, sizeof(name_enc)); + util_strscpyl(dirname, sizeof(dirname), TEST_PREFIX "/run/udev/links/", name_enc, NULL); util_strscpyl(filename, sizeof(filename), dirname, "/", udev_device_get_id_filename(dev), NULL); if (!add && unlink(filename) == 0) @@ -329,8 +329,7 @@ void udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid) return; /* always add /dev/{block,char}/$major:$minor */ - snprintf(filename, sizeof(filename), "%s/%s/%u:%u", - udev_get_dev_path(udev), + snprintf(filename, sizeof(filename), TEST_PREFIX "/dev/%s/%u:%u", strcmp(udev_device_get_subsystem(dev), "block") == 0 ? "block" : "char", major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev))); node_symlink(udev, udev_device_get_devnode(dev), filename); @@ -347,7 +346,6 @@ void udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid) void udev_node_remove(struct udev_device *dev) { - struct udev *udev = udev_device_get_udev(dev); struct udev_list_entry *list_entry; char filename[UTIL_PATH_SIZE]; @@ -356,8 +354,7 @@ void udev_node_remove(struct udev_device *dev) link_update(dev, udev_list_entry_get_name(list_entry), 0); /* remove /dev/{block,char}/$major:$minor */ - snprintf(filename, sizeof(filename), "%s/%s/%u:%u", - udev_get_dev_path(udev), + snprintf(filename, sizeof(filename), TEST_PREFIX "/dev/%s/%u:%u", strcmp(udev_device_get_subsystem(dev), "block") == 0 ? "block" : "char", major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev))); unlink(filename); diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 55d7e30c02..1ec817872d 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -36,6 +36,13 @@ #define PREALLOC_STRBUF 32 * 1024 #define PREALLOC_TRIE 256 +/* configuration directories with last modification timestamp */ +static const char *rules_dirs[] = { + TEST_PREFIX UDEVLIBEXECDIR "/rules.d", + TEST_PREFIX "/run/udev/rules.d", + TEST_PREFIX SYSCONFDIR "/udev/rules.d", +}; + struct uid_gid { unsigned int name_off; union { @@ -58,6 +65,7 @@ struct trie_node { struct udev_rules { struct udev *udev; + unsigned long long dirs_ts_usec[ELEMENTSOF(rules_dirs)]; int resolve_names; /* every key in the rules file becomes a token */ @@ -664,7 +672,6 @@ static gid_t add_gid(struct udev_rules *rules, const char *group) static int import_property_from_string(struct udev_device *dev, char *line) { - struct udev *udev = udev_device_get_udev(dev); char *key; char *val; size_t len; @@ -724,7 +731,7 @@ static int import_property_from_string(struct udev_device *dev, char *line) log_debug("updating devpath from '%s' to '%s'\n", udev_device_get_devpath(dev), val); - util_strscpyl(syspath, sizeof(syspath), udev_get_sys_path(udev), val, NULL); + util_strscpyl(syspath, sizeof(syspath), "/sys", val, NULL); udev_device_set_syspath(dev, syspath); } else { struct udev_list_entry *entry; @@ -807,7 +814,6 @@ static int import_parent_into_properties(struct udev_device *dev, const char *fi #define WAIT_LOOP_PER_SECOND 50 static int wait_for_file(struct udev_device *dev, const char *file, int timeout) { - struct udev *udev = udev_device_get_udev(dev); char filepath[UTIL_PATH_SIZE]; char devicepath[UTIL_PATH_SIZE]; struct stat stats; @@ -816,8 +822,7 @@ static int wait_for_file(struct udev_device *dev, const char *file, int timeout) /* a relative path is a device attribute */ devicepath[0] = '\0'; if (file[0] != '/') { - util_strscpyl(devicepath, sizeof(devicepath), - udev_get_sys_path(udev), udev_device_get_devpath(dev), NULL); + util_strscpyl(devicepath, sizeof(devicepath), udev_device_get_syspath(dev), NULL); util_strscpyl(filepath, sizeof(filepath), devicepath, "/", file, NULL); file = filepath; } @@ -1746,7 +1751,7 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names) struct udev_list file_list; struct udev_list_entry *file_loop; struct token end_token; - char **s; + unsigned int i; rules = calloc(1, sizeof(struct udev_rules)); if (rules == NULL) @@ -1786,8 +1791,8 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names) memset(rules->trie_nodes, 0x00, sizeof(struct trie_node)); rules->trie_nodes_cur = 1; - for (udev_get_rules_path(udev, &s, NULL); *s != NULL; s++) - add_matching_files(udev, &file_list, *s, ".rules"); + for (i = 0; i < ELEMENTSOF(rules_dirs); i++) + add_matching_files(udev, &file_list, rules_dirs[i], ".rules"); /* add all filenames to the string buffer */ udev_list_entry_foreach(file_loop, udev_list_get_entry(&file_list)) { @@ -1884,6 +1889,33 @@ struct udev_rules *udev_rules_unref(struct udev_rules *rules) return NULL; } +bool udev_rules_check_timestamp(struct udev_rules *rules) +{ + unsigned int i; + bool changed = false; + + for (i = 0; i < ELEMENTSOF(rules_dirs); i++) { + struct stat stats; + + if (stat(rules_dirs[i], &stats) < 0) + continue; + + if (rules->dirs_ts_usec[i] == ts_usec(&stats.st_mtim)) + continue; + + /* first check */ + if (rules->dirs_ts_usec[i] != 0) { + log_debug("reload - timestamp of '%s' changed\n", rules_dirs[i]); + changed = true; + } + + /* update timestamp */ + rules->dirs_ts_usec[i] = ts_usec(&stats.st_mtim); + } + + return changed; +} + static int match_key(struct udev_rules *rules, struct token *token, const char *val) { char *key_value = &rules->buf[token->key.value_off]; @@ -2054,14 +2086,13 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event goto nomatch; break; case TK_M_DEVLINK: { - size_t devlen = strlen(udev_get_dev_path(event->udev))+1; struct udev_list_entry *list_entry; bool match = false; udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(event->dev)) { const char *devlink; - devlink = &udev_list_entry_get_name(list_entry)[devlen]; + devlink = udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/"); if (match_key(rules, cur, devlink) == 0) { match = true; break; @@ -2534,15 +2565,12 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event if (count > 0) log_debug("%i character(s) replaced\n", count); } - if (major(udev_device_get_devnum(event->dev))) { - size_t devlen = strlen(udev_get_dev_path(event->udev))+1; - - if (strcmp(name_str, &udev_device_get_devnode(event->dev)[devlen]) != 0) { - log_error("NAME=\"%s\" ignored, kernel device nodes " - "can not be renamed; please fix it in %s:%u\n", name, - &rules->buf[rule->rule.filename_off], rule->rule.filename_line); - break; - } + if (major(udev_device_get_devnum(event->dev)) && + (strcmp(name_str, udev_device_get_devnode(event->dev) + strlen(TEST_PREFIX "/dev/")) != 0)) { + log_error("NAME=\"%s\" ignored, kernel device nodes " + "can not be renamed; please fix it in %s:%u\n", name, + &rules->buf[rule->rule.filename_off], rule->rule.filename_line); + break; } free(event->name); event->name = strdup(name_str); @@ -2583,7 +2611,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event next[0] = '\0'; log_debug("LINK '%s' %s:%u\n", pos, &rules->buf[rule->rule.filename_off], rule->rule.filename_line); - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(event->udev), "/", pos, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/", pos, NULL); udev_device_add_devlink(event->dev, filename, cur->key.devlink_unique); while (isspace(next[1])) next++; @@ -2593,7 +2621,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event if (pos[0] != '\0') { log_debug("LINK '%s' %s:%u\n", pos, &rules->buf[rule->rule.filename_off], rule->rule.filename_line); - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(event->udev), "/", pos, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/", pos, NULL); udev_device_add_devlink(event->dev, filename, cur->key.devlink_unique); } break; @@ -2703,7 +2731,7 @@ void udev_rules_apply_static_dev_perms(struct udev_rules *rules) /* we assure, that the permissions tokens are sorted before the static token */ if (mode == 0 && uid == 0 && gid == 0) goto next; - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(rules->udev), "/", + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/", &rules->buf[cur->key.value_off], NULL); if (stat(filename, &stats) != 0) goto next; diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c index 968728eba9..7d5b30bd68 100644 --- a/src/udev/udev-watch.c +++ b/src/udev/udev-watch.c @@ -49,41 +49,33 @@ int udev_watch_init(struct udev *udev) */ void udev_watch_restore(struct udev *udev) { - char filename[UTIL_PATH_SIZE], oldname[UTIL_PATH_SIZE]; - if (inotify_fd < 0) return; - util_strscpyl(oldname, sizeof(oldname), udev_get_run_path(udev), "/watch.old", NULL); - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/watch", NULL); - if (rename(filename, oldname) == 0) { + if (rename("/run/udev/watch", "/run/udev/watch.old") == 0) { DIR *dir; struct dirent *ent; - dir = opendir(oldname); + dir = opendir("/run/udev/watch.old"); if (dir == NULL) { - log_error("unable to open old watches dir '%s', old watches will not be restored: %m", oldname); + log_error("unable to open old watches dir /run/udev/watch.old; old watches will not be restored: %m"); return; } for (ent = readdir(dir); ent != NULL; ent = readdir(dir)) { char device[UTIL_PATH_SIZE]; - char *s; - size_t l; ssize_t len; struct udev_device *dev; if (ent->d_name[0] == '.') continue; - s = device; - l = util_strpcpy(&s, sizeof(device), udev_get_sys_path(udev)); - len = readlinkat(dirfd(dir), ent->d_name, s, l); - if (len <= 0 || len == (ssize_t)l) + len = readlinkat(dirfd(dir), ent->d_name, device, sizeof(device)); + if (len <= 0 || len == (ssize_t)sizeof(device)) goto unlink; - s[len] = '\0'; + device[len] = '\0'; - dev = udev_device_new_from_id_filename(udev, s); + dev = udev_device_new_from_id_filename(udev, device); if (dev == NULL) goto unlink; @@ -95,10 +87,10 @@ unlink: } closedir(dir); - rmdir(oldname); + rmdir("/run/udev/watch.old"); } else if (errno != ENOENT) { - log_error("unable to move watches dir '%s', old watches will not be restored: %m", filename); + log_error("unable to move watches dir /run/udev/watch; old watches will not be restored: %m"); } } @@ -118,7 +110,7 @@ void udev_watch_begin(struct udev *udev, struct udev_device *dev) return; } - snprintf(filename, sizeof(filename), "%s/watch/%d", udev_get_run_path(udev), wd); + snprintf(filename, sizeof(filename), "/run/udev/watch/%d", wd); util_create_path(udev, filename); unlink(filename); symlink(udev_device_get_id_filename(dev), filename); @@ -141,7 +133,7 @@ void udev_watch_end(struct udev *udev, struct udev_device *dev) log_debug("removing watch on '%s'\n", udev_device_get_devnode(dev)); inotify_rm_watch(inotify_fd, wd); - snprintf(filename, sizeof(filename), "%s/watch/%d", udev_get_run_path(udev), wd); + snprintf(filename, sizeof(filename), "/run/udev/watch/%d", wd); unlink(filename); udev_device_set_watch_handle(dev, -1); @@ -150,21 +142,17 @@ void udev_watch_end(struct udev *udev, struct udev_device *dev) struct udev_device *udev_watch_lookup(struct udev *udev, int wd) { char filename[UTIL_PATH_SIZE]; - char majmin[UTIL_PATH_SIZE]; - char *s; - size_t l; + char device[UTIL_NAME_SIZE]; ssize_t len; if (inotify_fd < 0 || wd < 0) return NULL; - snprintf(filename, sizeof(filename), "%s/watch/%d", udev_get_run_path(udev), wd); - s = majmin; - l = util_strpcpy(&s, sizeof(majmin), udev_get_sys_path(udev)); - len = readlink(filename, s, l); - if (len <= 0 || (size_t)len == l) + snprintf(filename, sizeof(filename), "/run/udev/watch/%d", wd); + len = readlink(filename, device, sizeof(device)); + if (len <= 0 || (size_t)len == sizeof(device)) return NULL; - s[len] = '\0'; + device[len] = '\0'; - return udev_device_new_from_id_filename(udev, s); + return udev_device_new_from_id_filename(udev, device); } diff --git a/src/udev/udev.h b/src/udev/udev.h index 681660ecb7..ed5f768ea8 100644 --- a/src/udev/udev.h +++ b/src/udev/udev.h @@ -65,6 +65,7 @@ struct udev_watch { struct udev_rules; struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names); struct udev_rules *udev_rules_unref(struct udev_rules *rules); +bool udev_rules_check_timestamp(struct udev_rules *rules); int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event, const sigset_t *sigmask); void udev_rules_apply_static_dev_perms(struct udev_rules *rules); diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c index 39221b7374..3b14139459 100644 --- a/src/udev/udevadm-info.c +++ b/src/udev/udevadm-info.c @@ -131,26 +131,22 @@ static int print_device_chain(struct udev_device *device) static void print_record(struct udev_device *device) { - size_t len; const char *str; int i; struct udev_list_entry *list_entry; printf("P: %s\n", udev_device_get_devpath(device)); - len = strlen(udev_get_dev_path(udev_device_get_udev(device))); str = udev_device_get_devnode(device); if (str != NULL) - printf("N: %s\n", &str[len+1]); + printf("N: %s\n", str + strlen("/dev/")); i = udev_device_get_devlink_priority(device); if (i != 0) printf("L: %i\n", i); - udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device)) { - len = strlen(udev_get_dev_path(udev_device_get_udev(device))); - printf("S: %s\n", &udev_list_entry_get_name(list_entry)[len+1]); - } + udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device)) + printf("S: %s\n", udev_list_entry_get_name(list_entry) + strlen("/dev/")); udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(device)) printf("E: %s=%s\n", @@ -233,42 +229,35 @@ static void cleanup_dir(DIR *dir, mode_t mask, int depth) static void cleanup_db(struct udev *udev) { - char filename[UTIL_PATH_SIZE]; DIR *dir; - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/queue.bin", NULL); - unlink(filename); + unlink("/run/udev/queue.bin"); - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data", NULL); - dir = opendir(filename); + dir = opendir("/run/udev/data"); if (dir != NULL) { cleanup_dir(dir, S_ISVTX, 1); closedir(dir); } - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/links", NULL); - dir = opendir(filename); + dir = opendir("/run/udev/links"); if (dir != NULL) { cleanup_dir(dir, 0, 2); closedir(dir); } - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/tags", NULL); - dir = opendir(filename); + dir = opendir("/run/udev/tags"); if (dir != NULL) { cleanup_dir(dir, 0, 2); closedir(dir); } - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/watch", NULL); - dir = opendir(filename); + dir = opendir("/run/udev/watch"); if (dir != NULL) { cleanup_dir(dir, 0, 1); closedir(dir); } - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/firmware-missing", NULL); - dir = opendir(filename); + dir = opendir("/run/udev/firmware-missing"); if (dir != NULL) { cleanup_dir(dir, 0, 1); closedir(dir); @@ -335,9 +324,9 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) rc = 2; goto exit; } - /* remove /dev if given */ - if (strncmp(optarg, udev_get_dev_path(udev), strlen(udev_get_dev_path(udev))) != 0) - util_strscpyl(name, sizeof(name), udev_get_dev_path(udev), "/", optarg, NULL); + /* add /dev if not given */ + if (strncmp(optarg, "/dev", strlen("/dev")) != 0) + util_strscpyl(name, sizeof(name), "/dev/", optarg, NULL); else util_strscpy(name, sizeof(name), optarg); util_remove_trailing_chars(name, '/'); @@ -372,8 +361,8 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) goto exit; } /* add sys dir if needed */ - if (strncmp(optarg, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) - util_strscpyl(path, sizeof(path), udev_get_sys_path(udev), optarg, NULL); + if (strncmp(optarg, "/sys", strlen("/sys")) != 0) + util_strscpyl(path, sizeof(path), "/sys", optarg, NULL); else util_strscpy(path, sizeof(path), optarg); util_remove_trailing_chars(path, '/'); @@ -408,7 +397,7 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) root = true; break; case 'R': - printf("%s\n", udev_get_run_path(udev)); + printf("/run/udev\n"); goto exit; case 'd': action = ACTION_DEVICE_ID_FILE; @@ -476,26 +465,19 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) goto exit; } - if (root) { + if (root) printf("%s\n", udev_device_get_devnode(device)); - } else { - size_t len = strlen(udev_get_dev_path(udev)); - - printf("%s\n", &udev_device_get_devnode(device)[len+1]); - } + else + printf("%s\n", udev_device_get_devnode(device) + strlen("/dev/")); break; } case QUERY_SYMLINK: list_entry = udev_device_get_devlinks_list_entry(device); while (list_entry != NULL) { - if (root) { + if (root) printf("%s", udev_list_entry_get_name(list_entry)); - } else { - size_t len; - - len = strlen(udev_get_dev_path(udev_device_get_udev(device))); - printf("%s", &udev_list_entry_get_name(list_entry)[len+1]); - } + else + printf("%s", udev_list_entry_get_name(list_entry) + strlen("/dev/")); list_entry = udev_list_entry_get_next(list_entry); if (list_entry != NULL) printf(" "); @@ -543,7 +525,7 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) rc = 1; break; case ACTION_ROOT: - printf("%s\n", udev_get_dev_path(udev)); + printf("/dev\n"); break; default: fprintf(stderr, "missing option\n"); diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c index 19c1e99ccb..e70b351eb9 100644 --- a/src/udev/udevadm-settle.c +++ b/src/udev/udevadm-settle.c @@ -152,8 +152,8 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) if (pfd[0].fd < 0) { log_error("inotify_init failed: %m\n"); } else { - if (inotify_add_watch(pfd[0].fd, udev_get_run_path(udev), IN_MOVED_TO) < 0) { - log_error("watching '%s' failed\n", udev_get_run_path(udev)); + if (inotify_add_watch(pfd[0].fd, "/run/udev" , IN_MOVED_TO) < 0) { + log_error("watching /run/udev failed\n"); close(pfd[0].fd); pfd[0].fd = -1; } diff --git a/src/udev/udevadm-test-builtin.c b/src/udev/udevadm-test-builtin.c index 94bb24f5f8..e63b1f4eb7 100644 --- a/src/udev/udevadm-test-builtin.c +++ b/src/udev/udevadm-test-builtin.c @@ -95,8 +95,8 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[]) } /* add /sys if needed */ - if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) - util_strscpyl(filename, sizeof(filename), udev_get_sys_path(udev), syspath, NULL); + if (strncmp(syspath, "/sys", strlen("/sys")) != 0) + util_strscpyl(filename, sizeof(filename), "/sys", syspath, NULL); else util_strscpy(filename, sizeof(filename), syspath); util_remove_trailing_chars(filename, '/'); diff --git a/src/udev/udevadm-test.c b/src/udev/udevadm-test.c index f963c1b510..0c8a762540 100644 --- a/src/udev/udevadm-test.c +++ b/src/udev/udevadm-test.c @@ -112,8 +112,8 @@ static int adm_test(struct udev *udev, int argc, char *argv[]) } /* add /sys if needed */ - if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) - util_strscpyl(filename, sizeof(filename), udev_get_sys_path(udev), syspath, NULL); + if (strncmp(syspath, "/sys", strlen("/sys")) != 0) + util_strscpyl(filename, sizeof(filename), "/sys", syspath, NULL); else util_strscpy(filename, sizeof(filename), syspath); util_remove_trailing_chars(filename, '/'); diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c index 99ef12cb85..a910121ecd 100644 --- a/src/udev/udevadm-trigger.c +++ b/src/udev/udevadm-trigger.c @@ -164,8 +164,8 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) struct udev_device *dev; /* add sys dir if needed */ - if (strncmp(optarg, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) - util_strscpyl(path, sizeof(path), udev_get_sys_path(udev), optarg, NULL); + if (strncmp(optarg, "/sys", strlen("/sys")) != 0) + util_strscpyl(path, sizeof(path), "/sys", optarg, NULL); else util_strscpy(path, sizeof(path), optarg); util_remove_trailing_chars(path, '/'); diff --git a/src/udev/udevadm.c b/src/udev/udevadm.c index 0858c37be8..2b4a845d77 100644 --- a/src/udev/udevadm.c +++ b/src/udev/udevadm.c @@ -128,8 +128,6 @@ int main(int argc, char *argv[]) } command = argv[optind]; - log_debug("runtime dir '%s'\n", udev_get_run_path(udev)); - if (command != NULL) for (i = 0; i < ELEMENTSOF(udevadm_cmds); i++) { if (strcmp(udevadm_cmds[i]->name, command) == 0) { diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 24f0bf6d1e..d6de2aa222 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -856,7 +856,7 @@ static void static_dev_create_from_modules(struct udev *udev) else continue; - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/", devname, NULL); + util_strscpyl(filename, sizeof(filename), "/dev/", devname, NULL); util_create_path_selinux(udev, filename); udev_selinux_setfscreatecon(udev, filename, mode); log_debug("mknod '%s' %c%u:%u\n", filename, type, maj, min); @@ -885,7 +885,7 @@ static void static_dev_create_links(struct udev *udev) }; unsigned int i; - dir = opendir(udev_get_dev_path(udev)); + dir = opendir("/dev"); if (dir == NULL) return; @@ -934,16 +934,15 @@ static int convert_db(struct udev *udev) struct udev_list_entry *list_entry; /* current database */ - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data", NULL); - if (access(filename, F_OK) >= 0) + if (access("/run/udev/data", F_OK) >= 0) return 0; /* make sure we do not get here again */ - util_create_path(udev, filename); + util_create_path(udev, "/run/udev/data"); mkdir(filename, 0755); /* old database */ - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/db", NULL); + util_strscpyl(filename, sizeof(filename), "/dev/.udev/db", NULL); if (access(filename, F_OK) < 0) return 0; @@ -976,7 +975,7 @@ static int convert_db(struct udev *udev) /* find database in old location */ id = udev_device_get_id_filename(device); - util_strscpyl(from, sizeof(from), udev_get_dev_path(udev), "/.udev/db/", id, NULL); + util_strscpyl(from, sizeof(from), "/dev/.udev/db/", id, NULL); if (lstat(from, &stats) == 0) { if (!have_db) { udev_device_read_db(device, from); @@ -986,9 +985,8 @@ static int convert_db(struct udev *udev) } /* find old database with $subsys:$sysname name */ - util_strscpyl(from, sizeof(from), udev_get_dev_path(udev), - "/.udev/db/", udev_device_get_subsystem(device), ":", - udev_device_get_sysname(device), NULL); + util_strscpyl(from, sizeof(from), "/dev/.udev/db/", + udev_device_get_subsystem(device), ":", udev_device_get_sysname(device), NULL); if (lstat(from, &stats) == 0) { if (!have_db) { udev_device_read_db(device, from); @@ -999,7 +997,7 @@ static int convert_db(struct udev *udev) /* find old database with the encoded devpath name */ util_path_encode(udev_device_get_devpath(device), devpath, sizeof(devpath)); - util_strscpyl(from, sizeof(from), udev_get_dev_path(udev), "/.udev/db/", devpath, NULL); + util_strscpyl(from, sizeof(from), "/dev/.udev/db/", devpath, NULL); if (lstat(from, &stats) == 0) { if (!have_db) { udev_device_read_db(device, from); @@ -1054,36 +1052,6 @@ static int systemd_fds(struct udev *udev, int *rctrl, int *rnetlink) return 0; } -static bool check_rules_timestamp(struct udev *udev) -{ - char **p; - unsigned long long *stamp_usec; - int i, n; - bool changed = false; - - n = udev_get_rules_path(udev, &p, &stamp_usec); - for (i = 0; i < n; i++) { - struct stat stats; - - if (stat(p[i], &stats) < 0) - continue; - - if (stamp_usec[i] == ts_usec(&stats.st_mtim)) - continue; - - /* first check */ - if (stamp_usec[i] != 0) { - log_debug("reload - timestamp of '%s' changed\n", p[i]); - changed = true; - } - - /* update timestamp */ - stamp_usec[i] = ts_usec(&stats.st_mtim); - } - - return changed; -} - int main(int argc, char *argv[]) { struct udev *udev; @@ -1216,8 +1184,7 @@ int main(int argc, char *argv[]) chdir("/"); umask(022); - /* /run/udev */ - mkdir(udev_get_run_path(udev), 0755); + mkdir("/run/udev", 0755); /* create standard links, copy static nodes, create nodes from modules */ static_dev_create_links(udev); @@ -1557,7 +1524,7 @@ int main(int argc, char *argv[]) /* check for changed config, every 3 seconds at most */ if ((now_usec() - last_usec) > 3 * 1000 * 1000) { - if (check_rules_timestamp(udev)) + if (udev_rules_check_timestamp(rules)) reload = true; if (udev_builtin_validate(udev)) reload = true; diff --git a/test/udev-test.pl b/test/udev-test.pl index 0a2571a1d5..d80b00c374 100755 --- a/test/udev-test.pl +++ b/test/udev-test.pl @@ -14,20 +14,19 @@ # After creation and removal the result is checked against the # expected value and the result is printed. # -# Copyright (C) 2004-2011 Kay Sievers +# Copyright (C) 2004-2012 Kay Sievers # Copyright (C) 2004 Leann Ogasawara use warnings; use strict; -my $PWD = $ENV{PWD}; -my $sysfs = "test/sys"; my $udev_bin = "./test-udev"; my $valgrind = 0; my $udev_bin_valgrind = "valgrind --tool=memcheck --leak-check=yes --quiet $udev_bin"; -my $udev_root = "udev-root"; -my $udev_conf = "udev-test.conf"; -my $udev_rules = "udev-test.rules"; +my $udev_dev = "test/dev"; +my $udev_run = "test/run"; +my $udev_rules_dir = "$udev_run/udev/rules.d"; +my $udev_rules = "$udev_rules_dir/udev-test.rules"; my @tests = ( { @@ -251,15 +250,6 @@ EOF exp_name => "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" , rules => < "import of shell-value file", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "subdir/err/node" , - rules => < "tty33", exp_perms => "0:0:0600", rules => < "udev_root substitution", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "start-udev-root-end", + exp_name => "start-test/dev-end", rules => <$udev_rules" || die "unable to create rules file: $udev_rules"; print CONF $$rules; close CONF; @@ -1416,13 +1404,15 @@ sub major_minor_test { } } -sub make_udev_root { - system("rm -rf $udev_root"); - mkdir($udev_root) || die "unable to create udev_root: $udev_root\n"; - # setting group and mode of udev_root ensures the tests work +sub udev_setup { + system("rm", "-rf", "$udev_dev"); + mkdir($udev_dev) || die "unable to create udev_dev: $udev_dev\n"; + # setting group and mode of udev_dev ensures the tests work # even if the parent directory has setgid bit enabled. - chown (0, 0, $udev_root) || die "unable to chown $udev_root\n"; - chmod (0755, $udev_root) || die "unable to chmod $udev_root\n"; + chown (0, 0, $udev_dev) || die "unable to chown $udev_dev\n"; + chmod (0755, $udev_dev) || die "unable to chmod $udev_dev\n"; + + system("rm", "-rf", "$udev_run"); } sub run_test { @@ -1433,19 +1423,19 @@ sub run_test { udev("add", $rules->{devpath}, \$rules->{rules}); if (defined($rules->{not_exp_name})) { - if ((-e "$PWD/$udev_root/$rules->{not_exp_name}") || - (-l "$PWD/$udev_root/$rules->{not_exp_name}")) { + if ((-e "$udev_dev/$rules->{not_exp_name}") || + (-l "$udev_dev/$rules->{not_exp_name}")) { print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n"; $error++; sleep(1); } } - if ((-e "$PWD/$udev_root/$rules->{exp_name}") || - (-l "$PWD/$udev_root/$rules->{exp_name}")) { + if ((-e "$udev_dev/$rules->{exp_name}") || + (-l "$udev_dev/$rules->{exp_name}")) { my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, - $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root/$rules->{exp_name}"); + $atime, $mtime, $ctime, $blksize, $blocks) = stat("$udev_dev/$rules->{exp_name}"); if (defined($rules->{exp_perms})) { permissions_test($rules, $uid, $gid, $mode); @@ -1460,7 +1450,7 @@ sub run_test { print " as expected\n"; } else { print "\n"; - system("tree $udev_root"); + system("tree", "$udev_dev"); print "\n"; $error++; sleep(1); @@ -1473,14 +1463,14 @@ sub run_test { } udev("remove", $rules->{devpath}, \$rules->{rules}); - if ((-e "$PWD/$udev_root/$rules->{exp_name}") || - (-l "$PWD/$udev_root/$rules->{exp_name}")) { + if ((-e "$udev_dev/$rules->{exp_name}") || + (-l "$udev_dev/$rules->{exp_name}")) { print "remove: error"; if ($rules->{exp_rem_error}) { print " as expected\n"; } else { print "\n"; - system("tree $udev_root"); + system("tree", "$udev_dev"); print "\n"; $error++; sleep(1); @@ -1492,7 +1482,7 @@ sub run_test { print "\n"; if (defined($rules->{option}) && $rules->{option} eq "clean") { - make_udev_root(); + udev_setup(); } } @@ -1504,17 +1494,7 @@ if (!($<==0)) { exit; } -# prepare -make_udev_root(); - -# create config file -open CONF, ">$udev_conf" || die "unable to create config file: $udev_conf"; -print CONF "udev_root=\"$udev_root\"\n"; -print CONF "udev_run=\"$udev_root/.udev\"\n"; -print CONF "udev_sys=\"$sysfs\"\n"; -print CONF "udev_rules=\"$PWD\"\n"; -print CONF "udev_log=\"err\"\n"; -close CONF; +udev_setup(); my $test_num = 1; my @list; @@ -1550,9 +1530,8 @@ if ($list[0]) { print "$error errors occured\n\n"; # cleanup -system("rm -rf $udev_root"); -unlink($udev_rules); -unlink($udev_conf); +system("rm", "-rf", "$udev_dev"); +system("rm", "-rf", "$udev_run"); if ($error > 0) { exit(1); -- cgit v1.2.3-54-g00ecf From 898720b7e9cf3bdf7a93e435cbed5dd6942ecf9b Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Mon, 21 May 2012 18:55:48 +0200 Subject: test: introduce a basic testsuite framework $ cd test $ sudo make check will run all tests in the TEST-* subdirectories $ cd test/TEST-01-BASIC $ sudo make clean setup run will run the different stages of the test for debugging purposes --- test/Makefile | 15 +- test/TEST-01-BASIC/Makefile | 10 + test/TEST-01-BASIC/test.sh | 190 +++++++++++++ test/test-functions | 636 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 850 insertions(+), 1 deletion(-) create mode 100644 test/TEST-01-BASIC/Makefile create mode 100755 test/TEST-01-BASIC/test.sh create mode 100644 test/test-functions (limited to 'test') diff --git a/test/Makefile b/test/Makefile index 9aa46b4eb6..987a32548f 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,7 +1,20 @@ # Just a little hook script to easy building when in this directory +.PHONY: all check clean all: $(MAKE) -C .. clean: - $(MAKE) -C .. clean + @for i in TEST-[0-9]*; do \ + [ -d $$i ] || continue ; \ + [ -f $$i/Makefile ] || continue ; \ + make -C $$i clean ; \ + done + +check: + $(MAKE) -C .. all + @for i in TEST-[0-9]*; do \ + [ -d $$i ] || continue ; \ + [ -f $$i/Makefile ] || continue ; \ + make -C $$i all ; \ + done diff --git a/test/TEST-01-BASIC/Makefile b/test/TEST-01-BASIC/Makefile new file mode 100644 index 0000000000..5e89a29eff --- /dev/null +++ b/test/TEST-01-BASIC/Makefile @@ -0,0 +1,10 @@ +all: + @make -s --no-print-directory -C ../.. all + @basedir=../.. TEST_BASE_DIR=../ ./test.sh --all +setup: + @make --no-print-directory -C ../.. all + @basedir=../.. TEST_BASE_DIR=../ ./test.sh --setup +clean: + @basedir=../.. TEST_BASE_DIR=../ ./test.sh --clean +run: + @basedir=../.. TEST_BASE_DIR=../ ./test.sh --run diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh new file mode 100755 index 0000000000..13b731d94d --- /dev/null +++ b/test/TEST-01-BASIC/test.sh @@ -0,0 +1,190 @@ +#!/bin/bash +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh +TEST_DESCRIPTION="Basic systemd setup" + +KVERSION=${KVERSION-$(uname -r)} + +# Uncomment this to debug failures +#DEBUGFAIL="systemd.unit=multi-user.target" + +test_run() { + qemu-kvm \ + -hda $TESTDIR/rootdisk.img \ + -m 256M -nographic \ + -net none -kernel /boot/vmlinuz-$KVERSION \ + -append "root=/dev/sda1 systemd.log_level=debug raid=noautodetect loglevel=2 init=/usr/lib/systemd/systemd rw console=ttyS0,115200n81 selinux=0 $DEBUGFAIL" + ret=1 + mkdir -p $TESTDIR/root + mount ${LOOPDEV}p1 $TESTDIR/root + [[ -e $TESTDIR/root/testok ]] && ret=0 + cp -a $TESTDIR/root/var/log/journal $TESTDIR + umount $TESTDIR/root + ls -l $TESTDIR/journal/*/*.journal + return $ret +} + +test_setup() { + rm -f $TESTDIR/rootdisk.img + # Create the blank file to use as a root filesystem + dd if=/dev/null of=$TESTDIR/rootdisk.img bs=1M seek=100 + LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img) + [ -b $LOOPDEV ] || return 1 + echo "LOOPDEV=$LOOPDEV" >> $STATEFILE + sfdisk -C 3200 -H 2 -S 32 -L $LOOPDEV <> $initdir/etc/systemd/journald.conf + + # make a journal directory + mkdir -p $initdir/var/log/journal + + # install some basic config files + inst /etc/sysconfig/init + inst /etc/passwd + inst /etc/shadow + inst /etc/group + inst /etc/shells + inst /etc/nsswitch.conf + inst /etc/pam.conf + inst /etc/securetty + inst /etc/os-release + + # we want an empty environment + > $initdir/etc/environment + + # set the hostname + echo systemd-testsuite > $initdir/etc/hostname + + # setup the testsuite target + cat >$initdir/etc/systemd/system/testsuite.target <$initdir/etc/systemd/system/testsuite.service < /testok; /bin/sleep 5' +ExecStartPost=/usr/sbin/poweroff +Type=oneshot + +EOF + mkdir -p $initdir/etc/systemd/system/testsuite.target.wants + ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service + + # make the testsuite the default target + ln -fs testsuite.target $initdir/etc/systemd/system/default.target + + # install basic tools needed + dracut_install sh bash setsid loadkeys setfont \ + login sushell sulogin gzip sleep echo + + # install libnss_files for login + inst_libdir_file "libnss_files*" + + # install dbus and pam + find \ + /etc/dbus-1 \ + /etc/pam.d \ + /etc/security \ + /lib64/security \ + /lib/security -xtype f \ + | while read file; do + inst $file + done + + # install dbus socket and service file + inst /usr/lib/systemd/system/dbus.socket + inst /usr/lib/systemd/system/dbus.service + + # install basic keyboard maps and fonts + for i in \ + /usr/lib/kbd/consolefonts/latarcyrheb-sun16* \ + /usr/lib/kbd/keymaps/include/* \ + /usr/lib/kbd/keymaps/i386/include/* \ + /usr/lib/kbd/keymaps/i386/qwerty/us.*; do + [[ -f $i ]] || continue + inst $i + done + + # some basic terminfo files + for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do + [ -f ${_terminfodir}/l/linux ] && break + done + dracut_install -o ${_terminfodir}/l/linux + + # softlink mtab + ln -fs /proc/self/mounts $initdir/etc/mtab + + # install any Exec's from the service files + egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \ + | while read i; do + i=${i##Exec*=}; i=${i##-} + inst $i + done + + # install plymouth, if found... else remove plymouth service files + if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then + PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \ + /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir + dracut_install plymouth plymouthd + else + rm -f $initdir/usr/lib/systemd/system/plymouth* $initdir/usr/lib/systemd/system/*/plymouth* + fi + + # some helper tools for debugging + dracut_install sh df free ls shutdown poweroff \ + stty cat ps ln ip route \ + mount dmesg dhclient mkdir cp ping dhclient \ + umount strace less grep + + # install ld.so.conf* and run ldconfig + cp -a /etc/ld.so.conf* $initdir/etc + ldconfig -r "$initdir" + + ) + umount $TESTDIR/root + +} + +test_cleanup() { + umount $TESTDIR/root 2>/dev/null + [[ $LOOPDEV ]] && losetup -d $LOOPDEV + return 0 +} + +. $TEST_BASE_DIR/test-functions +do_test "$@" diff --git a/test/test-functions b/test/test-functions new file mode 100644 index 0000000000..d0c5f6ca9e --- /dev/null +++ b/test/test-functions @@ -0,0 +1,636 @@ +#!/bin/bash +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh +PATH=/sbin:/bin:/usr/sbin:/usr/bin +export PATH + +setup_basic_dirs() { + for d in usr/bin usr/sbin bin etc lib "$libdir" sbin tmp usr var var/log; do + [[ -e "${initdir}${prefix}/$d" ]] && continue + if [ -L "/$d" ]; then + inst_symlink "/$d" "${prefix}/$d" + else + mkdir -m 0755 -p "${initdir}${prefix}/$d" + fi + done + + for d in dev proc sys sysroot root run run/lock run/initramfs; do + if [ -L "/$d" ]; then + inst_symlink "/$d" + else + mkdir -m 0755 -p "$initdir/$d" + fi + done + + ln -sfn /run "$initdir/var/run" + ln -sfn /run/lock "$initdir/var/lock" +} + +inst_libs() { + local _bin=$1 + local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)' + local _file _line + + LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do + [[ $_line = 'not a dynamic executable' ]] && break + + if [[ $_line =~ $_so_regex ]]; then + _file=${BASH_REMATCH[1]} + [[ -e ${initdir}/$_file ]] && continue + inst_library "$_file" + continue + fi + + if [[ $_line =~ not\ found ]]; then + dfatal "Missing a shared library required by $_bin." + dfatal "Run \"ldd $_bin\" to find out what it is." + dfatal "$_line" + dfatal "dracut cannot create an initrd." + exit 1 + fi + done +} + +import_testdir() { + STATEFILE=".testdir" + [[ -e $STATEFILE ]] && . $STATEFILE + if [[ -z "$TESTDIR" ]] || [[ ! -d "$TESTDIR" ]]; then + TESTDIR=$(mktemp --tmpdir=/var/tmp -d -t systemd-test.XXXXXX) + echo "TESTDIR=\"$TESTDIR\"" > $STATEFILE + export TESTDIR + fi +} + +## @brief Converts numeric logging level to the first letter of level name. +# +# @param lvl Numeric logging level in range from 1 to 6. +# @retval 1 if @a lvl is out of range. +# @retval 0 if @a lvl is correct. +# @result Echoes first letter of level name. +_lvl2char() { + case "$1" in + 1) echo F;; + 2) echo E;; + 3) echo W;; + 4) echo I;; + 5) echo D;; + 6) echo T;; + *) return 1;; + esac +} + +## @brief Internal helper function for _do_dlog() +# +# @param lvl Numeric logging level. +# @param msg Message. +# @retval 0 It's always returned, even if logging failed. +# +# @note This function is not supposed to be called manually. Please use +# dtrace(), ddebug(), or others instead which wrap this one. +# +# This function calls _do_dlog() either with parameter msg, or if +# none is given, it will read standard input and will use every line as +# a message. +# +# This enables: +# dwarn "This is a warning" +# echo "This is a warning" | dwarn +LOG_LEVEL=4 + +dlog() { + [ -z "$LOG_LEVEL" ] && return 0 + [ $1 -le $LOG_LEVEL ] || return 0 + local lvl="$1"; shift + local lvlc=$(_lvl2char "$lvl") || return 0 + + if [ $# -ge 1 ]; then + echo "$lvlc: $*" + else + while read line; do + echo "$lvlc: " "$line" + done + fi +} + +## @brief Logs message at TRACE level (6) +# +# @param msg Message. +# @retval 0 It's always returned, even if logging failed. +dtrace() { + set +x + dlog 6 "$@" + [ -n "$debug" ] && set -x || : +} + +## @brief Logs message at DEBUG level (5) +# +# @param msg Message. +# @retval 0 It's always returned, even if logging failed. +ddebug() { + set +x + dlog 5 "$@" + [ -n "$debug" ] && set -x || : +} + +## @brief Logs message at INFO level (4) +# +# @param msg Message. +# @retval 0 It's always returned, even if logging failed. +dinfo() { + set +x + dlog 4 "$@" + [ -n "$debug" ] && set -x || : +} + +## @brief Logs message at WARN level (3) +# +# @param msg Message. +# @retval 0 It's always returned, even if logging failed. +dwarn() { + set +x + dlog 3 "$@" + [ -n "$debug" ] && set -x || : +} + +## @brief Logs message at ERROR level (2) +# +# @param msg Message. +# @retval 0 It's always returned, even if logging failed. +derror() { + set +x + dlog 2 "$@" + [ -n "$debug" ] && set -x || : +} + +## @brief Logs message at FATAL level (1) +# +# @param msg Message. +# @retval 0 It's always returned, even if logging failed. +dfatal() { + set +x + dlog 1 "$@" + [ -n "$debug" ] && set -x || : +} + + +# Generic substring function. If $2 is in $1, return 0. +strstr() { [ "${1#*$2*}" != "$1" ]; } + +# normalize_path +# Prints the normalized path, where it removes any duplicated +# and trailing slashes. +# Example: +# $ normalize_path ///test/test// +# /test/test +normalize_path() { + shopt -q -s extglob + set -- "${1//+(\/)//}" + shopt -q -u extglob + echo "${1%/}" +} + +# convert_abs_rel +# Prints the relative path, when creating a symlink to from . +# Example: +# $ convert_abs_rel /usr/bin/test /bin/test-2 +# ../../bin/test-2 +# $ ln -s $(convert_abs_rel /usr/bin/test /bin/test-2) /usr/bin/test +convert_abs_rel() { + local __current __absolute __abssize __cursize __newpath + local -i __i __level + + set -- "$(normalize_path "$1")" "$(normalize_path "$2")" + + # corner case #1 - self looping link + [[ "$1" == "$2" ]] && { echo "${1##*/}"; return; } + + # corner case #2 - own dir link + [[ "${1%/*}" == "$2" ]] && { echo "."; return; } + + IFS="/" __current=($1) + IFS="/" __absolute=($2) + + __abssize=${#__absolute[@]} + __cursize=${#__current[@]} + + while [[ ${__absolute[__level]} == ${__current[__level]} ]] + do + (( __level++ )) + if (( __level > __abssize || __level > __cursize )) + then + break + fi + done + + for ((__i = __level; __i < __cursize-1; __i++)) + do + if ((__i > __level)) + then + __newpath=$__newpath"/" + fi + __newpath=$__newpath".." + done + + for ((__i = __level; __i < __abssize; __i++)) + do + if [[ -n $__newpath ]] + then + __newpath=$__newpath"/" + fi + __newpath=$__newpath${__absolute[__i]} + done + + echo "$__newpath" +} + + +# Install a directory, keeping symlinks as on the original system. +# Example: if /lib points to /lib64 on the host, "inst_dir /lib/file" +# will create ${initdir}/lib64, ${initdir}/lib64/file, +# and a symlink ${initdir}/lib -> lib64. +inst_dir() { + [[ -e ${initdir}/"$1" ]] && return 0 # already there + + local _dir="$1" _part="${1%/*}" _file + while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do + _dir="$_part $_dir" + _part=${_part%/*} + done + + # iterate over parent directories + for _file in $_dir; do + [[ -e "${initdir}/$_file" ]] && continue + if [[ -L $_file ]]; then + inst_symlink "$_file" + else + # create directory + mkdir -m 0755 -p "${initdir}/$_file" || return 1 + [[ -e "$_file" ]] && chmod --reference="$_file" "${initdir}/$_file" + chmod u+w "${initdir}/$_file" + fi + done +} + +# $1 = file to copy to ramdisk +# $2 (optional) Name for the file on the ramdisk +# Location of the image dir is assumed to be $initdir +# We never overwrite the target if it exists. +inst_simple() { + [[ -f "$1" ]] || return 1 + strstr "$1" "/" || return 1 + + local _src=$1 target="${2:-$1}" + if ! [[ -d ${initdir}/$target ]]; then + [[ -e ${initdir}/$target ]] && return 0 + [[ -L ${initdir}/$target ]] && return 0 + [[ -d "${initdir}/${target%/*}" ]] || inst_dir "${target%/*}" + fi + # install checksum files also + if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then + inst "${_src%/*}/.${_src##*/}.hmac" "${target%/*}/.${target##*/}.hmac" + fi + ddebug "Installing $_src" + cp --sparse=always -pfL "$_src" "${initdir}/$target" +} + +# find symlinks linked to given library file +# $1 = library file +# Function searches for symlinks by stripping version numbers appended to +# library filename, checks if it points to the same target and finally +# prints the list of symlinks to stdout. +# +# Example: +# rev_lib_symlinks libfoo.so.8.1 +# output: libfoo.so.8 libfoo.so +# (Only if libfoo.so.8 and libfoo.so exists on host system.) +rev_lib_symlinks() { + [[ ! $1 ]] && return 0 + + local fn="$1" orig="$(readlink -f "$1")" links='' + + [[ ${fn} =~ .*\.so\..* ]] || return 1 + + until [[ ${fn##*.} == so ]]; do + fn="${fn%.*}" + [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}" + done + + echo "${links}" +} + +# Same as above, but specialized to handle dynamic libraries. +# It handles making symlinks according to how the original library +# is referenced. +inst_library() { + local _src="$1" _dest=${2:-$1} _lib _reallib _symlink + strstr "$1" "/" || return 1 + [[ -e $initdir/$_dest ]] && return 0 + if [[ -L $_src ]]; then + # install checksum files also + if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then + inst "${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac" + fi + _reallib=$(readlink -f "$_src") + inst_simple "$_reallib" "$_reallib" + inst_dir "${_dest%/*}" + [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/} + ln -sfn $(convert_abs_rel "${_dest}" "${_reallib}") "${initdir}/${_dest}" + else + inst_simple "$_src" "$_dest" + fi + + # Create additional symlinks. See rev_symlinks description. + for _symlink in $(rev_lib_symlinks $_src) $(rev_lib_symlinks $_reallib); do + [[ ! -e $initdir/$_symlink ]] && { + ddebug "Creating extra symlink: $_symlink" + inst_symlink $_symlink + } + done +} + +# find a binary. If we were not passed the full path directly, +# search in the usual places to find the binary. +find_binary() { + if [[ -z ${1##/*} ]]; then + if [[ -x $1 ]] || { strstr "$1" ".so" && ldd $1 &>/dev/null; }; then + echo $1 + return 0 + fi + fi + + type -P $1 +} + +# Same as above, but specialized to install binary executables. +# Install binary executable, and all shared library dependencies, if any. +inst_binary() { + local _bin _target + _bin=$(find_binary "$1") || return 1 + _target=${2:-$_bin} + [[ -e $initdir/$_target ]] && return 0 + [[ -L $_bin ]] && inst_symlink $_bin $_target && return 0 + local _file _line + local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)' + # I love bash! + LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do + [[ $_line = 'not a dynamic executable' ]] && break + + if [[ $_line =~ $_so_regex ]]; then + _file=${BASH_REMATCH[1]} + [[ -e ${initdir}/$_file ]] && continue + inst_library "$_file" + continue + fi + + if [[ $_line =~ not\ found ]]; then + dfatal "Missing a shared library required by $_bin." + dfatal "Run \"ldd $_bin\" to find out what it is." + dfatal "$_line" + dfatal "dracut cannot create an initrd." + exit 1 + fi + done + inst_simple "$_bin" "$_target" +} + +# same as above, except for shell scripts. +# If your shell script does not start with shebang, it is not a shell script. +inst_script() { + local _bin + _bin=$(find_binary "$1") || return 1 + shift + local _line _shebang_regex + read -r -n 80 _line <"$_bin" + # If debug is set, clean unprintable chars to prevent messing up the term + [[ $debug ]] && _line=$(echo -n "$_line" | tr -c -d '[:print:][:space:]') + _shebang_regex='(#! *)(/[^ ]+).*' + [[ $_line =~ $_shebang_regex ]] || return 1 + inst "${BASH_REMATCH[2]}" && inst_simple "$_bin" "$@" +} + +# same as above, but specialized for symlinks +inst_symlink() { + local _src=$1 _target=${2:-$1} _realsrc + strstr "$1" "/" || return 1 + [[ -L $1 ]] || return 1 + [[ -L $initdir/$_target ]] && return 0 + _realsrc=$(readlink -f "$_src") + if ! [[ -e $initdir/$_realsrc ]]; then + if [[ -d $_realsrc ]]; then + inst_dir "$_realsrc" + else + inst "$_realsrc" + fi + fi + [[ ! -e $initdir/${_target%/*} ]] && inst_dir "${_target%/*}" + [[ -d ${_target%/*} ]] && _target=$(readlink -f ${_target%/*})/${_target##*/} + ln -sfn $(convert_abs_rel "${_target}" "${_realsrc}") "$initdir/$_target" +} + +# attempt to install any programs specified in a udev rule +inst_rule_programs() { + local _prog _bin + + if grep -qE 'PROGRAM==?"[^ "]+' "$1"; then + for _prog in $(grep -E 'PROGRAM==?"[^ "]+' "$1" | sed -r 's/.*PROGRAM==?"([^ "]+).*/\1/'); do + if [ -x /lib/udev/$_prog ]; then + _bin=/lib/udev/$_prog + else + _bin=$(find_binary "$_prog") || { + dinfo "Skipping program $_prog using in udev rule $(basename $1) as it cannot be found" + continue; + } + fi + + #dinfo "Installing $_bin due to it's use in the udev rule $(basename $1)" + dracut_install "$_bin" + done + fi +} + +# udev rules always get installed in the same place, so +# create a function to install them to make life simpler. +inst_rules() { + local _target=/etc/udev/rules.d _rule _found + + inst_dir "/lib/udev/rules.d" + inst_dir "$_target" + for _rule in "$@"; do + if [ "${rule#/}" = "$rule" ]; then + for r in /lib/udev/rules.d /etc/udev/rules.d; do + if [[ -f $r/$_rule ]]; then + _found="$r/$_rule" + inst_simple "$_found" + inst_rule_programs "$_found" + fi + done + fi + for r in '' ./ $dracutbasedir/rules.d/; do + if [[ -f ${r}$_rule ]]; then + _found="${r}$_rule" + inst_simple "$_found" "$_target/${_found##*/}" + inst_rule_programs "$_found" + fi + done + [[ $_found ]] || dinfo "Skipping udev rule: $_rule" + done +} + +# general purpose installation function +# Same args as above. +inst() { + local _x + + case $# in + 1) ;; + 2) [[ ! $initdir && -d $2 ]] && export initdir=$2 + [[ $initdir = $2 ]] && set $1;; + 3) [[ -z $initdir ]] && export initdir=$2 + set $1 $3;; + *) dfatal "inst only takes 1 or 2 or 3 arguments" + exit 1;; + esac + for _x in inst_symlink inst_script inst_binary inst_simple; do + $_x "$@" && return 0 + done + return 1 +} + +# install any of listed files +# +# If first argument is '-d' and second some destination path, first accessible +# source is installed into this path, otherwise it will installed in the same +# path as source. If none of listed files was installed, function return 1. +# On first successful installation it returns with 0 status. +# +# Example: +# +# inst_any -d /bin/foo /bin/bar /bin/baz +# +# Lets assume that /bin/baz exists, so it will be installed as /bin/foo in +# initramfs. +inst_any() { + local to f + + [[ $1 = '-d' ]] && to="$2" && shift 2 + + for f in "$@"; do + if [[ -e $f ]]; then + [[ $to ]] && inst "$f" "$to" && return 0 + inst "$f" && return 0 + fi + done + + return 1 +} + +# dracut_install [-o ] [ ... ] +# Install to the initramfs image +# -o optionally install the and don't fail, if it is not there +dracut_install() { + local _optional=no + if [[ $1 = '-o' ]]; then + _optional=yes + shift + fi + while (($# > 0)); do + if ! inst "$1" ; then + if [[ $_optional = yes ]]; then + dinfo "Skipping program $1 as it cannot be found and is" \ + "flagged to be optional" + else + dfatal "Failed to install $1" + exit 1 + fi + fi + shift + done +} + + +# inst_libdir_file [-n ] [...] +# Install a located on a lib directory to the initramfs image +# -n install non-matching files +inst_libdir_file() { + if [[ "$1" == "-n" ]]; then + local _pattern=$1 + shift 2 + for _dir in $libdirs; do + for _i in "$@"; do + for _f in "$_dir"/$_i; do + [[ "$_i" =~ $_pattern ]] || continue + [[ -e "$_i" ]] && dracut_install "$_i" + done + done + done + else + for _dir in $libdirs; do + for _i in "$@"; do + for _f in "$_dir"/$_i; do + [[ -e "$_f" ]] && dracut_install "$_f" + done + done + done + fi +} + +do_test() { + [[ $UID != "0" ]] && exit 0 + command -v qemu-kvm &>/dev/null || exit 0 +# Detect lib paths + [[ $libdir ]] || for libdir in /lib64 /lib; do + [[ -d $libdir ]] && libdirs+=" $libdir" && break + done + + [[ $usrlibdir ]] || for usrlibdir in /usr/lib64 /usr/lib; do + [[ -d $usrlibdir ]] && libdirs+=" $usrlibdir" && break + done + + import_testdir + + while (($# > 0)); do + case $1 in + --run) + echo "TEST RUN: $TEST_DESCRIPTION" + test_run + ret=$? + if [ $ret -eq 0 ]; then + echo "TEST RUN: $TEST_DESCRIPTION [OK]" + else + echo "TEST RUN: $TEST_DESCRIPTION [FAILED]" + fi + exit $ret;; + --setup) + echo "TEST SETUP: $TEST_DESCRIPTION" + test_setup + exit $?;; + --clean) + echo "TEST CLEANUP: $TEST_DESCRIPTION" + test_cleanup + rm -fr "$TESTDIR" + rm -f .testdir + exit $?;; + --all) + echo -n "TEST: $TEST_DESCRIPTION "; + ( + test_setup && test_run + ret=$? + test_cleanup + rm -fr "$TESTDIR" + rm -f .testdir + exit $ret + ) test.log 2>&1 + ret=$? + if [ $ret -eq 0 ]; then + rm test.log + echo "[OK]" + else + echo "[FAILED]" + echo "see $(pwd)/test.log" + fi + exit $ret;; + *) break ;; + esac + shift + done +} -- cgit v1.2.3-54-g00ecf From 32d965851d8cbb39f8ee0eeaf76a89e8f5fc174f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 24 May 2012 14:32:48 +0200 Subject: test: check systemctl --failed in test VM --- test/TEST-01-BASIC/test.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index 13b731d94d..42107baa11 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -19,8 +19,11 @@ test_run() { mount ${LOOPDEV}p1 $TESTDIR/root [[ -e $TESTDIR/root/testok ]] && ret=0 cp -a $TESTDIR/root/var/log/journal $TESTDIR + cp -a $TESTDIR/root/failed $TESTDIR umount $TESTDIR/root + cat $TESTDIR/failed ls -l $TESTDIR/journal/*/*.journal + test -s $TESTDIR/failed && ret=$(($ret+1)) return $ret } @@ -97,7 +100,7 @@ Description=Testsuite service After=multi-user.target [Service] -ExecStart=/bin/sh -c 'echo OK > /testok; /bin/sleep 5' +ExecStart=/bin/sh -c 'systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok' ExecStartPost=/usr/sbin/poweroff Type=oneshot @@ -169,7 +172,7 @@ EOF dracut_install sh df free ls shutdown poweroff \ stty cat ps ln ip route \ mount dmesg dhclient mkdir cp ping dhclient \ - umount strace less grep + umount strace less grep id tty # install ld.so.conf* and run ldconfig cp -a /etc/ld.so.conf* $initdir/etc -- cgit v1.2.3-54-g00ecf From 680705351da905b6e797be61b51e6cba275b1ea5 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 24 May 2012 15:21:43 +0200 Subject: test: add touch to test machine --- TODO | 2 ++ test/TEST-01-BASIC/test.sh | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/TODO b/TODO index 6d5eb73262..bf0236861c 100644 --- a/TODO +++ b/TODO @@ -23,6 +23,8 @@ Bugfixes: Features: +* also reset /proc/sys/kernel/usermodehelper/bset /proc/sys/kernel/usermodehelper/inheritable in system.conf's CapabilityBoundingSet= + * make use of /sys/power/wake_lock in inhibitors * introduce "systemctl help" which invokes man for the man pages listed in Documentation= diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index 42107baa11..a34b55aa6a 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -172,7 +172,7 @@ EOF dracut_install sh df free ls shutdown poweroff \ stty cat ps ln ip route \ mount dmesg dhclient mkdir cp ping dhclient \ - umount strace less grep id tty + umount strace less grep id tty touch # install ld.so.conf* and run ldconfig cp -a /etc/ld.so.conf* $initdir/etc -- cgit v1.2.3-54-g00ecf From 7c1856aacd4f5d41dc320860490afda18c4a7495 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Thu, 24 May 2012 15:26:09 +0200 Subject: test/TEST-01-BASIC: add /etc/localtime to test image --- test/TEST-01-BASIC/test.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index a34b55aa6a..5987edf3de 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -10,10 +10,10 @@ KVERSION=${KVERSION-$(uname -r)} test_run() { qemu-kvm \ - -hda $TESTDIR/rootdisk.img \ - -m 256M -nographic \ - -net none -kernel /boot/vmlinuz-$KVERSION \ - -append "root=/dev/sda1 systemd.log_level=debug raid=noautodetect loglevel=2 init=/usr/lib/systemd/systemd rw console=ttyS0,115200n81 selinux=0 $DEBUGFAIL" + -hda $TESTDIR/rootdisk.img \ + -m 256M -nographic \ + -net none -kernel /boot/vmlinuz-$KVERSION \ + -append "root=/dev/sda1 systemd.log_level=debug raid=noautodetect loglevel=2 init=/usr/lib/systemd/systemd rw console=ttyS0,115200n81 selinux=0 $DEBUGFAIL" ret=1 mkdir -p $TESTDIR/root mount ${LOOPDEV}p1 $TESTDIR/root @@ -47,7 +47,7 @@ EOF # Create what will eventually be our root filesystem onto an overlay ( LOG_LEVEL=5 - initdir=$TESTDIR/root + initdir=$TESTDIR/root # create the basic filesystem layout setup_basic_dirs @@ -76,7 +76,7 @@ EOF inst /etc/pam.conf inst /etc/securetty inst /etc/os-release - + inst /etc/localtime # we want an empty environment > $initdir/etc/environment -- cgit v1.2.3-54-g00ecf From 3d3035e80c7deab9b0bf7050228385664a022fe3 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Thu, 24 May 2012 15:27:13 +0200 Subject: test/TEST-01-BASIC: add a defined rc.local --- test/TEST-01-BASIC/test.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index 5987edf3de..ace159f59a 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -110,7 +110,12 @@ EOF # make the testsuite the default target ln -fs testsuite.target $initdir/etc/systemd/system/default.target - + mkdir -p $initdir/etc/rc.d + cat >$initdir/etc/rc.d/rc.local < Date: Thu, 24 May 2012 15:27:53 +0200 Subject: test/TEST-01-BASIC: untabified --- test/TEST-01-BASIC/test.sh | 78 +++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 39 deletions(-) (limited to 'test') diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index ace159f59a..c84fb668b4 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -56,35 +56,35 @@ EOF (cd ../..; make DESTDIR=$initdir install) # install possible missing libraries - for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do + for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do inst_libs $i done # activate kmsg import - echo 'ImportKernel=yes' >> $initdir/etc/systemd/journald.conf + echo 'ImportKernel=yes' >> $initdir/etc/systemd/journald.conf # make a journal directory - mkdir -p $initdir/var/log/journal + mkdir -p $initdir/var/log/journal # install some basic config files - inst /etc/sysconfig/init - inst /etc/passwd - inst /etc/shadow - inst /etc/group - inst /etc/shells - inst /etc/nsswitch.conf - inst /etc/pam.conf - inst /etc/securetty - inst /etc/os-release + inst /etc/sysconfig/init + inst /etc/passwd + inst /etc/shadow + inst /etc/group + inst /etc/shells + inst /etc/nsswitch.conf + inst /etc/pam.conf + inst /etc/securetty + inst /etc/os-release inst /etc/localtime # we want an empty environment - > $initdir/etc/environment + > $initdir/etc/environment # set the hostname - echo systemd-testsuite > $initdir/etc/hostname + echo systemd-testsuite > $initdir/etc/hostname # setup the testsuite target - cat >$initdir/etc/systemd/system/testsuite.target <$initdir/etc/systemd/system/testsuite.target <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/systemd/system/testsuite.service <$initdir/etc/rc.d/rc.local < Date: Thu, 24 May 2012 15:51:10 +0200 Subject: test/TEST-01-BASIC: add systemd-nspawn run with the root image --- test/TEST-01-BASIC/test.sh | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index c84fb668b4..ca8a5ee872 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -8,7 +8,7 @@ KVERSION=${KVERSION-$(uname -r)} # Uncomment this to debug failures #DEBUGFAIL="systemd.unit=multi-user.target" -test_run() { +run_qemu() { qemu-kvm \ -hda $TESTDIR/rootdisk.img \ -m 256M -nographic \ @@ -27,6 +27,26 @@ test_run() { return $ret } + +run_nspawn() { + systemd-nspawn -b -D $TESTDIR/nspawn-root /usr/lib/systemd/systemd + ret=1 + [[ -e $TESTDIR/nspawn-root/testok ]] && ret=0 + cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR + cp -a $TESTDIR/nspawn-root/failed $TESTDIR + cat $TESTDIR/failed + ls -l $TESTDIR/journal/*/*.journal + test -s $TESTDIR/failed && ret=$(($ret+1)) + return $ret +} + + +test_run() { + run_qemu || return 1 + run_nspawn || return 1 + return 0 +} + test_setup() { rm -f $TESTDIR/rootdisk.img # Create the blank file to use as a root filesystem @@ -184,8 +204,10 @@ EOF ldconfig -r "$initdir" ) - umount $TESTDIR/root + rm -fr $TESTDIR/nspawn-root + cp -avr $TESTDIR/root $TESTDIR/nspawn-root + umount $TESTDIR/root } test_cleanup() { -- cgit v1.2.3-54-g00ecf From 7b17d413b11bfbdb4442c87b1db25b37ed5162ac Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Thu, 24 May 2012 16:00:33 +0200 Subject: test/TEST-01-BASIC: only test systemd-nspawn, if the test system uses systemd --- test/TEST-01-BASIC/test.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index ca8a5ee872..22517a831e 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -43,7 +43,9 @@ run_nspawn() { test_run() { run_qemu || return 1 - run_nspawn || return 1 + if [[ -d /sys/fs/cgroup/systemd ]] + run_nspawn || return 1 + fi return 0 } -- cgit v1.2.3-54-g00ecf From bd2b15138e1e1da8bc21072cf585179985c902e1 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Thu, 24 May 2012 16:07:35 +0200 Subject: test/TEST-01-BASIC: add missing "; then" --- test/TEST-01-BASIC/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index 22517a831e..6e7e97ef43 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -43,7 +43,7 @@ run_nspawn() { test_run() { run_qemu || return 1 - if [[ -d /sys/fs/cgroup/systemd ]] + if [[ -d /sys/fs/cgroup/systemd ]]; then run_nspawn || return 1 fi return 0 -- cgit v1.2.3-54-g00ecf From 33a5e20ffaa2cbb2853f14265566bac66a7f9026 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Fri, 25 May 2012 14:53:29 +0200 Subject: test/test-functions: be more verbose about skipping tests --- test/test-functions | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/test-functions b/test/test-functions index d0c5f6ca9e..84ce1e9475 100644 --- a/test/test-functions +++ b/test/test-functions @@ -575,8 +575,21 @@ inst_libdir_file() { } do_test() { - [[ $UID != "0" ]] && exit 0 - command -v qemu-kvm &>/dev/null || exit 0 + if [[ $UID != "0" ]]; then + echo "TEST: $TEST_DESCRIPTION [SKIPPED]: not root" >&2 + exit 0 + fi + + if ! command -v qemu-kvm &>/dev/null; then + echo "TEST: $TEST_DESCRIPTION [SKIPPED]: no qemu-kvm found" >&2 + exit 0 + fi + + if ! [[ -c /dev/kvm ]]; then + echo "TEST: $TEST_DESCRIPTION [SKIPPED]: /dev/kvm not found" >&2 + exit 0 + fi + # Detect lib paths [[ $libdir ]] || for libdir in /lib64 /lib; do [[ -d $libdir ]] && libdirs+=" $libdir" && break -- cgit v1.2.3-54-g00ecf From f7c05f7de6069ba8a2d61e77421ddd6c558f388e Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Fri, 25 May 2012 14:54:38 +0200 Subject: test/TEST-01-BASIC: make DEBUGTOOLS an environment variable --- test/TEST-01-BASIC/test.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index 6e7e97ef43..19676454ac 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -7,6 +7,8 @@ KVERSION=${KVERSION-$(uname -r)} # Uncomment this to debug failures #DEBUGFAIL="systemd.unit=multi-user.target" +DEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort" + run_qemu() { qemu-kvm \ @@ -196,10 +198,7 @@ EOF fi # some helper tools for debugging - dracut_install sh df free ls shutdown poweroff \ - stty cat ps ln ip route \ - mount dmesg dhclient mkdir cp ping dhclient \ - umount strace less grep id tty touch + [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS # install ld.so.conf* and run ldconfig cp -a /etc/ld.so.conf* $initdir/etc -- cgit v1.2.3-54-g00ecf From 6ea4364c7b40d21464b5fc64d6c5506658eb9401 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Fri, 25 May 2012 14:55:26 +0200 Subject: test/TEST-01-BASIC: fail test, if qemu failed --- test/TEST-01-BASIC/test.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index 19676454ac..efdf449a82 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -15,7 +15,8 @@ run_qemu() { -hda $TESTDIR/rootdisk.img \ -m 256M -nographic \ -net none -kernel /boot/vmlinuz-$KVERSION \ - -append "root=/dev/sda1 systemd.log_level=debug raid=noautodetect loglevel=2 init=/usr/lib/systemd/systemd rw console=ttyS0,115200n81 selinux=0 $DEBUGFAIL" + -append "root=/dev/sda1 systemd.log_level=debug raid=noautodetect loglevel=2 init=/usr/lib/systemd/systemd rw console=ttyS0,115200n81 selinux=0 $DEBUGFAIL" || return 1 + ret=1 mkdir -p $TESTDIR/root mount ${LOOPDEV}p1 $TESTDIR/root -- cgit v1.2.3-54-g00ecf From 1ecf6a2b4960229ad1d06c591b4776ddf065e834 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Fri, 25 May 2012 18:31:58 +0200 Subject: test/test-functions: add check_qemu() and check_nspawn() functions --- test/test-functions | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/test-functions b/test/test-functions index 84ce1e9475..5fdf0a18bd 100644 --- a/test/test-functions +++ b/test/test-functions @@ -574,22 +574,21 @@ inst_libdir_file() { fi } +check_qemu() { + command -v qemu-kvm &>/dev/null && [[ -c /dev/kvm ]] +} + +check_nspawn() { + [[ -d /sys/fs/cgroup/systemd ]] +} + + do_test() { if [[ $UID != "0" ]]; then echo "TEST: $TEST_DESCRIPTION [SKIPPED]: not root" >&2 exit 0 fi - if ! command -v qemu-kvm &>/dev/null; then - echo "TEST: $TEST_DESCRIPTION [SKIPPED]: no qemu-kvm found" >&2 - exit 0 - fi - - if ! [[ -c /dev/kvm ]]; then - echo "TEST: $TEST_DESCRIPTION [SKIPPED]: /dev/kvm not found" >&2 - exit 0 - fi - # Detect lib paths [[ $libdir ]] || for libdir in /lib64 /lib; do [[ -d $libdir ]] && libdirs+=" $libdir" && break -- cgit v1.2.3-54-g00ecf From 0d6e798a784ef0ba6b95512e4453067b2f84a91a Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Fri, 25 May 2012 18:32:55 +0200 Subject: test/TEST-01-BASIC: add /var on cryptoluks and wait for the journal --- test/TEST-01-BASIC/test.sh | 114 ++++++++++++++++----- test/test-functions | 246 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 320 insertions(+), 40 deletions(-) (limited to 'test') diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index efdf449a82..d50c835e50 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -4,26 +4,31 @@ TEST_DESCRIPTION="Basic systemd setup" KVERSION=${KVERSION-$(uname -r)} +KERNEL_VER=$(uname -r) # Uncomment this to debug failures #DEBUGFAIL="systemd.unit=multi-user.target" DEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort" - run_qemu() { + # TODO: qemu wrapper script: http://www.spinics.net/lists/kvm/msg72389.html qemu-kvm \ -hda $TESTDIR/rootdisk.img \ - -m 256M -nographic \ - -net none -kernel /boot/vmlinuz-$KVERSION \ - -append "root=/dev/sda1 systemd.log_level=debug raid=noautodetect loglevel=2 init=/usr/lib/systemd/systemd rw console=ttyS0,115200n81 selinux=0 $DEBUGFAIL" || return 1 + -m 512M -nographic \ + -net none -kernel /boot/vmlinuz-$KERNEL_VER \ + -append "root=/dev/sda1 systemd.log_level=debug raid=noautodetect loglevel=2 init=/usr/lib/systemd/systemd ro console=ttyS0,115200n81 selinux=0 $DEBUGFAIL" || return 1 ret=1 mkdir -p $TESTDIR/root mount ${LOOPDEV}p1 $TESTDIR/root [[ -e $TESTDIR/root/testok ]] && ret=0 - cp -a $TESTDIR/root/var/log/journal $TESTDIR cp -a $TESTDIR/root/failed $TESTDIR + cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile + mount /dev/mapper/varcrypt $TESTDIR/root/var + cp -a $TESTDIR/root/var/log/journal $TESTDIR + umount $TESTDIR/root/var umount $TESTDIR/root + cryptsetup luksClose /dev/mapper/varcrypt cat $TESTDIR/failed ls -l $TESTDIR/journal/*/*.journal test -s $TESTDIR/failed && ret=$(($ret+1)) @@ -45,9 +50,16 @@ run_nspawn() { test_run() { - run_qemu || return 1 - if [[ -d /sys/fs/cgroup/systemd ]]; then - run_nspawn || return 1 + if check_qemu ; then + run_qemu || return 1 + else + dwarn "can't run qemu-kvm, skipping" + fi + if check_nspawn; then +#run_nspawn || return 1 + : + else + dwarn "can't run systemd-nspawn, skipping" fi return 0 } @@ -55,20 +67,26 @@ test_run() { test_setup() { rm -f $TESTDIR/rootdisk.img # Create the blank file to use as a root filesystem - dd if=/dev/null of=$TESTDIR/rootdisk.img bs=1M seek=100 + dd if=/dev/null of=$TESTDIR/rootdisk.img bs=1M seek=200 LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img) [ -b $LOOPDEV ] || return 1 echo "LOOPDEV=$LOOPDEV" >> $STATEFILE - sfdisk -C 3200 -H 2 -S 32 -L $LOOPDEV <$TESTDIR/keyfile + cryptsetup -q luksFormat ${LOOPDEV}p2 $TESTDIR/keyfile + cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile + mkfs.ext3 -L var /dev/mapper/varcrypt mkdir -p $TESTDIR/root mount ${LOOPDEV}p1 $TESTDIR/root mkdir -p $TESTDIR/root/run + mkdir -p $TESTDIR/root/var + mount /dev/mapper/varcrypt $TESTDIR/root/var - kernel=$KVERSION # Create what will eventually be our root filesystem onto an overlay ( LOG_LEVEL=5 @@ -80,6 +98,9 @@ EOF # install compiled files (cd ../..; make DESTDIR=$initdir install) + # remove unneeded documentation + rm -fr $initdir/usr/share/{man,doc,gtk-doc} + # install possible missing libraries for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do inst_libs $i @@ -104,10 +125,25 @@ EOF inst /etc/localtime # we want an empty environment > $initdir/etc/environment + > $initdir/etc/machine-id # set the hostname echo systemd-testsuite > $initdir/etc/hostname + eval $(udevadm info --export --query=env --name=/dev/mapper/varcrypt) + eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) + + cat >$initdir/etc/crypttab < $initdir/etc/varkey + cat $initdir/etc/crypttab | ddebug + + cat >$initdir/etc/fstab <$initdir/etc/systemd/system/testsuite.target < /failed ; echo OK > /testok' -ExecStartPost=/usr/sbin/poweroff +ExecStart=/bin/bash -c 'set -x; systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok; while : ;do systemd-cat echo "testsuite service waiting for /var/log/journal" ; echo "testsuite service waiting for journal to move to /var/log/journal" > /dev/console ; for i in /var/log/journal/*;do [ -d "\$i" ] && echo "\$i" && break 2; done; sleep 1; done; sleep 1; exit 0;' +ExecStopPost=/usr/bin/systemctl poweroff Type=oneshot - EOF mkdir -p $initdir/etc/systemd/system/testsuite.target.wants ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service @@ -143,7 +178,16 @@ EOF chmod 0755 $initdir/etc/rc.d/rc.local # install basic tools needed dracut_install sh bash setsid loadkeys setfont \ - login sushell sulogin gzip sleep echo + login sushell sulogin gzip sleep echo mount umount cryptsetup + dracut_install dmsetup modprobe + + instmods dm_crypt =crypto + + type -P dmeventd >/dev/null && dracut_install dmeventd + + inst_libdir_file "libdevmapper-event.so*" + + inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules # install libnss_files for login inst_libdir_file "libnss_files*" @@ -190,13 +234,13 @@ EOF done # install plymouth, if found... else remove plymouth service files - if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then - PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \ - /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir - dracut_install plymouth plymouthd - else - rm -f $initdir/usr/lib/systemd/system/plymouth* $initdir/usr/lib/systemd/system/*/plymouth* - fi + # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then + # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \ + # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir + # dracut_install plymouth plymouthd + # else + rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth* + # fi # some helper tools for debugging [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS @@ -204,15 +248,35 @@ EOF # install ld.so.conf* and run ldconfig cp -a /etc/ld.so.conf* $initdir/etc ldconfig -r "$initdir" - + ddebug "Strip binaeries" + find "$initdir" -perm +111 -type f | xargs strip --strip-unneeded | ddebug + + # copy depmod files + inst /lib/modules/$KERNEL_VER/modules.order + inst /lib/modules/$KERNEL_VER/modules.builtin + # generate module dependencies + if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \ + ! depmod -a -b "$initdir" $KERNEL_VER; then + dfatal "\"depmod -a $KERNEL_VER\" failed." + exit 1 + fi ) rm -fr $TESTDIR/nspawn-root - cp -avr $TESTDIR/root $TESTDIR/nspawn-root - + ddebug "cp -ar $TESTDIR/root $TESTDIR/nspawn-root" + cp -ar $TESTDIR/root $TESTDIR/nspawn-root + # we don't mount in the nspawn root + rm -fr $TESTDIR/nspawn-root/etc/fstab + + ddebug "umount $TESTDIR/root/var" + umount $TESTDIR/root/var + cryptsetup luksClose /dev/mapper/varcrypt + ddebug "umount $TESTDIR/root" umount $TESTDIR/root } test_cleanup() { + umount $TESTDIR/root/var 2>/dev/null + [[ -b /dev/mapper/varcrypt ]] && cryptsetup luksClose /dev/mapper/varcrypt umount $TESTDIR/root 2>/dev/null [[ $LOOPDEV ]] && losetup -d $LOOPDEV return 0 diff --git a/test/test-functions b/test/test-functions index 5fdf0a18bd..c355423192 100644 --- a/test/test-functions +++ b/test/test-functions @@ -4,21 +4,15 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH -setup_basic_dirs() { - for d in usr/bin usr/sbin bin etc lib "$libdir" sbin tmp usr var var/log; do - [[ -e "${initdir}${prefix}/$d" ]] && continue - if [ -L "/$d" ]; then - inst_symlink "/$d" "${prefix}/$d" - else - mkdir -m 0755 -p "${initdir}${prefix}/$d" - fi - done +KERNEL_VER=${KERNEL_VER-$(uname -r)} +KERNEL_MODS="/lib/modules/$KERNEL_VER/" - for d in dev proc sys sysroot root run run/lock run/initramfs; do +setup_basic_dirs() { + for d in usr/bin usr/sbin bin etc lib "$libdir" sbin tmp usr var var/log dev proc sys sysroot root run run/lock run/initramfs; do if [ -L "/$d" ]; then inst_symlink "/$d" else - mkdir -m 0755 -p "$initdir/$d" + inst_dir "/$d" fi done @@ -127,9 +121,9 @@ dtrace() { # @param msg Message. # @retval 0 It's always returned, even if logging failed. ddebug() { - set +x +# set +x dlog 5 "$@" - [ -n "$debug" ] && set -x || : +# [ -n "$debug" ] && set -x || : } ## @brief Logs message at INFO level (4) @@ -157,9 +151,9 @@ dwarn() { # @param msg Message. # @retval 0 It's always returned, even if logging failed. derror() { - set +x +# set +x dlog 2 "$@" - [ -n "$debug" ] && set -x || : +# [ -n "$debug" ] && set -x || : } ## @brief Logs message at FATAL level (1) @@ -547,6 +541,228 @@ dracut_install() { done } +# Install a single kernel module along with any firmware it may require. +# $1 = full path to kernel module to install +install_kmod_with_fw() { + # no need to go further if the module is already installed + + [[ -e "${initdir}/lib/modules/$KERNEL_VER/${1##*/lib/modules/$KERNEL_VER/}" ]] \ + && return 0 + + [[ -e "$initdir/.kernelmodseen/${1##*/}" ]] && return 0 + + if [[ $omit_drivers ]]; then + local _kmod=${1##*/} + _kmod=${_kmod%.ko} + _kmod=${_kmod/-/_} + if [[ "$_kmod" =~ $omit_drivers ]]; then + dinfo "Omitting driver $_kmod" + return 1 + fi + if [[ "${1##*/lib/modules/$KERNEL_VER/}" =~ $omit_drivers ]]; then + dinfo "Omitting driver $_kmod" + return 1 + fi + fi + + [ -d "$initdir/.kernelmodseen" ] && \ + > "$initdir/.kernelmodseen/${1##*/}" + + inst_simple "$1" "/lib/modules/$KERNEL_VER/${1##*/lib/modules/$KERNEL_VER/}" \ + || return $? + + local _modname=${1##*/} _fwdir _found _fw + _modname=${_modname%.ko*} + for _fw in $(modinfo -k $KERNEL_VER -F firmware $1 2>/dev/null); do + _found='' + for _fwdir in $fw_dir; do + if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then + inst_simple "$_fwdir/$_fw" "/lib/firmware/$_fw" + _found=yes + fi + done + if [[ $_found != yes ]]; then + if ! grep -qe "\<${_modname//-/_}\>" /proc/modules; then + dinfo "Possible missing firmware \"${_fw}\" for kernel module" \ + "\"${_modname}.ko\"" + else + dwarn "Possible missing firmware \"${_fw}\" for kernel module" \ + "\"${_modname}.ko\"" + fi + fi + done + return 0 +} + +# Do something with all the dependencies of a kernel module. +# Note that kernel modules depend on themselves using the technique we use +# $1 = function to call for each dependency we find +# It will be passed the full path to the found kernel module +# $2 = module to get dependencies for +# rest of args = arguments to modprobe +# _fderr specifies FD passed from surrounding scope +for_each_kmod_dep() { + local _func=$1 _kmod=$2 _cmd _modpath _options _found=0 + shift 2 + modprobe "$@" --ignore-install --show-depends $_kmod 2>&${_fderr} | ( + while read _cmd _modpath _options; do + [[ $_cmd = insmod ]] || continue + $_func ${_modpath} || exit $? + _found=1 + done + [[ $_found -eq 0 ]] && exit 1 + exit 0 + ) +} + +# filter kernel modules to install certain modules that meet specific +# requirements. +# $1 = search only in subdirectory of /kernel/$1 +# $2 = function to call with module name to filter. +# This function will be passed the full path to the module to test. +# The behaviour of this function can vary depending on whether $hostonly is set. +# If it is, we will only look at modules that are already in memory. +# If it is not, we will look at all kernel modules +# This function returns the full filenames of modules that match $1 +filter_kernel_modules_by_path () ( + local _modname _filtercmd + if ! [[ $hostonly ]]; then + _filtercmd='find "$KERNEL_MODS/kernel/$1" "$KERNEL_MODS/extra"' + _filtercmd+=' "$KERNEL_MODS/weak-updates" -name "*.ko" -o -name "*.ko.gz"' + _filtercmd+=' -o -name "*.ko.xz"' + _filtercmd+=' 2>/dev/null' + else + _filtercmd='cut -d " " -f 1 $initdir/$$.ko + $2 $initdir/$$.ko && echo "$_modname" + rm -f $initdir/$$.ko + ;; + *.ko.xz) xz -dc "$_modname" > $initdir/$$.ko + $2 $initdir/$$.ko && echo "$_modname" + rm -f $initdir/$$.ko + ;; + esac + done +) +find_kernel_modules_by_path () ( + if ! [[ $hostonly ]]; then + find "$KERNEL_MODS/kernel/$1" "$KERNEL_MODS/extra" "$KERNEL_MODS/weak-updates" \ + -name "*.ko" -o -name "*.ko.gz" -o -name "*.ko.xz" 2>/dev/null + else + cut -d " " -f 1 /dev/null + fi +) + +filter_kernel_modules () { + filter_kernel_modules_by_path drivers "$1" +} + +find_kernel_modules () { + find_kernel_modules_by_path drivers +} + +# instmods [-c] [ ... ] +# instmods [-c] +# install kernel modules along with all their dependencies. +# can be e.g. "=block" or "=drivers/usb/storage" +instmods() { + [[ $no_kernel = yes ]] && return + # called [sub]functions inherit _fderr + local _fderr=9 + local _check=no + if [[ $1 = '-c' ]]; then + _check=yes + shift + fi + + function inst1mod() { + local _ret=0 _mod="$1" + case $_mod in + =*) + if [ -f $KERNEL_MODS/modules.${_mod#=} ]; then + ( [[ "$_mpargs" ]] && echo $_mpargs + cat "${KERNEL_MODS}/modules.${_mod#=}" ) \ + | instmods + else + ( [[ "$_mpargs" ]] && echo $_mpargs + find "$KERNEL_MODS" -path "*/${_mod#=}/*" -printf '%f\n' ) \ + | instmods + fi + ;; + --*) _mpargs+=" $_mod" ;; + i2o_scsi) return ;; # Do not load this diagnostic-only module + *) + _mod=${_mod##*/} + # if we are already installed, skip this module and go on + # to the next one. + [[ -f "$initdir/.kernelmodseen/${_mod%.ko}.ko" ]] && return + + if [[ $omit_drivers ]] && [[ "$1" =~ $omit_drivers ]]; then + dinfo "Omitting driver ${_mod##$KERNEL_MODS}" + return + fi + # If we are building a host-specific initramfs and this + # module is not already loaded, move on to the next one. + [[ $hostonly ]] && ! grep -qe "\<${_mod//-/_}\>" /proc/modules \ + && ! echo $add_drivers | grep -qe "\<${_mod}\>" \ + && return + + # We use '-d' option in modprobe only if modules prefix path + # differs from default '/'. This allows us to use Dracut with + # old version of modprobe which doesn't have '-d' option. + local _moddirname=${KERNEL_MODS%%/lib/modules/*} + [[ -n ${_moddirname} ]] && _moddirname="-d ${_moddirname}/" + + # ok, load the module, all its dependencies, and any firmware + # it may require + for_each_kmod_dep install_kmod_with_fw $_mod \ + --set-version $KERNEL_VER ${_moddirname} $_mpargs + ((_ret+=$?)) + ;; + esac + return $_ret + } + + function instmods_1() { + local _mod _mpargs + if (($# == 0)); then # filenames from stdin + while read _mod; do + inst1mod "${_mod%.ko*}" || { + if [ "$_check" = "yes" ]; then + dfatal "Failed to install $_mod" + return 1 + fi + } + done + fi + while (($# > 0)); do # filenames as arguments + inst1mod ${1%.ko*} || { + if [ "$_check" = "yes" ]; then + dfatal "Failed to install $1" + return 1 + fi + } + shift + done + return 0 + } + + local _ret _filter_not_found='FATAL: Module .* not found.' + set -o pipefail + # Capture all stderr from modprobe to _fderr. We could use {var}>... + # redirections, but that would make dracut require bash4 at least. + eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \ + | while read line; do [[ "$line" =~ $_filter_not_found ]] && echo $line || echo $line >&2 ;done | derror + _ret=$? + set +o pipefail + return $_ret +} # inst_libdir_file [-n ] [...] # Install a located on a lib directory to the initramfs image -- cgit v1.2.3-54-g00ecf From c452e3725497b873bce9289d2858fb8baf367bf9 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Fri, 25 May 2012 18:44:42 +0200 Subject: test/README.testsuite: add documentation for the testsuite --- test/README.testsuite | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/README.testsuite (limited to 'test') diff --git a/test/README.testsuite b/test/README.testsuite new file mode 100644 index 0000000000..0f96b984a9 --- /dev/null +++ b/test/README.testsuite @@ -0,0 +1,35 @@ +The extended testsuite only works with uid=0. It contains of several +subdirectories named "test/TEST-??-*", which are run one by one. + +To run the extended testsuite do the following: + +$ make all +$ cd test +$ sudo make clean check +... +make[1]: Entering directory `/mnt/data/harald/git/systemd/test/TEST-01-BASIC' +Making all in . +Making all in po +Making all in docs/libudev +Making all in docs/gudev +TEST: Basic systemd setup [OK] +make[1]: Leaving directory `/mnt/data/harald/git/systemd/test/TEST-01-BASIC' +... + +If one of the tests fails, then $subdir/test.log contains the log file of +the test. + +To debug a special testcase of the testsuite do: + +$ make all +$ cd test/TEST-01-BASIC +$ sudo make clean setup run + +If you want to log in the testsuite virtual machine, you can specify +additional kernel command line parameter with $DEBUGFAIL. + +$ sudo sh -c 'DEBUGFAIL="systemd.unit=multi-user.target" make clean setup run' + +you can even skip the "clean" and "setup" if you want to run the machine again. + +$ sudo sh -c 'DEBUGFAIL="systemd.unit=multi-user.target" make run' -- cgit v1.2.3-54-g00ecf From 5fa594df8de6fed8e18146096a7b7d45b2187441 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 28 Jun 2012 12:14:18 +0200 Subject: test: reenable nspawn, even if it fails for now --- test/TEST-01-BASIC/test.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test') diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index d50c835e50..06b80c2a15 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -56,8 +56,7 @@ test_run() { dwarn "can't run qemu-kvm, skipping" fi if check_nspawn; then -#run_nspawn || return 1 - : + run_nspawn || return 1 else dwarn "can't run systemd-nspawn, skipping" fi -- cgit v1.2.3-54-g00ecf From 5076f0ccfd36b67512d44fe355b80305ced7dcba Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 28 Jun 2012 13:44:39 +0200 Subject: nspawn: introduce new --capabilities= flag and make use of it in the nspawn test case --- man/systemd-nspawn.xml | 24 ++++++++++++++ src/nspawn/nspawn.c | 83 +++++++++++++++++++++++++++++++--------------- test/TEST-01-BASIC/test.sh | 2 +- 3 files changed, 81 insertions(+), 28 deletions(-) (limited to 'test') diff --git a/man/systemd-nspawn.xml b/man/systemd-nspawn.xml index a926a7e5d3..76e291881c 100644 --- a/man/systemd-nspawn.xml +++ b/man/systemd-nspawn.xml @@ -206,6 +206,30 @@ container. + + + + List one or more + additional capabilities to grant the + container. Takes a comma separated + list of capability names, see + capabilities7 + for more information. Note that the + the following capabilities will be + granted in any way: CAP_CHOWN, + CAP_DAC_OVERRIDE, CAP_DAC_READ_SEARCH, + CAP_FOWNER, CAP_FSETID, CAP_IPC_OWNER, + CAP_KILL, CAP_LEASE, + CAP_LINUX_IMMUTABLE, + CAP_NET_BIND_SERVICE, + CAP_NET_BROADCAST, CAP_NET_RAW, + CAP_SETGID, CAP_SETFCAP, CAP_SETPCAP, + CAP_SETUID, CAP_SYS_ADMIN, + CAP_SYS_CHROOT, CAP_SYS_NICE, + CAP_SYS_PTRACE, CAP_SYS_TTY_CONFIG, + CAP_SYS_RESOURCE. + + diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index fec39d6448..ffd8fd4ef5 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -60,6 +60,29 @@ static char *arg_uuid = NULL; static bool arg_private_network = false; static bool arg_read_only = false; static bool arg_boot = false; +static uint64_t arg_retain = + (1ULL << CAP_CHOWN) | + (1ULL << CAP_DAC_OVERRIDE) | + (1ULL << CAP_DAC_READ_SEARCH) | + (1ULL << CAP_FOWNER) | + (1ULL << CAP_FSETID) | + (1ULL << CAP_IPC_OWNER) | + (1ULL << CAP_KILL) | + (1ULL << CAP_LEASE) | + (1ULL << CAP_LINUX_IMMUTABLE) | + (1ULL << CAP_NET_BIND_SERVICE) | + (1ULL << CAP_NET_BROADCAST) | + (1ULL << CAP_NET_RAW) | + (1ULL << CAP_SETGID) | + (1ULL << CAP_SETFCAP) | + (1ULL << CAP_SETPCAP) | + (1ULL << CAP_SETUID) | + (1ULL << CAP_SYS_ADMIN) | + (1ULL << CAP_SYS_CHROOT) | + (1ULL << CAP_SYS_NICE) | + (1ULL << CAP_SYS_PTRACE) | + (1ULL << CAP_SYS_TTY_CONFIG) | + (1ULL << CAP_SYS_RESOURCE); static int help(void) { @@ -72,7 +95,8 @@ static int help(void) { " -C --controllers=LIST Put the container in specified comma-separated cgroup hierarchies\n" " --uuid=UUID Set a specific machine UUID for the container\n" " --private-network Disable network in container\n" - " --read-only Mount the root directory read-only\n", + " --read-only Mount the root directory read-only\n" + " --capability=CAP In addition to the default, retain specified capability\n", program_invocation_short_name); return 0; @@ -83,7 +107,8 @@ static int parse_argv(int argc, char *argv[]) { enum { ARG_PRIVATE_NETWORK = 0x100, ARG_UUID, - ARG_READ_ONLY + ARG_READ_ONLY, + ARG_CAPABILITY }; static const struct option options[] = { @@ -95,6 +120,7 @@ static int parse_argv(int argc, char *argv[]) { { "boot", no_argument, NULL, 'b' }, { "uuid", required_argument, NULL, ARG_UUID }, { "read-only", no_argument, NULL, ARG_READ_ONLY }, + { "capability", required_argument, NULL, ARG_CAPABILITY }, { NULL, 0, NULL, 0 } }; @@ -157,6 +183,33 @@ static int parse_argv(int argc, char *argv[]) { arg_read_only = true; break; + case ARG_CAPABILITY: { + char *state, *word; + size_t length; + + FOREACH_WORD_SEPARATOR(word, length, optarg, ",", state) { + cap_value_t cap; + char *t; + + t = strndup(word, length); + if (!t) { + log_error("Out of memory."); + return -ENOMEM; + } + + if (cap_from_name(t, &cap) < 0) { + log_error("Failed to parse capability %s.", t); + free(t); + return -EINVAL; + } + + free(t); + arg_retain |= 1ULL << (uint64_t) cap; + } + + break; + } + case '?': return -EINVAL; @@ -544,31 +597,7 @@ static int setup_hostname(void) { } static int drop_capabilities(void) { - - static const uint64_t retain = - (1ULL << CAP_CHOWN) | - (1ULL << CAP_DAC_OVERRIDE) | - (1ULL << CAP_DAC_READ_SEARCH) | - (1ULL << CAP_FOWNER) | - (1ULL << CAP_FSETID) | - (1ULL << CAP_IPC_OWNER) | - (1ULL << CAP_KILL) | - (1ULL << CAP_LEASE) | - (1ULL << CAP_LINUX_IMMUTABLE) | - (1ULL << CAP_NET_BIND_SERVICE) | - (1ULL << CAP_NET_BROADCAST) | - (1ULL << CAP_NET_RAW) | - (1ULL << CAP_SETGID) | - (1ULL << CAP_SETFCAP) | - (1ULL << CAP_SETPCAP) | - (1ULL << CAP_SETUID) | - (1ULL << CAP_SYS_ADMIN) | - (1ULL << CAP_SYS_CHROOT) | - (1ULL << CAP_SYS_NICE) | - (1ULL << CAP_SYS_PTRACE) | - (1ULL << CAP_SYS_TTY_CONFIG); - - return capability_bounding_set_drop(~retain, false); + return capability_bounding_set_drop(~arg_retain, false); } static int is_os_tree(const char *path) { diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index 06b80c2a15..8979872ef2 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -37,7 +37,7 @@ run_qemu() { run_nspawn() { - systemd-nspawn -b -D $TESTDIR/nspawn-root /usr/lib/systemd/systemd + systemd-nspawn -b -D $TESTDIR/nspawn-root --capability=CAP_AUDIT_CONTROL,CAP_AUDIT_WRITE /usr/lib/systemd/systemd ret=1 [[ -e $TESTDIR/nspawn-root/testok ]] && ret=0 cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR -- cgit v1.2.3-54-g00ecf From 4cb72937d3c10948e4904388ea27efae75775f08 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sun, 15 Jul 2012 22:10:46 +0200 Subject: udev: get rid of TEST_PREFIX and use unshare() to fake /sys, /dev, /run --- Makefile.am | 16 ++----------- TODO | 2 -- src/libudev/libudev-device-private.c | 8 +++---- src/libudev/libudev-device.c | 38 +++++++++++++++---------------- src/libudev/libudev-private.h | 4 ---- src/test/test-udev.c | 44 ++++++++++++++++++++++++++++++++++-- src/udev/udev-event.c | 12 +++++----- src/udev/udev-node.c | 8 +++---- src/udev/udev-rules.c | 16 ++++++------- test/udev-test.pl | 2 +- 10 files changed, 86 insertions(+), 64 deletions(-) (limited to 'test') diff --git a/Makefile.am b/Makefile.am index d9fb72f8e5..c9ea8047ad 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1756,22 +1756,10 @@ test_libudev_LDADD = \ libudev.la test_udev_SOURCES = \ - src/test/test-udev.c \ - $(libudev_core_la_SOURCES) \ - $(libudev_private_la_SOURCES) - -# The test-udev program needs everything compiled with relative path -# names for /sys, /dev, /run prefixed, pointing to our test/ directory. -test_udev_CFLAGS = \ - -DTEST_PREFIX=\"test\" \ - $(libudev_core_la_CFLAGS) \ - $(libudev_private_la_CFLAGS) - -test_udev_CPPFLAGS =\ - $(libudev_core_la_CPPFLAGS) + src/test/test-udev.c test_udev_LDADD = \ - libsystemd-label.la \ + libudev-core.la \ libsystemd-shared.la \ $(BLKID_LIBS) \ $(KMOD_LIBS) \ diff --git a/TODO b/TODO index e3debb45d1..1ec59b2f53 100644 --- a/TODO +++ b/TODO @@ -33,8 +33,6 @@ Bugfixes: Jul 09 18:22:37 mop [21866]: Process 21865 (systemd) dumped core. Features: -* udev: use 'unshare' to test udev with fake sysfs tree, and kill TEST_PREFIX entirely - * change mount access mode of 0700 or so for debugfs? * logind: wakelock/opportunistic suspend support diff --git a/src/libudev/libudev-device-private.c b/src/libudev/libudev-device-private.c index 234773662b..00fa3b8890 100644 --- a/src/libudev/libudev-device-private.c +++ b/src/libudev/libudev-device-private.c @@ -30,7 +30,7 @@ static void udev_device_tag(struct udev_device *dev, const char *tag, bool add) id = udev_device_get_id_filename(dev); if (id == NULL) return; - util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/tags/", tag, "/", id, NULL); + util_strscpyl(filename, sizeof(filename), "/run/udev/tags/", tag, "/", id, NULL); if (add) { int fd; @@ -107,7 +107,7 @@ int udev_device_update_db(struct udev_device *udev_device) return -1; has_info = device_has_info(udev_device); - util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/data/", id, NULL); + util_strscpyl(filename, sizeof(filename), "/run/udev/data/", id, NULL); /* do not store anything for otherwise empty devices */ if (!has_info && @@ -138,7 +138,7 @@ int udev_device_update_db(struct udev_device *udev_device) if (major(udev_device_get_devnum(udev_device)) > 0) { udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(udev_device)) - fprintf(f, "S:%s\n", udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/")); + fprintf(f, "S:%s\n", udev_list_entry_get_name(list_entry) + strlen("/dev/")); if (udev_device_get_devlink_priority(udev_device) != 0) fprintf(f, "L:%i\n", udev_device_get_devlink_priority(udev_device)); if (udev_device_get_watch_handle(udev_device) >= 0) @@ -175,7 +175,7 @@ int udev_device_delete_db(struct udev_device *udev_device) id = udev_device_get_id_filename(udev_device); if (id == NULL) return -1; - util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/data/", id, NULL); + util_strscpyl(filename, sizeof(filename), "/run/udev/data/", id, NULL); unlink(filename); return 0; } diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index a8277d1363..98077e777d 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -360,7 +360,7 @@ void udev_device_add_property_from_string_parse(struct udev_device *udev_device, if (startswith(property, "DEVPATH=")) { char path[UTIL_PATH_SIZE]; - util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys", &property[8], NULL); + util_strscpyl(path, sizeof(path), "/sys", &property[8], NULL); udev_device_set_syspath(udev_device, path); } else if (startswith(property, "SUBSYSTEM=")) { udev_device_set_subsystem(udev_device, &property[10]); @@ -479,7 +479,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile) id = udev_device_get_id_filename(udev_device); if (id == NULL) return -1; - util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/data/", id, NULL); + util_strscpyl(filename, sizeof(filename), "/run/udev/data/", id, NULL); dbfile = filename; } @@ -502,7 +502,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile) val = &line[2]; switch(line[0]) { case 'S': - util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/", val, NULL); + util_strscpyl(filename, sizeof(filename), "/dev/", val, NULL); udev_device_add_devlink(udev_device, filename, 0); break; case 'L': @@ -642,13 +642,13 @@ _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, con return NULL; /* path starts in sys */ - if (!startswith(syspath, TEST_PREFIX "/sys")) { + if (!startswith(syspath, "/sys")) { udev_dbg(udev, "not in sys :%s\n", syspath); return NULL; } /* path is not a root directory */ - subdir = syspath + strlen(TEST_PREFIX "/sys"); + subdir = syspath + strlen("/sys"); pos = strrchr(subdir, '/'); if (pos == NULL || pos[1] == '\0' || pos < &subdir[2]) return NULL; @@ -657,7 +657,7 @@ _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, con util_strscpy(path, sizeof(path), syspath); util_resolve_sys_link(udev, path, sizeof(path)); - if (startswith(path + strlen(TEST_PREFIX "/sys"), "/devices/")) { + if (startswith(path + strlen("/sys"), "/devices/")) { char file[UTIL_PATH_SIZE]; /* all "devices" require a "uevent" file */ @@ -709,7 +709,7 @@ _public_ struct udev_device *udev_device_new_from_devnum(struct udev *udev, char return NULL; /* use /sys/dev/{block,char}/: link */ - snprintf(path, sizeof(path), TEST_PREFIX "/sys/dev/%s/%u:%u", + snprintf(path, sizeof(path), "/sys/dev/%s/%u:%u", type_str, major(devnum), minor(devnum)); return udev_device_new_from_syspath(udev, path); } @@ -790,22 +790,22 @@ _public_ struct udev_device *udev_device_new_from_subsystem_sysname(struct udev struct stat statbuf; if (streq(subsystem, "subsystem")) { - util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/subsystem/", sysname, NULL); + util_strscpyl(path, sizeof(path), "/sys/subsystem/", sysname, NULL); if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/bus/", sysname, NULL); + util_strscpyl(path, sizeof(path), "/sys/bus/", sysname, NULL); if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/class/", sysname, NULL); + util_strscpyl(path, sizeof(path), "/sys/class/", sysname, NULL); if (stat(path, &statbuf) == 0) goto found; goto out; } if (streq(subsystem, "module")) { - util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/module/", sysname, NULL); + util_strscpyl(path, sizeof(path), "/sys/module/", sysname, NULL); if (stat(path, &statbuf) == 0) goto found; goto out; @@ -821,26 +821,26 @@ _public_ struct udev_device *udev_device_new_from_subsystem_sysname(struct udev driver[0] = '\0'; driver = &driver[1]; - util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/subsystem/", subsys, "/drivers/", driver, NULL); + util_strscpyl(path, sizeof(path), "/sys/subsystem/", subsys, "/drivers/", driver, NULL); if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/bus/", subsys, "/drivers/", driver, NULL); + util_strscpyl(path, sizeof(path), "/sys/bus/", subsys, "/drivers/", driver, NULL); if (stat(path, &statbuf) == 0) goto found; } goto out; } - util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/subsystem/", subsystem, "/devices/", sysname, NULL); + util_strscpyl(path, sizeof(path), "/sys/subsystem/", subsystem, "/devices/", sysname, NULL); if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/bus/", subsystem, "/devices/", sysname, NULL); + util_strscpyl(path, sizeof(path), "/sys/bus/", subsystem, "/devices/", sysname, NULL); if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/class/", subsystem, "/", sysname, NULL); + util_strscpyl(path, sizeof(path), "/sys/class/", subsystem, "/", sysname, NULL); if (stat(path, &statbuf) == 0) goto found; out: @@ -892,7 +892,7 @@ static struct udev_device *device_new_from_parent(struct udev_device *udev_devic const char *subdir; util_strscpy(path, sizeof(path), udev_device->syspath); - subdir = path + strlen(TEST_PREFIX "/sys/"); + subdir = path + strlen("/sys/"); for (;;) { char *pos; @@ -1443,7 +1443,7 @@ int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath udev_device->syspath = strdup(syspath); if (udev_device->syspath == NULL) return -ENOMEM; - udev_device->devpath = udev_device->syspath + strlen(TEST_PREFIX "/sys"); + udev_device->devpath = udev_device->syspath + strlen("/sys"); udev_device_add_property(udev_device, "DEVPATH", udev_device->devpath); pos = strrchr(udev_device->syspath, '/'); @@ -1476,7 +1476,7 @@ int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode { free(udev_device->devnode); if (devnode[0] != '/') { - if (asprintf(&udev_device->devnode, TEST_PREFIX "/dev/%s", devnode) < 0) + if (asprintf(&udev_device->devnode, "/dev/%s", devnode) < 0) udev_device->devnode = NULL; } else { udev_device->devnode = strdup(devnode); diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h index bc58424636..5990605445 100644 --- a/src/libudev/libudev-private.h +++ b/src/libudev/libudev-private.h @@ -25,10 +25,6 @@ #define READ_END 0 #define WRITE_END 1 -#ifndef TEST_PREFIX -#define TEST_PREFIX "" -#endif - /* avoid (sometimes expensive) calculations of parameters for debug output */ #define udev_log_cond(udev, prio, arg...) \ do { \ diff --git a/src/test/test-udev.c b/src/test/test-udev.c index 414eabc7b8..89827c02cb 100644 --- a/src/test/test-udev.c +++ b/src/test/test-udev.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include "udev.h" @@ -34,6 +36,40 @@ void udev_main_log(struct udev *udev, int priority, const char *file, int line, const char *fn, const char *format, va_list args) {} +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"); + return err; + } + + 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; + } + } + return err; +} + + int main(int argc, char *argv[]) { struct udev *udev; @@ -44,7 +80,11 @@ int main(int argc, char *argv[]) const char *devpath; const char *action; sigset_t mask, sigmask_orig; - int err = -EINVAL; + int err; + + err = fake_filesystems(); + if (err < 0) + return EXIT_FAILURE; udev = udev_new(); if (udev == NULL) @@ -68,7 +108,7 @@ int main(int argc, char *argv[]) rules = udev_rules_new(udev, 1); - util_strscpyl(syspath, sizeof(syspath), TEST_PREFIX "/sys", devpath, NULL); + util_strscpyl(syspath, sizeof(syspath), "/sys", devpath, NULL); dev = udev_device_new_from_syspath(udev, syspath); if (dev == NULL) { log_debug("unknown device '%s'\n", devpath); diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index d5dd1f3ba4..2ade0ab81a 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -319,7 +319,7 @@ subst: break; devnode = udev_device_get_devnode(dev_parent); if (devnode != NULL) - l = util_strpcpy(&s, l, devnode + strlen(TEST_PREFIX "/dev/")); + l = util_strpcpy(&s, l, devnode + strlen("/dev/")); break; } case SUBST_DEVNODE: @@ -330,7 +330,7 @@ subst: if (event->name != NULL) l = util_strpcpy(&s, l, event->name); else if (udev_device_get_devnode(dev) != NULL) - l = util_strpcpy(&s, l, udev_device_get_devnode(dev) + strlen(TEST_PREFIX "/dev/")); + l = util_strpcpy(&s, l, udev_device_get_devnode(dev) + strlen("/dev/")); else l = util_strpcpy(&s, l, udev_device_get_sysname(dev)); break; @@ -340,16 +340,16 @@ subst: list_entry = udev_device_get_devlinks_list_entry(dev); if (list_entry == NULL) break; - l = util_strpcpy(&s, l, udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/")); + l = util_strpcpy(&s, l, udev_list_entry_get_name(list_entry) + strlen("/dev/")); udev_list_entry_foreach(list_entry, udev_list_entry_get_next(list_entry)) - l = util_strpcpyl(&s, l, " ", udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/"), NULL); + l = util_strpcpyl(&s, l, " ", udev_list_entry_get_name(list_entry) + strlen("/dev/"), NULL); break; } case SUBST_ROOT: - l = util_strpcpy(&s, l, TEST_PREFIX "/dev"); + l = util_strpcpy(&s, l, "/dev"); break; case SUBST_SYS: - l = util_strpcpy(&s, l, TEST_PREFIX "/sys"); + l = util_strpcpy(&s, l, "/sys"); break; case SUBST_ENV: if (attr == NULL) { diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 9add76547f..738d02fa25 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -190,8 +190,8 @@ static void link_update(struct udev_device *dev, const char *slink, bool add) const char *target; char buf[UTIL_PATH_SIZE]; - util_path_encode(slink + strlen(TEST_PREFIX "/dev"), name_enc, sizeof(name_enc)); - util_strscpyl(dirname, sizeof(dirname), TEST_PREFIX "/run/udev/links/", name_enc, NULL); + util_path_encode(slink + strlen("/dev"), name_enc, sizeof(name_enc)); + util_strscpyl(dirname, sizeof(dirname), "/run/udev/links/", name_enc, NULL); util_strscpyl(filename, sizeof(filename), dirname, "/", udev_device_get_id_filename(dev), NULL); if (!add && unlink(filename) == 0) @@ -315,7 +315,7 @@ void udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid) return; /* always add /dev/{block,char}/$major:$minor */ - snprintf(filename, sizeof(filename), TEST_PREFIX "/dev/%s/%u:%u", + snprintf(filename, sizeof(filename), "/dev/%s/%u:%u", strcmp(udev_device_get_subsystem(dev), "block") == 0 ? "block" : "char", major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev))); node_symlink(udev, udev_device_get_devnode(dev), filename); @@ -340,7 +340,7 @@ void udev_node_remove(struct udev_device *dev) link_update(dev, udev_list_entry_get_name(list_entry), 0); /* remove /dev/{block,char}/$major:$minor */ - snprintf(filename, sizeof(filename), TEST_PREFIX "/dev/%s/%u:%u", + snprintf(filename, sizeof(filename), "/dev/%s/%u:%u", strcmp(udev_device_get_subsystem(dev), "block") == 0 ? "block" : "char", major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev))); unlink(filename); diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index c571c82877..d3b33e4bbf 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -1757,9 +1757,9 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names) memset(rules->trie_nodes, 0x00, sizeof(struct trie_node)); rules->trie_nodes_cur = 1; - rules->dirs = strv_new(TEST_PREFIX SYSCONFDIR "/udev/rules.d", - TEST_PREFIX "/run/udev/rules.d", - TEST_PREFIX UDEVLIBEXECDIR "/rules.d", + rules->dirs = strv_new(SYSCONFDIR "/udev/rules.d", + "/run/udev/rules.d", + UDEVLIBEXECDIR "/rules.d", NULL); if (!rules->dirs) { log_error("failed to build config directory array"); @@ -2059,7 +2059,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(event->dev)) { const char *devlink; - devlink = udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/"); + devlink = udev_list_entry_get_name(list_entry) + strlen("/dev/"); if (match_key(rules, cur, devlink) == 0) { match = true; break; @@ -2533,7 +2533,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event log_debug("%i character(s) replaced\n", count); } if (major(udev_device_get_devnum(event->dev)) && - (!streq(name_str, udev_device_get_devnode(event->dev) + strlen(TEST_PREFIX "/dev/")))) { + (!streq(name_str, udev_device_get_devnode(event->dev) + strlen("/dev/")))) { log_error("NAME=\"%s\" ignored, kernel device nodes " "can not be renamed; please fix it in %s:%u\n", name, &rules->buf[rule->rule.filename_off], rule->rule.filename_line); @@ -2578,7 +2578,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event next[0] = '\0'; log_debug("LINK '%s' %s:%u\n", pos, &rules->buf[rule->rule.filename_off], rule->rule.filename_line); - util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/", pos, NULL); + util_strscpyl(filename, sizeof(filename), "/dev/", pos, NULL); udev_device_add_devlink(event->dev, filename, cur->key.devlink_unique); while (isspace(next[1])) next++; @@ -2588,7 +2588,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event if (pos[0] != '\0') { log_debug("LINK '%s' %s:%u\n", pos, &rules->buf[rule->rule.filename_off], rule->rule.filename_line); - util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/", pos, NULL); + util_strscpyl(filename, sizeof(filename), "/dev/", pos, NULL); udev_device_add_devlink(event->dev, filename, cur->key.devlink_unique); } break; @@ -2698,7 +2698,7 @@ void udev_rules_apply_static_dev_perms(struct udev_rules *rules) /* we assure, that the permissions tokens are sorted before the static token */ if (mode == 0 && uid == 0 && gid == 0) goto next; - util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/", + util_strscpyl(filename, sizeof(filename), "/dev/", &rules->buf[cur->key.value_off], NULL); if (stat(filename, &stats) != 0) goto next; diff --git a/test/udev-test.pl b/test/udev-test.pl index d80b00c374..e91dda11cf 100755 --- a/test/udev-test.pl +++ b/test/udev-test.pl @@ -891,7 +891,7 @@ EOF { desc => "udev_root substitution", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "start-test/dev-end", + exp_name => "start-/dev-end", rules => < Date: Tue, 4 Sep 2012 19:24:16 +0200 Subject: man: fix a bunch of typos in docs https://bugs.freedesktop.org/show_bug.cgi?id=54501 --- man/bootup.xml | 2 +- man/crypttab.xml | 8 ++++---- man/daemon.xml | 10 +++++----- man/kernel-command-line.xml | 2 +- man/locale.conf.xml | 2 +- man/pam_systemd.xml | 4 ++-- man/sd_journal_print.xml | 2 +- man/sd_seat_get_active.xml | 2 +- man/systemctl.xml | 6 +++--- man/systemd.device.xml | 2 +- man/systemd.exec.xml | 6 +++--- man/systemd.service.xml | 12 ++++++------ man/systemd.socket.xml | 8 ++++---- man/systemd.unit.xml | 2 +- src/core/dbus-unit.c | 2 +- src/core/transaction.c | 2 +- src/core/unit.c | 2 +- src/core/unit.h | 2 +- src/journal/journal-file.c | 2 +- src/journal/lookup3.c | 2 +- src/journal/mmap-cache.c | 2 +- src/libudev/libudev-device.c | 2 +- src/udev/udevd.c | 2 +- test/test-functions | 2 +- 24 files changed, 44 insertions(+), 44 deletions(-) (limited to 'test') diff --git a/man/bootup.xml b/man/bootup.xml index ae70c953f5..4cc4bafab7 100644 --- a/man/bootup.xml +++ b/man/bootup.xml @@ -111,7 +111,7 @@ target units are available, as listed on systemd.special7. - The follow chart is a structural overview of + The following chart is a structural overview of these well-known units and their position in the boot-up logic. The arrows describe which units are pulled in and ordered before which other units. Units diff --git a/man/crypttab.xml b/man/crypttab.xml index 8711272a87..2a839944dc 100644 --- a/man/crypttab.xml +++ b/man/crypttab.xml @@ -175,7 +175,7 @@ verify - If the the encryption + If the encryption password is read from console, it has to be entered twice (to prevent typos). @@ -217,9 +217,9 @@ timeout= Specify the timeout - for querying for a password. If not - unit is specified in - seconds. Supported units are s, ms, + for querying for a password. If no + unit is specified seconds is used. + Supported units are s, ms, us, min, h, d. diff --git a/man/daemon.xml b/man/daemon.xml index 9d43353f90..e3c038e46a 100644 --- a/man/daemon.xml +++ b/man/daemon.xml @@ -181,11 +181,11 @@ exit() in the original process. The process that invoked the daemon must be able to - rely that this + rely on that this exit() happens after initialization is complete and all external communication channels - established and + are established and accessible. @@ -196,7 +196,7 @@ compatibility with SysV systems should implement the scheme pointed out above. However, it is recommended to make this - behaviour optional and configurable via a + behavior optional and configurable via a command line argument, to ease debugging as well as to simplify integration into systems using systemd. @@ -271,7 +271,7 @@ for details. As much as possible, - rely on the init systemd's + rely on the init system's functionality to limit the access of the daemon to files, services and other resources. i.e. in the case of @@ -462,7 +462,7 @@ New-style daemons which support socket activation must be able to receive their - sockets from the init system, instead of of + sockets from the init system, instead of creating and binding them themselves. For details about the programming interfaces for this scheme provided by systemd see diff --git a/man/kernel-command-line.xml b/man/kernel-command-line.xml index cfc9b8599e..27f0d4036f 100644 --- a/man/kernel-command-line.xml +++ b/man/kernel-command-line.xml @@ -93,7 +93,7 @@ Parameters understood by the system and service manager - to control system behaviour. For details see + to control system behavior. For details see systemd1. diff --git a/man/locale.conf.xml b/man/locale.conf.xml index 2cbcdc66de..06c0af0bf7 100644 --- a/man/locale.conf.xml +++ b/man/locale.conf.xml @@ -117,7 +117,7 @@ LC_TELEPHONE=, LC_MEASUREMENT=, LC_IDENTIFICATION=. Note that - LC_ALL may not be be configured in + LC_ALL may not be configured in this file. For details about the meaning and semantics of these settings, refer to locale7. diff --git a/man/pam_systemd.xml b/man/pam_systemd.xml index f2c1ab8ca6..27edea7779 100644 --- a/man/pam_systemd.xml +++ b/man/pam_systemd.xml @@ -157,7 +157,7 @@ listed in this argument will not be subject to the effect of . Note - that that this option takes precedence + that this option takes precedence over , and hence whatever is listed for @@ -272,7 +272,7 @@ in again, the directory contents will have been lost in between, but applications should not rely on this - behaviour and must be able to deal with + behavior and must be able to deal with stale files. To store session-private data in this directory the user should include the value of $XDG_SESSION_ID diff --git a/man/sd_journal_print.xml b/man/sd_journal_print.xml index c03762ac2c..41414bbc09 100644 --- a/man/sd_journal_print.xml +++ b/man/sd_journal_print.xml @@ -123,7 +123,7 @@ object of type va_list (see stdarg3 for more information) instead of the format string. It - is otherwise equivalent in behaviour. + is otherwise equivalent in behavior. sd_journal_send() may be used to submit structured log entries to the system diff --git a/man/sd_seat_get_active.xml b/man/sd_seat_get_active.xml index 801c16a4bb..778f9aeaf9 100644 --- a/man/sd_seat_get_active.xml +++ b/man/sd_seat_get_active.xml @@ -93,7 +93,7 @@ a seat, if there is any. Returns the session identifier and the user identifier of the Unix user the session is belonging to. Either the session or the - user identifier parameter can be be passed NULL, in + user identifier parameter can be passed NULL, in case only one of the parameters shall be queried. The returned string needs to be freed with the libc free3 diff --git a/man/systemctl.xml b/man/systemctl.xml index c5fae825aa..fedc588766 100644 --- a/man/systemctl.xml +++ b/man/systemctl.xml @@ -1107,7 +1107,7 @@ mounted read-only, immediately followed by the system halt. If is specified - twice the the operation is immediately + twice the operation is immediately executed without terminating any processes or unmounting any file systems. This may result in data @@ -1128,7 +1128,7 @@ unmounted or mounted read-only, immediately followed by the powering off. If is - specified twice the the operation is + specified twice the operation is immediately executed without terminating any processes or unmounting any file systems. This may @@ -1149,7 +1149,7 @@ unmounted or mounted read-only, immediately followed by the reboot. If is specified - twice the the operation is immediately + twice the operation is immediately executed without terminating any processes or unmounting any file systems. This may result in data diff --git a/man/systemd.device.xml b/man/systemd.device.xml index 7c05ab035b..c360319d23 100644 --- a/man/systemd.device.xml +++ b/man/systemd.device.xml @@ -131,7 +131,7 @@ to 1 the device will be considered plugged the moment it shows up in the udev tree. This property has no - influence on the behaviour when a + influence on the behavior when a device disappears from the udev tree. This option is useful to support devices that initially show up in an diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml index cf6ab1778e..7ab9b5c1ed 100644 --- a/man/systemd.exec.xml +++ b/man/systemd.exec.xml @@ -471,7 +471,7 @@ TTYVTDisallocate= - If the the terminal + If the terminal device specified with TTYPath= is a virtual console terminal try to @@ -806,7 +806,7 @@ Set a specific control group attribute for executed - processes, and (if needed) add the the + processes, and (if needed) add the executed processes to a cgroup in the hierarchy of the controller the attribute belongs to. Takes two @@ -1055,7 +1055,7 @@ UtmpIdentifier= - Takes a a four + Takes a four character identifier string for an utmp/wtmp entry for this service. This should only be set for services such diff --git a/man/systemd.service.xml b/man/systemd.service.xml index c547948c6e..339dea9aa5 100644 --- a/man/systemd.service.xml +++ b/man/systemd.service.xml @@ -160,7 +160,7 @@ complete and all communication channels set up. The child continues to run as the main daemon - process. This is the behaviour of + process. This is the behavior of traditional UNIX daemons. If this setting is used, it is recommended to also use the @@ -171,7 +171,7 @@ soon as the parent process exits. - Behaviour of + Behavior of is similar to , however it is expected that the process has to @@ -180,7 +180,7 @@ is particularly useful for this type of service. - Behaviour of + Behavior of is similar to , however it is expected that the daemon acquires a @@ -197,7 +197,7 @@ BusName= is specified. - Behaviour of + Behavior of is similar to , however it is expected that the daemon sends a @@ -216,7 +216,7 @@ not set, it will be implicitly set to . - Behaviour of + Behavior of is very similar to , however actual execution of a the service @@ -599,7 +599,7 @@ SIGTERM and SIGPIPE. Exit status definitions can either be numeric exit codes or termination signal names, and - are are separated by spaces. Example: + are separated by spaces. Example: "SuccessExitStatus=1 2 8 SIGKILL", ensures that exit codes 1, 2, 8 and the termination diff --git a/man/systemd.socket.xml b/man/systemd.socket.xml index 8a12e25cf4..6cf6c79e11 100644 --- a/man/systemd.socket.xml +++ b/man/systemd.socket.xml @@ -217,7 +217,7 @@ Specifies a file system FIFO to listen on. This expects an absolute file system path as - argument. Behaviour otherwise is very + argument. Behavior otherwise is very similar to the ListenDatagram= directive above. @@ -228,7 +228,7 @@ Specifies a special file in the file system to listen on. This expects an absolute file - system path as argument. Behaviour + system path as argument. Behavior otherwise is very similar to the ListenFIFO= directive above. Use this to open @@ -248,7 +248,7 @@ or kobject-uevent) as argument, optionally suffixed by a whitespace followed by a multicast - group integer. Behaviour otherwise is + group integer. Behavior otherwise is very similar to the ListenDatagram= directive above. @@ -259,7 +259,7 @@ Specifies a POSIX message queue name to listen on. This expects a valid message queue name - (i.e. beginning with /). Behaviour + (i.e. beginning with /). Behavior otherwise is very similar to the ListenFIFO= directive above. On Linux message diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml index 00f6066717..e0aadf4cd3 100644 --- a/man/systemd.unit.xml +++ b/man/systemd.unit.xml @@ -440,7 +440,7 @@ Configures requirement dependencies, very similar in style to Requires=, however - in addition to this behaviour it also + in addition to this behavior it also declares that this unit is stopped when any of the units listed suddenly disappears. Units can suddenly, diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index ad817d7ee8..fdfa5ee200 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -682,7 +682,7 @@ void bus_unit_send_change_signal(Unit *u) { /* Send a properties changed signal. First for the * specific type, then for the generic unit. The * clients may rely on this order to get atomic - * behaviour if needed. */ + * behavior if needed. */ if (UNIT_VTABLE(u)->bus_invalidating_properties) { diff --git a/src/core/transaction.c b/src/core/transaction.c index 1f8d803aeb..4bce942012 100644 --- a/src/core/transaction.c +++ b/src/core/transaction.c @@ -392,7 +392,7 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi j->marker = from ? from : j; j->generation = generation; - /* We assume that the the dependencies are bidirectional, and + /* We assume that the dependencies are bidirectional, and * hence can ignore UNIT_AFTER */ SET_FOREACH(u, j->unit->dependencies[UNIT_BEFORE], i) { Job *o; diff --git a/src/core/unit.c b/src/core/unit.c index c9cd9ee2a0..3950c43f5e 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1327,7 +1327,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su /* Note that this is called for all low-level state changes, * even if they might map to the same high-level * UnitActiveState! That means that ns == os is OK an expected - * behaviour here. For example: if a mount point is remounted + * behavior here. For example: if a mount point is remounted * this function will be called too! */ if (u->manager->n_reloading <= 0) { diff --git a/src/core/unit.h b/src/core/unit.h index 89bd61c2d8..5b4dda4cb0 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -285,7 +285,7 @@ struct UnitVTable { * UNIT_STUB if no configuration could be found. */ int (*load)(Unit *u); - /* If a a lot of units got created via enumerate(), this is + /* If a lot of units got created via enumerate(), this is * where to actually set the state and call unit_notify(). */ int (*coldplug)(Unit *u); diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 8dc0a3a669..e778e1c67c 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -1051,7 +1051,7 @@ void journal_file_post_change(JournalFile *f) { __sync_synchronize(); if (ftruncate(f->fd, f->last_stat.st_size) < 0) - log_error("Failed to to truncate file to its own size: %m"); + log_error("Failed to truncate file to its own size: %m"); } int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const struct iovec iovec[], unsigned n_iovec, uint64_t *seqnum, Object **ret, uint64_t *offset) { diff --git a/src/journal/lookup3.c b/src/journal/lookup3.c index 31eac8c543..ee9a1834cf 100644 --- a/src/journal/lookup3.c +++ b/src/journal/lookup3.c @@ -14,7 +14,7 @@ if SELF_TEST is defined. You can use this free for any purpose. It's in the public domain. It has no warranty. You probably want to use hashlittle(). hashlittle() and hashbig() -hash byte arrays. hashlittle() is is faster than hashbig() on +hash byte arrays. hashlittle() is faster than hashbig() on little-endian machines. Intel and AMD are little-endian machines. On second thought, you probably want hashlittle2(), which is identical to hashlittle() except it returns two 32-bit hashes for the price of one. diff --git a/src/journal/mmap-cache.c b/src/journal/mmap-cache.c index 2b45e375c5..7d6c6c22ba 100644 --- a/src/journal/mmap-cache.c +++ b/src/journal/mmap-cache.c @@ -392,7 +392,7 @@ static int mmap_cache_put( if (st) { /* Memory maps that are larger then the files - underneath have undefined behaviour. Hence, clamp + underneath have undefined behavior. Hence, clamp things to the file size if we know it */ if (woffset >= (uint64_t) st->st_size) diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index 1bef70962c..972ace5d39 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -1124,7 +1124,7 @@ _public_ const char *udev_device_get_sysname(struct udev_device *udev_device) * * Get the instance number of the device. * - * Returns: the trailing number string of of the device name + * Returns: the trailing number string of the device name **/ _public_ const char *udev_device_get_sysnum(struct udev_device *udev_device) { diff --git a/src/udev/udevd.c b/src/udev/udevd.c index b4fc624db3..35263ff135 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -1177,7 +1177,7 @@ int main(int argc, char *argv[]) } if (systemd_fds(udev, &fd_ctrl, &fd_netlink) >= 0) { - /* get control and netlink socket from from systemd */ + /* get control and netlink socket from systemd */ udev_ctrl = udev_ctrl_new_from_fd(udev, fd_ctrl); if (udev_ctrl == NULL) { log_error("error taking over udev control socket"); diff --git a/test/test-functions b/test/test-functions index c355423192..0587cd4feb 100644 --- a/test/test-functions +++ b/test/test-functions @@ -620,7 +620,7 @@ for_each_kmod_dep() { # $1 = search only in subdirectory of /kernel/$1 # $2 = function to call with module name to filter. # This function will be passed the full path to the module to test. -# The behaviour of this function can vary depending on whether $hostonly is set. +# The behavior of this function can vary depending on whether $hostonly is set. # If it is, we will only look at modules that are already in memory. # If it is not, we will look at all kernel modules # This function returns the full filenames of modules that match $1 -- cgit v1.2.3-54-g00ecf From 71dc3ed1d95dfe246004018c2ca85156fc73c146 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 13 Sep 2012 23:19:05 +0200 Subject: test: split of cryptsetup into its own test --- test/.gitignore | 2 + test/TEST-01-BASIC/test.sh | 37 +----- test/TEST-02-CRYPTSETUP/Makefile | 1 + test/TEST-02-CRYPTSETUP/test.sh | 264 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 269 insertions(+), 35 deletions(-) create mode 120000 test/TEST-02-CRYPTSETUP/Makefile create mode 100755 test/TEST-02-CRYPTSETUP/test.sh (limited to 'test') diff --git a/test/.gitignore b/test/.gitignore index 98fa886530..93c1f950fe 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1 +1,3 @@ +.testdir +test.log /sys diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index 8979872ef2..eb6a80a07c 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -23,12 +23,8 @@ run_qemu() { mount ${LOOPDEV}p1 $TESTDIR/root [[ -e $TESTDIR/root/testok ]] && ret=0 cp -a $TESTDIR/root/failed $TESTDIR - cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile - mount /dev/mapper/varcrypt $TESTDIR/root/var cp -a $TESTDIR/root/var/log/journal $TESTDIR - umount $TESTDIR/root/var umount $TESTDIR/root - cryptsetup luksClose /dev/mapper/varcrypt cat $TESTDIR/failed ls -l $TESTDIR/journal/*/*.journal test -s $TESTDIR/failed && ret=$(($ret+1)) @@ -40,8 +36,8 @@ run_nspawn() { systemd-nspawn -b -D $TESTDIR/nspawn-root --capability=CAP_AUDIT_CONTROL,CAP_AUDIT_WRITE /usr/lib/systemd/systemd ret=1 [[ -e $TESTDIR/nspawn-root/testok ]] && ret=0 - cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR cp -a $TESTDIR/nspawn-root/failed $TESTDIR + cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR cat $TESTDIR/failed ls -l $TESTDIR/journal/*/*.journal test -s $TESTDIR/failed && ret=$(($ret+1)) @@ -77,14 +73,9 @@ EOF mkfs.ext3 -L systemd ${LOOPDEV}p1 echo -n test >$TESTDIR/keyfile - cryptsetup -q luksFormat ${LOOPDEV}p2 $TESTDIR/keyfile - cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile - mkfs.ext3 -L var /dev/mapper/varcrypt mkdir -p $TESTDIR/root mount ${LOOPDEV}p1 $TESTDIR/root mkdir -p $TESTDIR/root/run - mkdir -p $TESTDIR/root/var - mount /dev/mapper/varcrypt $TESTDIR/root/var # Create what will eventually be our root filesystem onto an overlay ( @@ -105,9 +96,6 @@ EOF inst_libs $i done - # activate kmsg import - echo 'ImportKernel=yes' >> $initdir/etc/systemd/journald.conf - # make a journal directory mkdir -p $initdir/var/log/journal @@ -129,18 +117,10 @@ EOF # set the hostname echo systemd-testsuite > $initdir/etc/hostname - eval $(udevadm info --export --query=env --name=/dev/mapper/varcrypt) eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) - cat >$initdir/etc/crypttab < $initdir/etc/varkey - cat $initdir/etc/crypttab | ddebug - cat >$initdir/etc/fstab < /failed ; echo OK > /testok; while : ;do systemd-cat echo "testsuite service waiting for /var/log/journal" ; echo "testsuite service waiting for journal to move to /var/log/journal" > /dev/console ; for i in /var/log/journal/*;do [ -d "\$i" ] && echo "\$i" && break 2; done; sleep 1; done; sleep 1; exit 0;' +ExecStart=/bin/bash -c 'set -x; systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok; while : ;do echo "testsuite service waiting for journal to move to /var/log/journal" > /dev/console ; for i in /var/log/journal/*;do [ -d "\$i" ] && echo "\$i" && break 2; done; sleep 1; done; sleep 1; exit 0;' ExecStopPost=/usr/bin/systemctl poweroff Type=oneshot EOF @@ -180,14 +160,6 @@ EOF login sushell sulogin gzip sleep echo mount umount cryptsetup dracut_install dmsetup modprobe - instmods dm_crypt =crypto - - type -P dmeventd >/dev/null && dracut_install dmeventd - - inst_libdir_file "libdevmapper-event.so*" - - inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules - # install libnss_files for login inst_libdir_file "libnss_files*" @@ -266,16 +238,11 @@ EOF # we don't mount in the nspawn root rm -fr $TESTDIR/nspawn-root/etc/fstab - ddebug "umount $TESTDIR/root/var" - umount $TESTDIR/root/var - cryptsetup luksClose /dev/mapper/varcrypt ddebug "umount $TESTDIR/root" umount $TESTDIR/root } test_cleanup() { - umount $TESTDIR/root/var 2>/dev/null - [[ -b /dev/mapper/varcrypt ]] && cryptsetup luksClose /dev/mapper/varcrypt umount $TESTDIR/root 2>/dev/null [[ $LOOPDEV ]] && losetup -d $LOOPDEV return 0 diff --git a/test/TEST-02-CRYPTSETUP/Makefile b/test/TEST-02-CRYPTSETUP/Makefile new file mode 120000 index 0000000000..e9f93b1104 --- /dev/null +++ b/test/TEST-02-CRYPTSETUP/Makefile @@ -0,0 +1 @@ +../TEST-01-BASIC/Makefile \ No newline at end of file diff --git a/test/TEST-02-CRYPTSETUP/test.sh b/test/TEST-02-CRYPTSETUP/test.sh new file mode 100755 index 0000000000..790dc3074c --- /dev/null +++ b/test/TEST-02-CRYPTSETUP/test.sh @@ -0,0 +1,264 @@ +#!/bin/bash +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh +TEST_DESCRIPTION="cryptsetup systemd setup" + +KVERSION=${KVERSION-$(uname -r)} +KERNEL_VER=$(uname -r) + +# Uncomment this to debug failures +#DEBUGFAIL="systemd.unit=multi-user.target" +DEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort" + +run_qemu() { + # TODO: qemu wrapper script: http://www.spinics.net/lists/kvm/msg72389.html + qemu-kvm \ + -hda $TESTDIR/rootdisk.img \ + -m 512M -nographic \ + -net none -kernel /boot/vmlinuz-$KERNEL_VER \ + -append "root=/dev/sda1 systemd.log_level=debug raid=noautodetect loglevel=2 init=/usr/lib/systemd/systemd ro console=ttyS0,115200n81 selinux=0 $DEBUGFAIL" || return 1 + + ret=1 + mkdir -p $TESTDIR/root + mount ${LOOPDEV}p1 $TESTDIR/root + [[ -e $TESTDIR/root/testok ]] && ret=0 + cp -a $TESTDIR/root/failed $TESTDIR + cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile + mount /dev/mapper/varcrypt $TESTDIR/root/var + cp -a $TESTDIR/root/var/log/journal $TESTDIR + umount $TESTDIR/root/var + umount $TESTDIR/root + cryptsetup luksClose /dev/mapper/varcrypt + cat $TESTDIR/failed + ls -l $TESTDIR/journal/*/*.journal + test -s $TESTDIR/failed && ret=$(($ret+1)) + return $ret +} + + +test_run() { + if check_qemu ; then + run_qemu || return 1 + else + dwarn "can't run qemu-kvm, skipping" + fi + return 0 +} + +test_setup() { + rm -f $TESTDIR/rootdisk.img + # Create the blank file to use as a root filesystem + dd if=/dev/null of=$TESTDIR/rootdisk.img bs=1M seek=200 + LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img) + [ -b $LOOPDEV ] || return 1 + echo "LOOPDEV=$LOOPDEV" >> $STATEFILE + sfdisk -C 6400 -H 2 -S 32 -L $LOOPDEV <$TESTDIR/keyfile + cryptsetup -q luksFormat ${LOOPDEV}p2 $TESTDIR/keyfile + cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile + mkfs.ext3 -L var /dev/mapper/varcrypt + mkdir -p $TESTDIR/root + mount ${LOOPDEV}p1 $TESTDIR/root + mkdir -p $TESTDIR/root/run + mkdir -p $TESTDIR/root/var + mount /dev/mapper/varcrypt $TESTDIR/root/var + + # Create what will eventually be our root filesystem onto an overlay + ( + LOG_LEVEL=5 + initdir=$TESTDIR/root + + # create the basic filesystem layout + setup_basic_dirs + + # install compiled files + (cd ../..; make DESTDIR=$initdir install) + + # remove unneeded documentation + rm -fr $initdir/usr/share/{man,doc,gtk-doc} + + # install possible missing libraries + for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do + inst_libs $i + done + + # make a journal directory + mkdir -p $initdir/var/log/journal + + # install some basic config files + inst /etc/sysconfig/init + inst /etc/passwd + inst /etc/shadow + inst /etc/group + inst /etc/shells + inst /etc/nsswitch.conf + inst /etc/pam.conf + inst /etc/securetty + inst /etc/os-release + inst /etc/localtime + # we want an empty environment + > $initdir/etc/environment + > $initdir/etc/machine-id + + # set the hostname + echo systemd-testsuite > $initdir/etc/hostname + + eval $(udevadm info --export --query=env --name=/dev/mapper/varcrypt) + eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) + + cat >$initdir/etc/crypttab < $initdir/etc/varkey + cat $initdir/etc/crypttab | ddebug + + cat >$initdir/etc/fstab <$initdir/etc/systemd/system/testsuite.target <$initdir/etc/systemd/system/testsuite.service < /failed ; echo OK > /testok; while : ;do systemd-cat echo "testsuite service waiting for /var/log/journal" ; echo "testsuite service waiting for journal to move to /var/log/journal" > /dev/console ; for i in /var/log/journal/*;do [ -d "\$i" ] && echo "\$i" && break 2; done; sleep 1; done; sleep 1; exit 0;' +ExecStopPost=/usr/bin/systemctl poweroff +Type=oneshot +EOF + mkdir -p $initdir/etc/systemd/system/testsuite.target.wants + ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service + + # make the testsuite the default target + ln -fs testsuite.target $initdir/etc/systemd/system/default.target + mkdir -p $initdir/etc/rc.d + cat >$initdir/etc/rc.d/rc.local </dev/null && dracut_install dmeventd + + inst_libdir_file "libdevmapper-event.so*" + + inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules + + # install libnss_files for login + inst_libdir_file "libnss_files*" + + # install dbus and pam + find \ + /etc/dbus-1 \ + /etc/pam.d \ + /etc/security \ + /lib64/security \ + /lib/security -xtype f \ + | while read file; do + inst $file + done + + # install dbus socket and service file + inst /usr/lib/systemd/system/dbus.socket + inst /usr/lib/systemd/system/dbus.service + + # install basic keyboard maps and fonts + for i in \ + /usr/lib/kbd/consolefonts/latarcyrheb-sun16* \ + /usr/lib/kbd/keymaps/include/* \ + /usr/lib/kbd/keymaps/i386/include/* \ + /usr/lib/kbd/keymaps/i386/qwerty/us.*; do + [[ -f $i ]] || continue + inst $i + done + + # some basic terminfo files + for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do + [ -f ${_terminfodir}/l/linux ] && break + done + dracut_install -o ${_terminfodir}/l/linux + + # softlink mtab + ln -fs /proc/self/mounts $initdir/etc/mtab + + # install any Exec's from the service files + egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \ + | while read i; do + i=${i##Exec*=}; i=${i##-} + inst $i + done + + # install plymouth, if found... else remove plymouth service files + # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then + # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \ + # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir + # dracut_install plymouth plymouthd + # else + rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth* + # fi + + # some helper tools for debugging + [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS + + # install ld.so.conf* and run ldconfig + cp -a /etc/ld.so.conf* $initdir/etc + ldconfig -r "$initdir" + ddebug "Strip binaeries" + find "$initdir" -perm +111 -type f | xargs strip --strip-unneeded | ddebug + + # copy depmod files + inst /lib/modules/$KERNEL_VER/modules.order + inst /lib/modules/$KERNEL_VER/modules.builtin + # generate module dependencies + if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \ + ! depmod -a -b "$initdir" $KERNEL_VER; then + dfatal "\"depmod -a $KERNEL_VER\" failed." + exit 1 + fi + ) + rm -fr $TESTDIR/nspawn-root + ddebug "cp -ar $TESTDIR/root $TESTDIR/nspawn-root" + cp -ar $TESTDIR/root $TESTDIR/nspawn-root + # we don't mount in the nspawn root + rm -fr $TESTDIR/nspawn-root/etc/fstab + + ddebug "umount $TESTDIR/root/var" + umount $TESTDIR/root/var + cryptsetup luksClose /dev/mapper/varcrypt + ddebug "umount $TESTDIR/root" + umount $TESTDIR/root +} + +test_cleanup() { + umount $TESTDIR/root/var 2>/dev/null + [[ -b /dev/mapper/varcrypt ]] && cryptsetup luksClose /dev/mapper/varcrypt + umount $TESTDIR/root 2>/dev/null + [[ $LOOPDEV ]] && losetup -d $LOOPDEV + return 0 +} + +. $TEST_BASE_DIR/test-functions +do_test "$@" -- cgit v1.2.3-54-g00ecf From 8a1733871ffe9bfc47958e9056fd53ce216b1802 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Mon, 8 Oct 2012 21:54:39 +0200 Subject: udev: remove SYMLINK "unique" option --- src/libudev/libudev-device.c | 10 ++++------ src/libudev/libudev-private.h | 2 +- src/udev/udev-node.c | 13 ++++--------- src/udev/udev-rules.c | 24 +++++++----------------- test/udev-test.pl | 9 --------- 5 files changed, 16 insertions(+), 42 deletions(-) (limited to 'test') diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index 972ace5d39..08476e6596 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -378,12 +378,12 @@ void udev_device_add_property_from_string_parse(struct udev_device *udev_device, next = strchr(slink, ' '); while (next != NULL) { next[0] = '\0'; - udev_device_add_devlink(udev_device, slink, 0); + udev_device_add_devlink(udev_device, slink); slink = &next[1]; next = strchr(slink, ' '); } if (slink[0] != '\0') - udev_device_add_devlink(udev_device, slink, 0); + udev_device_add_devlink(udev_device, slink); } else if (startswith(property, "TAGS=")) { char tags[UTIL_PATH_SIZE]; char *next; @@ -503,7 +503,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile) switch(line[0]) { case 'S': util_strscpyl(filename, sizeof(filename), "/dev/", val, NULL); - udev_device_add_devlink(udev_device, filename, 0); + udev_device_add_devlink(udev_device, filename); break; case 'L': udev_device_set_devlink_priority(udev_device, atoi(val)); @@ -1505,7 +1505,7 @@ int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode return 0; } -int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink, int unique) +int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink) { struct udev_list_entry *list_entry; @@ -1513,8 +1513,6 @@ int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink list_entry = udev_list_entry_add(&udev_device->devlinks_list, devlink, NULL); if (list_entry == NULL) return -ENOMEM; - if (unique) - udev_list_entry_set_num(list_entry, true); return 0; } diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h index 30c70e6428..2add8b3577 100644 --- a/src/libudev/libudev-private.h +++ b/src/libudev/libudev-private.h @@ -50,7 +50,7 @@ struct udev_device *udev_device_new(struct udev *udev); mode_t udev_device_get_devnode_mode(struct udev_device *udev_device); int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath); int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode); -int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink, int unique); +int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink); void udev_device_cleanup_devlinks_list(struct udev_device *udev_device); struct udev_list_entry *udev_device_add_property(struct udev_device *udev_device, const char *key, const char *value); void udev_device_add_property_from_string_parse(struct udev_device *udev_device, const char *property); diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index df4c8f0152..ca536be3f5 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -250,7 +250,7 @@ void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev log_debug("update old name, '%s' no longer belonging to '%s'\n", name, udev_device_get_devpath(dev)); - link_update(dev, name, 0); + link_update(dev, name, false); } } @@ -321,13 +321,8 @@ void udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid) node_symlink(udev, udev_device_get_devnode(dev), filename); /* create/update symlinks, add symlinks to name index */ - udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev)) { - if (udev_list_entry_get_num(list_entry)) - /* simple unmanaged link name */ - node_symlink(udev, udev_device_get_devnode(dev), udev_list_entry_get_name(list_entry)); - else - link_update(dev, udev_list_entry_get_name(list_entry), 1); - } + udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev)) + link_update(dev, udev_list_entry_get_name(list_entry), true); } void udev_node_remove(struct udev_device *dev) @@ -337,7 +332,7 @@ void udev_node_remove(struct udev_device *dev) /* remove/update symlinks, remove symlinks from name index */ udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev)) - link_update(dev, udev_list_entry_get_name(list_entry), 0); + link_update(dev, udev_list_entry_get_name(list_entry), false); /* remove /dev/{block,char}/$major:$minor */ snprintf(filename, sizeof(filename), "/dev/%s/%u:%u", diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 0900928d0b..b3b42fe989 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -202,7 +202,6 @@ struct token { unsigned int value_off; union { unsigned int attr_off; - int devlink_unique; unsigned int rule_goto; mode_t mode; uid_t uid; @@ -1020,6 +1019,7 @@ static int rule_add_key(struct rule_tmp *rule_tmp, enum token_type type, case TK_A_OWNER: case TK_A_GROUP: case TK_A_MODE: + case TK_A_DEVLINK: case TK_A_NAME: case TK_A_GOTO: case TK_M_TAG: @@ -1039,10 +1039,6 @@ static int rule_add_key(struct rule_tmp *rule_tmp, enum token_type type, token->key.value_off = add_string(rule_tmp->rules, value); token->key.attr_off = add_string(rule_tmp->rules, attr); break; - case TK_A_DEVLINK: - token->key.value_off = add_string(rule_tmp->rules, value); - token->key.devlink_unique = *(int *)data; - break; case TK_M_TEST: token->key.value_off = add_string(rule_tmp->rules, value); if (data != NULL) @@ -1496,17 +1492,11 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (startswith(key, "SYMLINK")) { - if (op < OP_MATCH_MAX) { + if (streq(key, "SYMLINK")) { + if (op < OP_MATCH_MAX) rule_add_key(&rule_tmp, TK_M_DEVLINK, op, value, NULL); - } else { - int flag = 0; - - attr = get_key_attribute(rules->udev, key + sizeof("SYMLINK")-1); - if (attr != NULL && strstr(attr, "unique") != NULL) - flag = 1; - rule_add_key(&rule_tmp, TK_A_DEVLINK, op, value, &flag); - } + else + rule_add_key(&rule_tmp, TK_A_DEVLINK, op, value, NULL); rule_tmp.rule.rule.can_set_name = true; continue; } @@ -2578,7 +2568,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event log_debug("LINK '%s' %s:%u\n", pos, &rules->buf[rule->rule.filename_off], rule->rule.filename_line); util_strscpyl(filename, sizeof(filename), "/dev/", pos, NULL); - udev_device_add_devlink(event->dev, filename, cur->key.devlink_unique); + udev_device_add_devlink(event->dev, filename); while (isspace(next[1])) next++; pos = &next[1]; @@ -2588,7 +2578,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event log_debug("LINK '%s' %s:%u\n", pos, &rules->buf[rule->rule.filename_off], rule->rule.filename_line); util_strscpyl(filename, sizeof(filename), "/dev/", pos, NULL); - udev_device_add_devlink(event->dev, filename, cur->key.devlink_unique); + udev_device_add_devlink(event->dev, filename); } break; } diff --git a/test/udev-test.pl b/test/udev-test.pl index e91dda11cf..ef3707e09b 100755 --- a/test/udev-test.pl +++ b/test/udev-test.pl @@ -932,15 +932,6 @@ EOF rules => < "test for whitespace between the operator", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "true", - rules => < Date: Tue, 9 Oct 2012 00:49:15 +0200 Subject: udev: fix rule-syntax-check.py --- test/rule-syntax-check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/rule-syntax-check.py b/test/rule-syntax-check.py index 4fa3042d4f..4b602a925a 100755 --- a/test/rule-syntax-check.py +++ b/test/rule-syntax-check.py @@ -28,7 +28,7 @@ if len(sys.argv) < 2: no_args_tests = re.compile('(ACTION|DEVPATH|KERNELS?|NAME|SYMLINK|SUBSYSTEMS?|DRIVERS?|TAG|RESULT|TEST)\s*(?:=|!)=\s*"([^"]*)"$') args_tests = re.compile('(ATTRS?|ENV|TEST){([a-zA-Z0-9/_.*%-]+)}\s*(?:=|!)=\s*"([^"]*)"$') no_args_assign = re.compile('(NAME|SYMLINK|OWNER|GROUP|MODE|TAG|PROGRAM|RUN|LABEL|GOTO|WAIT_FOR|OPTIONS|IMPORT)\s*(?:\+=|:=|=)\s*"([^"]*)"$') -args_assign = re.compile('(ATTR|ENV|IMPORT|RUN){([a-zA-Z0-9/_.*%-]+)}\s*=\s*"([^"]*)"$') +args_assign = re.compile('(ATTR|ENV|IMPORT|RUN){([a-zA-Z0-9/_.*%-]+)}\s*(=|\+=)\s*"([^"]*)"$') result = 0 buffer = '' -- cgit v1.2.3-54-g00ecf From 1298001ec5e320f9f9b6a9b925c8939b2579396d Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Mon, 12 Nov 2012 19:36:23 +0100 Subject: use the same email address everywhere --- src/shared/strbuf.c | 2 +- src/shared/strbuf.h | 2 +- src/test/test-libudev.c | 28 ++++++++++++++++++---------- src/test/test-udev.c | 36 +++++++++++++++++++----------------- src/udev/ata_id/ata_id.c | 2 +- src/udev/cdrom_id/cdrom_id.c | 2 +- src/udev/udev-builtin-blkid.c | 2 +- src/udev/udev-builtin-firmware.c | 2 +- src/udev/udev-builtin-input_id.c | 2 +- src/udev/udev-builtin-kmod.c | 2 +- src/udev/udev-builtin-path_id.c | 2 +- src/udev/udev-builtin-usb_id.c | 2 +- src/udev/udev-ctrl.c | 2 +- src/udev/udev-event.c | 2 +- src/udev/udev-node.c | 2 +- src/udev/udev-rules.c | 2 +- src/udev/udev-watch.c | 2 +- src/udev/udev.h | 2 +- src/udev/udevadm-control.c | 2 +- src/udev/udevadm-hwdb.c | 2 +- src/udev/udevadm-info.c | 2 +- src/udev/udevadm-monitor.c | 2 +- src/udev/udevadm-test-builtin.c | 2 +- src/udev/udevadm-test.c | 2 +- src/udev/udevadm-trigger.c | 2 +- src/udev/udevadm.c | 2 +- src/udev/udevd.c | 2 +- src/udev/v4l_id/v4l_id.c | 2 +- test/udev-test.pl | 2 +- 29 files changed, 64 insertions(+), 54 deletions(-) (limited to 'test') diff --git a/src/shared/strbuf.c b/src/shared/strbuf.c index 96b15a7b2a..915cd3ac99 100644 --- a/src/shared/strbuf.c +++ b/src/shared/strbuf.c @@ -3,7 +3,7 @@ /*** This file is part of systemd. - Copyright 2012 Kay Sievers + Copyright 2012 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 diff --git a/src/shared/strbuf.h b/src/shared/strbuf.h index 35f232ddb0..2347fd4328 100644 --- a/src/shared/strbuf.h +++ b/src/shared/strbuf.h @@ -5,7 +5,7 @@ /*** This file is part of systemd. - Copyright 2012 Kay Sievers + Copyright 2012 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 diff --git a/src/test/test-libudev.c b/src/test/test-libudev.c index b89d900121..caa3b4d14c 100644 --- a/src/test/test-libudev.c +++ b/src/test/test-libudev.c @@ -1,13 +1,21 @@ -/* - * test-libudev - * - * Copyright (C) 2008 Kay Sievers - * - * This library 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. - */ +/*** + This file is part of systemd. + + Copyright 2008-2012 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 . +***/ #include #include diff --git a/src/test/test-udev.c b/src/test/test-udev.c index 77380628bb..db9d36124e 100644 --- a/src/test/test-udev.c +++ b/src/test/test-udev.c @@ -1,20 +1,22 @@ -/* - * Copyright (C) 2003-2004 Greg Kroah-Hartman - * Copyright (C) 2004-2008 Kay Sievers - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ +/*** + This file is part of systemd. + + Copyright 2003-2004 Greg Kroah-Hartman + Copyright 2004-2012 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 . +***/ #include #include diff --git a/src/udev/ata_id/ata_id.c b/src/udev/ata_id/ata_id.c index e1069b5c6e..488fed4ac4 100644 --- a/src/udev/ata_id/ata_id.c +++ b/src/udev/ata_id/ata_id.c @@ -1,7 +1,7 @@ /* * ata_id - reads product/serial number from ATA drives * - * Copyright (C) 2005-2008 Kay Sievers + * Copyright (C) 2005-2008 Kay Sievers * Copyright (C) 2009 Lennart Poettering * Copyright (C) 2009-2010 David Zeuthen * diff --git a/src/udev/cdrom_id/cdrom_id.c b/src/udev/cdrom_id/cdrom_id.c index 870dfc89fe..1056536b7d 100644 --- a/src/udev/cdrom_id/cdrom_id.c +++ b/src/udev/cdrom_id/cdrom_id.c @@ -1,7 +1,7 @@ /* * cdrom_id - optical drive and media information prober * - * Copyright (C) 2008-2010 Kay Sievers + * Copyright (C) 2008-2010 Kay Sievers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/udev/udev-builtin-blkid.c b/src/udev/udev-builtin-blkid.c index 39f286a745..4293103046 100644 --- a/src/udev/udev-builtin-blkid.c +++ b/src/udev/udev-builtin-blkid.c @@ -1,7 +1,7 @@ /* * probe disks for filesystems and partitions * - * Copyright (C) 2011 Kay Sievers + * Copyright (C) 2011 Kay Sievers * Copyright (C) 2011 Karel Zak * * This program is free software: you can redistribute it and/or modify diff --git a/src/udev/udev-builtin-firmware.c b/src/udev/udev-builtin-firmware.c index de93d7b34c..2fb75a7335 100644 --- a/src/udev/udev-builtin-firmware.c +++ b/src/udev/udev-builtin-firmware.c @@ -2,7 +2,7 @@ * firmware - Kernel firmware loader * * Copyright (C) 2009 Piter Punk - * Copyright (C) 2009-2011 Kay Sievers + * Copyright (C) 2009-2011 Kay Sievers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as diff --git a/src/udev/udev-builtin-input_id.c b/src/udev/udev-builtin-input_id.c index ce696eead0..445b602f9c 100644 --- a/src/udev/udev-builtin-input_id.c +++ b/src/udev/udev-builtin-input_id.c @@ -3,7 +3,7 @@ * * Copyright (C) 2009 Martin Pitt * Portions Copyright (C) 2004 David Zeuthen, - * Copyright (C) 2011 Kay Sievers + * Copyright (C) 2011 Kay Sievers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/udev/udev-builtin-kmod.c b/src/udev/udev-builtin-kmod.c index aacdff87b7..17aca2944d 100644 --- a/src/udev/udev-builtin-kmod.c +++ b/src/udev/udev-builtin-kmod.c @@ -1,7 +1,7 @@ /* * load kernel modules * - * Copyright (C) 2011-2012 Kay Sievers + * Copyright (C) 2011-2012 Kay Sievers * Copyright (C) 2011 ProFUSION embedded systems * * This program is free software: you can redistribute it and/or modify diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c index 6a78a476ac..cbdeb38daa 100644 --- a/src/udev/udev-builtin-path_id.c +++ b/src/udev/udev-builtin-path_id.c @@ -1,7 +1,7 @@ /* * compose persistent device path * - * Copyright (C) 2009-2011 Kay Sievers + * Copyright (C) 2009-2011 Kay Sievers * * Logic based on Hannes Reinecke's shell script. * diff --git a/src/udev/udev-builtin-usb_id.c b/src/udev/udev-builtin-usb_id.c index 18e10c4cc8..13d1226393 100644 --- a/src/udev/udev-builtin-usb_id.c +++ b/src/udev/udev-builtin-usb_id.c @@ -4,7 +4,7 @@ * Copyright (c) 2005 SUSE Linux Products GmbH, Germany * Author: Hannes Reinecke * - * Copyright (C) 2005-2011 Kay Sievers + * Copyright (C) 2005-2011 Kay Sievers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c index fcb0cd48a6..a235912ffb 100644 --- a/src/udev/udev-ctrl.c +++ b/src/udev/udev-ctrl.c @@ -1,7 +1,7 @@ /* * libudev - interface to udev device information * - * Copyright (C) 2008 Kay Sievers + * Copyright (C) 2008 Kay Sievers * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index 11540f7bc1..2f4db3cc0c 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2010 Kay Sievers + * Copyright (C) 2003-2010 Kay Sievers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index ca536be3f5..7774303704 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2010 Kay Sievers + * Copyright (C) 2003-2010 Kay Sievers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 494ca7b689..e6f0f5da7e 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2012 Kay Sievers + * Copyright (C) 2003-2012 Kay Sievers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c index eebcee6555..311f5bdf23 100644 --- a/src/udev/udev-watch.c +++ b/src/udev/udev-watch.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2012 Kay Sievers + * Copyright (C) 2004-2012 Kay Sievers * Copyright (C) 2009 Canonical Ltd. * Copyright (C) 2009 Scott James Remnant * diff --git a/src/udev/udev.h b/src/udev/udev.h index a1dc3ee617..82cd2ad6d0 100644 --- a/src/udev/udev.h +++ b/src/udev/udev.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2003 Greg Kroah-Hartman - * Copyright (C) 2003-2010 Kay Sievers + * Copyright (C) 2003-2010 Kay Sievers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/udev/udevadm-control.c b/src/udev/udevadm-control.c index cafa214944..c5a189257d 100644 --- a/src/udev/udevadm-control.c +++ b/src/udev/udevadm-control.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2011 Kay Sievers + * Copyright (C) 2005-2011 Kay Sievers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c index 4017526d1c..02d8d01f8a 100644 --- a/src/udev/udevadm-hwdb.c +++ b/src/udev/udevadm-hwdb.c @@ -1,7 +1,7 @@ /*** This file is part of systemd. - Copyright 2012 Kay Sievers + Copyright 2012 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 diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c index 907e961f4a..95f077ca95 100644 --- a/src/udev/udevadm-info.c +++ b/src/udev/udevadm-info.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2009 Kay Sievers + * Copyright (C) 2004-2009 Kay Sievers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/udev/udevadm-monitor.c b/src/udev/udevadm-monitor.c index 1a6f71a465..ffa70d8300 100644 --- a/src/udev/udevadm-monitor.c +++ b/src/udev/udevadm-monitor.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2010 Kay Sievers + * Copyright (C) 2004-2010 Kay Sievers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/udev/udevadm-test-builtin.c b/src/udev/udevadm-test-builtin.c index 92f07f1389..9853d83b49 100644 --- a/src/udev/udevadm-test-builtin.c +++ b/src/udev/udevadm-test-builtin.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Kay Sievers + * Copyright (C) 2011 Kay Sievers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/udev/udevadm-test.c b/src/udev/udevadm-test.c index 65e9f3ecca..2d8aa7913e 100644 --- a/src/udev/udevadm-test.c +++ b/src/udev/udevadm-test.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2003-2004 Greg Kroah-Hartman - * Copyright (C) 2004-2008 Kay Sievers + * Copyright (C) 2004-2008 Kay Sievers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c index 7735e4b67b..d52ae461fe 100644 --- a/src/udev/udevadm-trigger.c +++ b/src/udev/udevadm-trigger.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2009 Kay Sievers + * Copyright (C) 2008-2009 Kay Sievers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/udev/udevadm.c b/src/udev/udevadm.c index 5e69e192c0..53419ffa62 100644 --- a/src/udev/udevadm.c +++ b/src/udev/udevadm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2012 Kay Sievers + * Copyright (C) 2007-2012 Kay Sievers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/udev/udevd.c b/src/udev/udevd.c index b69f3f87de..ebd601e262 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2012 Kay Sievers + * Copyright (C) 2004-2012 Kay Sievers * Copyright (C) 2004 Chris Friesen * Copyright (C) 2009 Canonical Ltd. * Copyright (C) 2009 Scott James Remnant diff --git a/src/udev/v4l_id/v4l_id.c b/src/udev/v4l_id/v4l_id.c index a2a80b5f43..8dcb645ed9 100644 --- a/src/udev/v4l_id/v4l_id.c +++ b/src/udev/v4l_id/v4l_id.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Kay Sievers + * Copyright (C) 2009 Kay Sievers * Copyright (c) 2009 Filippo Argiolas * * This program is free software; you can redistribute it and/or diff --git a/test/udev-test.pl b/test/udev-test.pl index ef3707e09b..a9f5db03cf 100755 --- a/test/udev-test.pl +++ b/test/udev-test.pl @@ -14,7 +14,7 @@ # After creation and removal the result is checked against the # expected value and the result is printed. # -# Copyright (C) 2004-2012 Kay Sievers +# Copyright (C) 2004-2012 Kay Sievers # Copyright (C) 2004 Leann Ogasawara use warnings; -- cgit v1.2.3-54-g00ecf