| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
set -euo pipefail |
| 4 |
|
| 5 |
# enable job control |
| 6 |
set -m |
| 7 |
|
| 8 |
die() { |
| 9 |
echo "$1" |
| 10 |
exit 1 |
| 11 |
} |
| 12 |
|
| 13 |
export XDG_RUNTIME_DIR="$(pwd)" |
| 14 |
|
| 15 |
(stdbuf -o0 ./server | stdbuf -o0 tee ./server.log | sed -re 's/^/\[server] /') & |
| 16 |
sleep 1 |
| 17 |
|
| 18 |
(stdbuf -o0 ./client | stdbuf -o0 tee ./client.log | sed -re 's/^/\[client] /') & |
| 19 |
sleep 2 |
| 20 |
|
| 21 |
# kill the server |
| 22 |
kill -INT %1 |
| 23 |
|
| 24 |
# wait 5 seconds for client to exit itself |
| 25 |
sleep 5 |
| 26 |
|
| 27 |
# client should have exited itself after receiving fatal protocol error |
| 28 |
if kill -0 %2 2>/dev/null; then |
| 29 |
echo "Client is STILL ALIVE — this is a failure!" |
| 30 |
kill -INT %2 |
| 31 |
die "Client should have died after fatal protocol error!" |
| 32 |
else |
| 33 |
echo "Client exited on its own (correct behavior)." |
| 34 |
fi |
| 35 |
wait |
| 36 |
|
| 37 |
expected_client_strings=( |
| 38 |
'test protocol supported at version 1. Binding.' |
| 39 |
'Bound!' |
| 40 |
'Sent hello!' |
| 41 |
'Will send fd' |
| 42 |
|
| 43 |
# these two sometimes don't show up due to race conditions in the client |
| 44 |
# code (server sends messages before handler callback is registered) |
| 45 |
# 'Server says Hello manager |
| 46 |
# 'Server says on object Hello Object' |
| 47 |
|
| 48 |
# client sometimes terminates before the error is logged |
| 49 |
# '[hw] err: fatal protocol error: object 2 error 1: Important error occurred!' |
| 50 |
|
| 51 |
) |
| 52 |
|
| 53 |
expected_server_strings=( |
| 54 |
'Object bound XD' |
| 55 |
'Recvd message: Hello!' |
| 56 |
'Recvd fd' |
| 57 |
'Received 2 fds' |
| 58 |
'with data: pipe!' |
| 59 |
'with data: o kurwa' |
| 60 |
'with data: bober!!' |
| 61 |
'Got array message: "Hello, via, array!"' |
| 62 |
'Got array message: ""' |
| 63 |
'Got uint array message: "69, 420, 2137"' |
| 64 |
'Object says hello: Hello on object' |
| 65 |
'Object sent enum: 4' |
| 66 |
'Erroring out the client!' |
| 67 |
) |
| 68 |
|
| 69 |
for s in "${expected_client_strings[@]}"; do |
| 70 |
echo -n "Checking client.log for '$s'... " |
| 71 |
if grep -q --fixed-strings "$s" client.log; then |
| 72 |
echo "Pass" |
| 73 |
else |
| 74 |
die "Fail" |
| 75 |
fi |
| 76 |
done |
| 77 |
|
| 78 |
for s in "${expected_server_strings[@]}"; do |
| 79 |
echo -n "Checking server.log for '$s'... " |
| 80 |
if grep -q --fixed-strings "$s" server.log; then |
| 81 |
echo "Pass" |
| 82 |
else |
| 83 |
die "Fail" |
| 84 |
fi |
| 85 |
done |