tests: test alarms and led coordination through sysrepo-ietf-alarms

Depends-On: https://gerrit.cesnet.cz/c/CzechLight/sysrepo-ietf-alarms/+/6052
Change-Id: If964baf29774dc1aa15f5e87887b269d832f3e5a
diff --git a/tests/sysrepo_sysrepo-ietf-alarms_control.sh b/tests/sysrepo_sysrepo-ietf-alarms_control.sh
new file mode 100755
index 0000000..c839b98
--- /dev/null
+++ b/tests/sysrepo_sysrepo-ietf-alarms_control.sh
@@ -0,0 +1,55 @@
+#!/usr/bin/env bash
+
+PIDFILE="./test-alarms.pid"
+
+set -x
+
+stop() {
+    [[ ! -r "$PIDFILE" ]] && return 0 # no pidfile
+
+    PID="$(cat "$PIDFILE")"
+
+    if ps --pid "$PID" >/dev/null; then
+      kill -15 -- "$PID" 2>/dev/null  # please terminate
+      sleep 0.5
+      while ps --pid "$PID" >/dev/null; do
+        kill -9 -- "$PID" 2>/dev/null # shots fired
+      done
+    fi
+    echo "" > "$PIDFILE"
+}
+
+# $1 ... path to daemon
+start() {
+    rm -f "$PIDFILE" # in case these files already exist
+
+    if [[ ! -x "$1" ]]; then
+        echo "$1 is not executable" >&2
+        return 1
+    fi
+
+    $1 --sysrepo-log-level=5 1>$2 2>&1 &
+    PID="$!"
+    echo "$PID" > $PIDFILE
+
+    # wait for init
+    sleep 2
+
+    echo "Started $1 (pid=$PID)" >&2
+}
+
+help() {
+    echo "Usage:" >&2
+    echo "  $1 start PATH_TO_SYSREPO_IETF_ALARMSD LOGFILE" >&2
+    echo "  $1 stop" >&2
+}
+
+if [[ "$1" == "start" && $# == 3 ]]; then
+    stop
+    start "$2" "$3"
+elif [[ "$1" == "stop" && $# == 1 ]]; then
+    stop
+else
+    help
+    exit 1
+fi