LCOV - code coverage report
Current view: top level - test - test-procfs-util.c (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 22 22 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: 22 46 47.8 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: LGPL-2.1+ */
       2                 :            : 
       3                 :            : #include <errno.h>
       4                 :            : 
       5                 :            : #include "format-util.h"
       6                 :            : #include "log.h"
       7                 :            : #include "procfs-util.h"
       8                 :            : 
       9                 :          4 : int main(int argc, char *argv[]) {
      10                 :            :         char buf[CONST_MAX(FORMAT_TIMESPAN_MAX, FORMAT_BYTES_MAX)];
      11                 :            :         nsec_t nsec;
      12                 :            :         uint64_t v;
      13                 :            :         int r;
      14                 :            : 
      15                 :          4 :         log_parse_environment();
      16                 :          4 :         log_open();
      17                 :            : 
      18         [ -  + ]:          4 :         assert_se(procfs_cpu_get_usage(&nsec) >= 0);
      19         [ +  - ]:          4 :         log_info("Current system CPU time: %s", format_timespan(buf, sizeof(buf), nsec/NSEC_PER_USEC, 1));
      20                 :            : 
      21         [ -  + ]:          4 :         assert_se(procfs_memory_get_used(&v) >= 0);
      22         [ +  - ]:          4 :         log_info("Current memory usage: %s", format_bytes(buf, sizeof(buf), v));
      23                 :            : 
      24         [ -  + ]:          4 :         assert_se(procfs_tasks_get_current(&v) >= 0);
      25         [ +  - ]:          4 :         log_info("Current number of tasks: %" PRIu64, v);
      26                 :            : 
      27         [ -  + ]:          4 :         assert_se(procfs_tasks_get_limit(&v) >= 0);
      28         [ +  - ]:          4 :         log_info("Limit of tasks: %" PRIu64, v);
      29         [ -  + ]:          4 :         assert_se(v > 0);
      30         [ -  + ]:          4 :         assert_se(procfs_tasks_set_limit(v) >= 0);
      31                 :            : 
      32         [ +  - ]:          4 :         if (v > 100) {
      33                 :            :                 uint64_t w;
      34                 :          4 :                 r = procfs_tasks_set_limit(v-1);
      35   [ +  -  -  + ]:          4 :                 assert_se(IN_SET(r, 0, -EPERM, -EACCES, -EROFS));
      36                 :            : 
      37         [ -  + ]:          4 :                 assert_se(procfs_tasks_get_limit(&w) >= 0);
      38   [ -  +  #  #  :          4 :                 assert_se((r == 0 && w == v - 1) || (r < 0 && w == v));
          +  -  +  -  -  
                +  -  + ]
      39                 :            : 
      40         [ -  + ]:          4 :                 assert_se(procfs_tasks_set_limit(v) >= 0);
      41                 :            : 
      42         [ -  + ]:          4 :                 assert_se(procfs_tasks_get_limit(&w) >= 0);
      43         [ -  + ]:          4 :                 assert_se(v == w);
      44                 :            :         }
      45                 :            : 
      46                 :          4 :         return 0;
      47                 :            : }

Generated by: LCOV version 1.14