setup.sh (2827B)
1 # This file is in the public domain. 2 # 3 # Inlined into test scripts that need a live GNU Taler system. Defines 4 # setup(), which wraps `taler-unified-setup.sh': it launches the services, 5 # waits until they report READY, and installs an exit handler that stops 6 # them again. Pass setup() the arguments for taler-unified-setup.sh. 7 # 8 # This is the same wrapper the merchant and anastasis test suites use. 9 # Keep it in step with them rather than improving it here. 10 11 set -eu 12 13 # The Taler services write into TALER_TEST_HOME (see test_paywall.conf); 14 # an XDG variable inherited from the caller would send parts of them 15 # somewhere else and the run would use a mix of the two. 16 unset XDG_DATA_HOME 17 unset XDG_CONFIG_HOME 18 19 20 # Exit with the meson/automake "skip" status. A missing component is an 21 # environment problem, not a regression, and must not fail the suite. 22 function exit_skip() { 23 echo "SKIPPING: $*" >&2 24 exit 77 25 } 26 27 function exit_fail() { 28 echo "$@" >&2 29 exit 1 30 } 31 32 # Cleanup to run whenever we exit 33 function exit_cleanup() 34 { 35 if [ ! -z ${SETUP_PID+x} ] 36 then 37 echo "Killing taler-unified-setup ($SETUP_PID)" >&2 38 kill -TERM "$SETUP_PID" 2> /dev/null || true 39 wait "$SETUP_PID" 2> /dev/null || true 40 fi 41 } 42 43 # Install cleanup handler (except for kill -9) 44 trap exit_cleanup EXIT 45 46 function setup() 47 { 48 echo "Starting test system ..." >&2 49 # Create a named pipe in a temp directory we own. 50 FIFO_DIR=$(mktemp -p "${TMPDIR:-/tmp}" -d fifo-XXXXXX) 51 FIFO_OUT="$FIFO_DIR/out" 52 mkfifo "$FIFO_OUT" 53 # Open pipe as FD 3 (RW) and FD 4 (RO) 54 exec 3<> "$FIFO_OUT" 4< "$FIFO_OUT" 55 rm -rf "$FIFO_DIR" 56 # We require '-W' for our termination logic to work. 57 taler-unified-setup.sh -W "$@" >&3 & 58 SETUP_PID=$! 59 # Close FD3 60 exec 3>&- 61 # Pass the setup's output through until it announces READY:. Note that 62 # reaching end-of-pipe is NOT success: that is what happens when 63 # taler-unified-setup.sh dies during startup, and continuing then makes 64 # the test fail much later against a system that was never brought up, 65 # hiding the actual error. So insist on having seen the marker. 66 SETUP_READY=0 67 while IFS= read -r line <&4 68 do 69 printf '%s\n' "$line" 70 case "$line" in 71 *READY:*) 72 SETUP_READY=1 73 break 74 ;; 75 esac 76 done 77 # Close FD4 78 exec 4>&- 79 if [ "1" != "$SETUP_READY" ] 80 then 81 wait "$SETUP_PID" || SETUP_STATUS=$? 82 unset SETUP_PID 83 if [ "${SETUP_STATUS:-1}" = "77" ] 84 then 85 exit_skip "taler-unified-setup.sh could not launch the test system" 86 fi 87 exit_fail "taler-unified-setup.sh died with status ${SETUP_STATUS:-?} before the test system was ready" 88 fi 89 echo "Test system ready" >&2 90 }