]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-job-type.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
9 int main(int argc
, char *argv
[]) {
10 JobType a
, b
, c
, ab
, bc
, ab_c
, bc_a
, a_bc
;
11 const ServiceState test_states
[] = { SERVICE_DEAD
, SERVICE_RUNNING
};
17 .meta
.load_state
= UNIT_LOADED
,
18 .type
= SERVICE_SIMPLE
,
22 for (i
= 0; i
< ELEMENTSOF(test_states
); i
++) {
23 s
.state
= test_states
[i
];
24 printf("\nWith collapsing for service state %s\n"
25 "=========================================\n", service_state_to_string(s
.state
));
26 for (a
= 0; a
< _JOB_TYPE_MAX_MERGING
; a
++) {
27 for (b
= 0; b
< _JOB_TYPE_MAX_MERGING
; b
++) {
30 merged_ab
= (job_type_merge_and_collapse(&ab
, b
, u
) >= 0);
32 if (!job_type_is_mergeable(a
, b
)) {
33 assert_se(!merged_ab
);
34 printf("Not mergeable: %s + %s\n", job_type_to_string(a
), job_type_to_string(b
));
39 printf("%s + %s = %s\n", job_type_to_string(a
), job_type_to_string(b
), job_type_to_string(ab
));
41 for (c
= 0; c
< _JOB_TYPE_MAX_MERGING
; c
++) {
43 /* Verify transitivity of mergeability of job types */
44 assert_se(!job_type_is_mergeable(a
, b
) ||
45 !job_type_is_mergeable(b
, c
) ||
46 job_type_is_mergeable(a
, c
));
48 /* Verify that merged entries can be merged with the same entries
49 * they can be merged with separately */
50 assert_se(!job_type_is_mergeable(a
, c
) || job_type_is_mergeable(ab
, c
));
51 assert_se(!job_type_is_mergeable(b
, c
) || job_type_is_mergeable(ab
, c
));
53 /* Verify that if a merged with b is not mergeable with c, then
54 * either a or b is not mergeable with c either. */
55 assert_se(job_type_is_mergeable(ab
, c
) || !job_type_is_mergeable(a
, c
) || !job_type_is_mergeable(b
, c
));
58 if (job_type_merge_and_collapse(&bc
, c
, u
) >= 0) {
60 /* Verify associativity */
63 assert_se(job_type_merge_and_collapse(&ab_c
, c
, u
) == 0);
66 assert_se(job_type_merge_and_collapse(&bc_a
, a
, u
) == 0);
69 assert_se(job_type_merge_and_collapse(&a_bc
, bc
, u
) == 0);
71 assert_se(ab_c
== bc_a
);
72 assert_se(ab_c
== a_bc
);
74 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
));