mirror of
https://github.com/troglobit/finit.git
synced 2026-11-06 15:51:03 +00:00
test: New test: test_start_stop_service
Add a new test that verifies that Finit will: - Start a service that's been added to the config - Stop the service once it's removed from the config The second step is currently failing. Signed-off-by: Jacques de Laval <jacques@de-laval.se>
This commit is contained in:
1 parent
4f82cb8261
commit
4224c2e8fe
7 files changed
+98
-6
No files matched your search
+8
-4
@@ -8,18 +8,22 @@ testroot_bin = $(testroot)/bin
|
|||||||
binaries = $(testroot_bin)/cat \
|
binaries = $(testroot_bin)/cat \
|
||||||
$(testroot_bin)/date \
|
$(testroot_bin)/date \
|
||||||
$(testroot_bin)/echo \
|
$(testroot_bin)/echo \
|
||||||
|
$(testroot_bin)/kill \
|
||||||
$(testroot_bin)/ls \
|
$(testroot_bin)/ls \
|
||||||
$(testroot_bin)/mkdir \
|
$(testroot_bin)/mkdir \
|
||||||
$(testroot_bin)/mkfifo \
|
$(testroot_bin)/mkfifo \
|
||||||
$(testroot_bin)/mknod \
|
$(testroot_bin)/mknod \
|
||||||
$(testroot_bin)/mount \
|
$(testroot_bin)/mount \
|
||||||
$(testroot_bin)/printf \
|
$(testroot_bin)/printf \
|
||||||
|
$(testroot_bin)/pgrep \
|
||||||
$(testroot_bin)/ps \
|
$(testroot_bin)/ps \
|
||||||
|
$(testroot_bin)/rm \
|
||||||
$(testroot_bin)/sh \
|
$(testroot_bin)/sh \
|
||||||
$(testroot_bin)/sleep \
|
$(testroot_bin)/sleep \
|
||||||
$(testroot_bin)/top \
|
$(testroot_bin)/top \
|
||||||
$(testroot_bin)/touch
|
$(testroot_bin)/touch
|
||||||
dirs = $(testroot)/dev \
|
dirs = $(testroot)/dev \
|
||||||
|
$(testroot)/etc \
|
||||||
$(testroot)/lib \
|
$(testroot)/lib \
|
||||||
$(testroot)/proc \
|
$(testroot)/proc \
|
||||||
$(testroot)/sbin \
|
$(testroot)/sbin \
|
||||||
@@ -45,8 +49,8 @@ $(testroot_bin)/%: $(testroot_bin)/$(busybox-bin)
|
|||||||
cd $(testroot_bin); \
|
cd $(testroot_bin); \
|
||||||
ln -s $(busybox-bin) $(notdir $@)
|
ln -s $(busybox-bin) $(notdir $@)
|
||||||
|
|
||||||
$(testroot_bin)/testwrapper.sh:
|
$(testroot_bin)/chrootsetup.sh: chrootsetup.sh
|
||||||
cp testwrapper.sh $@
|
cp $< $@
|
||||||
|
|
||||||
$(testroot)/sbin/finit: ../src/finit $(testroot)/lib/ld-musl-x86_64.so.1 $(testroot)/usr/local/lib/libite.so.5 $(testroot)/usr/local/lib/libuev.so.2
|
$(testroot)/sbin/finit: ../src/finit $(testroot)/lib/ld-musl-x86_64.so.1 $(testroot)/usr/local/lib/libite.so.5 $(testroot)/usr/local/lib/libuev.so.2
|
||||||
cp $< $@
|
cp $< $@
|
||||||
@@ -61,8 +65,8 @@ $(testroot)/usr/local/lib/libuev.so.2:
|
|||||||
cp test_root.backup/usr/local/lib/libuev.so.2 $@
|
cp test_root.backup/usr/local/lib/libuev.so.2 $@
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: $(binaries) $(testroot_bin)/testwrapper.sh $(dirs) $(testroot)/sbin/finit
|
test: $(binaries) $(testroot_bin)/chrootsetup.sh $(dirs) $(testroot)/sbin/finit
|
||||||
./run.sh finit
|
./runtest.sh ./test_start_stop_service/test.sh
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ mount -n -t tmpfs none /dev
|
|||||||
mount -t proc none /proc
|
mount -t proc none /proc
|
||||||
mount -t sysfs none /sys
|
mount -t sysfs none /sys
|
||||||
mount -t tmpfs none /tmp
|
mount -t tmpfs none /tmp
|
||||||
|
mount -t tmpfs none /etc
|
||||||
|
|
||||||
# mkdir -p /dev/pts
|
# mkdir -p /dev/pts
|
||||||
# mount -t devpts none /dev/pts
|
# mount -t devpts none /dev/pts
|
||||||
Executable
+52
@@ -0,0 +1,52 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
texec() {
|
||||||
|
./testenv_exec.sh $(pgrep -P $finit_ppid) "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
fg_red='31'
|
||||||
|
fg_green='32'
|
||||||
|
fg_yellow='33'
|
||||||
|
log() {
|
||||||
|
printf "< TEST > \e[1;%dm%s\e[0m %s\n" "$1" "$2" "$3"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert() {
|
||||||
|
msg=$1
|
||||||
|
shift
|
||||||
|
if [ ! "$@" ]; then
|
||||||
|
log "$fg_red" ✘ "$msg"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
log "$fg_green" ✔ "$msg"
|
||||||
|
}
|
||||||
|
|
||||||
|
say() {
|
||||||
|
log "$fg_yellow" ● "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
teardown() {
|
||||||
|
texec kill 1
|
||||||
|
|
||||||
|
wait
|
||||||
|
}
|
||||||
|
|
||||||
|
trap teardown EXIT
|
||||||
|
|
||||||
|
# Setup
|
||||||
|
./testenv_start.sh finit &
|
||||||
|
finit_ppid=$!
|
||||||
|
for i in $(seq 1 50); do
|
||||||
|
sleep 0.1
|
||||||
|
finit_pid=$(pgrep -P "$finit_ppid") || continue
|
||||||
|
break
|
||||||
|
done
|
||||||
|
|
||||||
|
texec cat /dev/tty0 &
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
TEST_DIR=$(dirname $1)
|
||||||
|
|
||||||
|
source "$1"
|
||||||
Executable
+7
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
while [ 1 ]; do
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
Executable
+28
@@ -0,0 +1,28 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
# Test
|
||||||
|
say 'Set up a service'
|
||||||
|
cp "$TEST_DIR"/service.sh test_root/bin
|
||||||
|
texec sh -c 'echo "service [2345] kill:20 log /bin/service.sh" > /etc/finit.conf'
|
||||||
|
|
||||||
|
say 'Reload Finit'
|
||||||
|
texec kill -SIGHUP 1
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
service_pids=( $(texec pgrep -P 1) )
|
||||||
|
assert 'One service is running' ${#service_pids[@]} -eq 1
|
||||||
|
|
||||||
|
say 'Remove the service'
|
||||||
|
texec sh -c 'echo > /etc/finit.conf'
|
||||||
|
|
||||||
|
say 'Reload Finit'
|
||||||
|
texec kill -SIGHUP 1
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
service_pids=( $(texec pgrep -P 1) )
|
||||||
|
assert 'Zero services are running' ${#service_pids[@]} -eq 0
|
||||||
|
|
||||||
|
# Teardown
|
||||||
|
rm -f test_root/bin/service.sh
|
||||||
File renamed without changes.
@@ -5,7 +5,7 @@ set -eu
|
|||||||
TEST_DIR=$(dirname "$0")
|
TEST_DIR=$(dirname "$0")
|
||||||
TESTS_ROOT="$(pwd)/${TEST_DIR}/test_root"
|
TESTS_ROOT="$(pwd)/${TEST_DIR}/test_root"
|
||||||
|
|
||||||
echo "Hint: Execute './test/testenter.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"
|
||||||
|
|
||||||
# Not supported by Busybox unshare:
|
# Not supported by Busybox unshare:
|
||||||
# --cgroup --time
|
# --cgroup --time
|
||||||
@@ -16,4 +16,4 @@ exec unshare \
|
|||||||
--mount \
|
--mount \
|
||||||
--mount-proc \
|
--mount-proc \
|
||||||
--uts --ipc --net \
|
--uts --ipc --net \
|
||||||
chroot "$TESTS_ROOT" /bin/testwrapper.sh "$@"
|
chroot "$TESTS_ROOT" /bin/chrootsetup.sh "$@"
|
||||||
Reference in new issue
Block a user