LCOV - code coverage report
Current view: top level - test - test-job-type.c (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 33 33 100.0 %
Date: 2019-08-23 13:36:53 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 36 52 69.2 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: LGPL-2.1+ */
       2                 :            : 
       3                 :            : #include <stdio.h>
       4                 :            : 
       5                 :            : #include "job.h"
       6                 :            : #include "service.h"
       7                 :            : #include "unit.h"
       8                 :            : 
       9                 :          4 : int main(int argc, char *argv[]) {
      10                 :            :         JobType a, b, c, ab, bc, ab_c, bc_a, a_bc;
      11                 :          4 :         const ServiceState test_states[] = { SERVICE_DEAD, SERVICE_RUNNING };
      12                 :            :         unsigned i;
      13                 :            :         bool merged_ab;
      14                 :            : 
      15                 :            :         /* fake a unit */
      16                 :            :         static Service s = {
      17                 :            :                 .meta.load_state = UNIT_LOADED,
      18                 :            :                 .type = SERVICE_SIMPLE,
      19                 :            :         };
      20         [ +  - ]:          4 :         Unit *u = UNIT(&s);
      21                 :            : 
      22         [ +  + ]:         12 :         for (i = 0; i < ELEMENTSOF(test_states); i++) {
      23                 :          8 :                 s.state = test_states[i];
      24                 :          8 :                 printf("\nWith collapsing for service state %s\n"
      25                 :            :                        "=========================================\n", service_state_to_string(s.state));
      26         [ +  + ]:         48 :                 for (a = 0; a < _JOB_TYPE_MAX_MERGING; a++) {
      27         [ +  + ]:        240 :                         for (b = 0; b < _JOB_TYPE_MAX_MERGING; b++) {
      28                 :            : 
      29                 :        200 :                                 ab = a;
      30                 :        200 :                                 merged_ab = (job_type_merge_and_collapse(&ab, b, u) >= 0);
      31                 :            : 
      32         [ +  + ]:        200 :                                 if (!job_type_is_mergeable(a, b)) {
      33         [ -  + ]:         64 :                                         assert_se(!merged_ab);
      34                 :         64 :                                         printf("Not mergeable: %s + %s\n", job_type_to_string(a), job_type_to_string(b));
      35                 :         64 :                                         continue;
      36                 :            :                                 }
      37                 :            : 
      38         [ -  + ]:        136 :                                 assert_se(merged_ab);
      39                 :        136 :                                 printf("%s + %s = %s\n", job_type_to_string(a), job_type_to_string(b), job_type_to_string(ab));
      40                 :            : 
      41         [ +  + ]:        816 :                                 for (c = 0; c < _JOB_TYPE_MAX_MERGING; c++) {
      42                 :            : 
      43                 :            :                                         /* Verify transitivity of mergeability of job types */
      44   [ +  -  +  +  :        680 :                                         assert_se(!job_type_is_mergeable(a, b) ||
             +  +  -  + ]
      45                 :            :                                                !job_type_is_mergeable(b, c) ||
      46                 :            :                                                job_type_is_mergeable(a, c));
      47                 :            : 
      48                 :            :                                         /* Verify that merged entries can be merged with the same entries
      49                 :            :                                          * they can be merged with separately */
      50   [ +  +  -  + ]:        680 :                                         assert_se(!job_type_is_mergeable(a, c) || job_type_is_mergeable(ab, c));
      51   [ +  +  -  + ]:        680 :                                         assert_se(!job_type_is_mergeable(b, c) || job_type_is_mergeable(ab, c));
      52                 :            : 
      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   [ +  +  -  +  :        680 :                                         assert_se(job_type_is_mergeable(ab, c) || !job_type_is_mergeable(a, c) || !job_type_is_mergeable(b, c));
             -  +  #  # ]
      56                 :            : 
      57                 :        680 :                                         bc = b;
      58         [ +  + ]:        680 :                                         if (job_type_merge_and_collapse(&bc, c, u) >= 0) {
      59                 :            : 
      60                 :            :                                                 /* Verify associativity */
      61                 :            : 
      62                 :        520 :                                                 ab_c = ab;
      63         [ -  + ]:        520 :                                                 assert_se(job_type_merge_and_collapse(&ab_c, c, u) == 0);
      64                 :            : 
      65                 :        520 :                                                 bc_a = bc;
      66         [ -  + ]:        520 :                                                 assert_se(job_type_merge_and_collapse(&bc_a, a, u) == 0);
      67                 :            : 
      68                 :        520 :                                                 a_bc = a;
      69         [ -  + ]:        520 :                                                 assert_se(job_type_merge_and_collapse(&a_bc, bc, u) == 0);
      70                 :            : 
      71         [ -  + ]:        520 :                                                 assert_se(ab_c == bc_a);
      72         [ -  + ]:        520 :                                                 assert_se(ab_c == a_bc);
      73                 :            : 
      74                 :        520 :                                                 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));
      75                 :            :                                         }
      76                 :            :                                 }
      77                 :            :                         }
      78                 :            :                 }
      79                 :            :         }
      80                 :            : 
      81                 :          4 :         return 0;
      82                 :            : }

Generated by: LCOV version 1.14