forked from DGNum/liminix
extract common shell fns in tests
This commit is contained in:
parent
d8cc6ab61c
commit
55387b0ee3
5 changed files with 24 additions and 78 deletions
|
@ -15,29 +15,6 @@ in pkgs.runCommand "check" {
|
||||||
socat
|
socat
|
||||||
] ;
|
] ;
|
||||||
} ''
|
} ''
|
||||||
serverstatedir=$(mktemp -d -t routeros-XXXXXX)
|
|
||||||
|
|
||||||
killpid(){
|
|
||||||
if test -e $1 && test -d /proc/`cat $1` ; then
|
|
||||||
pid=$(cat $1)
|
|
||||||
kill $pid
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup(){
|
|
||||||
killpid $serverstatedir/pid
|
|
||||||
test -n "$MPLCONFIGDIR" && test -d "$MPLCONFIGDIR" && rm -rf "$MPLCONFIGDIR"
|
|
||||||
killpid foo.pid
|
|
||||||
}
|
|
||||||
trap cleanup EXIT
|
|
||||||
|
|
||||||
fatal(){
|
|
||||||
err=$?
|
|
||||||
echo "FAIL: command $(eval echo $BASH_COMMAND) exited with code $err"
|
|
||||||
exit $err
|
|
||||||
}
|
|
||||||
trap fatal ERR
|
|
||||||
|
|
||||||
mkdir vm
|
mkdir vm
|
||||||
mips-vm --background ./vm ${img}/vmlinux ${img}/rootfs
|
mips-vm --background ./vm ${img}/vmlinux ${img}/rootfs
|
||||||
expect ${./script.expect} >$out
|
expect ${./script.expect} >$out
|
||||||
|
|
|
@ -19,24 +19,7 @@ in pkgs.runCommand "check" {
|
||||||
rogue
|
rogue
|
||||||
] ;
|
] ;
|
||||||
} ''
|
} ''
|
||||||
killpid(){
|
. ${../test-helpers.sh}
|
||||||
if test -e $1 && test -d /proc/`cat $1` ; then
|
|
||||||
pid=$(cat $1)
|
|
||||||
kill $pid
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup(){
|
|
||||||
killpid ./vm/pid
|
|
||||||
}
|
|
||||||
|
|
||||||
trap cleanup EXIT
|
|
||||||
fatal(){
|
|
||||||
err=$?
|
|
||||||
echo "FAIL: command $(eval echo $BASH_COMMAND) exited with code $err"
|
|
||||||
exit $err
|
|
||||||
}
|
|
||||||
trap fatal ERR
|
|
||||||
|
|
||||||
mkdir vm
|
mkdir vm
|
||||||
LAN=user,hostfwd=tcp::2022-:22 mips-vm --background ./vm ${img}/vmlinux ${img}/rootfs
|
LAN=user,hostfwd=tcp::2022-:22 mips-vm --background ./vm ${img}/vmlinux ${img}/rootfs
|
||||||
|
|
|
@ -23,26 +23,7 @@ serverstatedir=$(mktemp -d -t routeros-XXXXXX)
|
||||||
# a sandbox with no $HOME, hence this environment variable
|
# a sandbox with no $HOME, hence this environment variable
|
||||||
export MPLCONFIGDIR=$(mktemp -d -t routeros-XXXXXX)
|
export MPLCONFIGDIR=$(mktemp -d -t routeros-XXXXXX)
|
||||||
|
|
||||||
killpid(){
|
. ${../test-helpers.sh}
|
||||||
if test -e $1 && test -d /proc/`cat $1` ; then
|
|
||||||
pid=$(cat $1)
|
|
||||||
kill $pid
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup(){
|
|
||||||
killpid $serverstatedir/pid
|
|
||||||
test -n "$MPLCONFIGDIR" && test -d "$MPLCONFIGDIR" && rm -rf "$MPLCONFIGDIR"
|
|
||||||
killpid foo.pid
|
|
||||||
}
|
|
||||||
trap cleanup EXIT
|
|
||||||
|
|
||||||
fatal(){
|
|
||||||
err=$?
|
|
||||||
echo "FAIL: command $(eval echo $BASH_COMMAND) exited with code $err"
|
|
||||||
exit $err
|
|
||||||
}
|
|
||||||
trap fatal ERR
|
|
||||||
|
|
||||||
routeros $serverstatedir
|
routeros $serverstatedir
|
||||||
mkdir vm
|
mkdir vm
|
||||||
|
|
21
tests/test-helpers.sh
Normal file
21
tests/test-helpers.sh
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
killpid(){
|
||||||
|
if test -e $1 && test -d /proc/`cat $1` ; then
|
||||||
|
pid=$(cat $1)
|
||||||
|
kill $pid
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup(){
|
||||||
|
killpid $serverstatedir/pid
|
||||||
|
test -n "$MPLCONFIGDIR" && test -d "$MPLCONFIGDIR" && rm -rf "$MPLCONFIGDIR"
|
||||||
|
killpid foo.pid
|
||||||
|
killpid ./vm/pid
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
fatal(){
|
||||||
|
err=$?
|
||||||
|
echo "FAIL: command $(eval echo $BASH_COMMAND) exited with code $err"
|
||||||
|
exit $err
|
||||||
|
}
|
||||||
|
trap fatal ERR
|
|
@ -15,23 +15,7 @@ in pkgs.runCommand "check" {
|
||||||
socat
|
socat
|
||||||
] ;
|
] ;
|
||||||
} ''
|
} ''
|
||||||
killpid(){
|
. ${../test-helpers.sh}
|
||||||
if test -e $1 && test -d /proc/`cat $1` ; then
|
|
||||||
pid=$(cat $1)
|
|
||||||
kill $pid
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup(){
|
|
||||||
killpid ./vm/pid
|
|
||||||
}
|
|
||||||
trap cleanup EXIT
|
|
||||||
fatal(){
|
|
||||||
err=$?
|
|
||||||
echo "FAIL: command $(eval echo $BASH_COMMAND) exited with code $err"
|
|
||||||
exit $err
|
|
||||||
}
|
|
||||||
trap fatal ERR
|
|
||||||
|
|
||||||
mkdir vm
|
mkdir vm
|
||||||
mips-vm --background ./vm ${img}/vmlinux ${img}/rootfs
|
mips-vm --background ./vm ${img}/vmlinux ${img}/rootfs
|
||||||
|
|
Loading…
Reference in a new issue