Mercurial > hg > piper-cpp
comparison vamp-server/test.sh @ 178:353f842ed73f
Add a more relaxed comparision of JSON responses if the initial comparision fails. Some optional fields aren't populated from the JSON serialisation code.
| author | Lucas Thompson <dev@lucas.im> | 
|---|---|
| date | Tue, 31 Jan 2017 23:01:49 +0000 | 
| parents | 718dd5404855 | 
| children | 0e13b7b80464 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 177:1990dd9570d8 | 178:353f842ed73f | 
|---|---|
| 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/obtained-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 request_response_conversion in none json_to_json json_to_capnp ; do | 94 for request_response_conversion in none json_to_json json_to_capnp ; do | 
| 118 | 120 | 
| 119 # Skip plugin lists | 121 # Skip plugin lists | 
| 120 tail -n +4 "$allrespfile" > "$obtained" | 122 tail -n +4 "$allrespfile" > "$obtained" | 
| 121 | 123 | 
| 122 echo "Checking response contents against expected contents..." | 124 echo "Checking response contents against expected contents..." | 
| 123 if ! cmp "$obtained" "$expected"; then | 125 | 
| 124 diff -U 1 "$obtained" "$expected" | 126 # the expected configuration response is fragile, capnp fills in optional fields, | 
| 127 # json doesn't - which is fine behaviour, but causes the test to fail - remove empty binCount and binNames | |
| 128 expected_without_optional_fields=$( cat "$expected" | sed -E 's/\"(binCount|binNames)\": ?((\[\])|0),? ?//g') | |
| 129 echo "$expected_without_optional_fields" > "$expected_less_strict" | |
| 130 | |
| 131 if cmp "$obtained" "$expected" -s || cmp "$obtained" "$expected_less_strict" -s; then | |
| 132 echo "OK" | |
| 125 else | 133 else | 
| 126 echo "OK" | 134 diff -U 1 "$obtained" "$expected" | 
| 127 fi | 135 fi | 
| 128 | 136 | 
| 129 echo "Checking plugin counts from list responses..." | 137 echo "Checking plugin counts from list responses..." | 
| 130 | 138 | 
| 131 # Now check the plugin lists, but as the descriptions etc are | 139 # Now check the plugin lists, but as the descriptions etc are | 
