summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-02-01 21:15:07 +0100
committerLennart Poettering <lennart@poettering.net>2016-02-01 22:18:16 +0100
commit99d4f5e5c0d2532159542519e683f976f881f0f5 (patch)
treeb80732d258a9a3abf896231996eb8e8856c1da30 /src/test
parentgpt-auto: don't log an EIO error if blkid finds something which is not a part... (diff)
downloadsystemd-99d4f5e5c0d2532159542519e683f976f881f0f5.tar.xz
systemd-99d4f5e5c0d2532159542519e683f976f881f0f5.zip
basic: add new rlimit_format() call
This formats a struct rlimit the way rlimit_parse() expects it.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-rlimit-util.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/test/test-rlimit-util.c b/src/test/test-rlimit-util.c
index 24bfe7a60e..d9ac9368cd 100644
--- a/src/test/test-rlimit-util.c
+++ b/src/test/test-rlimit-util.c
@@ -17,12 +17,37 @@
#include <sys/resource.h>
+#include "alloc-util.h"
#include "capability-util.h"
#include "macro.h"
#include "rlimit-util.h"
#include "string-util.h"
#include "util.h"
+static void test_rlimit_parse_format(int resource, const char *string, rlim_t soft, rlim_t hard, int ret, const char *formatted) {
+ _cleanup_free_ char *f = NULL;
+ struct rlimit rl = {
+ .rlim_cur = 4711,
+ .rlim_max = 4712,
+ }, rl2 = {
+ .rlim_cur = 4713,
+ .rlim_max = 4714
+ };
+
+ assert_se(rlimit_parse(resource, string, &rl) == ret);
+ if (ret < 0)
+ return;
+
+ assert_se(rl.rlim_cur == soft);
+ assert_se(rl.rlim_max == hard);
+
+ assert_se(rlimit_format(&rl, &f) >= 0);
+ assert_se(streq(formatted, f));
+
+ assert_se(rlimit_parse(resource, formatted, &rl2) >= 0);
+ assert_se(memcmp(&rl, &rl2, sizeof(struct rlimit)) == 0);
+}
+
int main(int argc, char *argv[]) {
struct rlimit old, new, high;
struct rlimit err = {
@@ -65,5 +90,15 @@ int main(int argc, char *argv[]) {
assert_se(old.rlim_cur == new.rlim_cur);
assert_se(old.rlim_max == new.rlim_max);
+ test_rlimit_parse_format(RLIMIT_NOFILE, "4:5", 4, 5, 0, "4:5");
+ test_rlimit_parse_format(RLIMIT_NOFILE, "6", 6, 6, 0, "6");
+ test_rlimit_parse_format(RLIMIT_NOFILE, "infinity", RLIM_INFINITY, RLIM_INFINITY, 0, "infinity");
+ test_rlimit_parse_format(RLIMIT_NOFILE, "infinity:infinity", RLIM_INFINITY, RLIM_INFINITY, 0, "infinity");
+ test_rlimit_parse_format(RLIMIT_NOFILE, "8:infinity", 8, RLIM_INFINITY, 0, "8:infinity");
+ test_rlimit_parse_format(RLIMIT_CPU, "25min:13h", (25*USEC_PER_MINUTE) / USEC_PER_SEC, (13*USEC_PER_HOUR) / USEC_PER_SEC, 0, "1500:46800");
+ test_rlimit_parse_format(RLIMIT_NOFILE, "", 0, 0, -EINVAL, NULL);
+ test_rlimit_parse_format(RLIMIT_NOFILE, "5:4", 0, 0, -EILSEQ, NULL);
+ test_rlimit_parse_format(RLIMIT_NOFILE, "5:4:3", 0, 0, -EINVAL, NULL);
+
return 0;
}