diff --git a/scripts/run-qemu.sh b/scripts/run-qemu.sh index cad03e48..9ec94582 100755 --- 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 new file mode 100644 index 00000000..6cacb78e --- /dev/null +++ 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 index 4c87b63a..541b8a7d 100755 --- 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 '' -I liminix-config=./configuration.nix --arg device "import " -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"