Skip to content

Commit f49896d

Browse files
wtarreaupaulmckrcu
authored andcommitted
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>
1 parent 95bc989 commit f49896d

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

tools/testing/selftests/nolibc/nolibc-test.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,20 @@ int main(int argc, char **argv, char **envp)
626626
}
627627

628628
printf("Total number of errors: %d\n", ret);
629+
630+
if (getpid() == 1) {
631+
/* we're running as init, there's no other process on the
632+
* system, thus likely started from a VM for a quick check.
633+
* Exiting will provoke a kernel panic that may be reported
634+
* as an error by Qemu or the hypervisor, while stopping
635+
* cleanly will often be reported as a success. This allows
636+
* to use the output of this program for bisecting kernels.
637+
*/
638+
printf("Leaving init with final status: %d\n", !!ret);
639+
if (ret == 0)
640+
reboot(LINUX_REBOOT_CMD_POWER_OFF);
641+
}
642+
629643
printf("Exiting with status %d\n", !!ret);
630644
return !!ret;
631645
}

0 commit comments

Comments
 (0)