LCOV - code coverage report
Current view: top level - test - test-procfs-util.c (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 22 22 100.0 %
Date: 2019-08-22 15:41:25 Functions: 1 1 100.0 %

          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           1 : 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           1 :         log_parse_environment();
      16           1 :         log_open();
      17             : 
      18           1 :         assert_se(procfs_cpu_get_usage(&nsec) >= 0);
      19           1 :         log_info("Current system CPU time: %s", format_timespan(buf, sizeof(buf), nsec/NSEC_PER_USEC, 1));
      20             : 
      21           1 :         assert_se(procfs_memory_get_used(&v) >= 0);
      22           1 :         log_info("Current memory usage: %s", format_bytes(buf, sizeof(buf), v));
      23             : 
      24           1 :         assert_se(procfs_tasks_get_current(&v) >= 0);
      25           1 :         log_info("Current number of tasks: %" PRIu64, v);
      26             : 
      27           1 :         assert_se(procfs_tasks_get_limit(&v) >= 0);
      28           1 :         log_info("Limit of tasks: %" PRIu64, v);
      29           1 :         assert_se(v > 0);
      30           1 :         assert_se(procfs_tasks_set_limit(v) >= 0);
      31             : 
      32           1 :         if (v > 100) {
      33             :                 uint64_t w;
      34           1 :                 r = procfs_tasks_set_limit(v-1);
      35           1 :                 assert_se(IN_SET(r, 0, -EPERM, -EACCES, -EROFS));
      36             : 
      37           1 :                 assert_se(procfs_tasks_get_limit(&w) >= 0);
      38           1 :                 assert_se((r == 0 && w == v - 1) || (r < 0 && w == v));
      39             : 
      40           1 :                 assert_se(procfs_tasks_set_limit(v) >= 0);
      41             : 
      42           1 :                 assert_se(procfs_tasks_get_limit(&w) >= 0);
      43           1 :                 assert_se(v == w);
      44             :         }
      45             : 
      46           1 :         return 0;
      47             : }

Generated by: LCOV version 1.14