test: whitespace changes only

Coding style for shell scripts:

  - Tabs for indent (change in Emacs needed)
  - Braces on their own line, like C functions

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2022-04-02 10:45:30 +02:00
parent 879721839e
commit 6f802a7ff1
14 changed files with 216 additions and 187 deletions
@@ -7,12 +7,13 @@ TEST_DIR=$(dirname "$0")
# shellcheck source=/dev/null
. "$TEST_DIR/tenv/lib.sh"
test_teardown() {
say "Test done $(date)"
say "Running test teardown."
test_teardown()
{
say "Test done $(date)"
say "Running test teardown."
texec rm -f "$FINIT_RCSD/service.conf"
texec rm -f /test_assets/service.sh
texec rm -f "$FINIT_RCSD/service.conf"
texec rm -f /test_assets/service.sh
}
say "Test start $(date)"
+6 -5
View File
@@ -7,12 +7,13 @@ TEST_DIR=$(dirname "$0")
# shellcheck source=/dev/null
. "$TEST_DIR/tenv/lib.sh"
test_teardown() {
say "Test done $(date)"
say "Running test teardown."
test_teardown()
{
say "Test done $(date)"
say "Running test teardown."
texec rm -f "$FINIT_CONF"
texec rm -f /test_assets/service.sh
texec rm -f "$FINIT_CONF"
texec rm -f /test_assets/service.sh
}
say "Test start $(date)"
+12 -4
View File
@@ -4,31 +4,38 @@
DAEMON="/test_assets/service.sh"
PIDFILE="/var/run/service.pid"
start() {
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() {
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() {
restart()
{
stop
sleep 1
start
@@ -36,7 +43,8 @@ restart() {
case "$1" in
start|stop|restart)
"$1";;
"$1"
;;
*)
echo "Usage: $0 {start|stop|restart}, got $0 $1"
exit 1
+4 -4
View File
@@ -2,9 +2,9 @@
cleanup()
{
echo "Got signal, stopping ..."
rm -f /run/service.pid
exit 0
echo "Got signal, stopping ..."
rm -f /run/service.pid
exit 0
}
# Hook SIGUSR1 and dump trace to file system
@@ -20,5 +20,5 @@ echo $$ > /run/service.pid
# sleep may exit on known signal, so
# we cannot use 'set -e'
while true; do
sleep 1
sleep 1
done
+6 -5
View File
@@ -8,12 +8,13 @@ TEST_DIR=$(dirname "$0")
# shellcheck source=/dev/null
. "$TEST_DIR/tenv/lib.sh"
test_teardown() {
say "Test done $(date)"
say "Running test teardown."
test_teardown()
{
say "Test done $(date)"
say "Running test teardown."
texec rm -f "$FINIT_CONF"
texec rm -f /test_assets/service.sh
texec rm -f "$FINIT_CONF"
texec rm -f /test_assets/service.sh
}
say "Test start $(date)"
+9 -8
View File
@@ -9,12 +9,13 @@ TEST_DIR=$(dirname "$0")
# shellcheck source=/dev/null
. "$TEST_DIR/tenv/lib.sh"
test_teardown() {
say "Test done $(date)"
say "Running test teardown."
test_teardown()
{
say "Test done $(date)"
say "Running test teardown."
texec rm -f "$FINIT_CONF"
texec rm -f /test_assets/service.sh
texec rm -f "$FINIT_CONF"
texec rm -f /test_assets/service.sh
}
say "Test start $(date)"
@@ -37,9 +38,9 @@ say 'Simulate service crash (kill -9 ..)'
i=0
laps=1000
while [ $i -lt $laps ]; do
i=$((i + 1))
say "Lap $i/$laps, killing service ..." # we have this, no sleep needed
texec sh -c "/test_assets/slay.sh service.sh"
i=$((i + 1))
say "Lap $i/$laps, killing service ..." # we have this, no sleep needed
texec sh -c "/test_assets/slay.sh service.sh"
done
retry 'assert_new_pid service.sh /run/service.pid'
+6 -5
View File
@@ -7,12 +7,13 @@ TEST_DIR=$(dirname "$0")
# shellcheck source=/dev/null
. "$TEST_DIR/tenv/lib.sh"
test_teardown() {
say "Test done $(date)"
say "Running test teardown."
test_teardown()
{
say "Test done $(date)"
say "Running test teardown."
texec rm -f "$FINIT_RCSD/service.conf"
texec rm -f /test_assets/service.sh
texec rm -f "$FINIT_RCSD/service.conf"
texec rm -f /test_assets/service.sh
}
say "Test start $(date)"
+6 -5
View File
@@ -7,12 +7,13 @@ TEST_DIR=$(dirname "$0")
# shellcheck source=/dev/null
. "$TEST_DIR/tenv/lib.sh"
test_teardown() {
say "Test done $(date)"
say "Running test teardown."
test_teardown()
{
say "Test done $(date)"
say "Running test teardown."
texec rm -f "$FINIT_CONF"
texec rm -f /test_assets/service.sh
texec rm -f "$FINIT_CONF"
texec rm -f /test_assets/service.sh
}
say "Test start $(date)"
+5 -5
View File
@@ -33,12 +33,12 @@ mount -t proc none /proc
mount -t sysfs none /sys
if [ "$(ls -A /tmp)" ]; then
mkdir -p /tmp.shadow
mount --bind /tmp /tmp.shadow
mount -t tmpfs none /tmp
cp -a /tmp.shadow/* /tmp/
mkdir -p /tmp.shadow
mount --bind /tmp /tmp.shadow
mount -t tmpfs none /tmp
cp -a /tmp.shadow/* /tmp/
else
mount -t tmpfs none /tmp
mount -t tmpfs none /tmp
fi
mkdir -p "$FINIT_RCSD"
+7 -7
View File
@@ -4,10 +4,10 @@ set -eu
cmd=""
if [ "$#" -lt 1 ]; then
cmd="/bin/sh"
cmd="/bin/sh"
else
cmd=$1
shift
cmd=$1
shift
fi
TEST_DIR=$(dirname "$0")/..
@@ -15,11 +15,11 @@ TENV_ROOT="${TENV_ROOT:-$(pwd)/${TEST_DIR}/tenv-root}"
PID_FILE="$TENV_ROOT/running_test.pid"
if [ -f "$PID_FILE" ] ; then
target=$(cat "$PID_FILE")
target=$(pgrep -P "$target")
target=$(cat "$PID_FILE")
target=$(pgrep -P "$target")
else
echo "No test running!"
exit 1
echo "No test running!"
exit 1
fi
source "$TEST_DIR/test.env"
+13 -13
View File
@@ -24,9 +24,9 @@
set -eu
if [ "$#" -lt 2 ]; then
echo "Usage:"
echo " $0 [target-pid] [command [arguments]]"
exit 1
echo "Usage:"
echo " $0 [target-pid] [command [arguments]]"
exit 1
fi
target="$1"
shift
@@ -45,13 +45,13 @@ export PS4='+ '
PATH="$TESTENV_PATH"
export PATH
"$nsenter" \
--preserve-credentials \
--user \
--mount \
--uts \
--ipc \
--net \
--pid \
-w -t "$target" \
"$chroot" "$TENV_ROOT" "$@"
"$nsenter" \
--preserve-credentials \
--user \
--mount \
--uts \
--ipc \
--net \
--pid \
-w -t "$target" \
"$chroot" "$TENV_ROOT" "$@"
+86 -71
View File
@@ -21,103 +21,118 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
assert_num_children() {
assert "$1 services are running" "$(texec pgrep -P 1 "$2" | wc -l)" -eq "$1"
assert_num_children()
{
assert "$1 services are running" "$(texec pgrep -P 1 "$2" | wc -l)" -eq "$1"
}
assert_new_pid() {
# shellcheck disable=SC2086
assert "Finit has registered new PID" "$(texec initctl |grep $1 |awk '{print $1}')" -eq "$(texec cat $2)"
# shellcheck disable=SC2086
assert_new_pid()
{
assert "Finit has registered new PID" "$(texec initctl |grep $1 |awk '{print $1}')" -eq "$(texec cat $2)"
}
texec() {
# shellcheck disable=SC2154
"$TEST_DIR/tenv/exec.sh" "$finit_pid" "$@"
# shellcheck disable=SC2154
texec()
{
"$TEST_DIR/tenv/exec.sh" "$finit_pid" "$@"
}
pause() {
echo "Press any key to continue... "
read -r REPLY
pause()
{
echo "Press any key to continue... "
read -r REPLY
}
toggle_finit_debug() {
say 'Toggle finit debug'
texec initctl debug
sleep 0.5
toggle_finit_debug()
{
say 'Toggle finit debug'
texec initctl debug
sleep 0.5
}
color_reset='\e[0m'
fg_red='\e[1;31m'
fg_green='\e[1;32m'
fg_yellow='\e[1;33m'
log() {
test=$(basename "$0" ".sh")
printf "\e[2m[%s]\e[0m %b%b%b %s\n" "$test" "$1" "$2" "$color_reset" "$3"
log()
{
test=$(basename "$0" ".sh")
printf "\e[2m[%s]\e[0m %b%b%b %s\n" "$test" "$1" "$2" "$color_reset" "$3"
}
assert() {
__assert_msg=$1
shift
if [ ! "$@" ]; then
log "$fg_red" ✘ "$__assert_msg ($*)"
return 1
fi
log "$fg_green" ✔ "$__assert_msg"
assert()
{
__assert_msg=$1
shift
if [ ! "$@" ]; then
log "$fg_red" ✘ "$__assert_msg ($*)"
return 1
fi
log "$fg_green" ✔ "$__assert_msg"
}
retry() {
__retry_cmd=$1
shift
case "$#" in
2)
__retry_n=$1
__retry_sleep=$2
;;
1)
__retry_n=$1
__retry_sleep=0.1
;;
*)
__retry_n=50
__retry_sleep=0.1
;;
esac
retry()
{
__retry_cmd=$1
shift
for _ in $(seq 1 "$__retry_n"); do
sleep "$__retry_sleep"
__retry_cmd_out=$(eval "$__retry_cmd") && \
echo "$__retry_cmd_out" && \
return 0
done
__retry_cmd_exit="$?"
echo "$__retry_cmd_out"
return "$__retry_cmd_exit"
case "$#" in
2)
__retry_n=$1
__retry_sleep=$2
;;
1)
__retry_n=$1
__retry_sleep=0.1
;;
*)
__retry_n=50
__retry_sleep=0.1
;;
esac
for _ in $(seq 1 "$__retry_n"); do
sleep "$__retry_sleep"
__retry_cmd_out=$(eval "$__retry_cmd") && \
echo "$__retry_cmd_out" && \
return 0
done
__retry_cmd_exit="$?"
echo "$__retry_cmd_out"
return "$__retry_cmd_exit"
}
say() {
log "$fg_yellow" • "$@"
say()
{
log "$fg_yellow" • "$@"
}
teardown() {
test_status="$?"
teardown()
{
test_status="$?"
if type test_teardown > /dev/null 2>&1 ; then
test_teardown
fi
if type test_teardown > /dev/null 2>&1 ; then
test_teardown
fi
log "$color_reset" '--' ''
if [ "$test_status" -eq 0 ]; then
log "$fg_green" 'TEST PASS' ''
else
log "$fg_red" 'TEST FAIL' ''
fi
if [ -n "${finit_pid+x}" ]; then
texec kill -SIGUSR2 1
fi
log "$color_reset" '--' ''
if [ "$test_status" -eq 0 ]; then
log "$fg_green" 'TEST PASS' ''
else
log "$fg_red" 'TEST FAIL' ''
fi
if [ -n "${finit_pid+x}" ]; then
texec kill -SIGUSR2 1
fi
wait
wait
rm -f "$TENV_ROOT"/running_test.pid
rm -f "$TENV_ROOT"/running_test.pid
}
trap teardown EXIT
@@ -130,7 +145,7 @@ export TENV_ROOT
# Setup test environment
if [ -n "${DEBUG:-}" ]; then
FINIT_ARGS="${FINIT_ARGS:-} finit.debug=on"
FINIT_ARGS="${FINIT_ARGS:-} finit.debug=on"
fi
# shellcheck disable=2086
"$TEST_DIR/tenv/start.sh" finit ${FINIT_ARGS:-} &
+43 -43
View File
@@ -20,55 +20,55 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
DEST ?= ../tenv-root
srcdir ?= ../
DEST ?= ../tenv-root
srcdir ?= ../
ARCH ?= x86_64
ARCH ?= x86_64
FINITBIN ?= ./sbin/finit
FINITBIN ?= ./sbin/finit
BBVER ?= 1.31.0
BBBIN = busybox-$(ARCH)
BBURL ?= https://www.busybox.net/downloads/binaries/$(BBVER)-defconfig-multiarch-musl/$(BBBIN)
BBVER ?= 1.31.0
BBBIN = busybox-$(ARCH)
BBURL ?= https://www.busybox.net/downloads/binaries/$(BBVER)-defconfig-multiarch-musl/$(BBBIN)
binaries = $(DEST)/bin/awk \
$(DEST)/bin/cat \
$(DEST)/bin/cp \
$(DEST)/bin/date \
$(DEST)/bin/echo \
$(DEST)/bin/env \
$(DEST)/bin/find \
$(DEST)/bin/grep \
$(DEST)/bin/kill \
$(DEST)/bin/ls \
$(DEST)/bin/mkdir \
$(DEST)/bin/mkfifo \
$(DEST)/bin/mknod \
$(DEST)/bin/mount \
$(DEST)/bin/printf \
$(DEST)/bin/pgrep \
$(DEST)/bin/ps \
$(DEST)/bin/rm \
$(DEST)/bin/sh \
$(DEST)/bin/sleep \
$(DEST)/bin/tail \
$(DEST)/bin/top \
$(DEST)/bin/touch \
$(DEST)/bin/start-stop-daemon
binaries = $(DEST)/bin/awk \
$(DEST)/bin/cat \
$(DEST)/bin/cp \
$(DEST)/bin/date \
$(DEST)/bin/echo \
$(DEST)/bin/env \
$(DEST)/bin/find \
$(DEST)/bin/grep \
$(DEST)/bin/kill \
$(DEST)/bin/ls \
$(DEST)/bin/mkdir \
$(DEST)/bin/mkfifo \
$(DEST)/bin/mknod \
$(DEST)/bin/mount \
$(DEST)/bin/printf \
$(DEST)/bin/pgrep \
$(DEST)/bin/ps \
$(DEST)/bin/rm \
$(DEST)/bin/sh \
$(DEST)/bin/sleep \
$(DEST)/bin/tail \
$(DEST)/bin/top \
$(DEST)/bin/touch \
$(DEST)/bin/start-stop-daemon
dirs = $(DEST)/bin \
$(DEST)/dev \
$(DEST)/etc \
$(DEST)/proc \
$(DEST)/sbin \
$(DEST)/var \
$(DEST)/run \
$(DEST)/sys \
$(DEST)/test_assets \
$(DEST)/tmp
dirs = $(DEST)/bin \
$(DEST)/dev \
$(DEST)/etc \
$(DEST)/proc \
$(DEST)/sbin \
$(DEST)/var \
$(DEST)/run \
$(DEST)/sys \
$(DEST)/test_assets \
$(DEST)/tmp
_libs_src = $(shell ldd $(FINITBIN) | grep -Eo '/[^ ]+')
libs = $(foreach path,$(_libs_src),$(abspath $(DEST))$(path))
_libs_src = $(shell ldd $(FINITBIN) | grep -Eo '/[^ ]+')
libs = $(foreach path,$(_libs_src),$(abspath $(DEST))$(path))
all: $(dirs) $(binaries) $(libs) $(DEST)/bin/chrootsetup.sh
touch $(DEST)/etc/fstab
+7 -7
View File
@@ -40,10 +40,10 @@ export PATH
# Not supported by Busybox unshare:
# --cgroup --time
exec "$unshare" \
--user --map-root-user \
--fork --pid --mount-proc \
--mount \
--mount-proc \
--uts --ipc --net \
"$chroot" "$TENV_ROOT" /bin/chrootsetup.sh "$@"
exec "$unshare" \
--user --map-root-user \
--fork --pid --mount-proc \
--mount \
--mount-proc \
--uts --ipc --net \
"$chroot" "$TENV_ROOT" /bin/chrootsetup.sh "$@"