mirror of
https://github.com/troglobit/finit.git
synced 2026-11-29 21:08:21 +00:00
Test case for initctl signal
This commit implements a test for the signal feature of initctl. The existing service used in tests (`common/service.sh`) has been extended with a signal trap handler. When SIGUSR1 is received, it will write the string `'USR1'` to `/tmp/usr1.log`. The test will run `initctl signal service.sh SIGUSR1` and assert that the contents of the file `/tmp/usr1.log` really is `USR1`.
This commit is contained in:
1 parent
4121113688
commit
beec0ee590
3 files changed
+42
No files matched your search
@@ -8,6 +8,7 @@ EXTRA_DIST += add-remove-dynamic-service-sub-config.sh
|
|||||||
EXTRA_DIST += start-stop-service.sh
|
EXTRA_DIST += start-stop-service.sh
|
||||||
EXTRA_DIST += start-stop-service-sub-config.sh
|
EXTRA_DIST += start-stop-service-sub-config.sh
|
||||||
EXTRA_DIST += start-kill-service.sh
|
EXTRA_DIST += start-kill-service.sh
|
||||||
|
EXTRA_DIST += signal-service.sh
|
||||||
|
|
||||||
AM_TESTS_ENVIRONMENT = TENV_ROOT='$(abs_builddir)/tenv-root/';
|
AM_TESTS_ENVIRONMENT = TENV_ROOT='$(abs_builddir)/tenv-root/';
|
||||||
AM_TESTS_ENVIRONMENT += export TENV_ROOT;
|
AM_TESTS_ENVIRONMENT += export TENV_ROOT;
|
||||||
@@ -28,6 +29,7 @@ TESTS += add-remove-dynamic-service-sub-config.sh
|
|||||||
TESTS += start-stop-service.sh
|
TESTS += start-stop-service.sh
|
||||||
TESTS += start-stop-service-sub-config.sh
|
TESTS += start-stop-service-sub-config.sh
|
||||||
TESTS += start-kill-service.sh
|
TESTS += start-kill-service.sh
|
||||||
|
TESTS += signal-service.sh
|
||||||
|
|
||||||
clean-local:
|
clean-local:
|
||||||
-rm -rf $(builddir)/tenv-root/
|
-rm -rf $(builddir)/tenv-root/
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
# Hook SIGUSR1 and dump trace to file system
|
||||||
|
# shellcheck disable=SC2172
|
||||||
|
trap 'echo USR1 > /tmp/usr1.log' 10
|
||||||
|
|
||||||
echo $$ > /run/service.pid
|
echo $$ > /run/service.pid
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
|
|||||||
Executable
+36
@@ -0,0 +1,36 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Verifies initctl can send arbitrary signals (USR1 in this case) to finit managed services
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
TEST_DIR=$(dirname "$0")
|
||||||
|
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "$TEST_DIR/tenv/lib.sh"
|
||||||
|
|
||||||
|
test_teardown() {
|
||||||
|
say "Test done $(date)"
|
||||||
|
say "Running test teardown."
|
||||||
|
|
||||||
|
texec rm -f "$FINIT_CONF"
|
||||||
|
texec rm -f /test_assets/service.sh
|
||||||
|
}
|
||||||
|
|
||||||
|
say "Test start $(date)"
|
||||||
|
|
||||||
|
cp "$TEST_DIR"/common/service.sh "$TENV_ROOT"/test_assets/
|
||||||
|
|
||||||
|
say 'Ensure file system is cleared'
|
||||||
|
texec rm -f /tmp/usr1.log
|
||||||
|
|
||||||
|
say "Add service stanza in $FINIT_CONF"
|
||||||
|
texec sh -c "echo 'service [2345] kill:20 log /test_assets/service.sh -- Test service' > $FINIT_CONF"
|
||||||
|
|
||||||
|
say 'Reload Finit'
|
||||||
|
texec sh -c "initctl reload"
|
||||||
|
|
||||||
|
say 'Send SIGUSR1 to service...'
|
||||||
|
texec sh -c "initctl signal service.sh SIGUSR1"
|
||||||
|
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
retry 'assert "service.sh received SIGUSR" "$(texec cat /tmp/usr1.log)" = "USR1"' 10 1
|
||||||
Reference in new issue
Block a user