mirror of
https://github.com/troglobit/finit.git
synced 2026-11-27 20:48:24 +00:00
test: Add test suite to Automake
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
This commit is contained in:
1 parent
ee31c8551f
commit
e44d348f09
10 files changed
+41
-36
No files matched your search
@@ -31,6 +31,9 @@ GTAGS
|
|||||||
/Makefile.in
|
/Makefile.in
|
||||||
/stamp-h1
|
/stamp-h1
|
||||||
|
|
||||||
|
/test-driver
|
||||||
|
/test-suite.log
|
||||||
|
|
||||||
# TroglOS build system
|
# TroglOS build system
|
||||||
/.config
|
/.config
|
||||||
/.stamp
|
/.stamp
|
||||||
|
|||||||
+3
-1
@@ -62,4 +62,6 @@ script:
|
|||||||
- unshare -V
|
- unshare -V
|
||||||
- nsenter -V
|
- nsenter -V
|
||||||
- chroot --version
|
- chroot --version
|
||||||
- LD_LIBRARY_PATH=/tmp/lib make -C test/ check
|
- LD_LIBRARY_PATH=/tmp/lib make check
|
||||||
|
- cat ./test-suite.log
|
||||||
|
- make -C test/ clean
|
||||||
@@ -10,6 +10,9 @@ if DOC
|
|||||||
SUBDIRS += doc
|
SUBDIRS += doc
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
AM_TESTS_ENVIRONMENT = make -C $(srcdir)/test test_root;
|
||||||
|
TESTS = test/test_start_stop_service/test.sh
|
||||||
|
|
||||||
# Compat hook
|
# Compat hook
|
||||||
install-dev:
|
install-dev:
|
||||||
@make -C src install-pkgincludeHEADERS
|
@make -C src install-pkgincludeHEADERS
|
||||||
|
|||||||
+2
-1
@@ -1,2 +1,3 @@
|
|||||||
busybox-x86_64
|
busybox-x86_64
|
||||||
test_root
|
*.log
|
||||||
|
*.trs
|
||||||
+6
-5
@@ -51,8 +51,7 @@ $(BBBIN):
|
|||||||
wget -O $@ $(BBURL)
|
wget -O $@ $(BBURL)
|
||||||
md5sum -c $@.md5
|
md5sum -c $@.md5
|
||||||
|
|
||||||
$(testroot):
|
$(testroot): $(binaries) $(testroot_bin)/chrootsetup.sh $(dirs) $(testroot)/sbin/finit $(testroot)/bin/initctl test-check
|
||||||
mkdir $(testroot)
|
|
||||||
|
|
||||||
$(testroot_bin)/$(BBBIN): $(BBBIN)
|
$(testroot_bin)/$(BBBIN): $(BBBIN)
|
||||||
mkdir -p $(testroot_bin)
|
mkdir -p $(testroot_bin)
|
||||||
@@ -76,12 +75,14 @@ $(libs):
|
|||||||
mkdir -p $(dir $@)
|
mkdir -p $(dir $@)
|
||||||
cp $(shell echo $@ | sed s/^$(testroot)//) $@
|
cp $(shell echo $@ | sed s/^$(testroot)//) $@
|
||||||
|
|
||||||
check: $(binaries) $(testroot_bin)/chrootsetup.sh $(dirs) $(testroot)/sbin/finit $(testroot)/bin/initctl test-check
|
check: $(testroot)
|
||||||
./runtest.sh test_start_stop_service/test.sh
|
./test_start_stop_service/test.sh
|
||||||
|
|
||||||
test-check:
|
test-check:
|
||||||
shellcheck $(shell find . -name '*.sh')
|
shellcheck $(shell find . -name '*.sh')
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(testroot)
|
rm -rf $(testroot)/*
|
||||||
rm -f $(BBBIN)
|
rm -f $(BBBIN)
|
||||||
|
rm -f ./test_start_stop_service/*.log
|
||||||
|
rm -f ./test_start_stop_service/*.trs
|
||||||
+5
-24
@@ -1,10 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
texec() {
|
texec() {
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
./testenv_exec.sh "$finit_pid" "$@"
|
"$TEST_DIR/testenv_exec.sh" "$finit_pid" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
pause() {
|
pause() {
|
||||||
@@ -23,7 +21,7 @@ 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() {
|
||||||
printf "< $TEST_DIR > %b%b%b %s\n" "$1" "$2" "$color_reset" "$3"
|
printf "< TEST > %b%b%b %s\n" "$1" "$2" "$color_reset" "$3"
|
||||||
}
|
}
|
||||||
|
|
||||||
assert() {
|
assert() {
|
||||||
@@ -59,7 +57,7 @@ retry() {
|
|||||||
eval "$__retry_cmd" || continue
|
eval "$__retry_cmd" || continue
|
||||||
return 0
|
return 0
|
||||||
done
|
done
|
||||||
return 1
|
eval "$__retry_cmd"
|
||||||
}
|
}
|
||||||
|
|
||||||
say() {
|
say() {
|
||||||
@@ -79,13 +77,9 @@ teardown() {
|
|||||||
wait
|
wait
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST="$1"
|
|
||||||
TEST_DIR=$(dirname "$TEST")
|
|
||||||
shift
|
|
||||||
|
|
||||||
trap teardown EXIT
|
trap teardown EXIT
|
||||||
|
|
||||||
FINIT_CONF=$(grep FINIT_CONF "$(dirname "$0")/../config.h" | cut -d' ' -f3 | cut -d'"' -f2)
|
FINIT_CONF=$(grep FINIT_CONF "$TEST_DIR/../config.h" | cut -d' ' -f3 | cut -d'"' -f2)
|
||||||
export FINIT_CONF
|
export FINIT_CONF
|
||||||
FINIT_CONF_DIR="$(dirname "$FINIT_CONF")"/finit.d
|
FINIT_CONF_DIR="$(dirname "$FINIT_CONF")"/finit.d
|
||||||
export FINIT_CONF_DIR
|
export FINIT_CONF_DIR
|
||||||
@@ -93,18 +87,8 @@ export FINIT_CONF_DIR
|
|||||||
log "$color_reset" 'Test start' ''
|
log "$color_reset" 'Test start' ''
|
||||||
log "$color_reset" '--' ''
|
log "$color_reset" '--' ''
|
||||||
|
|
||||||
|
|
||||||
>&2 echo Environment:
|
|
||||||
>&2 ./testenv_start.sh env
|
|
||||||
>&2 echo --
|
|
||||||
>&2 echo Filesystem:
|
|
||||||
>&2 ./testenv_start.sh find / -path /sys -prune -o -print -path /proc -prune -o -print
|
|
||||||
>&2 echo --
|
|
||||||
>&2 echo "FINIT_CONF='$FINIT_CONF'"
|
|
||||||
>&2 echo "FINIT_CONF_DIR='$FINIT_CONF_DIR/'"
|
|
||||||
|
|
||||||
# Setup
|
# Setup
|
||||||
./testenv_start.sh finit &
|
"$TEST_DIR/testenv_start.sh" finit &
|
||||||
finit_ppid=$!
|
finit_ppid=$!
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
retry 'finit_pid=$(pgrep -P '"$finit_ppid"')'
|
retry 'finit_pid=$(pgrep -P '"$finit_ppid"')'
|
||||||
@@ -112,6 +96,3 @@ retry 'finit_pid=$(pgrep -P '"$finit_ppid"')'
|
|||||||
tty=/dev/$(texec cat /sys/class/tty/console/active)
|
tty=/dev/$(texec cat /sys/class/tty/console/active)
|
||||||
texec cat "$tty" &
|
texec cat "$tty" &
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
|
||||||
. "$TEST"
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
/bin
|
||||||
|
/dev
|
||||||
|
/etc
|
||||||
|
/lib64
|
||||||
|
/proc
|
||||||
|
/sbin
|
||||||
|
/sys
|
||||||
|
/tmp
|
||||||
|
/usr
|
||||||
|
/var
|
||||||
@@ -2,13 +2,17 @@
|
|||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
TEST_DIR=$(dirname "$0")/..
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "$TEST_DIR/runtest.sh"
|
||||||
|
|
||||||
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"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test
|
# Test
|
||||||
say 'Set up a service'
|
say 'Set up a service'
|
||||||
cp "$TEST_DIR"/service.sh test_root/bin
|
cp "$TEST_DIR"/test_start_stop_service/service.sh "$TEST_DIR"/test_root/bin
|
||||||
texec sh -c "echo 'service [2345] kill:20 log /bin/service.sh' > $FINIT_CONF"
|
texec sh -c "echo 'service [2345] kill:20 log /bin/service.sh' > $FINIT_CONF"
|
||||||
|
|
||||||
say 'Reload Finit'
|
say 'Reload Finit'
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ shift
|
|||||||
TEST_DIR=$(dirname "$0")
|
TEST_DIR=$(dirname "$0")
|
||||||
TESTS_ROOT="$(pwd)/${TEST_DIR}/test_root"
|
TESTS_ROOT="$(pwd)/${TEST_DIR}/test_root"
|
||||||
|
|
||||||
nsenter=$(which nsenter)
|
nsenter=$(command -v nsenter)
|
||||||
chroot=$(which chroot)
|
chroot=$(command -v chroot)
|
||||||
|
|
||||||
export PATH=/sbin:/bin
|
export PATH=/sbin:/bin
|
||||||
export PS1='\w \$ '
|
export PS1='\w \$ '
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ TESTS_ROOT="$(pwd)/${TEST_DIR}/test_root"
|
|||||||
|
|
||||||
>&2 echo "Hint: Execute '${TEST_DIR}/testenv_exec.sh \$(pgrep -P $$) /bin/sh; reset' to enter the test namespace"
|
>&2 echo "Hint: Execute '${TEST_DIR}/testenv_exec.sh \$(pgrep -P $$) /bin/sh; reset' to enter the test namespace"
|
||||||
|
|
||||||
unshare=$(which unshare)
|
unshare=$(command -v unshare)
|
||||||
chroot=$(which chroot)
|
chroot=$(command -v chroot)
|
||||||
|
|
||||||
export PATH=/sbin:/bin
|
export PATH=/sbin:/bin
|
||||||
export PS1='\w \$ '
|
export PS1='\w \$ '
|
||||||
|
|||||||
Reference in new issue
Block a user