]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-job-type.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
14 int main(int argc
, char*argv
[]) {
15 JobType a
, b
, c
, ab
, bc
, ab_c
, bc_a
, a_bc
;
16 const ServiceState test_states
[] = { SERVICE_DEAD
, SERVICE_RUNNING
};
22 .meta
.load_state
= UNIT_LOADED
,
23 .type
= SERVICE_SIMPLE
,
27 for (i
= 0; i
< ELEMENTSOF(test_states
); i
++) {
28 s
.state
= test_states
[i
];
29 printf("\nWith collapsing for service state %s\n"
30 "=========================================\n", service_state_to_string(s
.state
));
31 for (a
= 0; a
< _JOB_TYPE_MAX_MERGING
; a
++) {
32 for (b
= 0; b
< _JOB_TYPE_MAX_MERGING
; b
++) {
35 merged_ab
= (job_type_merge_and_collapse(&ab
, b
, u
) >= 0);
37 if (!job_type_is_mergeable(a
, b
)) {
38 assert_se(!merged_ab
);
39 printf("Not mergeable: %s + %s\n", job_type_to_string(a
), job_type_to_string(b
));
44 printf("%s + %s = %s\n", job_type_to_string(a
), job_type_to_string(b
), job_type_to_string(ab
));
46 for (c
= 0; c
< _JOB_TYPE_MAX_MERGING
; c
++) {
48 /* Verify transitivity of mergeability of job types */
49 assert_se(!job_type_is_mergeable(a
, b
) ||
50 !job_type_is_mergeable(b
, c
) ||
51 job_type_is_mergeable(a
, c
));
53 /* Verify that merged entries can be merged with the same entries
54 * they can be merged with separately */
55 assert_se(!job_type_is_mergeable(a
, c
) || job_type_is_mergeable(ab
, c
));
56 assert_se(!job_type_is_mergeable(b
, c
) || job_type_is_mergeable(ab
, c
));
58 /* Verify that if a merged with b is not mergeable with c, then
59 * either a or b is not mergeable with c either. */
60 assert_se(job_type_is_mergeable(ab
, c
) || !job_type_is_mergeable(a
, c
) || !job_type_is_mergeable(b
, c
));
63 if (job_type_merge_and_collapse(&bc
, c
, u
) >= 0) {
65 /* Verify associativity */
68 assert_se(job_type_merge_and_collapse(&ab_c
, c
, u
) == 0);
71 assert_se(job_type_merge_and_collapse(&bc_a
, a
, u
) == 0);
74 assert_se(job_type_merge_and_collapse(&a_bc
, bc
, u
) == 0);
76 assert_se(ab_c
== bc_a
);
77 assert_se(ab_c
== a_bc
);
79 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
));