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