]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-job-type.c
Merge pull request #7388 from keszybz/doc-tweak
[thirdparty/systemd.git] / src / test / test-job-type.c
CommitLineData
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
1ffba6fe 20#include <stdio.h>
1ffba6fe
LP
21
22#include "job.h"
e0209d83 23#include "service.h"
cf0fbc49 24#include "unit.h"
1ffba6fe
LP
25
26int main(int argc, char*argv[]) {
e0209d83
MS
27 JobType a, b, c, ab, bc, ab_c, bc_a, a_bc;
28 const ServiceState test_states[] = { SERVICE_DEAD, SERVICE_RUNNING };
29 unsigned i;
30 bool merged_ab;
31
32 /* fake a unit */
33 static Service s = {
34 .meta.load_state = UNIT_LOADED,
335c8d5a 35 .type = SERVICE_SIMPLE,
e0209d83
MS
36 };
37 Unit *u = UNIT(&s);
38
39 for (i = 0; i < ELEMENTSOF(test_states); i++) {
40 s.state = test_states[i];
41 printf("\nWith collapsing for service state %s\n"
42 "=========================================\n", service_state_to_string(s.state));
43 for (a = 0; a < _JOB_TYPE_MAX_MERGING; a++) {
44 for (b = 0; b < _JOB_TYPE_MAX_MERGING; b++) {
45
46 ab = a;
47 merged_ab = (job_type_merge_and_collapse(&ab, b, u) >= 0);
48
49 if (!job_type_is_mergeable(a, b)) {
bdf7026e 50 assert_se(!merged_ab);
e0209d83
MS
51 printf("Not mergeable: %s + %s\n", job_type_to_string(a), job_type_to_string(b));
52 continue;
53 }
1ffba6fe 54
bdf7026e 55 assert_se(merged_ab);
e0209d83 56 printf("%s + %s = %s\n", job_type_to_string(a), job_type_to_string(b), job_type_to_string(ab));
1ffba6fe 57
e0209d83 58 for (c = 0; c < _JOB_TYPE_MAX_MERGING; c++) {
1ffba6fe 59
e0209d83 60 /* Verify transitivity of mergeability of job types */
bdf7026e 61 assert_se(!job_type_is_mergeable(a, b) ||
e0209d83
MS
62 !job_type_is_mergeable(b, c) ||
63 job_type_is_mergeable(a, c));
1ffba6fe 64
e0209d83
MS
65 /* Verify that merged entries can be merged with the same entries
66 * they can be merged with separately */
bdf7026e
TA
67 assert_se(!job_type_is_mergeable(a, c) || job_type_is_mergeable(ab, c));
68 assert_se(!job_type_is_mergeable(b, c) || job_type_is_mergeable(ab, c));
1ffba6fe 69
e0209d83
MS
70 /* Verify that if a merged with b is not mergeable with c, then
71 * either a or b is not mergeable with c either. */
bdf7026e 72 assert_se(job_type_is_mergeable(ab, c) || !job_type_is_mergeable(a, c) || !job_type_is_mergeable(b, c));
1ffba6fe 73
e0209d83
MS
74 bc = b;
75 if (job_type_merge_and_collapse(&bc, c, u) >= 0) {
1ffba6fe
LP
76
77 /* Verify associativity */
78
e0209d83 79 ab_c = ab;
bdf7026e 80 assert_se(job_type_merge_and_collapse(&ab_c, c, u) == 0);
e0209d83
MS
81
82 bc_a = bc;
bdf7026e 83 assert_se(job_type_merge_and_collapse(&bc_a, a, u) == 0);
1ffba6fe 84
e0209d83 85 a_bc = a;
bdf7026e 86 assert_se(job_type_merge_and_collapse(&a_bc, bc, u) == 0);
1ffba6fe 87
bdf7026e
TA
88 assert_se(ab_c == bc_a);
89 assert_se(ab_c == a_bc);
1ffba6fe 90
e0209d83 91 printf("%s + %s + %s = %s\n", job_type_to_string(a), job_type_to_string(b), job_type_to_string(c), job_type_to_string(ab_c));
1ffba6fe
LP
92 }
93 }
94 }
95 }
e0209d83 96 }
1ffba6fe
LP
97
98
99 return 0;
100}