taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

phase.sh (4780B)


      1 #!/bin/bash
      2 # This file is part of GNU Taler
      3 # (C) 2026 Taler Systems S.A.
      4 #
      5 # GNU Taler is free software; you can redistribute it and/or modify it under the
      6 # terms of the GNU General Public License as published by the Free Software
      7 # Foundation; either version 3, or (at your option) any later version.
      8 #
      9 # GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
     10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 #
     13 # You should have received a copy of the GNU General Public License along with
     14 # GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 #
     16 # Run a set of scenarios against a different stack, then put the default stack
     17 # back and resume the rounds.
     18 #
     19 #   ./phase.sh sim-kyc.conf kyc_withdraw_trips_rule kyc_transaction_actions
     20 #   ./phase.sh sim-twister.conf twister_withdraw_faults twister_field_faults
     21 #
     22 # Only one stack can run at a time (the exchange's secmod sockets are shared),
     23 # so this stops the unattended loop first and restarts it afterwards at the
     24 # next round number.
     25 
     26 set -u
     27 
     28 HERE=$(cd "$(dirname "$0")" && pwd)
     29 RUN=${SIM_RUN_DIR:-/opt/taler-sim/run}
     30 BACKEND="$HERE/../backend"
     31 CONF=${1:?usage: phase.sh <config> <scenario>...}
     32 shift
     33 SCENARIOS=("$@")
     34 [ "${#SCENARIOS[@]}" -gt 0 ] || { echo "no scenarios given" >&2; exit 2; }
     35 TAG=${SIM_PHASE_TAG:-phase-${CONF%.conf}-$(date +%s)}
     36 
     37 say() { printf '%s phase %s: %s\n' "$(date -Is)" "$TAG" "$*" | tee -a "$RUN/rounds.log"; }
     38 
     39 # 1. Pause the unattended loop and wait for the round in flight to end.
     40 say "pausing the rounds"
     41 touch "$RUN/STOP"
     42 # A round is an exploration pass plus every scenario, which is well over an
     43 # hour now; waiting only 40 minutes meant the stack was swapped *under* a
     44 # running round, which corrupts both it and the phase.  Three hours, and if a
     45 # campaign is still running after that, do not swap the stack at all.
     46 for _ in $(seq 1 1080); do
     47     pgrep -f "python3 -u campaign.py" >/dev/null || break
     48     sleep 10
     49 done
     50 if pgrep -f "python3 -u campaign.py" >/dev/null; then
     51     say "a campaign is STILL running after three hours; not swapping the stack"
     52     rm -f "$RUN/STOP"
     53     exit 1
     54 fi
     55 
     56 # 2. Swap the stack.
     57 say "starting the stack from $CONF"
     58 (cd "$BACKEND" && ./stack.sh stop >/dev/null 2>&1)
     59 if ! (cd "$BACKEND" && SIM_CONF="$CONF" ./stack.sh start > "$RUN/$TAG-stack.log" 2>&1); then
     60     say "the stack would not start from $CONF; see $TAG-stack.log"
     61     tail -15 "$RUN/$TAG-stack.log" >&2
     62     (cd "$BACKEND" && ./stack.sh start >/dev/null 2>&1) && say "default stack restored"
     63     python3 "$HERE/stack.py" > "$RUN/$TAG-provision.log" 2>&1 || true
     64     for w in 0 1 2 3 4; do
     65         "$HERE/../emu/emu.sh" reverse "$w" >> "$RUN/$TAG-reverse.log" 2>&1 || true
     66     done
     67     # The rounds must carry on even when a variant will not start, or a failed
     68     # phase silently ends the campaign.
     69     rm -f "$RUN/STOP"
     70     NEXT=$(( $(grep -c 'round .*: starting' "$RUN/rounds.log" 2>/dev/null || echo 5) + 5 ))
     71     say "resuming rounds at $NEXT after the failed phase"
     72     nohup setsid "$HERE/forever.sh" "$NEXT" > "$RUN/forever-after-$TAG.log" 2>&1 < /dev/null &
     73     exit 1
     74 fi
     75 python3 "$HERE/stack.py" > "$RUN/$TAG-provision.log" 2>&1 || say "provisioning complained"
     76 
     77 # The variant may serve on a port the emulators have never had mapped (the
     78 # twister proxy, for one), and adb reverse only knows what it was told.
     79 for w in 0 1 2 3 4; do
     80     "$HERE/../emu/emu.sh" reverse "$w" >> "$RUN/$TAG-reverse.log" 2>&1 || true
     81 done
     82 say "re-mapped the stack ports into the emulators"
     83 
     84 # 3. Run the scenarios across the workers.
     85 say "running ${SCENARIOS[*]}"
     86 python3 -u "$HERE/campaign.py" suite --workers 4 --tag "$TAG" \
     87     --only "${SCENARIOS[@]}" > "$RUN/$TAG.log" 2>&1
     88 ok=$(grep -cE '^   [a-z_]+ ' "$RUN/$TAG.log" 2>/dev/null || echo 0)
     89 bad=$(grep -cE '^ ! [a-z_]+ ' "$RUN/$TAG.log" 2>/dev/null || echo 0)
     90 serious=$(grep -c '^ \*\*\*' "$RUN/$TAG.log" 2>/dev/null || echo 0)
     91 say "$ok ok, $bad driver errors, $serious serious findings (see $TAG.log)"
     92 
     93 # 4. Put the default stack back and let the rounds continue.
     94 say "restoring the default stack"
     95 (cd "$BACKEND" && ./stack.sh stop >/dev/null 2>&1)
     96 (cd "$BACKEND" && ./stack.sh start > "$RUN/$TAG-restore.log" 2>&1) ||
     97     say "WARNING: the default stack did not come back; see $TAG-restore.log"
     98 python3 "$HERE/stack.py" >> "$RUN/$TAG-provision.log" 2>&1
     99 for w in 0 1 2 3 4; do
    100     "$HERE/../emu/emu.sh" reverse "$w" >> "$RUN/$TAG-reverse.log" 2>&1 || true
    101 done
    102 rm -f "$RUN/STOP"
    103 NEXT=$(( $(grep -c 'round .*: starting' "$RUN/rounds.log" 2>/dev/null || echo 5) + 5 ))
    104 say "resuming rounds at $NEXT"
    105 nohup setsid "$HERE/forever.sh" "$NEXT" > "$RUN/forever-after-$TAG.log" 2>&1 < /dev/null &