]>
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[]) { | |
d2120590 | 31 | _cleanup_(rm_rf_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 | |
d2120590 LP |
40 | assert_se(runtime_dir = setup_fake_runtime_dir()); |
41 | ||
0d8c31ff ZJS |
42 | /* prepare the test */ |
43 | assert_se(set_unit_path(TEST_DIR) >= 0); | |
463d0d15 | 44 | r = manager_new(UNIT_FILE_USER, true, &m); |
8b3aa503 | 45 | if (MANAGER_SKIP_TEST(r)) { |
1d31abf7 | 46 | printf("Skipping test: manager_new: %s\n", strerror(-r)); |
0d8c31ff ZJS |
47 | return EXIT_TEST_SKIP; |
48 | } | |
bdf7026e | 49 | assert_se(r >= 0); |
0d8c31ff | 50 | assert_se(manager_startup(m, serial, fdset) >= 0); |
279ade13 | 51 | |
e094e853 | 52 | printf("Load1:\n"); |
398ef8ba LP |
53 | assert_se(manager_load_unit(m, "a.service", NULL, NULL, &a) >= 0); |
54 | assert_se(manager_load_unit(m, "b.service", NULL, NULL, &b) >= 0); | |
55 | assert_se(manager_load_unit(m, "c.service", NULL, NULL, &c) >= 0); | |
87f0e418 | 56 | manager_dump_units(m, stdout, "\t"); |
279ade13 LP |
57 | |
58 | printf("Test1: (Trivial)\n"); | |
4bd29fe5 | 59 | r = manager_add_job(m, JOB_START, c, JOB_REPLACE, &err, &j); |
0d8c31ff ZJS |
60 | if (sd_bus_error_is_set(&err)) |
61 | log_error("error: %s: %s", err.name, err.message); | |
bdf7026e | 62 | assert_se(r == 0); |
279ade13 LP |
63 | manager_dump_jobs(m, stdout, "\t"); |
64 | ||
e094e853 | 65 | printf("Load2:\n"); |
279ade13 | 66 | manager_clear_jobs(m); |
398ef8ba LP |
67 | assert_se(manager_load_unit(m, "d.service", NULL, NULL, &d) >= 0); |
68 | assert_se(manager_load_unit(m, "e.service", NULL, NULL, &e) >= 0); | |
87f0e418 | 69 | manager_dump_units(m, stdout, "\t"); |
279ade13 LP |
70 | |
71 | printf("Test2: (Cyclic Order, Unfixable)\n"); | |
4bd29fe5 | 72 | assert_se(manager_add_job(m, JOB_START, d, JOB_REPLACE, NULL, &j) == -EDEADLK); |
279ade13 LP |
73 | manager_dump_jobs(m, stdout, "\t"); |
74 | ||
1ffba6fe | 75 | printf("Test3: (Cyclic Order, Fixable, Garbage Collector)\n"); |
4bd29fe5 | 76 | assert_se(manager_add_job(m, JOB_START, e, JOB_REPLACE, NULL, &j) == 0); |
279ade13 LP |
77 | manager_dump_jobs(m, stdout, "\t"); |
78 | ||
1ffba6fe | 79 | printf("Test4: (Identical transaction)\n"); |
4bd29fe5 | 80 | assert_se(manager_add_job(m, JOB_START, e, JOB_FAIL, NULL, &j) == 0); |
1ffba6fe LP |
81 | manager_dump_jobs(m, stdout, "\t"); |
82 | ||
e094e853 | 83 | printf("Load3:\n"); |
398ef8ba | 84 | assert_se(manager_load_unit(m, "g.service", NULL, NULL, &g) >= 0); |
87f0e418 | 85 | manager_dump_units(m, stdout, "\t"); |
1ffba6fe LP |
86 | |
87 | printf("Test5: (Colliding transaction, fail)\n"); | |
4bd29fe5 | 88 | assert_se(manager_add_job(m, JOB_START, g, JOB_FAIL, NULL, &j) == -EDEADLK); |
1ffba6fe LP |
89 | |
90 | printf("Test6: (Colliding transaction, replace)\n"); | |
4bd29fe5 | 91 | assert_se(manager_add_job(m, JOB_START, g, JOB_REPLACE, NULL, &j) == 0); |
1ffba6fe LP |
92 | manager_dump_jobs(m, stdout, "\t"); |
93 | ||
35b8ca3a | 94 | printf("Test7: (Unmergeable job type, fail)\n"); |
4bd29fe5 | 95 | assert_se(manager_add_job(m, JOB_STOP, g, JOB_FAIL, NULL, &j) == -EDEADLK); |
e094e853 LP |
96 | |
97 | printf("Test8: (Mergeable job type, fail)\n"); | |
4bd29fe5 | 98 | assert_se(manager_add_job(m, JOB_RESTART, g, JOB_FAIL, NULL, &j) == 0); |
e094e853 LP |
99 | manager_dump_jobs(m, stdout, "\t"); |
100 | ||
35b8ca3a | 101 | printf("Test9: (Unmergeable job type, replace)\n"); |
4bd29fe5 | 102 | assert_se(manager_add_job(m, JOB_STOP, g, JOB_REPLACE, NULL, &j) == 0); |
e094e853 LP |
103 | manager_dump_jobs(m, stdout, "\t"); |
104 | ||
105 | printf("Load4:\n"); | |
398ef8ba | 106 | assert_se(manager_load_unit(m, "h.service", NULL, NULL, &h) >= 0); |
87f0e418 | 107 | manager_dump_units(m, stdout, "\t"); |
e094e853 | 108 | |
35b8ca3a | 109 | printf("Test10: (Unmergeable job type of auxiliary job, fail)\n"); |
4bd29fe5 | 110 | assert_se(manager_add_job(m, JOB_START, h, JOB_FAIL, NULL, &j) == 0); |
e094e853 LP |
111 | manager_dump_jobs(m, stdout, "\t"); |
112 | ||
279ade13 LP |
113 | manager_free(m); |
114 | ||
115 | return 0; | |
116 | } |