test: Add test suite to Automake

Signed-off-by: Jacques de Laval <jacques@de-laval.se>
This commit is contained in:
Jacques de Laval
2021-02-22 20:33:30 +01:00
parent ee31c8551f
commit e44d348f09
10 changed files with 41 additions and 36 deletions
+3
View File
@@ -31,6 +31,9 @@ GTAGS
/Makefile.in
/stamp-h1
/test-driver
/test-suite.log
# TroglOS build system
/.config
/.stamp
+3 -1
View File
@@ -62,4 +62,6 @@ script:
- unshare -V
- nsenter -V
- 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
+3
View File
@@ -10,6 +10,9 @@ if DOC
SUBDIRS += doc
endif
AM_TESTS_ENVIRONMENT = make -C $(srcdir)/test test_root;
TESTS = test/test_start_stop_service/test.sh
# Compat hook
install-dev:
@make -C src install-pkgincludeHEADERS
+2 -1
View File
@@ -1,2 +1,3 @@
busybox-x86_64
test_root
*.log
*.trs
+6 -5
View File
@@ -51,8 +51,7 @@ $(BBBIN):
wget -O $@ $(BBURL)
md5sum -c $@.md5
$(testroot):
mkdir $(testroot)
$(testroot): $(binaries) $(testroot_bin)/chrootsetup.sh $(dirs) $(testroot)/sbin/finit $(testroot)/bin/initctl test-check
$(testroot_bin)/$(BBBIN): $(BBBIN)
mkdir -p $(testroot_bin)
@@ -76,12 +75,14 @@ $(libs):
mkdir -p $(dir $@)
cp $(shell echo $@ | sed s/^$(testroot)//) $@
check: $(binaries) $(testroot_bin)/chrootsetup.sh $(dirs) $(testroot)/sbin/finit $(testroot)/bin/initctl test-check
./runtest.sh test_start_stop_service/test.sh
check: $(testroot)
./test_start_stop_service/test.sh
test-check:
shellcheck $(shell find . -name '*.sh')
clean:
rm -rf $(testroot)
rm -rf $(testroot)/*
rm -f $(BBBIN)
rm -f ./test_start_stop_service/*.log
rm -f ./test_start_stop_service/*.trs
+5 -24
View File
@@ -1,10 +1,8 @@
#!/bin/sh
set -eu
texec() {
# shellcheck disable=SC2154
./testenv_exec.sh "$finit_pid" "$@"
"$TEST_DIR/testenv_exec.sh" "$finit_pid" "$@"
}
pause() {
@@ -23,7 +21,7 @@ fg_red='\e[1;31m'
fg_green='\e[1;32m'
fg_yellow='\e[1;33m'
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() {
@@ -59,7 +57,7 @@ retry() {
eval "$__retry_cmd" || continue
return 0
done
return 1
eval "$__retry_cmd"
}
say() {
@@ -79,13 +77,9 @@ teardown() {
wait
}
TEST="$1"
TEST_DIR=$(dirname "$TEST")
shift
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
FINIT_CONF_DIR="$(dirname "$FINIT_CONF")"/finit.d
export FINIT_CONF_DIR
@@ -93,18 +87,8 @@ export FINIT_CONF_DIR
log "$color_reset" 'Test start' ''
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
./testenv_start.sh finit &
"$TEST_DIR/testenv_start.sh" finit &
finit_ppid=$!
# shellcheck disable=SC2016
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)
texec cat "$tty" &
sleep 1
# shellcheck source=/dev/null
. "$TEST"
+10
View File
@@ -0,0 +1,10 @@
/bin
/dev
/etc
/lib64
/proc
/sbin
/sys
/tmp
/usr
/var
+5 -1
View File
@@ -2,13 +2,17 @@
set -eu
TEST_DIR=$(dirname "$0")/..
# shellcheck source=/dev/null
. "$TEST_DIR/runtest.sh"
assert_num_children() {
assert "$1 services are running" "$(texec pgrep -P 1 "$2" | wc -l)" -eq "$1"
}
# Test
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"
say 'Reload Finit'
+2 -2
View File
@@ -13,8 +13,8 @@ shift
TEST_DIR=$(dirname "$0")
TESTS_ROOT="$(pwd)/${TEST_DIR}/test_root"
nsenter=$(which nsenter)
chroot=$(which chroot)
nsenter=$(command -v nsenter)
chroot=$(command -v chroot)
export PATH=/sbin:/bin
export PS1='\w \$ '
+2 -2
View File
@@ -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"
unshare=$(which unshare)
chroot=$(which chroot)
unshare=$(command -v unshare)
chroot=$(command -v chroot)
export PATH=/sbin:/bin
export PS1='\w \$ '