File: test-runner

package info (click to toggle)
hyprwire 0.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 552 kB
  • sloc: cpp: 4,039; xml: 101; sh: 59; makefile: 5
file content (69 lines) | stat: -rwxr-xr-x 1,662 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash

set -euo pipefail

# enable job control
set -m

export XDG_RUNTIME_DIR="$(pwd)"

(stdbuf -o0 ./server | stdbuf -o0 tee ./server.log | sed -re 's/^/\[server] /') &
sleep 1

(stdbuf -o0 ./client | stdbuf -o0 tee ./client.log | sed -re 's/^/\[client] /') &

sleep 2

kill -INT %1
# client should have exited itself after receiving fatal protocol error
if kill -0 %2 2>/dev/null; then
    echo "Client is STILL ALIVE — this is a failure!"
    kill -INT %2
    die "Client should have died after fatal protocol error!"
else
    echo "Client exited on its own (correct behavior)."
fi
wait

expected_client_strings=(
    'test protocol supported at version 1. Binding.'
    'Bound!'
    'Sent hello!'
    '[hw] err: fatal protocol error: object 2 error 1: Important error occurred!'

    # these two sometimes don't show up due to race conditions in the client
    # code (server sends messages before handler callback is registered)
    # 'Server says Hello object
    # 'Server says on object Hello Object'
)

expected_server_strings=(
    'Object bound XD'
    'Recvd message: Hello!'
    'Got array message: "Hello, via, array!"'
    'Got uint array message: "69, 420, 2137"'
    'Object says hello'
)

die() {
    echo "$1"
    exit 1
}

for s in "${expected_client_strings[@]}"; do
    echo -n "Checking client.log for '$s'... "
    if grep -q --fixed-strings "$s" client.log; then
        echo "Pass"
    else
        die "Fail"
    fi
done

for s in "${expected_server_strings[@]}"; do
    echo -n "Checking server.log for '$s'... "
    if grep -q --fixed-strings "$s" server.log; then
        echo "Pass"
    else
        die "Fail"
    fi
done