mirror of
https://github.com/troglobit/finit.git
synced 2026-10-08 16:34:45 +07:00
test: refactor test framework to use a rootfs skeleton
Instead of having to create files, and copying them in place for each test, we move all static test files to a skeleton rootfs. This makes it a lot easier to get an overview of how things and how they work. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -1,4 +1,2 @@
|
||||
EXTRA_DIST = service.conf service.sh S01-service.sh slay.sh
|
||||
|
||||
noinst_PROGRAMS = serv
|
||||
serv_SOURCES = serv.c
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
#!/bin/sh
|
||||
# SysV style start script for service.sh
|
||||
|
||||
DAEMON="/test_assets/service.sh"
|
||||
PIDFILE="/var/run/service.pid"
|
||||
|
||||
start()
|
||||
{
|
||||
printf 'Starting %s: ' "$DAEMON"
|
||||
start-stop-daemon -S -b -q -p "$PIDFILE" -x "$DAEMON"
|
||||
|
||||
status=$?
|
||||
if [ "$status" -eq 0 ]; then
|
||||
echo "OK"
|
||||
else
|
||||
echo "FAIL"
|
||||
fi
|
||||
|
||||
return "$status"
|
||||
}
|
||||
|
||||
stop()
|
||||
{
|
||||
printf 'Stopping %s: ' "$DAEMON"
|
||||
start-stop-daemon -K -q -p "$PIDFILE"
|
||||
|
||||
status=$?
|
||||
if [ "$status" -eq 0 ]; then
|
||||
echo "OK"
|
||||
else
|
||||
echo "FAIL"
|
||||
fi
|
||||
|
||||
return "$status"
|
||||
}
|
||||
|
||||
restart()
|
||||
{
|
||||
stop
|
||||
sleep 1
|
||||
start
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start|stop|restart)
|
||||
"$1"
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart}, got $0 $1"
|
||||
exit 1
|
||||
esac
|
||||
@@ -1 +0,0 @@
|
||||
service [2345] kill:20 log /test_assets/service.sh
|
||||
@@ -1,24 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
cleanup()
|
||||
{
|
||||
echo "Got signal, stopping ..."
|
||||
rm -f /run/service.pid
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Hook SIGUSR1 and dump trace to file system
|
||||
# shellcheck disable=SC2172
|
||||
trap 'echo USR1 > /tmp/usr1.log' USR1
|
||||
trap cleanup INT
|
||||
trap cleanup TERM
|
||||
trap cleanup QUIT
|
||||
trap cleanup EXIT
|
||||
|
||||
echo $$ > /run/service.pid
|
||||
|
||||
# sleep may exit on known signal, so
|
||||
# we cannot use 'set -e'
|
||||
while true; do
|
||||
sleep 1
|
||||
done
|
||||
@@ -1,47 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
nm=$1
|
||||
|
||||
# shellcheck disable=SC2046
|
||||
getpid()
|
||||
{
|
||||
initctl status "$1" |awk '/PID :/{ print $3; }'
|
||||
}
|
||||
|
||||
pid=$(getpid "$nm")
|
||||
if [ -f oldpid ]; then
|
||||
oldpid=$(cat oldpid)
|
||||
if [ "$oldpid" = "$pid" ]; then
|
||||
echo "Looks bad, wait for it ..."
|
||||
sleep 3
|
||||
pid=$(getpid "$nm")
|
||||
if [ "$oldpid" = "$pid" ]; then
|
||||
echo "Finit did not deregister old PID $oldpid vs $pid"
|
||||
initctl status "$nm"
|
||||
ps
|
||||
echo "Reloading finit ..."
|
||||
initctl reload
|
||||
sleep 1
|
||||
initctl status "$nm"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$pid" -le 1 ]; then
|
||||
sleep 3
|
||||
pid=$(getpid "$nm")
|
||||
if [ "$pid" -le 1 ]; then
|
||||
echo "Got a bad PID: $pid, aborting ..."
|
||||
ps
|
||||
sleep 1
|
||||
initctl status "$nm"
|
||||
ps
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "$pid" > oldpid
|
||||
|
||||
#echo "PID $pid, kill -9 ..."
|
||||
kill -9 "$pid"
|
||||
Reference in New Issue
Block a user