LCOV - code coverage report
Current view: top level - test - test-exit-status.c (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 31 31 100.0 %
Date: 2019-08-23 13:36:53 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 27 42 64.3 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: LGPL-2.1+ */
       2                 :            : 
       3                 :            : #include "exit-status.h"
       4                 :            : #include "string-util.h"
       5                 :            : #include "tests.h"
       6                 :            : 
       7                 :          4 : static void test_exit_status_to_string(void) {
       8         [ +  - ]:          4 :         log_info("/* %s */", __func__);
       9                 :            : 
      10         [ +  + ]:       1036 :         for (int i = -1; i <= 256; i++) {
      11                 :            :                 const char *s, *class;
      12                 :            : 
      13                 :       1032 :                 s = exit_status_to_string(i, EXIT_STATUS_FULL);
      14                 :       1032 :                 class = exit_status_class(i);
      15   [ +  -  +  +  :       1032 :                 log_info("%d: %s%s%s%s",
          +  +  +  +  +  
                      + ]
      16                 :            :                          i, s ?: "-",
      17                 :            :                          class ? " (" : "", class ?: "", class ? ")" : "");
      18                 :            : 
      19         [ +  + ]:       1032 :                 if (s)
      20         [ -  + ]:        260 :                         assert_se(exit_status_from_string(s) == i);
      21                 :            :         }
      22                 :          4 : }
      23                 :            : 
      24                 :          4 : static void test_exit_status_from_string(void) {
      25         [ +  - ]:          4 :         log_info("/* %s */", __func__);
      26                 :            : 
      27         [ -  + ]:          4 :         assert_se(exit_status_from_string("11") == 11);
      28         [ -  + ]:          4 :         assert_se(exit_status_from_string("-1") == -ERANGE);
      29         [ -  + ]:          4 :         assert_se(exit_status_from_string("256") == -ERANGE);
      30         [ -  + ]:          4 :         assert_se(exit_status_from_string("foo") == -EINVAL);
      31         [ -  + ]:          4 :         assert_se(exit_status_from_string("SUCCESS") == 0);
      32         [ -  + ]:          4 :         assert_se(exit_status_from_string("FAILURE") == 1);
      33                 :          4 : }
      34                 :            : 
      35                 :          4 : static void test_exit_status_NUMA_POLICY(void) {
      36         [ +  - ]:          4 :         log_info("/* %s */", __func__);
      37                 :            : 
      38         [ -  + ]:          4 :         assert_se(streq(exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_FULL), "NUMA_POLICY"));
      39         [ -  + ]:          4 :         assert_se(streq(exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_SYSTEMD), "NUMA_POLICY"));
      40         [ -  + ]:          4 :         assert_se(!exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_BSD));
      41         [ -  + ]:          4 :         assert_se(!exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_LSB));
      42                 :          4 : }
      43                 :            : 
      44                 :          4 : int main(int argc, char *argv[]) {
      45                 :          4 :         test_setup_logging(LOG_DEBUG);
      46                 :            : 
      47                 :          4 :         test_exit_status_to_string();
      48                 :          4 :         test_exit_status_from_string();
      49                 :          4 :         test_exit_status_NUMA_POLICY();
      50                 :            : 
      51                 :          4 :         return 0;
      52                 :            : }

Generated by: LCOV version 1.14