summaryrefslogtreecommitdiff
path: root/src/test/test-procfs-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-01-17 18:40:10 +0100
committerSven Eden <yamakuzure@gmx.net>2018-05-30 07:50:17 +0200
commitf3cd1b1561675c3824734f15889d9309c1e58091 (patch)
tree6fb65c77f9f1ed1758b179e1eee451dfc4d95f82 /src/test/test-procfs-util.c
parent729aa3508600f570c9bb37e2e8c8253c0106dc56 (diff)
util-lib: add new procfs-util.[ch] API for dealing with tasks limits
As it turns out the limit on concurrent tasks on Linux nasty to determine, hence let's appropriate helpers for this.
Diffstat (limited to 'src/test/test-procfs-util.c')
-rw-r--r--src/test/test-procfs-util.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/test/test-procfs-util.c b/src/test/test-procfs-util.c
new file mode 100644
index 000000000..6c4d15ec8
--- /dev/null
+++ b/src/test/test-procfs-util.c
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+//#include <errno.h>
+
+//#include "log.h"
+//#include "procfs-util.h"
+
+int main(int argc, char *argv[]) {
+ uint64_t v;
+ int r;
+
+ log_parse_environment();
+ log_open();
+
+ assert_se(procfs_tasks_get_current(&v) >= 0);
+ log_info("Current number of tasks: %" PRIu64, v);
+
+ assert_se(procfs_tasks_get_limit(&v) >= 0);
+ log_info("Limit of tasks: %" PRIu64, v);
+ assert_se(v > 0);
+ assert_se(procfs_tasks_set_limit(v) >= 0);
+
+ if (v > 100) {
+ uint64_t w;
+ r = procfs_tasks_set_limit(v-1);
+ assert_se(IN_SET(r, 0, -EPERM, -EACCES, -EROFS));
+
+ assert_se(procfs_tasks_get_limit(&w) >= 0);
+ assert_se((r == 0 && w == v - 1) || (r < 0 && w == v));
+
+ assert_se(procfs_tasks_set_limit(v) >= 0);
+
+ assert_se(procfs_tasks_get_limit(&w) >= 0);
+ assert_se(v == w);
+ }
+
+ return 0;
+}