Skip to contentSkip to conversation

selftests: riscv: vector: Fix the checks of the child's exit status

PATCH New Danish Khateeb 1 participant 3 messages Sep 26

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover selftests: riscv: vector: Fix the checks of the child's exit status

Two fixes for vstate_exec_nolibc, found through a kernel test robot warning [1]. Patch 1 checks the return value of waitpid(), which GCC warns about. Patch 2 fixes a check which never matches, so that a child reporting a failure no longer lets the tests pass.

Tested in QEMU (virt, rv64 with and without V) on a v7.3-rc1 defconfig kernel, running vstate_prctl as init:

- vstate_prctl passes 13/13 with and without the series.
- With the child's vstate_ctrl check forced to fail, it still passes 13/13 without patch 2, and fails the 6 affected tests with it.
- The warning is gone with GCC 14.2 and 16.2.

[1] https://lore.kernel.org/r/[email protected]/

Danish Khateeb (2):
selftests: riscv: vstate_exec_nolibc: Check the return value of
waitpid()
selftests: riscv: vector: Fix the check for children exiting with -1

 tools/testing/selftests/riscv/vector/v_helpers.c          | 2 +-
 tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

base-commit: a06776565b9e73512e880a95b66c198ae8e7e24a

Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/2 selftests: riscv: vstate_exec_nolibc: Check the return value of waitpid()

vstate_exec_nolibc does not check whether waitpid() succeeds, so status is used uninitialized if it fails. Since nolibc implements waitpid() on top of waitid(), GCC can see this, and warns:

vstate_exec_nolibc.c:78:12: warning: 'status' may be used uninitialized [-Wmaybe-uninitialized]

Fail if waitpid() fails, as launch_test() does for the same call.

Fixes 7cf6198ce22d ("selftests: Test RISC-V Vector prctl interface")
Assisted-by LLM
---
 tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c +4 -0
index 12f1b1b1c7aa..5f53e5e8ac52 100644
@@ -69,6 +69,10 @@ int main(int argc, char **argv)
 	}
 
 	rc = waitpid(-1, &status, 0);
+	if (rc == -1) {
+		puts("waitpid failed\n");
+		exit(-1);
+	}
 
 	if (WIFEXITED(status) && WEXITSTATUS(status) == -1) {
 		puts("child exited abnormally\n");
Signature · 1 line
2.55.0
#2 lore raw

PATCH 2/2 selftests: riscv: vector: Fix the check for children exiting with -1

In reply to Danish Khateeb

vstate_exec_nolibc and launch_test() look for a child which failed with exit(-1) by checking WEXITSTATUS(status) == -1. But WEXITSTATUS() only returns the low 8 bits of the exit code, so the check never matches.

vstate_exec_nolibc then returns ctrl as if the child had succeeded, which is the value the harness expects. So when a child finds that its vstate_ctrl differs from its parent's, it prints an error, but the test still passes.

Compare the exit status with 255 instead. A successful child exits with its vstate_ctrl, which is at most 0x1f. launch_test() already failed the test on 255, but now reports it as an abnormal exit.

Fixes 7cf6198ce22d ("selftests: Test RISC-V Vector prctl interface")
Assisted-by LLM
---
 tools/testing/selftests/riscv/vector/v_helpers.c          | 2 +-
 tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/riscv/vector/v_helpers.c +1 -1
index de6da7c8d2f1..8942ddf2b52b 100644
@@ -81,7 +81,7 @@ int launch_test(char *next_program, int test_inherit, int xtheadvector)
 		return -3;
 	}
 
-	if ((WIFEXITED(status) && WEXITSTATUS(status) == -1) ||
+	if ((WIFEXITED(status) && WEXITSTATUS(status) == 255) ||
 	    WIFSIGNALED(status)) {
 		printf("child exited abnormally\n");
 		return -4;
tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c +1 -1
index 5f53e5e8ac52..05f18b13a36a 100644
@@ -74,7 +74,7 @@ int main(int argc, char **argv)
 		exit(-1);
 	}
 
-	if (WIFEXITED(status) && WEXITSTATUS(status) == -1) {
+	if (WIFEXITED(status) && WEXITSTATUS(status) == 255) {
 		puts("child exited abnormally\n");
 		exit(-1);
 	}
Signature · 1 line
2.55.0