File: test_harness.sh

package info (click to toggle)
mini-init-asm 0.3.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 372 kB
  • sloc: asm: 3,733; sh: 693; makefile: 85
file content (74 lines) | stat: -rw-r--r-- 1,689 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
set -euo pipefail
BIN="${1:-./build/mini-init-amd64}"

echo "[test] 1) Graceful termination"
set -m
EP_GRACE_SECONDS=5 "$BIN" -v -- /bin/bash scripts/fixtures/trap_exit0.sh &
pid=$!
sleep 1
if ! kill -0 "$pid" 2>/dev/null; then
  echo "[test] ERROR: init exited before TERM (pid=$pid)"
  wait "$pid" || true
  exit 1
fi
kill -TERM "$pid"
set +e
wait "$pid"
wait_rc=$?
set -e
echo "[test] rc=$wait_rc"
# our fixture exits 0 on TERM
test "$wait_rc" -eq 0

echo "[test] 2) Escalation after grace (app ignores TERM)"
EP_GRACE_SECONDS=1 "$BIN" -v -- /bin/bash -c 'trap "" TERM INT HUP QUIT; while :; do sleep 5; done' &
pid=$!
sleep 1
if ! kill -0 "$pid" 2>/dev/null; then
  echo "[test] ERROR: init exited before TERM (pid=$pid)"
  wait "$pid" || true
  exit 1
fi
kill -TERM "$pid"
set +e
wait "$pid"
wait_rc=$?
set -e
echo "[test] rc=$wait_rc"
test "$wait_rc" -eq 137
echo "[test] OK (got 137)"

echo "[test] 3) Forward custom EP_SIGNALS=USR1"
EP_SIGNALS=USR1 "$BIN" -v -- /bin/bash -c 'trap "echo got USR1; exit 0" USR1; sleep 99' &
pid=$!
sleep 1
if ! kill -0 "$pid" 2>/dev/null; then
  echo "[test] ERROR: init exited before USR1 (pid=$pid)"
  wait "$pid" || true
  exit 1
fi
kill -USR1 "$pid"
set +e
wait "$pid"
wait_rc=$?
set -e
echo "[test] rc=$wait_rc"
test "$wait_rc" -eq 0

echo "[test] 4) Forward numeric EP_SIGNALS=5 (SIGTRAP)"
EP_SIGNALS=5 "$BIN" -v -- /bin/sh -c 'trap "echo got TRAP; exit 0" TRAP; sleep 99' &
pid=$!
sleep 1
if ! kill -0 "$pid" 2>/dev/null; then
  echo "[test] ERROR: init exited before TRAP (pid=$pid)"
  wait "$pid" || true
  exit 1
fi
kill -TRAP "$pid"
set +e
wait "$pid"
wait_rc=$?
set -e
echo "[test] rc=$wait_rc"
test "$wait_rc" -eq 0