From 564dd81f2dcab492eb299b53730466193b617643 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 3 Oct 2022 04:58:52 -0500 Subject: [PATCH] Add test_mkroot.ssh and teach mkroot to call /mnt/init if present. --- scripts/mkroot.sh | 1 + scripts/test_mkroot.sh | 50 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100755 scripts/test_mkroot.sh diff --git a/scripts/mkroot.sh b/scripts/mkroot.sh index 57199c65..33949567 100755 --- a/scripts/mkroot.sh +++ b/scripts/mkroot.sh @@ -127,6 +127,7 @@ if [ $$ -eq 1 ]; then # Setup networking for QEMU (needs /proc) for i in $(ls -1 /etc/rc 2>/dev/null | sort); do . /etc/rc/"$i"; done [ -z "$CONSOLE" ] && CONSOLE="$( /proc/sys/kernel/printk exec oneit -c /dev/"${CONSOLE:-console}" $HANDOFF diff --git a/scripts/test_mkroot.sh b/scripts/test_mkroot.sh new file mode 100755 index 00000000..a876a873 --- /dev/null +++ b/scripts/test_mkroot.sh @@ -0,0 +1,50 @@ +#/bin/bash + +[ -n "$(which toybox)" -a -n "$(which mksquashfs)" ] || + { echo "Need toybox and mksquashfs in $PATH"; exit 1; } + +mkdir -p "${TEST:=root/build/test}" && + +# Setup test filesystem +cat > "$TEST"/init << EOF && +#!/bin/sh + +echo +echo === running init +[ "$(date +%s)" -gt 1500000000 ] && echo === date ok +wget http://10.0.2.2:65432 -O - +EOF +chmod +x "$TEST"/init && +mksquashfs "$TEST"/init "$TEST"/init.sqf -noappend >/dev/null && + +# Setup for network smoke test +echo === net ok > "$TEST"/index.html || exit 1 +toybox netcat -p 65432 -s 127.0.0.1 -L toybox httpd "$TEST" & +trap "kill $!" EXIT +sleep .25 + +[ -n "$(wget http://127.0.0.1:65432/ -O - | grep ===)" ] || exit 1 + +PASS= NOPASS= +for I in root/*/linux-kernel +do + [ ! -e "$I" ] && continue + X=$(dirname $I) Y=$(basename $X) + # Alas KARGS=quiet doesn't silence qemu's bios, so filter output ourselves. + # QEMU broke -hda because too many people know how to use it, this is + # the new edgier version they added to be -hda without gratuitous breakage. + { + cd $X || continue + echo === $X + # When stdin is a tty QEMU will SIGTTOU itself here. + toybox timeout -i 5 ./run-qemu.sh -drive format=raw,file=../build/test/init.sqf < /dev/null 2>/dev/null + cd ../.. + } | tee root/build/log/$Y-test.txt | grep '^=== ' + [ "$(grep '^=== ' root/build/log/$Y-test.txt | wc -l)" -eq 4 ] && + PASS+="$Y " || NOPASS+="$Y " +done + +[ -n "$PASS" ] && echo PASS=$PASS +[ -n "$NOPASS" ] && echo NOPASS=$NOPASS +X="$(ls root | egrep -xv "$(ls root/*/linux-kernel | sed 's@root/\([^/]*\)/linux-kernel@\1@' | tr '\n' '|')build" | xargs)" +[ -n "$X" ] && echo No kernel: $X -- 2.39.2