Add integration test for service "restart" function.
authorDavin McCall <davmac@davmac.org>
Thu, 8 Aug 2019 12:18:26 +0000 (22:18 +1000)
committerDavin McCall <davmac@davmac.org>
Thu, 8 Aug 2019 12:18:26 +0000 (22:18 +1000)
src/igr-tests/Makefile
src/igr-tests/igr-runner.cc
src/igr-tests/restart/basic-ran [new file with mode: 0644]
src/igr-tests/restart/basic.sh [new file with mode: 0755]
src/igr-tests/restart/run-test.sh [new file with mode: 0755]
src/igr-tests/restart/sd/basic [new file with mode: 0644]
src/igr-tests/restart/sd/parent [new file with mode: 0644]

index d033d917e65683f3bc80f5de35abb72e0a199333..ad73728fe42dcd3e8f58ac107682a10d4ca58f66 100644 (file)
@@ -8,3 +8,4 @@ igr-runner: igr-runner.cc
 
 clean:
        rm -f igr-runner basic/basic-ran environ/env-record ps-environ/env-record chain-to/recorded-output
+       rm -f restart/basic-ran
index 879fe7d6df5207660d724a70a307e27205ff1dcf..784355708dfa6df5bcc2100dba0f84731e30a039 100644 (file)
@@ -12,7 +12,7 @@ extern char **environ;
 
 int main(int argc, char **argv)
 {
-    const char * const test_dirs[] = { "basic", "environ", "ps-environ", "chain-to", "force-stop" };
+    const char * const test_dirs[] = { "basic", "environ", "ps-environ", "chain-to", "force-stop", "restart" };
     constexpr int num_tests = sizeof(test_dirs) / sizeof(test_dirs[0]);
 
     int passed = 0;
diff --git a/src/igr-tests/restart/basic-ran b/src/igr-tests/restart/basic-ran
new file mode 100644 (file)
index 0000000..817c028
--- /dev/null
@@ -0,0 +1 @@
+ran
diff --git a/src/igr-tests/restart/basic.sh b/src/igr-tests/restart/basic.sh
new file mode 100755 (executable)
index 0000000..398b17d
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/sh
+# basic test; record our run
+
+echo "ran" > ./basic-ran
+
+while true; do
+    sleep .2
+done
diff --git a/src/igr-tests/restart/run-test.sh b/src/igr-tests/restart/run-test.sh
new file mode 100755 (executable)
index 0000000..75f70b4
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+rm -f ./basic-ran
+
+../../dinit -d sd -u -p socket -q \
+       parent &
+DINITPID=$!
+
+# give time for socket to open
+while [ ! -e socket ]; do
+    sleep 0.1
+done
+
+# wait until parent (and therefore 'basic') has fully started
+../../dinitctl --quiet -p socket start parent
+
+sleep 0.1 # time for file to be written
+
+STATUS=FAIL
+if [ -e basic-ran ]; then
+   if [ "$(cat basic-ran)" = "ran" ]; then
+       STATUS=PASS
+   fi
+fi
+
+if [ $STATUS != PASS ]; then
+    ../../dinitctl --quiet -p socket shutdown
+    exit 1;
+fi
+
+rm basic-ran 
+
+STATUS=FAIL
+../../dinitctl --quiet -p socket restart basic
+sleep .1 # time for file write
+if [ -e basic-ran ]; then
+   if [ "$(cat basic-ran)" = "ran" ]; then
+       STATUS=PASS
+   fi
+fi
+
+../../dinitctl --quiet -p socket shutdown
+wait $DINITPID
+
+if [ $STATUS = PASS ]; then exit 0; fi
+exit 1
diff --git a/src/igr-tests/restart/sd/basic b/src/igr-tests/restart/sd/basic
new file mode 100644 (file)
index 0000000..808dbe3
--- /dev/null
@@ -0,0 +1,2 @@
+type = process
+command = ./basic.sh
diff --git a/src/igr-tests/restart/sd/parent b/src/igr-tests/restart/sd/parent
new file mode 100644 (file)
index 0000000..f7c6964
--- /dev/null
@@ -0,0 +1,2 @@
+type = internal
+waits-for = basic