[PATCH v4 1/2] tests: unify common code in prctl decoder tests
Srikavin Ramkumar
srikavinramkumar at gmail.com
Mon Jul 12 16:14:24 UTC 2021
* tests/prctl.sh: Extract common test code.
* tests/gen_tests.in (prctl-arg2-intptr, prctl-dumpable, prctl-name,
prctl-no-args, prctl-pdeathsig, prctl-seccomp-filter-v, prctl-securebits,
prctl-tid_address, prctl-tsc): New entries.
* tests/Makefile.am (DECODER_TESTS): Remove prctl-arg2-intptr.test,
prctl-dumpable.test, prctl-name.test, prctl-no-args.test,
prctl-pdeathsig.test, prctl-seccomp-filter-v.test, prctl-securebits.test,
prctl-tid_address.test, and prctl-tsc.test.
(EXTRA_DIST): Add prctl.sh.
* tests/prctl-seccomp-strict.test: Replace output filtering with a sed filter.
* tests/prctl-spec-inject.test: Likewise.
* tests/prctl-arg2-intptr.c: Add a marker to indicate the start of the
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-seccomp-filter-v.c: Likewise.
* tests/prctl-seccomp-strict.c: Likewise.
* tests/prctl-securebits.c: Likewise.
* tests/prctl-tid_address.c: Likewise.
* tests/prctl-tsc.c: Likewise.
* tests/prctl-arg2-intptr.test: Remove file.
* tests/prctl-dumpable.test: Likewise.
* tests/prctl-name.test: Likewise.
* tests/prctl-no-args.test: Likewise.
* tests/prctl-pdeathsig.test: Likewise.
* tests/prctl-seccomp-filter-v.test: Likewise.
* tests/prctl-securebits.test: Likewise.
* tests/prctl-spec-inject.c: Likewise.
* tests/prctl-tid_address.test: Likewise.
* tests/prctl-tsc.test: Likewise.
---
Sorry for the delay since v3.
Changes since v3:
- Updated commit descriptions to include modified list entries.
- Shortened commit message.
- Generate prctl-seccomp-filter-v.test as well.
- Replaced grep with marker syscall method in prctl-seccomp-strict.test,
prctl-fp-mode.test, and prctl-spec-inject.test
- Reordered header declaration in prctl-name.c
- Removed `-a25` in prctl.sh
I initially tried to use a similar synchronization method as ioctl-success.sh
for prctl-fp-mode, but it might run into issues on MIPS hardware since the
injected synchronization value may match the actual return value which would
throw off the synchronization.
I tried something similar to
strace -e trace=prctl -e inject=ioctl:retval=42:when=256 \
-e inject=prctl:error=ENOTTY:when=257+ \
tests/prctl-fp-mode 256 42 -1
but it looks like only the first inject expression is honored.
Instead of using the synchronization mechanism, I used the same approach with
the marker syscall to just filter out syscalls during program initialization.
I don't think the invalid injected return value should cause issues, but I have
not tested it on MIPS.
tests/Makefile.am | 10 +---------
tests/gen_tests.in | 9 +++++++++
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-seccomp-filter-v.c | 2 ++
tests/prctl-seccomp-filter-v.test | 16 ----------------
tests/prctl-seccomp-strict.c | 2 ++
tests/prctl-seccomp-strict.test | 2 +-
tests/prctl-securebits.c | 2 ++
tests/prctl-securebits.test | 16 ----------------
tests/prctl-spec-inject.c | 2 ++
tests/prctl-spec-inject.test | 3 +--
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 ++++++++++++++++
25 files changed, 55 insertions(+), 160 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-seccomp-filter-v.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..86687c800 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -418,17 +418,8 @@ 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 +580,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..125a0a5f2 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -564,6 +564,15 @@ 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-seccomp-filter-v +prctl.sh -v
+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..566ec082d 100644
--- a/tests/prctl-name.c
+++ b/tests/prctl-name.c
@@ -10,6 +10,7 @@
*/
#include "tests.h"
+#include "scno.h"
#include <stdio.h>
#include <string.h>
#include <unistd.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-seccomp-filter-v.c b/tests/prctl-seccomp-filter-v.c
index f8c39be2e..8115d8f9e 100644
--- a/tests/prctl-seccomp-filter-v.c
+++ b/tests/prctl-seccomp-filter-v.c
@@ -68,6 +68,8 @@ main(void)
{
int fds[2];
+ syscall(__NR_prctl, -1U, -2U, -3U, -4U, -5U);
+
puts("prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) = 0");
printf("prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, {len=%u, filter=[",
diff --git a/tests/prctl-seccomp-filter-v.test b/tests/prctl-seccomp-filter-v.test
deleted file mode 100755
index 9f94a66ed..000000000
--- a/tests/prctl-seccomp-filter-v.test
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-#
-# Check verbose decoding of prctl PR_SET_SECCOMP SECCOMP_MODE_FILTER.
-#
-# 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 -v -eprctl $args > "$EXP"
-grep -v '^prctl(PR_GET_' < "$LOG" > "$OUT"
-match_diff "$OUT" "$EXP"
diff --git a/tests/prctl-seccomp-strict.c b/tests/prctl-seccomp-strict.c
index 3867ca176..682a5a8c5 100644
--- a/tests/prctl-seccomp-strict.c
+++ b/tests/prctl-seccomp-strict.c
@@ -19,6 +19,8 @@ main(void)
"prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT) = 0\n";
static const char text2[] = "+++ exited with 0 +++\n";
+ syscall(__NR_prctl, -1U, -2U, -3U, -4U, -5U);
+
int rc = prctl(PR_SET_SECCOMP, -1L, 1, 2, 3);
printf("prctl(PR_SET_SECCOMP, %#lx /* SECCOMP_MODE_??? */, 0x1, 0x2, 0x3)"
" = %d %s (%m)\n", -1L, rc, errno2name());
diff --git a/tests/prctl-seccomp-strict.test b/tests/prctl-seccomp-strict.test
index e7e23df29..a16de8ba1 100755
--- a/tests/prctl-seccomp-strict.test
+++ b/tests/prctl-seccomp-strict.test
@@ -19,5 +19,5 @@ set -- "../$NAME"
esac
}
run_strace -eprctl "$@" > "$EXP"
-grep -v '^prctl(PR_GET_' < "$LOG" > "$OUT"
+sed '0,/^prctl(0xffffffff \/\* PR_??? \*\/, 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xfffffffb) = -1 /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-spec-inject.c b/tests/prctl-spec-inject.c
index 18ba584b5..58455e464 100644
--- a/tests/prctl-spec-inject.c
+++ b/tests/prctl-spec-inject.c
@@ -86,6 +86,8 @@ main(int argc, char **argv)
injected_val = strtol(argv[1], NULL, 0);
+ syscall(__NR_prctl, -1U, -2U, -3U, -4U, -5U);
+
/* PR_GET_SPECULATION_CTRL */
rc = do_prctl(52, 2, bogus_arg3);
printf("prctl(PR_GET_SPECULATION_CTRL, 0x2 /* PR_SPEC_??? */) "
diff --git a/tests/prctl-spec-inject.test b/tests/prctl-spec-inject.test
index c86fc204e..02887817f 100755
--- a/tests/prctl-spec-inject.test
+++ b/tests/prctl-spec-inject.test
@@ -21,8 +21,7 @@ test_run_rval()
injexpr="$1"; shift
run_strace $fault_args$injexpr $prog $rval > "$EXP"
- LC_ALL=C grep -Ev '^prctl\(PR_[GS]ET_([^S][^P][^E][^C]])' \
- < "$LOG" > "$OUT"
+ sed '0,/^prctl(0xffffffff \/\* PR_??? \*\/, 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xfffffffb) = .\+ (INJECTED)/d' < "$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..1e0029093
--- /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 -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