]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-job-type.c
2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
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
9 (at your option) any later version.
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
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
26 int main(int argc
, char*argv
[]) {
27 JobType a
, b
, c
, ab
, bc
, ab_c
, bc_a
, a_bc
;
28 const ServiceState test_states
[] = { SERVICE_DEAD
, SERVICE_RUNNING
};
34 .meta
.load_state
= UNIT_LOADED
,
35 .type
= SERVICE_SIMPLE
,
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
++) {
47 merged_ab
= (job_type_merge_and_collapse(&ab
, b
, u
) >= 0);
49 if (!job_type_is_mergeable(a
, b
)) {
50 assert_se(!merged_ab
);
51 printf("Not mergeable: %s + %s\n", job_type_to_string(a
), job_type_to_string(b
));
56 printf("%s + %s = %s\n", job_type_to_string(a
), job_type_to_string(b
), job_type_to_string(ab
));
58 for (c
= 0; c
< _JOB_TYPE_MAX_MERGING
; c
++) {
60 /* Verify transitivity of mergeability of job types */
61 assert_se(!job_type_is_mergeable(a
, b
) ||
62 !job_type_is_mergeable(b
, c
) ||
63 job_type_is_mergeable(a
, c
));
65 /* Verify that merged entries can be merged with the same entries
66 * they can be merged with separately */
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
));
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. */
72 assert_se(job_type_is_mergeable(ab
, c
) || !job_type_is_mergeable(a
, c
) || !job_type_is_mergeable(b
, c
));
75 if (job_type_merge_and_collapse(&bc
, c
, u
) >= 0) {
77 /* Verify associativity */
80 assert_se(job_type_merge_and_collapse(&ab_c
, c
, u
) == 0);
83 assert_se(job_type_merge_and_collapse(&bc_a
, a
, u
) == 0);
86 assert_se(job_type_merge_and_collapse(&a_bc
, bc
, u
) == 0);
88 assert_se(ab_c
== bc_a
);
89 assert_se(ab_c
== a_bc
);
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
));