From 6c2281fb66e2c9de0738d9bbe3c2e20e69cfebcd Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Sat, 27 Jul 2019 16:03:21 +1000 Subject: [PATCH] Add integration test for gentle stop/force stop. --- src/igr-tests/force-stop/expected-1 | 3 +++ src/igr-tests/force-stop/expected-2.err | 3 +++ src/igr-tests/force-stop/expected-3 | 1 + src/igr-tests/force-stop/run-test.sh | 33 ++++++++++++++++++++++++ src/igr-tests/force-stop/sd/boot | 3 +++ src/igr-tests/force-stop/sd/critical | 1 + src/igr-tests/force-stop/sd/intermediary | 2 ++ src/igr-tests/igr-runner.cc | 2 +- 8 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/igr-tests/force-stop/expected-1 create mode 100644 src/igr-tests/force-stop/expected-2.err create mode 100644 src/igr-tests/force-stop/expected-3 create mode 100755 src/igr-tests/force-stop/run-test.sh create mode 100644 src/igr-tests/force-stop/sd/boot create mode 100644 src/igr-tests/force-stop/sd/critical create mode 100644 src/igr-tests/force-stop/sd/intermediary diff --git a/src/igr-tests/force-stop/expected-1 b/src/igr-tests/force-stop/expected-1 new file mode 100644 index 0000000..6737262 --- /dev/null +++ b/src/igr-tests/force-stop/expected-1 @@ -0,0 +1,3 @@ +[{+} ] boot +[{+} ] critical +[{+} ] intermediary diff --git a/src/igr-tests/force-stop/expected-2.err b/src/igr-tests/force-stop/expected-2.err new file mode 100644 index 0000000..561b7d2 --- /dev/null +++ b/src/igr-tests/force-stop/expected-2.err @@ -0,0 +1,3 @@ +dinitctl: Cannot stop service due to the following dependents: +(Only direct dependents are listed. Exercise caution before using '--force' !!) + intermediary boot diff --git a/src/igr-tests/force-stop/expected-3 b/src/igr-tests/force-stop/expected-3 new file mode 100644 index 0000000..d081f7a --- /dev/null +++ b/src/igr-tests/force-stop/expected-3 @@ -0,0 +1 @@ +Service stopped. diff --git a/src/igr-tests/force-stop/run-test.sh b/src/igr-tests/force-stop/run-test.sh new file mode 100755 index 0000000..44d52b5 --- /dev/null +++ b/src/igr-tests/force-stop/run-test.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +../../dinit -d sd -u -p socket -q & +DINITPID=$! + +# give time for socket to open +while [ ! -e socket ]; do + sleep 0.1 +done + +DINITCTLOUT="$(../../dinitctl -p socket list)" +if [ "$DINITCTLOUT" != "$(cat expected-1)" ]; then + kill $DINITPID; wait $DINITPID + exit 1 +fi + +DINITCTLOUT="$(../../dinitctl -p socket stop critical 2>&1)" +if [ "$DINITCTLOUT" != "$(cat expected-2.err)" ]; then + kill $DINITPID; wait $DINITPID + exit 1 +fi + +DINITCTLOUT="$(../../dinitctl -p socket stop --force critical 2>&1)" +if [ "$DINITCTLOUT" != "$(cat expected-3)" ]; then + kill $DINITPID; wait $DINITPID + exit 1; +fi + +# Note dinit should shutdown since all services stopped. +wait $DINITPID + +# Passed: +exit 0 diff --git a/src/igr-tests/force-stop/sd/boot b/src/igr-tests/force-stop/sd/boot new file mode 100644 index 0000000..b55189a --- /dev/null +++ b/src/igr-tests/force-stop/sd/boot @@ -0,0 +1,3 @@ +type = internal +depends-on = critical +depends-on = intermediary diff --git a/src/igr-tests/force-stop/sd/critical b/src/igr-tests/force-stop/sd/critical new file mode 100644 index 0000000..06545a6 --- /dev/null +++ b/src/igr-tests/force-stop/sd/critical @@ -0,0 +1 @@ +type = internal diff --git a/src/igr-tests/force-stop/sd/intermediary b/src/igr-tests/force-stop/sd/intermediary new file mode 100644 index 0000000..187d6af --- /dev/null +++ b/src/igr-tests/force-stop/sd/intermediary @@ -0,0 +1,2 @@ +type = internal +depends-on = critical diff --git a/src/igr-tests/igr-runner.cc b/src/igr-tests/igr-runner.cc index e8a906b..879fe7d 100644 --- a/src/igr-tests/igr-runner.cc +++ b/src/igr-tests/igr-runner.cc @@ -12,7 +12,7 @@ extern char **environ; int main(int argc, char **argv) { - const char * const test_dirs[] = { "basic", "environ", "ps-environ", "chain-to" }; + const char * const test_dirs[] = { "basic", "environ", "ps-environ", "chain-to", "force-stop" }; constexpr int num_tests = sizeof(test_dirs) / sizeof(test_dirs[0]); int passed = 0; -- 2.25.1