[PATCH 1/3] selftests: riscv: Fix false passes in vector ptrace CSR tests
From: Ze Huang
Date: Sun Dec 06 2026 - 05:06:18 EST
The vector CSR test accepts any ptrace stop. If hardware does
not support e32,mf4, the tracee stop with SIGILL before reaching the
ebreak, and the test will report success anyway.
Use e8,mf4, which Zve32x guarantees, to retain fractional LMUL
coverage without probing an optional configuration. Require SIGTRAP
at each expected breakpoint so an unexpected stop fails the test.
Fixes: 849f05ae1ea6 ("selftests: riscv: verify ptrace accepts valid vector csr values")
Signed-off-by: Ze Huang <ze.huang@xxxxxxxxxxxxxxxx>
---
.../selftests/riscv/vector/validate_v_ptrace.c | 53 ++++++++++------------
1 file changed, 25 insertions(+), 28 deletions(-)
diff --git a/tools/testing/selftests/riscv/vector/validate_v_ptrace.c b/tools/testing/selftests/riscv/vector/validate_v_ptrace.c
index a388b7963d47..101c84143213 100644
--- a/tools/testing/selftests/riscv/vector/validate_v_ptrace.c
+++ b/tools/testing/selftests/riscv/vector/validate_v_ptrace.c
@@ -212,6 +212,25 @@ TEST(ptrace_v_early_debug)
}
}
+static void continue_to_next_ebreak(struct __test_metadata *_metadata, pid_t pid)
+{
+ struct user_regs_struct regs;
+ struct iovec iov = {
+ .iov_base = ®s,
+ .iov_len = sizeof(regs),
+ };
+ int status;
+
+ ASSERT_EQ(0, ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &iov));
+ regs.pc += 4; /* Skip the uncompressed ebreak. */
+ ASSERT_EQ(0, ptrace(PTRACE_SETREGSET, pid, NT_PRSTATUS, &iov));
+
+ ASSERT_EQ(0, ptrace(PTRACE_CONT, pid, NULL, NULL));
+ ASSERT_EQ(pid, waitpid(pid, &status, 0));
+ ASSERT_TRUE(WIFSTOPPED(status));
+ ASSERT_EQ(SIGTRAP, WSTOPSIG(status));
+}
+
TEST(ptrace_v_syscall_clobbering)
{
pid_t pid;
@@ -679,15 +698,15 @@ FIXTURE_VARIANT(v_csr_valid)
unsigned long spec;
};
-/* valid for VLEN >= 128: LMUL= 1/4, SEW = 32 */
+/* valid for VLEN >= 32: LMUL= 1/4, SEW = 8 */
FIXTURE_VARIANT_ADD(v_csr_valid, frac_lmul1)
{
.vstart = 0x0,
.vl = 0x0,
- .vtype = 0x16,
+ .vtype = 0x06,
.vcsr = 0x0,
.vlenb_mul = 0x1,
- .vlenb_min = 0x10,
+ .vlenb_min = 0x4,
.vlenb_max = 0x0,
.spec = VECTOR_1_0,
};
@@ -797,7 +816,6 @@ TEST_F(v_csr_valid, ptrace_v_valid_values)
".option pop\n");
} else {
struct __riscv_v_regset_state *regset_data;
- struct user_regs_struct regs;
size_t regset_size;
struct iovec iov;
int status;
@@ -817,6 +835,7 @@ TEST_F(v_csr_valid, ptrace_v_valid_values)
ASSERT_EQ(0, ptrace(PTRACE_CONT, pid, NULL, NULL));
ASSERT_EQ(pid, waitpid(pid, &status, 0));
ASSERT_TRUE(WIFSTOPPED(status));
+ ASSERT_EQ(SIGTRAP, WSTOPSIG(status));
/* read tracee vector csr regs using ptrace GETREGSET */
@@ -854,18 +873,7 @@ TEST_F(v_csr_valid, ptrace_v_valid_values)
ASSERT_EQ(0, ptrace(PTRACE_SETREGSET, pid, NT_RISCV_VECTOR, &iov));
- /* skip 1st ebreak, then resume and wait for the 2nd ebreak */
-
- iov.iov_base = ®s;
- iov.iov_len = sizeof(regs);
-
- ASSERT_EQ(0, ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &iov));
- regs.pc += 4;
- ASSERT_EQ(0, ptrace(PTRACE_SETREGSET, pid, NT_PRSTATUS, &iov));
-
- ASSERT_EQ(0, ptrace(PTRACE_CONT, pid, NULL, NULL));
- ASSERT_EQ(pid, waitpid(pid, &status, 0));
- ASSERT_TRUE(WIFSTOPPED(status));
+ continue_to_next_ebreak(_metadata, pid);
/* read tracee vector csr regs using ptrace GETREGSET */
@@ -882,18 +890,7 @@ TEST_F(v_csr_valid, ptrace_v_valid_values)
EXPECT_EQ(regset_data->vl, variant->vl);
EXPECT_EQ(regset_data->vlenb, vlenb);
- /* skip 2nd ebreak, then resume and wait for the 3rd ebreak */
-
- iov.iov_base = ®s;
- iov.iov_len = sizeof(regs);
-
- ASSERT_EQ(0, ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &iov));
- regs.pc += 4;
- ASSERT_EQ(0, ptrace(PTRACE_SETREGSET, pid, NT_PRSTATUS, &iov));
-
- ASSERT_EQ(0, ptrace(PTRACE_CONT, pid, NULL, NULL));
- ASSERT_EQ(pid, waitpid(pid, &status, 0));
- ASSERT_TRUE(WIFSTOPPED(status));
+ continue_to_next_ebreak(_metadata, pid);
/* read tracee vector csr regs using ptrace GETREGSET */
--
2.56.1