[PATCH v2 6/7] tests: check decoding of successful quotactl

Zhibin Li 08826794brmt at gmail.com
Thu Jul 12 09:32:13 UTC 2018


* tests/quotactl-success.c: New file.
* tests/quotactl-success-v.c: Likewise.
* tests/quotactl-xfs-success.c: Likewise.
* tests/quotactl-xfs-success-v.c: Likewise.
* tests/quotactl-success.test: New test.
* tests/quotactl-success-v.test: Likewise.
* tests/quotactl-xfs-success.test: Likewise.
* tests/quotactl-xfs-success-v.test: Likewise.
* tests/.gitignore: Add quotactl-success, quotactl-success-v,
quotactl-xfs-success and quotactl-xfs-success-v.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(DECODER_TESTS): Add four new tests listed above.
* tests/quotactl.h: [INJECT_RETVAL] (check_quota): Use errstr instead of
sprintrc; check that returned value is equivalent to the injected one;
append "(INJECTED)" string to errstr.
---
 tests/.gitignore                  |  4 ++++
 tests/Makefile.am                 |  8 ++++++++
 tests/quotactl-success-v.c        |  2 ++
 tests/quotactl-success-v.test     |  6 ++++++
 tests/quotactl-success.c          |  2 ++
 tests/quotactl-success.test       |  6 ++++++
 tests/quotactl-xfs-success-v.c    |  2 ++
 tests/quotactl-xfs-success-v.test |  6 ++++++
 tests/quotactl-xfs-success.c      |  2 ++
 tests/quotactl-xfs-success.test   |  6 ++++++
 tests/quotactl.h                  | 18 +++++++++++++++++-
 11 files changed, 61 insertions(+), 1 deletion(-)
 create mode 100644 tests/quotactl-success-v.c
 create mode 100755 tests/quotactl-success-v.test
 create mode 100644 tests/quotactl-success.c
 create mode 100755 tests/quotactl-success.test
 create mode 100644 tests/quotactl-xfs-success-v.c
 create mode 100755 tests/quotactl-xfs-success-v.test
 create mode 100644 tests/quotactl-xfs-success.c
 create mode 100755 tests/quotactl-xfs-success.test

diff --git a/tests/.gitignore b/tests/.gitignore
index 4c5b53ba..29a4077c 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -390,6 +390,10 @@ quotactl
 quotactl-v
 quotactl-xfs
 quotactl-xfs-v
+quotactl-success
+quotactl-success-v
+quotactl-xfs-success
+quotactl-xfs-success-v
 read-write
 readahead
 readdir
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 41643f01..48c5fd62 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -153,6 +153,10 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
 	qual_signal \
 	quotactl-v \
 	quotactl-xfs-v \
+	quotactl-success \
+	quotactl-success-v \
+	quotactl-xfs-success \
+	quotactl-xfs-success-v \
 	redirect-fds \
 	restart_syscall \
 	run_expect_termsig \
@@ -273,6 +277,10 @@ DECODER_TESTS = \
 	prctl-tid_address.test \
 	prctl-tsc.test \
 	qual_fault-exit_group.test \
+	quotactl-success.test \
+	quotactl-success-v.test \
+	quotactl-xfs-success.test \
+	quotactl-xfs-success-v.test \
 	readv.test \
 	rt_sigaction.test \
 	scm_rights-fd.test \
diff --git a/tests/quotactl-success-v.c b/tests/quotactl-success-v.c
new file mode 100644
index 00000000..4d1c7b30
--- /dev/null
+++ b/tests/quotactl-success-v.c
@@ -0,0 +1,2 @@
+#define INJECT_RETVAL 42
+#include "quotactl-v.c"
diff --git a/tests/quotactl-success-v.test b/tests/quotactl-success-v.test
new file mode 100755
index 00000000..a9937bd3
--- /dev/null
+++ b/tests/quotactl-success-v.test
@@ -0,0 +1,6 @@
+#!/bin/sh -efu
+
+. "${srcdir=.}/scno_tampering.sh"
+
+run_strace -v -e trace=quotactl -e inject=quotactl:retval=42 ../quotactl-success-v > "$EXP"
+match_diff "$LOG" "$EXP"
diff --git a/tests/quotactl-success.c b/tests/quotactl-success.c
new file mode 100644
index 00000000..aa2b9dc0
--- /dev/null
+++ b/tests/quotactl-success.c
@@ -0,0 +1,2 @@
+#define INJECT_RETVAL 42
+#include "quotactl.c"
diff --git a/tests/quotactl-success.test b/tests/quotactl-success.test
new file mode 100755
index 00000000..6cd95321
--- /dev/null
+++ b/tests/quotactl-success.test
@@ -0,0 +1,6 @@
+#!/bin/sh -efu
+
+. "${srcdir=.}/scno_tampering.sh"
+
+run_strace -e trace=quotactl -e inject=quotactl:retval=42 ../quotactl-success > "$EXP"
+match_diff "$LOG" "$EXP"
diff --git a/tests/quotactl-xfs-success-v.c b/tests/quotactl-xfs-success-v.c
new file mode 100644
index 00000000..6e7b2b51
--- /dev/null
+++ b/tests/quotactl-xfs-success-v.c
@@ -0,0 +1,2 @@
+#define INJECT_RETVAL 42
+#include "quotactl-xfs-v.c"
diff --git a/tests/quotactl-xfs-success-v.test b/tests/quotactl-xfs-success-v.test
new file mode 100755
index 00000000..4c4bb9cd
--- /dev/null
+++ b/tests/quotactl-xfs-success-v.test
@@ -0,0 +1,6 @@
+#!/bin/sh -efu
+
+. "${srcdir=.}/scno_tampering.sh"
+
+run_strace -v -e trace=quotactl -e inject=quotactl:retval=42 ../quotactl-xfs-success-v > "$EXP"
+match_diff "$LOG" "$EXP"
diff --git a/tests/quotactl-xfs-success.c b/tests/quotactl-xfs-success.c
new file mode 100644
index 00000000..f498b8ae
--- /dev/null
+++ b/tests/quotactl-xfs-success.c
@@ -0,0 +1,2 @@
+#define INJECT_RETVAL 42
+#include "quotactl-xfs.c"
diff --git a/tests/quotactl-xfs-success.test b/tests/quotactl-xfs-success.test
new file mode 100755
index 00000000..95077c8a
--- /dev/null
+++ b/tests/quotactl-xfs-success.test
@@ -0,0 +1,6 @@
+#!/bin/sh -efu
+
+. "${srcdir=.}/scno_tampering.sh"
+
+run_strace -e trace=quotactl -e inject=quotactl:retval=42 ../quotactl-xfs-success > "$EXP"
+match_diff "$LOG" "$EXP"
diff --git a/tests/quotactl.h b/tests/quotactl.h
index 352f9270..087747cc 100644
--- a/tests/quotactl.h
+++ b/tests/quotactl.h
@@ -78,6 +78,7 @@ enum check_quotactl_flags {
 	CQF_ADDR_CB   = 1 << CQF_ADDR_CB_BIT,
 };
 
+static const char *errstr;
 
 static inline void
 check_quota(uint32_t flags, int cmd, const char *cmd_str,
@@ -116,6 +117,21 @@ check_quota(uint32_t flags, int cmd, const char *cmd_str,
 	va_end(ap);
 
 	rc = syscall(__NR_quotactl, cmd, special, id, addr);
+
+	errstr = sprintrc(rc);
+
+#ifdef INJECT_RETVAL
+	if (rc != INJECT_RETVAL)
+		error_msg_and_fail("Got a return value of %ld != %d",
+				   rc, INJECT_RETVAL);
+
+	static char inj_errstr[4096];
+
+	snprintf(inj_errstr, sizeof(inj_errstr), "%s (INJECTED)", errstr);
+	errstr = inj_errstr;
+	addr_cb_arg = 0;
+#endif
+
 	printf("quotactl(%s, %s", cmd_str, special_str);
 
 	if (!(flags & CQF_ID_SKIP)) {
@@ -140,7 +156,7 @@ check_quota(uint32_t flags, int cmd, const char *cmd_str,
 		}
 	}
 
-	printf(") = %s\n", sprintrc(rc));
+	printf(") = %s\n", errstr);
 }
 
 
-- 
2.14.4



More information about the Strace-devel mailing list