|
| 1 | +#!/bin/bash |
| 2 | +#set -eu |
| 3 | +shopt -s nullglob |
| 4 | + |
| 5 | +trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT |
| 6 | + |
| 7 | +# assuming that we'll be using native provide && all processes will be executing locally |
| 8 | +# (we need absolute paths here, because they're used when scripts are called by zombienet from tmp folders) |
| 9 | +export POLKADOT_SDK_FOLDER=`realpath $(dirname "$0")/../..` |
| 10 | +export BRIDGE_TESTS_FOLDER=$POLKADOT_SDK_FOLDER/bridges/zombienet/tests |
| 11 | +export POLKADOT_BINARY_PATH=$POLKADOT_SDK_FOLDER/target/release/polkadot |
| 12 | +export POLKADOT_PARACHAIN_BINARY_PATH=$POLKADOT_SDK_FOLDER/target/release/polkadot-parachain |
| 13 | +export POLKADOT_PARACHAIN_BINARY_PATH_FOR_ASSET_HUB_ROCOCO=$POLKADOT_PARACHAIN_BINARY_PATH |
| 14 | +export POLKADOT_PARACHAIN_BINARY_PATH_FOR_ASSET_HUB_WOCOCO=$POLKADOT_PARACHAIN_BINARY_PATH |
| 15 | +export ZOMBIENET_BINARY_PATH=~/local_bridge_testing/bin/zombienet-linux |
| 16 | + |
| 17 | +# bridge configuration |
| 18 | +export LANE_ID="00000001" |
| 19 | + |
| 20 | +# tests configuration |
| 21 | +ALL_TESTS_FOLDER=`mktemp -d` |
| 22 | + |
| 23 | +function start_coproc() { |
| 24 | + local command=$1 |
| 25 | + local name=$2 |
| 26 | + local coproc_log=`mktemp -p $TEST_FOLDER` |
| 27 | + coproc COPROC { |
| 28 | + $command >$coproc_log 2>&1 |
| 29 | + } |
| 30 | + TEST_COPROCS[$COPROC_PID, 0]=$name |
| 31 | + TEST_COPROCS[$COPROC_PID, 1]=$coproc_log |
| 32 | + echo "Spawned $name coprocess. StdOut + StdErr: $coproc_log" |
| 33 | + |
| 34 | + return $COPROC_PID |
| 35 | +} |
| 36 | + |
| 37 | +# execute every test from tests folder |
| 38 | +TEST_INDEX=1 |
| 39 | +while true |
| 40 | +do |
| 41 | + declare -A TEST_COPROCS |
| 42 | + TEST_COPROCS_COUNT=0 |
| 43 | + TEST_PREFIX=$(printf "%04d" $TEST_INDEX) |
| 44 | + |
| 45 | + # it'll be used by the `sync-exit.sh` script |
| 46 | + export TEST_FOLDER=`mktemp -d -p $ALL_TESTS_FOLDER` |
| 47 | + |
| 48 | + # check if there are no more tests |
| 49 | + zndsl_files=($BRIDGE_TESTS_FOLDER/$TEST_PREFIX-*.zndsl) |
| 50 | + if [ ${#zndsl_files[@]} -eq 0 ]; then |
| 51 | + break |
| 52 | + fi |
| 53 | + |
| 54 | + # start relay |
| 55 | + if [ -f $BRIDGE_TESTS_FOLDER/$TEST_PREFIX-start-relay.sh ]; then |
| 56 | + start_coproc "${BRIDGE_TESTS_FOLDER}/${TEST_PREFIX}-start-relay.sh" "relay" |
| 57 | + RELAY_COPROC=$COPROC_PID |
| 58 | + ((TEST_COPROCS_COUNT++)) |
| 59 | + fi |
| 60 | + # start tests |
| 61 | + for zndsl_file in "${zndsl_files[@]}"; do |
| 62 | + start_coproc "$ZOMBIENET_BINARY_PATH --provider native test $zndsl_file" "$zndsl_file" |
| 63 | + echo -n "1">>$TEST_FOLDER/exit-sync |
| 64 | + ((TEST_COPROCS_COUNT++)) |
| 65 | + done |
| 66 | + # wait until all tests are completed |
| 67 | + relay_exited=0 |
| 68 | + for n in `seq 1 $TEST_COPROCS_COUNT`; do |
| 69 | + wait -n -p COPROC_PID |
| 70 | + exit_code=$? |
| 71 | + coproc_name=${TEST_COPROCS[$COPROC_PID, 0]} |
| 72 | + coproc_log=${TEST_COPROCS[$COPROC_PID, 1]} |
| 73 | + coproc_stdout=$(cat $coproc_log) |
| 74 | + relay_exited=$(expr "${coproc_name}" == "relay") |
| 75 | + echo "Process $coproc_name has finished with exit code: $exit_code" |
| 76 | + |
| 77 | + # if exit code is not zero, exit |
| 78 | + if [ $exit_code -ne 0 ]; then |
| 79 | + echo "=====================================================================" |
| 80 | + echo "=== Shutting down. Log of failed process below ===" |
| 81 | + echo "=====================================================================" |
| 82 | + echo $coproc_stdout |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | + |
| 86 | + # if last test has exited, exit relay too |
| 87 | + if [ $n -eq $(($TEST_COPROCS_COUNT - 1)) ] && [ $relay_exited -eq 0 ]; then |
| 88 | + kill $RELAY_COPROC |
| 89 | + break |
| 90 | + fi |
| 91 | + done |
| 92 | + ((TEST_INDEX++)) |
| 93 | +done |
| 94 | + |
| 95 | +echo "=====================================================================" |
| 96 | +echo "=== All tests have completed successfully ===" |
| 97 | +echo "=====================================================================" |
0 commit comments