blob: e7fcddad27f7930ada11a3ddbaac45cf412387ec (
plain)
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
|
#!/bin/bash
# Shared contract and execution helpers for maint scenario transports.
# Extract one declared variable from a scenario file in a clean subshell.
_scenario_var() { # <file> <varname>
bash -c 'set -eu; source "$1" || exit 9; eval "printf %s \"\${$2-}\""' \
_probe "$1" "$2" 2>/dev/null
}
_validate_scenario() { # <file> -> fatal on contract violation
local f="$1" base probe_err
base=$(basename "$f")
probe_err=$(bash -c 'set -eu; source "$1"
: "${SCENARIO_DESC:?missing SCENARIO_DESC}"
: "${SCENARIO_GROUP:?missing SCENARIO_GROUP}"
: "${SCENARIO_PROFILES:?missing SCENARIO_PROFILES}"
for p in $SCENARIO_PROFILES; do
case "$p" in btrfs|zfs|any) ;; *)
echo "bad profile token: $p" >&2; exit 1 ;;
esac
done
declare -f scenario_break scenario_fix scenario_assert >/dev/null \
|| { echo "missing scenario_break/fix/assert" >&2; exit 1; }' \
_probe "$f" 2>&1 >/dev/null) \
|| fatal "scenario contract violation in $base: $probe_err"
}
run_scenario() { # <index>
local i="$1" name="${S_NAMES[$1]}" f="${S_FILES[$1]}"
section "Scenario: $name — ${S_DESCS[$1]}"
# shellcheck disable=SC1090
source "$f"
local ok=true
step "break"
if ! scenario_break; then
error "$name: break step failed"
ok=false
fi
if [ "$ok" = "true" ]; then
step "fix"
if ! scenario_fix; then
error "$name: fix step failed"
ok=false
fi
fi
if [ "$ok" = "true" ]; then
step "assert"
if ! scenario_assert; then
error "$name: post-state assertion failed"
ok=false
fi
fi
unset -f scenario_break scenario_fix scenario_assert
unset SCENARIO_DESC SCENARIO_GROUP SCENARIO_PROFILES
if [ "$ok" = "true" ]; then
success "PASS: $name"
PASS+=("$name")
else
error "FAIL: $name"
FAIL+=("$name")
fi
}
|