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 committed 2022-04-02 10:45:30 +02:00
1 parent 879721839e
commit 6f802a7ff1
14 files changed
+216 -187

No files matched your search

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