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

diff --git a/tests/.gitignore b/tests/.gitignore
index 8f4d6f0..4b736f8 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -277,4 +277,5 @@ xet_robust_list
 xetitimer
 xetpgid
 xetpriority
+xetrlimit
 xettimeofday
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9eba306..2492d90 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -330,6 +330,7 @@ check_PROGRAMS = \
        xetitimer \
        xetpgid \
        xetpriority \
+       xetrlimit \
        xettimeofday \
        # end of check_PROGRAMS
 
@@ -622,6 +623,7 @@ DECODER_TESTS = \
        xetitimer.test \
        xetpgid.test \
        xetpriority.test \
+       xetrlimit.test \
        xettimeofday.test \
        # end of DECODER_TESTS
 
diff --git a/tests/xetrlimit.c b/tests/xetrlimit.c
new file mode 100644
index 0000000..69b7a9e
--- /dev/null
+++ b/tests/xetrlimit.c
@@ -0,0 +1,76 @@
+#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 <stdint.h>
+# include <unistd.h>
+# include <inttypes.h>
+
+static const char *
+print_rlimit64(uint64_t lim)
+{
+    static char buf[sizeof(uint64_t)*3 + sizeof("*1024")];
+
+    if (lim == UINT64_MAX)
+        return "RLIM64_INFINITY";
+
+    if (lim > 1024 && lim % 1024 == 0)
+        sprintf(buf, "%" PRIu64 "*1024", lim / 1024);
+    else
+        sprintf(buf, "%" PRIu64, lim);
+    return buf;
+}
+
+static const char *
+print_rlimit32(uint32_t lim)
+{
+    static char buf[sizeof(uint32_t)*3 + sizeof("*1024")];
+
+    if (lim == UINT32_MAX)
+        return "RLIM_INFINITY";
+
+    if (lim > 1024 && lim % 1024 == 0)
+        sprintf(buf, "%" PRIu32 "*1024", lim / 1024);
+    else
+        sprintf(buf, "%" PRIu32, lim);
+    return buf;
+}
+
+int
+main(void)
+{
+       struct rlimit *const rlim = tail_alloc(sizeof(struct rlimit));
+       int rc = syscall(__NR_getrlimit, RLIMIT_CPU, rlim);
+
+       if (sizeof(uint64_t) == sizeof(rlim->rlim_cur)) {
+               printf("getrlimit(RLIMIT_CPU, {rlim_cur=%s, rlim_max=%s}) = 
%d\n",
+                      print_rlimit64(rlim->rlim_cur),
+                      print_rlimit64(rlim->rlim_max), rc);
+               rc = syscall(__NR_setrlimit, RLIMIT_CPU, rlim);
+               printf("setrlimit(RLIMIT_CPU, {rlim_cur=%s, rlim_max=%s}) = 
%d\n",
+                      print_rlimit64(rlim->rlim_cur),
+                      print_rlimit64(rlim->rlim_max), rc);
+       } else if (sizeof(uint32_t) == sizeof(rlim->rlim_cur)) {
+               printf("getrlimit(RLIMIT_CPU, {rlim_cur=%s, rlim_max=%s}) = 
%d\n",
+                      print_rlimit32(rlim->rlim_cur),
+                      print_rlimit32(rlim->rlim_max), rc);
+               rc = syscall(__NR_setrlimit, RLIMIT_CPU, rlim);
+               printf("setrlimit(RLIMIT_CPU, {rlim_cur=%s, rlim_max=%s}) = 
%d\n",
+                      print_rlimit32(rlim->rlim_cur),
+                      print_rlimit32(rlim->rlim_max), rc);
+       }
+
+       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..e1ea51b
--- /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 $args > "$OUT"
+match_diff "$LOG" "$OUT"
+rm -f "$OUT"
-- 
1.8.3.1




------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Strace-devel mailing list
Strace-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to