| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | # Handle Ctrl-C by killing all sub-processing AND exiting |
| 4 | trap cleanup_and_exit INT |
| 5 | |
| 6 | function cleanup_and_exitscip-shell shell asymptote 3.11+ds-1 cleanup_and_exit(). { |
| 7 | local exit_code=${1:-1} |
| 8 | echoscip-shell system . . echo. "cleaning up..." |
| 9 | echoscip-shell system . . echo. |
| 10 | killscip-shell system . . kill. `catscip-shell system . . cat. /tmp/ws_test/pidfile.transferscip-shell filesystem . . `/tmp/ws_test/pidfile.transfer`.` &>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 11 | killscip-shell system . . kill. `catscip-shell system . . cat. /tmp/ws_test/pidfile.receivescip-shell filesystem . . `/tmp/ws_test/pidfile.receive`.` &>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 12 | killscip-shell system . . kill. `catscip-shell system . . cat. /tmp/ws_test/pidfile.sendscip-shell filesystem . . `/tmp/ws_test/pidfile.send`.` &>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 13 | exit ${exit_code} |
| 14 | } |
| 15 | |
| 16 | WITH_TLS=${WITH_TLS:-0} |
| 17 | BLOCKS=${BLOCKS:-20000} |
| 18 | |
| 19 | rmscip-shell system . . rm. -rf /tmp/ws_testscip-shell filesystem . . `/tmp/ws_test`. |
| 20 | mkdirscip-shell system . . mkdir. -p /tmp/ws_testscip-shell filesystem . . `/tmp/ws_test`. |
| 21 | client_tls='' |
| 22 | server_tls='' |
| 23 | protocol='ws://' |
| 24 | delay='--delay 10' |
| 25 | if [scip-shell system . . `[`. "$WITH_TLS" == "1" ]; then |
| 26 | certs="/tmp/ws_test/certsscip-shell filesystem . . `/tmp/ws_test/certs`." |
| 27 | ./generate_certs.sh "${certs}" |
| 28 | client_tls="--cert-file ${certs}/trusted-client-crt.pem" |
| 29 | client_tls="${client_tls} --key-file ${certs}/trusted-client-key.pem" |
| 30 | client_tls="${client_tls} --ca-file ${certs}/trusted-ca-crt.pem" |
| 31 | server_tls="--cert-file ${certs}/trusted-server-crt.pem" |
| 32 | server_tls="${server_tls} --key-file ${certs}/trusted-server-key.pem" |
| 33 | server_tls="${server_tls} --ca-file ${certs}/trusted-ca-crt.pem" |
| 34 | server_tls="${server_tls} --tls" |
| 35 | protocol='wss://' |
| 36 | delay='' |
| 37 | fi |
| 38 | |
| 39 | # Start a transport server |
| 40 | cd /tmp/ws_testscip-shell filesystem . . `/tmp/ws_test`. |
| 41 | ws transfer --port 8090 ${server_tls} --pidfile /tmp/ws_test/pidfile.transferscip-shell filesystem . . `/tmp/ws_test/pidfile.transfer`. & |
| 42 | |
| 43 | # Wait until the transfer server is up |
| 44 | while truescip-shell system . . true. |
| 45 | do |
| 46 | nc -zv 127.0.0.1 8090 && { |
| 47 | echoscip-shell system . . echo. "Transfer server up and running" |
| 48 | break |
| 49 | } |
| 50 | echoscip-shell system . . echo. "sleep ... wait for transfer server" |
| 51 | sleepscip-shell system . . sleep. 0.1 |
| 52 | done |
| 53 | |
| 54 | # Start a receiver |
| 55 | mkdirscip-shell system . . mkdir. -p /tmp/ws_test/receivescip-shell filesystem . . `/tmp/ws_test/receive`. |
| 56 | cd /tmp/ws_test/receivescip-shell filesystem . . `/tmp/ws_test/receive`. |
| 57 | ws receive "${protocol}127.0.0.1:8090" ${delay} --pidfile /tmp/ws_test/pidfile.receivescip-shell filesystem . . `/tmp/ws_test/pidfile.receive`. ${client_tls} & |
| 58 | |
| 59 | mkdirscip-shell system . . mkdir. -p /tmp/ws_test/sendscip-shell filesystem . . `/tmp/ws_test/send`. |
| 60 | cd /tmp/ws_test/sendscip-shell filesystem . . `/tmp/ws_test/send`. |
| 61 | ddscip-shell system . . dd. if=/dev/urandomscip-shell filesystem . . `/dev/urandom`. of=/tmp/ws_test/send/20M_filescip-shell filesystem . . `/tmp/ws_test/send/20M_file`. count=$BLOCKS bs=1024 |
| 62 | |
| 63 | # Start the sender job |
| 64 | ws send ${client_tls} --pidfile /tmp/ws_test/pidfile.sendscip-shell filesystem . . `/tmp/ws_test/pidfile.send`. "${protocol}127.0.0.1:8090" /tmp/ws_test/send/20M_filescip-shell filesystem . . `/tmp/ws_test/send/20M_file`. |
| 65 | |
| 66 | # Wait until the file has been written to disk |
| 67 | while truescip-shell system . . true. |
| 68 | do |
| 69 | if testscip-shell system . . test. -f /tmp/ws_test/receive/20M_filescip-shell filesystem . . `/tmp/ws_test/receive/20M_file`. ; then |
| 70 | echoscip-shell system . . echo. "Received file does exists, exiting loop" |
| 71 | break |
| 72 | fi |
| 73 | echoscip-shell system . . echo. "sleep ... wait for output file" |
| 74 | sleepscip-shell system . . sleep. 0.1 |
| 75 | done |
| 76 | |
| 77 | cksumscip-shell system . . cksum. /tmp/ws_test/send/20M_filescip-shell filesystem . . `/tmp/ws_test/send/20M_file`. |
| 78 | cksumscip-shell system . . cksum. /tmp/ws_test/receive/20M_filescip-shell filesystem . . `/tmp/ws_test/receive/20M_file`. |
| 79 | |
| 80 | # Give some time to ws receive to terminate |
| 81 | sleepscip-shell system . . sleep. 2 |
| 82 | |
| 83 | # Cleanup |
| 84 | cleanup_and_exitscip-shell shell asymptote 3.11+ds-1 cleanup_and_exit(). 0 |