summaryrefslogtreecommitdiff
path: root/tests/integration/run-live-audio-parallel-experiment.sh
blob: 12079251eb265d39d0cda4e835add72464a29db5 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env bash
# Local soak for overlapping GUI/audio smokes and non-GUI canaries.
# Not used by CI.
#
# --smoke checks the harness only (no GUI tests). Use that before a long soak.
set -u
set -o pipefail

usage () {
  cat <<'EOF'
Usage: run-live-audio-parallel-experiment.sh --build-dir DIR [options]

  --phase 1|2|3|all     Default: all
  --repeats-soak N      Full-suite passes per soak (serial then -j3). Default: 20
  --repeats-pair N      Full-suite passes per pairwise set. Default: 10
  --smoke               Validate the script and ctest listing; do not run GUI tests
EOF
}

build_dir=""
phase="all"
repeats_soak=20
repeats_pair=10
smoke=0
audio_re='test_wsjtx_live_audio_ft8|test_wsjtx_live_audio_jtty|test_wsjtx_jtty_tx_loopback|test_wsjtx_ft8_tx_loopback'
gui_audio_re="test_wsjtx_startup|${audio_re}"
canary_re='test_q65_decode_pipeline|test_tci_transceiver_characterization'
experiment_re="${gui_audio_re}|${canary_re}"
experiment_tests=(
  test_wsjtx_startup
  test_wsjtx_live_audio_ft8
  test_wsjtx_live_audio_jtty
  test_wsjtx_jtty_tx_loopback
  test_wsjtx_ft8_tx_loopback
  test_q65_decode_pipeline
  test_tci_transceiver_characterization
)
xvfb=(xvfb-run -a -s '-screen 0 1280x1024x24')
failures=0
ran=0

while [[ $# -gt 0 ]]; do
  case "$1" in
    --build-dir) build_dir=$2; shift 2 ;;
    --phase) phase=$2; shift 2 ;;
    --repeats-soak) repeats_soak=$2; shift 2 ;;
    --repeats-pair) repeats_pair=$2; shift 2 ;;
    --smoke) smoke=1; shift ;;
    -h|--help) usage; exit 0 ;;
    *) echo "unknown argument: $1" >&2; usage; exit 2 ;;
  esac
done

if [[ -z "${build_dir}" || ! -d "${build_dir}" ]]; then
  echo "--build-dir must be an existing CMake build directory" >&2
  exit 2
fi

if ! command -v xvfb-run >/dev/null 2>&1; then
  echo "xvfb-run is required" >&2
  exit 2
fi

if ! command -v ctest >/dev/null 2>&1; then
  echo "ctest is required" >&2
  exit 2
fi

listed=$(ctest --test-dir "${build_dir}" -N -R "${experiment_re}" | awk '/Test #/{print $3}')
for expected in "${experiment_tests[@]}"; do
  if [[ $'\n'"${listed}"$'\n' != *$'\n'"${expected}"$'\n'* ]]; then
    echo "ctest did not list ${expected}:" >&2
    echo "${listed}" >&2
    exit 2
  fi
done
listed_count=$(printf '%s\n' "${listed}" | awk 'NF { count++ } END { print count + 0 }')
if [[ "${listed_count}" -ne "${#experiment_tests[@]}" ]]; then
  echo "ctest listed unexpected experiment tests:" >&2
  echo "${listed}" >&2
  exit 2
fi

if [[ "${smoke}" -eq 1 ]]; then
  echo "smoke: xvfb-run and ctest listing ok"
  echo "smoke: tests:"
  printf '  %s\n' "${experiment_tests[@]}"
  echo "smoke: would run phase=${phase} soak=${repeats_soak} pair=${repeats_pair}"
  echo "======== 3 load start/stop ========"
  pids=()
  for ((i = 0; i < 2; i++)); do
    sleep 30 &
    pids+=($!)
  done
  kill "${pids[@]}" 2>/dev/null || true
  wait "${pids[@]}" 2>/dev/null || true
  echo "smoke: harness ok"
  exit 0
fi

run_ctest () {
  local label=$1
  shift
  echo
  echo "======== ${label} ========"
  printf '+'
  printf ' %q' "${xvfb[@]}" ctest --test-dir "${build_dir}" "$@"
  echo
  ran=$((ran + 1))
  if "${xvfb[@]}" ctest --test-dir "${build_dir}" "$@"; then
    echo "RESULT ${label}: pass"
  else
    echo "RESULT ${label}: fail (exit $?)"
    failures=$((failures + 1))
  fi
}

# Repeat whole matching suites N times. Do not use --repeat-until-fail:
# one flaky FT8 case must not skip later phases or later passes.
run_suite_repeats () {
  local label=$1
  local n=$2
  shift 2
  local i
  for ((i = 1; i <= n; i++)); do
    run_ctest "${label} pass ${i}/${n}" "$@"
  done
}

phase1 () {
  run_suite_repeats "1 serial" "${repeats_soak}" \
    -R "${experiment_re}" --output-on-failure
  run_suite_repeats "1 parallel -j3" "${repeats_soak}" \
    -j3 -R "${experiment_re}" --output-on-failure
}

phase2 () {
  run_suite_repeats "2 FT8 live || JTTY live" "${repeats_pair}" \
    -j2 -R 'test_wsjtx_live_audio_ft8|test_wsjtx_live_audio_jtty' \
    --output-on-failure
  run_suite_repeats "2 FT8 live || JTTY TX loopback" "${repeats_pair}" \
    -j2 -R 'test_wsjtx_live_audio_ft8|test_wsjtx_jtty_tx_loopback' \
    --output-on-failure
  run_suite_repeats "2 JTTY live || JTTY TX loopback" "${repeats_pair}" \
    -j2 -R 'test_wsjtx_live_audio_jtty|test_wsjtx_jtty_tx_loopback' \
    --output-on-failure
  run_suite_repeats "2 FT8 TX || FT8 live" "${repeats_pair}" \
    -j3 -R 'test_wsjtx_ft8_tx_loopback|test_wsjtx_live_audio_ft8' \
    --output-on-failure
  run_suite_repeats "2 FT8 TX || JTTY live" "${repeats_pair}" \
    -j3 -R 'test_wsjtx_ft8_tx_loopback|test_wsjtx_live_audio_jtty' \
    --output-on-failure
  run_suite_repeats "2 FT8 TX || JTTY TX loopback" "${repeats_pair}" \
    -j3 -R 'test_wsjtx_ft8_tx_loopback|test_wsjtx_jtty_tx_loopback' \
    --output-on-failure
  run_suite_repeats "2 FT8 TX || canaries" "${repeats_pair}" \
    -j3 -R "test_wsjtx_ft8_tx_loopback|${canary_re}" \
    --output-on-failure
  run_suite_repeats "2 startup || audio tests -j3" "${repeats_pair}" \
    -j3 -R "${gui_audio_re}" --output-on-failure
  run_suite_repeats "2 all four audio tests -j3" "${repeats_pair}" \
    -j3 -R "${audio_re}" --output-on-failure
}

phase3 () {
  echo
  echo "======== 3 contended: background gzip load ========"
  local pids=()
  local i
  for ((i = 0; i < 4; i++)); do
    (while true; do dd if=/dev/zero bs=1M count=64 2>/dev/null | gzip -1 >/dev/null; done) &
    pids+=($!)
  done
  run_suite_repeats "3 parallel -j3 under load" "${repeats_pair}" \
    -j3 -R "${experiment_re}" --output-on-failure
  kill "${pids[@]}" 2>/dev/null || true
  wait "${pids[@]}" 2>/dev/null || true
}

case "${phase}" in
  1) phase1 ;;
  2) phase2 ;;
  3) phase3 ;;
  all) phase1; phase2; phase3 ;;
  *) echo "phase must be 1, 2, 3, or all" >&2; exit 2 ;;
esac

echo
echo "======== summary ========"
echo "suites_run=${ran} suites_failed=${failures}"
if [[ "${failures}" -ne 0 ]]; then
  exit 1
fi
exit 0