[PATCH v3] tests: check decoding of successful quotactl

Zhibin Li 08826794brmt at gmail.com
Wed Jul 18 10:00:58 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/quotactl.c: Changed condition rc != 0 to rc < 0 in callback
functions and value of opaque pointer addr_cb_arg in order to check
successful injection.
* tests/quotactl-xfs.c: Likewise.
---
 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-xfs.c              | 12 ++++++------
 tests/quotactl.c                  | 12 ++++++------
 tests/quotactl.h                  | 17 ++++++++++++++++-
 13 files changed, 72 insertions(+), 13 deletions(-)
 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-xfs.c b/tests/quotactl-xfs.c
index 30d20c1b..2f474b5e 100644
--- a/tests/quotactl-xfs.c
+++ b/tests/quotactl-xfs.c
@@ -92,7 +92,7 @@ print_xdisk_quota(int rc, void *ptr, void *arg)
 	struct fs_disk_quota *dq = ptr;
 	long out_arg = (long) arg;
 
-	if (((rc != 0) && out_arg) || (out_arg > 1)) {
+	if (((rc < 0) && out_arg) || (out_arg > 1)) {
 		printf("%p", dq);
 		return;
 	}
@@ -132,7 +132,7 @@ print_xquota_stat(int rc, void *ptr, void *arg)
 	struct fs_quota_stat *qs = ptr;
 	long out_arg = (long) arg;
 
-	if (((rc != 0) && out_arg) || (out_arg > 1)) {
+	if (((rc < 0) && out_arg) || (out_arg > 1)) {
 		printf("%p", qs);
 		return;
 	}
@@ -166,7 +166,7 @@ print_xquota_statv(int rc, void *ptr, void *arg)
 	struct fs_quota_statv *qs = ptr;
 	long out_arg = (long) arg;
 
-	if (((rc != 0) && out_arg) || (out_arg > 1)) {
+	if (((rc < 0) && out_arg) || (out_arg > 1)) {
 		printf("%p", qs);
 		return;
 	}
@@ -269,7 +269,7 @@ main(void)
 		    (intptr_t) 1);
 
 	check_quota(CQF_ADDR_CB, ARG_STR(QCMD(Q_XGETQUOTA, GRPQUOTA)),
-		    ARG_STR(NULL), -1, xdq, print_xdisk_quota, (intptr_t) 2);
+		    ARG_STR(NULL), -1, xdq, print_xdisk_quota, (intptr_t) 1);
 
 
 	/* Q_XGETNEXTQUOTA */
@@ -299,7 +299,7 @@ main(void)
 
 	check_quota(CQF_ID_SKIP | CQF_ADDR_CB,
 		    ARG_STR(QCMD(Q_XGETQSTAT, USRQUOTA)),
-		    ARG_STR("NULL"), xqstat, print_xquota_stat, (intptr_t) 2);
+		    ARG_STR("NULL"), xqstat, print_xquota_stat, (intptr_t) 1);
 
 	check_quota(CQF_ID_SKIP,
 		    ARG_STR(QCMD(Q_XGETQSTAT, PRJQUOTA)),
@@ -315,7 +315,7 @@ main(void)
 
 	check_quota(CQF_ID_SKIP | CQF_ADDR_CB,
 		    ARG_STR(QCMD(Q_XGETQSTATV, GRPQUOTA)),
-		    ARG_STR(NULL), xqstatv, print_xquota_statv, (intptr_t) 2);
+		    ARG_STR(NULL), xqstatv, print_xquota_statv, (intptr_t) 1);
 
 	check_quota(CQF_ID_SKIP,
 		    ARG_STR(QCMD(Q_XGETQSTATV, PRJQUOTA)),
diff --git a/tests/quotactl.c b/tests/quotactl.c
index 90156a17..c8b1775e 100644
--- a/tests/quotactl.c
+++ b/tests/quotactl.c
@@ -83,7 +83,7 @@ print_dqblk(long rc, void *ptr, void *arg)
 	struct if_dqblk *db = ptr;
 	long out_arg = (long) arg;
 
-	if (((rc != 0) && out_arg) || (out_arg > 1)) {
+	if (((rc < 0) && out_arg) || (out_arg > 1)) {
 		printf("%p", db);
 		return;
 	}
@@ -113,7 +113,7 @@ print_nextdqblk(long rc, void *ptr, void *arg)
 	struct if_nextdqblk *db = ptr;
 	long out_arg = (long) arg;
 
-	if (((rc != 0) && out_arg) || (out_arg > 1)) {
+	if (((rc < 0) && out_arg) || (out_arg > 1)) {
 		printf("%p", db);
 		return;
 	}
@@ -146,7 +146,7 @@ print_dqinfo(long rc, void *ptr, void *arg)
 	struct if_dqinfo *di = ptr;
 	long out_arg = (long) arg;
 
-	if (((rc != 0) && out_arg) || (out_arg > 1)) {
+	if (((rc < 0) && out_arg) || (out_arg > 1)) {
 		printf("%p", di);
 		return;
 	}
@@ -168,7 +168,7 @@ print_dqfmt(long rc, void *ptr, void *arg)
 	long out_arg = (long) arg;
 	const char *fmtstr;
 
-	if (((rc != 0) && out_arg) || (out_arg > 1)) {
+	if (((rc < 0) && out_arg) || (out_arg > 1)) {
 		printf("%p", fmtval);
 		return;
 	}
@@ -272,7 +272,7 @@ main(void)
 		    (intptr_t) 1);
 
 	check_quota(CQF_ADDR_CB, ARG_STR(QCMD(Q_GETQUOTA, GRPQUOTA)),
-		    ARG_STR(NULL), -1, dqblk, print_dqblk, (intptr_t) 2);
+		    ARG_STR(NULL), -1, dqblk, print_dqblk, (intptr_t) 1);
 
 
 	/* Q_GETNEXTQUOTA */
@@ -303,7 +303,7 @@ main(void)
 	check_quota(CQF_ID_SKIP | CQF_ADDR_CB,
 		    ARG_STR(QCMD(Q_GETINFO, GRPQUOTA)),
 		    bogus_special, bogus_special_str, dqinfo,
-		    print_dqinfo, (intptr_t) 2);
+		    print_dqinfo, (intptr_t) 1);
 
 	/* Q_SETINFO */
 
diff --git a/tests/quotactl.h b/tests/quotactl.h
index 352f9270..e51ee975 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,20 @@ 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;
+#endif
+
 	printf("quotactl(%s, %s", cmd_str, special_str);
 
 	if (!(flags & CQF_ID_SKIP)) {
@@ -140,7 +155,7 @@ check_quota(uint32_t flags, int cmd, const char *cmd_str,
 		}
 	}
 
-	printf(") = %s\n", sprintrc(rc));
+	printf(") = %s\n", errstr);
 }
 
 
-- 
2.17.1



More information about the Strace-devel mailing list