[PATCH] tests: add getrusage.test

Fei Jie feij.fnst at cn.fujitsu.com
Thu Feb 18 08:04:57 UTC 2016


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

diff --git a/tests/.gitignore b/tests/.gitignore
index 5671978..a0ddb1b 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -37,6 +37,7 @@ ftruncate64
 getdents
 getdents64
 getrandom
+getrusage
 getxxid
 inet-cmsg
 ioctl
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2e77934..6d5e2e3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -87,6 +87,7 @@ check_PROGRAMS = \
 	getdents \
 	getdents64 \
 	getrandom \
+	getrusage \
 	getxxid \
 	inet-cmsg \
 	ioctl \
@@ -241,6 +242,7 @@ TESTS = \
 	getdents.test \
 	getdents64.test \
 	getrandom.test \
+	getrusage.test \
 	getxxid.test \
 	inet-cmsg.test \
 	ioctl.test \
diff --git a/tests/getrusage.c b/tests/getrusage.c
new file mode 100644
index 0000000..eea0168
--- /dev/null
+++ b/tests/getrusage.c
@@ -0,0 +1,38 @@
+#include "tests.h"
+#include <sys/syscall.h>
+
+#ifdef __NR_getrusage
+
+#include <sched.h>
+#include <stdio.h>
+#include <sys/resource.h>
+#include <unistd.h>
+
+int
+main(void)
+{
+	struct rusage usage;
+	int rc = syscall(__NR_getrusage, RUSAGE_SELF, &usage);
+	printf("getrusage(RUSAGE_SELF, {ru_utime={%ld, %ld}"
+	       ", ru_stime={%ld, %ld}, ru_maxrss=%ld, ru_ixrss=%ld"
+	       ", ru_idrss=%ld, ru_isrss=%ld, ru_minflt=%ld"
+	       ", ru_majflt=%ld, ru_nswap=%ld, ru_inblock=%ld"
+	       ", ru_oublock=%ld, ru_msgsnd=%ld, ru_msgrcv=%ld"
+	       ", ru_nsignals=%ld, ru_nvcsw=%ld, ru_nivcsw=%ld}) = %d\n",
+	       usage.ru_utime.tv_sec, usage.ru_utime.tv_usec,
+	       usage.ru_stime.tv_sec, usage.ru_stime.tv_usec,
+	       usage.ru_maxrss, usage.ru_ixrss, usage.ru_idrss,
+	       usage.ru_isrss, usage.ru_minflt, usage.ru_majflt,
+	       usage.ru_nswap, usage.ru_inblock, usage.ru_oublock,
+	       usage.ru_msgsnd, usage.ru_msgrcv, usage.ru_nsignals,
+	       usage.ru_nvcsw, usage.ru_nivcsw, rc);
+
+	puts("+++ exited with 0 +++");
+	return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_getrusage")
+
+#endif
diff --git a/tests/getrusage.test b/tests/getrusage.test
new file mode 100755
index 0000000..ed19011
--- /dev/null
+++ b/tests/getrusage.test
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+# Check getrusage syscall decoding.
+
+. "${srcdir=.}/init.sh"
+
+run_prog > /dev/null
+OUT="$LOG.out"
+run_strace -v -egetrusage $args > "$OUT"
+match_diff "$LOG" "$OUT"
+rm -f "$OUT"
-- 
1.8.3.1







More information about the Strace-devel mailing list