Mercurial > hg > piper-cpp
comparison vamp-server/test.sh @ 184:150cfa0c71e1
Merge pull request #1 from piper-audio/fix/regression-json-responses
Fix/regression json responses
| author | Chris Cannam <cannam@all-day-breakfast.com> |
|---|---|
| date | Fri, 03 Feb 2017 13:00:42 +0000 |
| parents | 02c3a8596c2b |
| children | 3eb00e5c76c4 |
comparison
equal
deleted
inserted
replaced
| 172:cfa115746cb3 | 184:150cfa0c71e1 |
|---|---|
| 25 reqfile="$tmpdir/req.json" | 25 reqfile="$tmpdir/req.json" |
| 26 respfile="$tmpdir/resp.json" | 26 respfile="$tmpdir/resp.json" |
| 27 allrespfile="$tmpdir/resp.all" | 27 allrespfile="$tmpdir/resp.all" |
| 28 input="$tmpdir/input" | 28 input="$tmpdir/input" |
| 29 expected="$tmpdir/expected" | 29 expected="$tmpdir/expected" |
| 30 expected_less_strict="$tmpdir/expected-less-strict" | |
| 30 obtained="$tmpdir/obtained" | 31 obtained="$tmpdir/obtained" |
| 31 | 32 |
| 32 validate() { | 33 validate() { |
| 33 local file="$1" | 34 local file="$1" |
| 34 local schemaname="$2" | 35 local schemaname="$2" |
| 80 {"jsonrpc": "2.0", "method": "process", "result": {"features": {}, "handle": 1}} | 81 {"jsonrpc": "2.0", "method": "process", "result": {"features": {}, "handle": 1}} |
| 81 {"jsonrpc": "2.0", "method": "finish", "result": {"features": {"detectionfunction": [{"featureValues": [0], "timestamp": {"n": 11609977, "s": 0}}]}, "handle": 1}} | 82 {"jsonrpc": "2.0", "method": "finish", "result": {"features": {"detectionfunction": [{"featureValues": [0], "timestamp": {"n": 11609977, "s": 0}}]}, "handle": 1}} |
| 82 {"error": {"code": 0, "message": "error in finish request: unknown plugin handle supplied to finish"}, "id": "blah", "jsonrpc": "2.0", "method": "finish"} | 83 {"error": {"code": 0, "message": "error in finish request: unknown plugin handle supplied to finish"}, "id": "blah", "jsonrpc": "2.0", "method": "finish"} |
| 83 EOF | 84 EOF |
| 84 | 85 |
| 85 # We run the whole test twice, once with the server in Capnp mode | 86 # We run the whole test three times, |
| 86 # (converting to JSON using piper-convert) and once with it directly | 87 # to cover (de)serialisation of json and capnp requests and responses |
| 87 # in JSON mode | 88 # as well as exercising both server modes (json and capnp) |
| 89 # converting / reading from capnp requests is currently not tested | |
| 88 | 90 |
| 89 #debugflag=-d | 91 #debugflag=-d |
| 90 debugflag= | 92 debugflag= |
| 91 | 93 |
| 92 for format in json capnp ; do # nb must be json first: see comment at end of loop | 94 for request_response_conversion in none json_to_json json_to_capnp ; do # nb json_to_capnp must be last: see comment in else case |
| 93 | 95 |
| 94 ( export VAMP_PATH="$vampsdkdir"/examples ; | 96 ( export VAMP_PATH="$vampsdkdir"/examples ; |
| 95 while read request ; do | 97 while read request ; do |
| 96 validate_request "$request" | 98 validate_request "$request" |
| 97 echo "$request" | 99 echo "$request" |
| 98 done | | 100 done | |
| 99 if [ "$format" = "json" ]; then | 101 if [ "$request_response_conversion" = "none" ]; then |
| 100 "$bindir"/piper-vamp-simple-server $debugflag json | 102 "$bindir"/piper-vamp-simple-server $debugflag json |
| 103 elif [ "$request_response_conversion" = "json_to_json" ]; then | |
| 104 "$bindir"/piper-convert request -i json -o json | | |
| 105 "$bindir"/piper-vamp-simple-server $debugflag json | | |
| 106 "$bindir"/piper-convert response -i json -o json | |
| 101 else | 107 else |
| 108 # The capnp output doesn't preserve the method name in error | |
| 109 # responses, so replace those now that we've done the json tests | |
| 110 perl -i -p -e 's/(error.*"method": )"[^"]*"/$1"invalid"/' "$expected" | |
| 102 "$bindir"/piper-convert request -i json -o capnp | | 111 "$bindir"/piper-convert request -i json -o capnp | |
| 103 "$bindir"/piper-vamp-simple-server $debugflag capnp | | 112 "$bindir"/piper-vamp-simple-server $debugflag capnp | |
| 104 "$bindir"/piper-convert response -i capnp -o json | 113 "$bindir"/piper-convert response -i capnp -o json |
| 105 fi | | 114 fi | |
| 106 while read response ; do | 115 while read response ; do |
| 110 ) < "$input" | 119 ) < "$input" |
| 111 | 120 |
| 112 # Skip plugin lists | 121 # Skip plugin lists |
| 113 tail -n +4 "$allrespfile" > "$obtained" | 122 tail -n +4 "$allrespfile" > "$obtained" |
| 114 | 123 |
| 115 echo "Checking response contents against expected contents..." | 124 echo "Checking response contents against expected contents..." |
| 116 if ! cmp "$obtained" "$expected"; then | 125 # the expected configuration response is fragile, capnp fills in optional fields, |
| 117 diff -U 1 "$obtained" "$expected" | 126 # json doesn't - which is fine behaviour, but causes the test to fail - remove empty binCount and binNames |
| 127 expected_without_optional_fields=$( cat "$expected" | sed -E 's/\"(binCount|binNames)\": ?((\[\])|0),? ?//g') | |
| 128 echo "$expected_without_optional_fields" > "$expected_less_strict" | |
| 129 | |
| 130 if cmp "$obtained" "$expected" -s || cmp "$obtained" "$expected_less_strict" -s; then | |
| 131 echo "OK" | |
| 118 else | 132 else |
| 119 echo "OK" | 133 diff -U 1 "$obtained" "$expected" |
| 120 fi | 134 fi |
| 121 | 135 |
| 122 echo "Checking plugin counts from list responses..." | 136 echo "Checking plugin counts from list responses..." |
| 123 | 137 |
| 124 # Now check the plugin lists, but as the descriptions etc are | 138 # Now check the plugin lists, but as the descriptions etc are |
| 151 false | 165 false |
| 152 fi | 166 fi |
| 153 echo OK | 167 echo OK |
| 154 | 168 |
| 155 rm "$allrespfile" | 169 rm "$allrespfile" |
| 156 | |
| 157 # The capnp output doesn't preserve the method name in error | |
| 158 # responses, so replace those now that we've done the json test | |
| 159 perl -i -p -e 's/(error.*"method": )"[^"]*"/$1"invalid"/' "$expected" | |
| 160 done | 170 done |
| 161 | 171 |
| 162 echo "Tests succeeded" # set -e at top should ensure we don't get here otherwise | 172 echo "Tests succeeded" # set -e at top should ensure we don't get here otherwise |
