[PATCH v3 1/2] tests: unify common code in prctl decoder tests

Srikavin Ramkumar srikavinramkumar at gmail.com
Thu Jun 3 20:17:53 UTC 2021


* tests/prctl.sh: Extract common test code.
* tests/gen_tests.in: Add entries.
* tests/Makefile.am: Remove entries for deleted tests.
* tests/prctl-arg2-intptr.c: Add marker to indicate start of expected output.
* tests/prctl-dumpable.c: Likewise.
* tests/prctl-name.c: Likewise.
* tests/prctl-no-args.c: Likewise.
* tests/prctl-pdeathsig.c: Likewise.
* tests/prctl-securebits.c: Likewise.
* tests/prctl-tid_address.c: Likewise.
* tests/prctl-tsc.c: Likewise.
* tests/prctl-arg2-intptr.test: Delete file.
* tests/prctl-dumpable.test: Likewise.
* tests/prctl-name.test: Likewise.
* tests/prctl-no-args.test: Likewise.
* tests/prctl-pdeathsig.test: Likewise.
* tests/prctl-securebits.test: Likewise.
* tests/prctl-tid_address.test: Likewise.
* tests/prctl-tsc.test: Likewise.
---
 Changes since V2:
   - Rebased onto master
   - Replaced duplicated prctl test code with test generator


 tests/Makefile.am            |  9 +--------
 tests/gen_tests.in           |  8 ++++++++
 tests/prctl-arg2-intptr.c    |  2 ++
 tests/prctl-arg2-intptr.test | 18 ------------------
 tests/prctl-dumpable.c       |  2 ++
 tests/prctl-dumpable.test    | 16 ----------------
 tests/prctl-name.c           |  3 +++
 tests/prctl-name.test        | 16 ----------------
 tests/prctl-no-args.c        |  3 +++
 tests/prctl-no-args.test     | 18 ------------------
 tests/prctl-pdeathsig.c      |  3 +++
 tests/prctl-pdeathsig.test   | 16 ----------------
 tests/prctl-securebits.c     |  2 ++
 tests/prctl-securebits.test  | 16 ----------------
 tests/prctl-tid_address.c    |  3 +++
 tests/prctl-tid_address.test | 16 ----------------
 tests/prctl-tsc.c            |  3 +++
 tests/prctl-tsc.test         | 16 ----------------
 tests/prctl.sh               | 16 ++++++++++++++++
 19 files changed, 46 insertions(+), 140 deletions(-)
 delete mode 100755 tests/prctl-arg2-intptr.test
 delete mode 100755 tests/prctl-dumpable.test
 delete mode 100755 tests/prctl-name.test
 delete mode 100755 tests/prctl-no-args.test
 delete mode 100755 tests/prctl-pdeathsig.test
 delete mode 100755 tests/prctl-securebits.test
 delete mode 100755 tests/prctl-tid_address.test
 delete mode 100755 tests/prctl-tsc.test
 create mode 100644 tests/prctl.sh

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 126e84361..d909573bb 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -418,17 +418,9 @@ DECODER_TESTS = \
 	pipe.test \
 	poll-P.test \
 	poll.test \
-	prctl-arg2-intptr.test \
-	prctl-dumpable.test \
-	prctl-name.test \
-	prctl-no-args.test \
-	prctl-pdeathsig.test \
 	prctl-seccomp-filter-v.test \
 	prctl-seccomp-strict.test \
-	prctl-securebits.test \
 	prctl-spec-inject.test \
-	prctl-tid_address.test \
-	prctl-tsc.test \
 	qual_fault-exit_group.test \
 	quotactl-success-v.test \
 	quotactl-success.test \
@@ -589,6 +581,7 @@ EXTRA_DIST = \
 	pipe.expected \
 	poke-range.expected \
 	poke-unaligned.expected \
+	prctl.sh \
 	print_user_desc.c \
 	printsignal.c \
 	printxval.c \
diff --git a/tests/gen_tests.in b/tests/gen_tests.in
index 747383368..3db831d44 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -564,6 +564,14 @@ poke-sendfile	--trace=/sendfile --inject=all:poke_enter=@arg3=0000000000000000:p
 ppoll	-s2
 ppoll-P	-s2 -e trace=ppoll -P /dev/full 9>>/dev/full
 ppoll-v	-v -s2 -e trace=ppoll
+prctl-arg2-intptr	+prctl.sh -a25
+prctl-dumpable		+prctl.sh -a23
+prctl-name			+prctl.sh -a23
+prctl-no-args		+prctl.sh -a21
+prctl-pdeathsig		+prctl.sh -a30
+prctl-securebits	+prctl.sh -a25
+prctl-tid_address	+prctl.sh -a23
+prctl-tsc			+prctl.sh -a24
 pread64-pwrite64	-a21 -eread=0 -ewrite=1 -e trace=pread64,pwrite64 -P pread64-pwrite64-tmpfile -P /dev/zero -P /dev/null
 preadv	-a21
 preadv-pwritev	-a19 -eread=0 -ewrite=1 -e trace=preadv,pwritev
diff --git a/tests/prctl-arg2-intptr.c b/tests/prctl-arg2-intptr.c
index d2dd32110..43cb8192a 100644
--- a/tests/prctl-arg2-intptr.c
+++ b/tests/prctl-arg2-intptr.c
@@ -53,6 +53,8 @@ main(void)
 	long rc;
 	unsigned int i;
 
+	syscall(__NR_prctl, -1U, -2U, -3U, -4U, -5U);
+
 	for (i = 0; i < ARRAY_SIZE(options); ++i) {
 		prctl(options[i].val | bogus_op_bits, 0);
 		printf("prctl(%s, NULL) = %s\n", options[i].str, errstr);
diff --git a/tests/prctl-arg2-intptr.test b/tests/prctl-arg2-intptr.test
deleted file mode 100755
index feb5a2b94..000000000
--- a/tests/prctl-arg2-intptr.test
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/sh
-#
-# Check decoding of prctl PR_GET_CHILD_SUBREAPER, PR_GET_ENDIAN, PR_GET_FPEMU,
-# and PR_GET_FPEXC operations.
-#
-# Copyright (c) 2016-2018 The strace developers.
-# All rights reserved.
-#
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-. "${srcdir=.}/init.sh"
-
-check_prog grep
-run_prog > /dev/null
-run_strace -a25 -eprctl $args > "$EXP"
-LC_ALL=C grep -Ev '^prctl\(PR_[GS]ET_([^CEF]|.[^HNP]|..[^DEI])' \
-	< "$LOG" > "$OUT"
-match_diff "$OUT" "$EXP"
diff --git a/tests/prctl-dumpable.c b/tests/prctl-dumpable.c
index 14c331faa..e56005311 100644
--- a/tests/prctl-dumpable.c
+++ b/tests/prctl-dumpable.c
@@ -33,6 +33,8 @@ prctl(kernel_ulong_t arg1, kernel_ulong_t arg2)
 int
 main(void)
 {
+	syscall(__NR_prctl, -1U, -2U, -3U, -4U, -5U);
+
 	static const kernel_ulong_t bogus_dumpable1 =
 		(kernel_ulong_t) 0xdeadc0de00000001ULL;
 	static const kernel_ulong_t bogus_dumpable2 =
diff --git a/tests/prctl-dumpable.test b/tests/prctl-dumpable.test
deleted file mode 100755
index 8662f79c1..000000000
--- a/tests/prctl-dumpable.test
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-#
-# Check decoding of prctl PR_GET_DUMPABLE and PR_SET_DUMPABLE operations.
-#
-# Copyright (c) 2016-2018 The strace developers.
-# All rights reserved.
-#
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-. "${srcdir=.}/init.sh"
-
-check_prog grep
-run_prog > /dev/null
-run_strace -a23 -eprctl $args > "$EXP"
-grep -v '^prctl(PR_[GS]ET_[^D][^U]' < "$LOG" > "$OUT"
-match_diff "$OUT" "$EXP"
diff --git a/tests/prctl-name.c b/tests/prctl-name.c
index 419a31062..3b95361dd 100644
--- a/tests/prctl-name.c
+++ b/tests/prctl-name.c
@@ -9,6 +9,7 @@
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
+#include "scno.h"
 #include "tests.h"
 #include <stdio.h>
 #include <string.h>
@@ -18,6 +19,8 @@
 int
 main(void)
 {
+	syscall(__NR_prctl, -1U, -2U, -3U, -4U, -5U);
+
 	static const char str[] = "0123456789abcdef";
 	static const int len = sizeof(str) - 1;
 	char *name = tail_memdup(str, sizeof(str));
diff --git a/tests/prctl-name.test b/tests/prctl-name.test
deleted file mode 100755
index b19efc0f6..000000000
--- a/tests/prctl-name.test
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-#
-# Check decoding of prctl PR_GET_NAME/PR_SET_NAME operations.
-#
-# Copyright (c) 2016-2018 The strace developers.
-# All rights reserved.
-#
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-. "${srcdir=.}/init.sh"
-
-check_prog grep
-run_prog > /dev/null
-run_strace -a23 -eprctl $args > "$EXP"
-grep -v '^prctl(PR_GET_[^N][^A]' < "$LOG" > "$OUT"
-match_diff "$OUT" "$EXP"
diff --git a/tests/prctl-no-args.c b/tests/prctl-no-args.c
index 9d33ae743..55c56a124 100644
--- a/tests/prctl-no-args.c
+++ b/tests/prctl-no-args.c
@@ -39,6 +39,9 @@ main(void)
 	};
 
 	TAIL_ALLOC_OBJECT_CONST_PTR(unsigned int, ptr);
+
+	syscall(__NR_prctl, -1U, -2U, -3U, -4U, -5U);
+
 	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(options); i++) {
diff --git a/tests/prctl-no-args.test b/tests/prctl-no-args.test
deleted file mode 100755
index 72d0f5253..000000000
--- a/tests/prctl-no-args.test
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/sh
-#
-# Check decoding of prctl PR_GET_KEEPCAPS, PR_GET_SECCOMP, PR_GET_TIMERSLACK,
-# PR_GET_TIMING, PR_TASK_PERF_EVENTS_DISABLE, and PR_TASK_PERF_EVENTS_ENABLE
-# operations.
-#
-# Copyright (c) 2016-2018 The strace developers.
-# All rights reserved.
-#
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-. "${srcdir=.}/init.sh"
-
-check_prog grep
-run_prog > /dev/null
-run_strace -a21 -eprctl $args > "$EXP"
-grep -v '^prctl(PR_[GS]ET_[^KST][^EI][^CEM]' < "$LOG" > "$OUT"
-match_diff "$OUT" "$EXP"
diff --git a/tests/prctl-pdeathsig.c b/tests/prctl-pdeathsig.c
index 4b7944bbf..ef527aec3 100644
--- a/tests/prctl-pdeathsig.c
+++ b/tests/prctl-pdeathsig.c
@@ -23,6 +23,9 @@ main(void)
 		(kernel_ulong_t) 0xbadc0deddeadfeedULL;
 
 	TAIL_ALLOC_OBJECT_CONST_PTR(int, pdeathsig);
+
+	syscall(__NR_prctl, -1U, -2U, -3U, -4U, -5U);
+
 	long rc;
 
 	rc = syscall(__NR_prctl, PR_SET_PDEATHSIG, bogus_signal);
diff --git a/tests/prctl-pdeathsig.test b/tests/prctl-pdeathsig.test
deleted file mode 100755
index faa40dbb2..000000000
--- a/tests/prctl-pdeathsig.test
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-#
-# Check prctl PR_GET_PDEATHSIG PR_SET_PDEATHSIG decoding.
-#
-# Copyright (c) 2016-2018 The strace developers.
-# All rights reserved.
-#
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-. "${srcdir=.}/init.sh"
-
-check_prog grep
-run_prog > /dev/null
-run_strace -a30 -eprctl $args > "$EXP"
-grep -v '^prctl(PR_[GS]ET_[^P][^D]' < "$LOG" > "$OUT"
-match_diff "$OUT" "$EXP"
diff --git a/tests/prctl-securebits.c b/tests/prctl-securebits.c
index d97b04552..ea7050db3 100644
--- a/tests/prctl-securebits.c
+++ b/tests/prctl-securebits.c
@@ -34,6 +34,8 @@ prctl(kernel_ulong_t arg1, kernel_ulong_t arg2)
 int
 main(void)
 {
+	syscall(__NR_prctl, -1U, -2U, -3U, -4U, -5U);
+
 	static const kernel_ulong_t bits1 =
 		(kernel_ulong_t) 0xdeadc0defacebeefULL;
 	static const kernel_ulong_t bits2 =
diff --git a/tests/prctl-securebits.test b/tests/prctl-securebits.test
deleted file mode 100755
index e50dc2ebd..000000000
--- a/tests/prctl-securebits.test
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-#
-# Check decoding of prctl PR_GET_SECUREBITS/PR_SET_SECUREBITS operations.
-#
-# Copyright (c) 2016-2018 The strace developers.
-# All rights reserved.
-#
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-. "${srcdir=.}/init.sh"
-
-check_prog grep
-run_prog > /dev/null
-run_strace -a25 -eprctl $args > "$EXP"
-grep -v '^prctl(PR_[GS]ET_[^S][^E][^C][^U]' < "$LOG" > "$OUT"
-match_diff "$OUT" "$EXP"
diff --git a/tests/prctl-tid_address.c b/tests/prctl-tid_address.c
index 2f3fdd245..5d7b7ad53 100644
--- a/tests/prctl-tid_address.c
+++ b/tests/prctl-tid_address.c
@@ -38,6 +38,9 @@ main(void)
 
 	/* Note that kernel puts kernel-sized pointer even on x32 */
 	TAIL_ALLOC_OBJECT_CONST_PTR(kernel_ulong_t, ptr);
+
+	syscall(__NR_prctl, -1U, -2U, -3U, -4U, -5U);
+
 	long rc;
 	long set_ok;
 
diff --git a/tests/prctl-tid_address.test b/tests/prctl-tid_address.test
deleted file mode 100755
index f4a229f91..000000000
--- a/tests/prctl-tid_address.test
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-#
-# Check decoding of prctl PR_GET_TID_ADDRESS operation.
-#
-# Copyright (c) 2016-2018 The strace developers.
-# All rights reserved.
-#
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-. "${srcdir=.}/init.sh"
-
-check_prog grep
-run_prog > /dev/null
-run_strace -a23 -eprctl $args > "$EXP"
-LC_ALL=C grep -Ev '^prctl\(PR_[GS]ET_([^T]|.[^I]|..[^D])' < "$LOG" > "$OUT"
-match_diff "$OUT" "$EXP"
diff --git a/tests/prctl-tsc.c b/tests/prctl-tsc.c
index e0be8bc18..0bf97a5a2 100644
--- a/tests/prctl-tsc.c
+++ b/tests/prctl-tsc.c
@@ -22,6 +22,9 @@ main(void)
 		(kernel_ulong_t) 0xdeadc0defacebeefULL;
 
 	TAIL_ALLOC_OBJECT_CONST_PTR(int, tsc);
+
+	syscall(__NR_prctl, -1U, -2U, -3U, -4U, -5U);
+
 	long rc;
 
 	rc = syscall(__NR_prctl, PR_SET_TSC, 0);
diff --git a/tests/prctl-tsc.test b/tests/prctl-tsc.test
deleted file mode 100755
index 6dd891d61..000000000
--- a/tests/prctl-tsc.test
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-#
-# Check prctl PR_GET_TSC PR_SET_TSC decoding.
-#
-# Copyright (c) 2016-2018 The strace developers.
-# All rights reserved.
-#
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-. "${srcdir=.}/init.sh"
-
-check_prog grep
-run_prog > /dev/null
-run_strace -a24 -eprctl $args > "$EXP"
-grep -v '^prctl(PR_[GS]ET_[^T][^S]' < "$LOG" > "$OUT"
-match_diff "$OUT" "$EXP"
diff --git a/tests/prctl.sh b/tests/prctl.sh
new file mode 100644
index 000000000..3d4f37d3f
--- /dev/null
+++ b/tests/prctl.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+#
+# Check prctl syscall decoding.
+#
+# Copyright (c) 2021 The strace developers.
+# All rights reserved.
+#
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+. "${srcdir=.}/init.sh"
+
+check_prog sed
+run_prog > /dev/null
+run_strace -a25 -eprctl "$@" $args > "$EXP"
+sed '0,/^prctl(0xffffffff \/\* PR_??? \*\/, 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xfffffffb) = -1 /d' < "$LOG" > "$OUT"
+match_diff "$OUT" "$EXP"
-- 
2.25.1



More information about the Strace-devel mailing list