]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-procfs-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
6 #include "parse-util.h"
7 #include "procfs-util.h"
9 int main(int argc
, char *argv
[]) {
10 char buf
[CONST_MAX(FORMAT_TIMESPAN_MAX
, FORMAT_BYTES_MAX
)];
15 log_parse_environment();
18 assert_se(procfs_cpu_get_usage(&nsec
) >= 0);
19 log_info("Current system CPU time: %s", format_timespan(buf
, sizeof(buf
), nsec
/NSEC_PER_USEC
, 1));
21 assert_se(procfs_memory_get_used(&v
) >= 0);
22 log_info("Current memory usage: %s", format_bytes(buf
, sizeof(buf
), v
));
24 assert_se(procfs_tasks_get_current(&v
) >= 0);
25 log_info("Current number of tasks: %" PRIu64
, v
);
27 assert_se(procfs_tasks_get_limit(&v
) >= 0);
28 log_info("Limit of tasks: %" PRIu64
, v
);
30 assert_se(procfs_tasks_set_limit(v
) >= 0);
34 r
= procfs_tasks_set_limit(v
-1);
35 assert_se(IN_SET(r
, 0, -EPERM
, -EACCES
, -EROFS
));
37 assert_se(procfs_tasks_get_limit(&w
) >= 0);
38 assert_se((r
== 0 && w
== v
- 1) || (r
< 0 && w
== v
));
40 assert_se(procfs_tasks_set_limit(v
) >= 0);
42 assert_se(procfs_tasks_get_limit(&w
) >= 0);