tests/roundtrip.sh (1398 bytes)
1 #!/bin/sh 2 # Round-trip test against a running p9c-server. Run it on the storage node. 3 # Writes 1 MiB of random bytes to /share, reads them back, and compares 4 # checksums; then runs a CPU job whose input and output live in /share. 5 # Prints PASS or FAIL and exits 0 or 1. 6 set -u 7 p9c=${P9C:-$(dirname "$0")/../bin/p9c} 8 t=/share/p9c-test.$$ 9 tmp=$(mktemp -d) 10 trap 'rm -rf "$tmp"' EXIT 11 12 head -c 1048576 /dev/urandom >"$tmp/in" 13 $p9c create $t.in && $p9c write $t.in <"$tmp/in" || { echo "FAIL: write"; exit 1; } 14 $p9c read $t.in >"$tmp/back" || { echo "FAIL: read"; exit 1; } 15 a=$(sha256sum <"$tmp/in" | cut -d' ' -f1) 16 b=$(sha256sum <"$tmp/back" | cut -d' ' -f1) 17 [ "$a" = "$b" ] || { echo "FAIL: read back $b, wrote $a"; exit 1; } 18 echo "storage round trip: $a" 19 20 # CPU job: input from /share, result to /share, result checked by a reader. 21 $p9c read $t.in | gzip -9 | wc -c >"$tmp/job" 22 $p9c create $t.out && $p9c write $t.out <"$tmp/job" || { echo "FAIL: job output"; exit 1; } 23 [ "$($p9c read $t.out)" = "$(cat "$tmp/job")" ] || { echo "FAIL: job output differs"; exit 1; } 24 echo "job output: $(cat "$tmp/job") bytes gzip" 25 26 # Removing files must not take the server down (stock plan9port fossil 27 # freed the source and then wrote to it in fileRemove: segfault). 28 $p9c rm $t.in $t.out || { echo "FAIL: rm"; exit 1; } 29 sleep 1 30 $p9c stat /share >/dev/null || { echo "FAIL: server gone after rm"; exit 1; } 31 echo PASS