selftests/nolibc: recreate and populate /dev and /proc if missing
authorWilly Tarreau <w@1wt.eu>
Tue, 19 Jul 2022 21:44:42 +0000 (23:44 +0200)
committerPaul E. McKenney <paulmck@kernel.org>
Wed, 31 Aug 2022 12:17:44 +0000 (05:17 -0700)
commit1a5454f625997049d886d8c3dae8e8de2a553125
tree260712f95b848f5151a9995d8342b5f2bbfe963d
parentaa73a86cda26705c7f0af1afe9bb255a52accf87
selftests/nolibc: recreate and populate /dev and /proc if missing

Most of the time the program will be run alone in an initramfs. There
is no value in requiring the user to populate /dev and /proc for such
tests, we can do it ourselves, and it participates to the tests at the
same time.

What's done here is that when called as init (getpid()==1) we check
if /dev exists or create it, if /dev/console and /dev/null exists,
otherwise we try to mount a devtmpfs there, and if it fails we fall
back to mknod. The console is reopened if stdout was closed. Finally
/proc is created and mounted if /proc/self cannot be found. This is
sufficient for most tests.

Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
tools/testing/selftests/nolibc/nolibc-test.c