1#!/usr/bin/env bash
2# SPDX-License-Identifier: LGPL-2.1-or-later
3set -eux
4set -o pipefail
5
6rm -f /test.log
7
8TESTLOG=/test.log.XXXXXXXX
9
10function wait_for()
11{
12    local service="${1:-wait_for: missing service argument}"
13    local result="${2:-success}"
14    local time="${3:-45}"
15
16    while [[ ! -f /${service}.terminated && ! -f /${service}.success && $time -gt 0 ]]; do
17        sleep 1
18        time=$((time - 1))
19    done
20
21    if [[ ! -f /${service}.${result} ]]; then
22        journalctl -u "${service/_/-}.service" >>"$TESTLOG"
23    fi
24}
25
26# This checks all stages, start, runtime and stop, can be extended by
27# EXTEND_TIMEOUT_USEC
28
29wait_for success_all
30
31# These check that EXTEND_TIMEOUT_USEC that occurs at greater than the
32# extend timeout interval but less then the stage limit (TimeoutStartSec,
33# RuntimeMaxSec, TimeoutStopSec) still succeed.
34
35wait_for success_start
36wait_for success_runtime
37wait_for success_stop
38
39# These ensure that EXTEND_TIMEOUT_USEC will still timeout in the
40# appropriate stage, after the stage limit, when the EXTEND_TIMEOUT_USEC
41# message isn't sent within the extend timeout interval.
42
43wait_for fail_start startfail
44wait_for fail_stop stopfail
45wait_for fail_runtime runtimefail
46
47if [[ -f "$TESTLOG" ]]; then
48    # no mv
49    cp "$TESTLOG" /test.log
50    exit 1
51fi
52
53touch /testok
54exit 0
55