summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/nolibc
diff options
context:
space:
mode:
authorWilly Tarreau <w@1wt.eu>2022-07-19 23:44:40 +0200
committerPaul E. McKenney <paulmck@kernel.org>2022-08-31 05:17:44 -0700
commitf49896d7d9a69b7565a59f5085c78ca1c08c7dd7 (patch)
tree08606a2034c261aee42c2c3fcbb5b6b218140221 /tools/testing/selftests/nolibc
parent95bc989488eb7150949cf2fcce3f486741d1c57f (diff)
selftests/nolibc: exit with poweroff on success when getpid() == 1
The idea is to ease automated testing under qemu. If the test succeeds while running as PID 1, indicating the system was booted with init=/test, let's just power off so that qemu can exit with a successful code. In other situations it will exit and provoke a panic, which may be caught for example with CONFIG_PVPANIC. Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Diffstat (limited to 'tools/testing/selftests/nolibc')
-rw-r--r--tools/testing/selftests/nolibc/nolibc-test.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index b928f099431f..291d96bfd7c1 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -626,6 +626,20 @@ int main(int argc, char **argv, char **envp)
}
printf("Total number of errors: %d\n", ret);
+
+ if (getpid() == 1) {
+ /* we're running as init, there's no other process on the
+ * system, thus likely started from a VM for a quick check.
+ * Exiting will provoke a kernel panic that may be reported
+ * as an error by Qemu or the hypervisor, while stopping
+ * cleanly will often be reported as a success. This allows
+ * to use the output of this program for bisecting kernels.
+ */
+ printf("Leaving init with final status: %d\n", !!ret);
+ if (ret == 0)
+ reboot(LINUX_REBOOT_CMD_POWER_OFF);
+ }
+
printf("Exiting with status %d\n", !!ret);
return !!ret;
}