[PATCH 1/4] tests: add xetrlimit.test

Fei Jie feij.fnst at cn.fujitsu.com
Tue Mar 8 06:23:19 UTC 2016


* tests/xetrlimit.c: New file.
* tests/xetrlimit.test: New test.
* tests/.gitignore: Add xetrlimit.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(TESTS): Add xetrlimit.test.
---
 tests/.gitignore     |  1 +
 tests/Makefile.am    |  2 ++
 tests/xetrlimit.c    | 38 ++++++++++++++++++++++++++++++++++++++
 tests/xetrlimit.test | 11 +++++++++++
 4 files changed, 52 insertions(+)
 create mode 100644 tests/xetrlimit.c
 create mode 100755 tests/xetrlimit.test

diff --git a/tests/.gitignore b/tests/.gitignore
index c6a94d8..c842781 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -139,4 +139,5 @@ xattr
 xet_robust_list
 xetitimer
 xetpgid
+xetrlimit
 xettimeofday
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 92d3255..32d7e0a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -187,6 +187,7 @@ check_PROGRAMS = \
 	xet_robust_list \
 	xetitimer \
 	xetpgid \
+	xetrlimit \
 	xettimeofday \
 	# end of check_PROGRAMS
 
@@ -344,6 +345,7 @@ TESTS = \
 	xet_robust_list.test \
 	xetitimer.test \
 	xetpgid.test \
+	xetrlimit.test \
 	xettimeofday.test \
 	\
 	count.test \
diff --git a/tests/xetrlimit.c b/tests/xetrlimit.c
new file mode 100644
index 0000000..a2444d9
--- /dev/null
+++ b/tests/xetrlimit.c
@@ -0,0 +1,38 @@
+#include "tests.h"
+#include <sys/syscall.h>
+
+#if defined __NR_getrlimit && defined __NR_setrlimit
+
+# include <errno.h>
+# include <sys/time.h>
+# include <sys/resource.h>
+# include <stdio.h>
+# include <unistd.h>
+
+int
+main(void)
+{
+	struct rlimit *const rlim = tail_alloc(sizeof(struct rlimit));
+	int rc = syscall(__NR_getrlimit, RLIMIT_NPROC, rlim);
+	if (rc == -1)
+		perror_msg_and_fail("getrlimit");
+
+	printf("getrlimit(RLIMIT_NPROC, {rlim_cur=%d, rlim_max=%d}) = %d\n",
+	       (int) rlim->rlim_cur, (int) rlim->rlim_max, rc);
+
+	rlim->rlim_cur = rlim->rlim_max + 1;
+	rc = syscall(__NR_setrlimit, RLIMIT_NPROC, rlim);
+
+	printf("setrlimit(RLIMIT_NPROC, {rlim_cur=%d, rlim_max=%d}) = %d %s (%m)\n",
+	       (int) rlim->rlim_cur, (int) rlim->rlim_max, rc,
+	       errno == EPERM ? "EPERM" : "EINVAL");
+
+	puts("+++ exited with 0 +++");
+	return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_getrlimit && __NR_setrlimit")
+
+#endif
diff --git a/tests/xetrlimit.test b/tests/xetrlimit.test
new file mode 100755
index 0000000..d19b576
--- /dev/null
+++ b/tests/xetrlimit.test
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+# Check getrlimit and setrlimit syscalls decoding.
+
+. "${srcdir=.}/init.sh"
+
+run_prog > /dev/null
+OUT="$LOG.out"
+run_strace -egetrlimit,setrlimit -a10 $args > "$OUT"
+match_diff "$LOG" "$OUT"
+rm -f "$OUT"
-- 
1.8.3.1







More information about the Strace-devel mailing list