commit cbee488d22487ef759057815a8186257b044ec53
parent f3f51ac6becc19f7fc9b1917195347a0103030fd
Author: Daniel Barlow <dan@telent.net>
Date: Mon, 26 Sep 2022 10:47:29 +0100
automated test for pppoe
Diffstat:
3 files changed, 35 insertions(+), 10 deletions(-)
diff --git a/scripts/run-qemu.sh b/scripts/run-qemu.sh
@@ -3,8 +3,9 @@
if test "$1" = "--background" ; then
socket=$2
- echo "running in background, socket is $socket"
- flags="--daemonize -chardev socket,id=sock,path=$2,server=on,wait=off,mux=on -mon chardev=sock,mode=readline -serial chardev:sock "
+ pid="`dirname $socket`/`basename $socket .sock`.pid"
+ echo "running in background, socket is $socket, pid $pid"
+ flags="--daemonize --pidfile $pid -chardev socket,id=sock,path=$2,server=on,wait=off,mux=on -mon chardev=sock,mode=readline -serial chardev:sock "
shift;shift
else
flags="-serial mon:stdio"
diff --git a/tests/pppoe/getaddress.expect b/tests/pppoe/getaddress.expect
@@ -0,0 +1,19 @@
+set timeout 60
+
+spawn socat unix-connect:foo.sock -
+send "\r\n"
+expect "login:" { send "root\r\n" }
+expect "/ #"
+set FINISHED 0
+set EXIT "1"
+while { $FINISHED < 5 } {
+ send "ip address show dev ppp0 | grep ppp0\r\n"
+
+ expect {
+ "192.168.100.1" { set FINISHED 10; set EXIT 0; }
+ "can't find device" { send_user "waiting ..." ; send "\r\n"; sleep 3 }
+ }
+ set FINISHED [ expr $FINISHED + 1 ]
+}
+
+exit $EXIT
diff --git a/tests/pppoe/run.sh b/tests/pppoe/run.sh
@@ -1,20 +1,25 @@
#!/usr/bin/env sh
-
-set -e
-
cleanup(){
- echo "do cleanup";
+ if test -e foo.pid && test -d /proc/`cat foo.pid` ; then
+ echo "killing qemu"
+ kill `cat foo.pid`
+ fi
}
trap cleanup EXIT
-trap 'echo "command $(eval echo $BASH_COMMAND) failed with exit code $?"; exit $?' ERR
+fatal(){
+ err=$?
+ echo "FAIL: command $(eval echo $BASH_COMMAND) exited with code $err"
+ exit $err
+}
+trap fatal ERR
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '<liminix>' -I liminix-config=./configuration.nix --arg device "import <liminix/devices/qemu.nix>" -A outputs.default $*
-
-if ! ( echo "cont" | socat - unix-connect:../support/ppp-server/qemu-monitor); then
+if ! ( echo "cont" | socat - unix-connect:../support/ppp-server/qemu-monitor); then
echo "need pppoe server running"
exit 1
fi
-../../scripts/run-qemu.sh result/vmlinux result/squashfs
+../../scripts/run-qemu.sh --background foo.sock result/vmlinux result/squashfs
+nix-shell -p expect --run "expect getaddress.expect"