]>
Commit | Line | Data |
---|---|---|
d6c9574f | 1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
279ade13 | 2 | |
a7334b09 LP |
3 | /*** |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2010 Lennart Poettering | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
9 | under the terms of the GNU Lesser General Public License as published by |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
a7334b09 LP |
11 | (at your option) any later version. |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
5430f7f2 | 16 | Lesser General Public License for more details. |
a7334b09 | 17 | |
5430f7f2 | 18 | You should have received a copy of the GNU Lesser General Public License |
a7334b09 LP |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
20 | ***/ | |
21 | ||
279ade13 | 22 | #include <errno.h> |
cf0fbc49 | 23 | #include <stdio.h> |
279ade13 | 24 | #include <string.h> |
279ade13 | 25 | |
0d8c31ff | 26 | #include "bus-util.h" |
cf0fbc49 | 27 | #include "manager.h" |
279ade13 LP |
28 | |
29 | int main(int argc, char *argv[]) { | |
0d8c31ff | 30 | _cleanup_bus_error_free_ sd_bus_error err = SD_BUS_ERROR_NULL; |
279ade13 | 31 | Manager *m = NULL; |
87f0e418 | 32 | Unit *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL, *g = NULL, *h = NULL; |
0d8c31ff ZJS |
33 | FILE *serial = NULL; |
34 | FDSet *fdset = NULL; | |
279ade13 | 35 | Job *j; |
0d8c31ff | 36 | int r; |
279ade13 | 37 | |
0d8c31ff ZJS |
38 | /* prepare the test */ |
39 | assert_se(set_unit_path(TEST_DIR) >= 0); | |
b2c23da8 | 40 | r = manager_new(MANAGER_USER, true, &m); |
3b3a64d7 | 41 | if (IN_SET(r, -EPERM, -EACCES, -EADDRINUSE, -EHOSTDOWN, -ENOENT, -ENOEXEC)) { |
0d8c31ff ZJS |
42 | printf("Skipping test: manager_new: %s", strerror(-r)); |
43 | return EXIT_TEST_SKIP; | |
44 | } | |
bdf7026e | 45 | assert_se(r >= 0); |
0d8c31ff | 46 | assert_se(manager_startup(m, serial, fdset) >= 0); |
279ade13 | 47 | |
e094e853 | 48 | printf("Load1:\n"); |
398ef8ba LP |
49 | assert_se(manager_load_unit(m, "a.service", NULL, NULL, &a) >= 0); |
50 | assert_se(manager_load_unit(m, "b.service", NULL, NULL, &b) >= 0); | |
51 | assert_se(manager_load_unit(m, "c.service", NULL, NULL, &c) >= 0); | |
87f0e418 | 52 | manager_dump_units(m, stdout, "\t"); |
279ade13 LP |
53 | |
54 | printf("Test1: (Trivial)\n"); | |
4bd29fe5 | 55 | r = manager_add_job(m, JOB_START, c, JOB_REPLACE, &err, &j); |
0d8c31ff ZJS |
56 | if (sd_bus_error_is_set(&err)) |
57 | log_error("error: %s: %s", err.name, err.message); | |
bdf7026e | 58 | assert_se(r == 0); |
279ade13 LP |
59 | manager_dump_jobs(m, stdout, "\t"); |
60 | ||
e094e853 | 61 | printf("Load2:\n"); |
279ade13 | 62 | manager_clear_jobs(m); |
398ef8ba LP |
63 | assert_se(manager_load_unit(m, "d.service", NULL, NULL, &d) >= 0); |
64 | assert_se(manager_load_unit(m, "e.service", NULL, NULL, &e) >= 0); | |
87f0e418 | 65 | manager_dump_units(m, stdout, "\t"); |
279ade13 LP |
66 | |
67 | printf("Test2: (Cyclic Order, Unfixable)\n"); | |
4bd29fe5 | 68 | assert_se(manager_add_job(m, JOB_START, d, JOB_REPLACE, NULL, &j) == -EDEADLK); |
279ade13 LP |
69 | manager_dump_jobs(m, stdout, "\t"); |
70 | ||
1ffba6fe | 71 | printf("Test3: (Cyclic Order, Fixable, Garbage Collector)\n"); |
4bd29fe5 | 72 | assert_se(manager_add_job(m, JOB_START, e, JOB_REPLACE, NULL, &j) == 0); |
279ade13 LP |
73 | manager_dump_jobs(m, stdout, "\t"); |
74 | ||
1ffba6fe | 75 | printf("Test4: (Identical transaction)\n"); |
4bd29fe5 | 76 | assert_se(manager_add_job(m, JOB_START, e, JOB_FAIL, NULL, &j) == 0); |
1ffba6fe LP |
77 | manager_dump_jobs(m, stdout, "\t"); |
78 | ||
e094e853 | 79 | printf("Load3:\n"); |
398ef8ba | 80 | assert_se(manager_load_unit(m, "g.service", NULL, NULL, &g) >= 0); |
87f0e418 | 81 | manager_dump_units(m, stdout, "\t"); |
1ffba6fe LP |
82 | |
83 | printf("Test5: (Colliding transaction, fail)\n"); | |
4bd29fe5 | 84 | assert_se(manager_add_job(m, JOB_START, g, JOB_FAIL, NULL, &j) == -EDEADLK); |
1ffba6fe LP |
85 | |
86 | printf("Test6: (Colliding transaction, replace)\n"); | |
4bd29fe5 | 87 | assert_se(manager_add_job(m, JOB_START, g, JOB_REPLACE, NULL, &j) == 0); |
1ffba6fe LP |
88 | manager_dump_jobs(m, stdout, "\t"); |
89 | ||
35b8ca3a | 90 | printf("Test7: (Unmergeable job type, fail)\n"); |
4bd29fe5 | 91 | assert_se(manager_add_job(m, JOB_STOP, g, JOB_FAIL, NULL, &j) == -EDEADLK); |
e094e853 LP |
92 | |
93 | printf("Test8: (Mergeable job type, fail)\n"); | |
4bd29fe5 | 94 | assert_se(manager_add_job(m, JOB_RESTART, g, JOB_FAIL, NULL, &j) == 0); |
e094e853 LP |
95 | manager_dump_jobs(m, stdout, "\t"); |
96 | ||
35b8ca3a | 97 | printf("Test9: (Unmergeable job type, replace)\n"); |
4bd29fe5 | 98 | assert_se(manager_add_job(m, JOB_STOP, g, JOB_REPLACE, NULL, &j) == 0); |
e094e853 LP |
99 | manager_dump_jobs(m, stdout, "\t"); |
100 | ||
101 | printf("Load4:\n"); | |
398ef8ba | 102 | assert_se(manager_load_unit(m, "h.service", NULL, NULL, &h) >= 0); |
87f0e418 | 103 | manager_dump_units(m, stdout, "\t"); |
e094e853 | 104 | |
35b8ca3a | 105 | printf("Test10: (Unmergeable job type of auxiliary job, fail)\n"); |
4bd29fe5 | 106 | assert_se(manager_add_job(m, JOB_START, h, JOB_FAIL, NULL, &j) == 0); |
e094e853 LP |
107 | manager_dump_jobs(m, stdout, "\t"); |
108 | ||
279ade13 LP |
109 | manager_free(m); |
110 | ||
111 | return 0; | |
112 | } |