comparison test/test-vampipe-server.sh @ 63:72c43bc69616

Validate JSON requests and responses
author Chris Cannam <c.cannam@qmul.ac.uk>
date Fri, 23 Sep 2016 14:20:06 +0100
parents e90fd30990eb
children 6f160dee1192
comparison
equal deleted inserted replaced
62:18951a1f1001 63:72c43bc69616
1 #!/bin/bash 1 #!/bin/bash
2 2
3 ( bin/vampipe-convert request -i json -o capnp | 3 set -eu
4 VAMP_PATH=./vamp-plugin-sdk/examples bin/vampipe-server |
5 4
6 # capnp decode capnproto/vamp.capnp VampResponse 5 reqfile="/tmp/$$.req.json"
6 respfile="/tmp/$$.resp.json"
7 trap "rm -f $reqfile $respfile" 0
7 8
8 bin/vampipe-convert response -i capnp -o json 9 schema=vamp-json-schema/schema
10
11 validate() {
12 local file="$1"
13 local schemaname="$2"
14 jsonschema -i "$file" "$schema/$schemaname.json" 1>&2 && \
15 echo "validated $schemaname" 1>&2 || \
16 echo "failed to validate $schemaname" 1>&2
17 }
18
19 validate_request() {
20 local json="$1"
21 echo "$json" > "$reqfile"
22 validate "$reqfile" "request"
23 type=$(grep '"type":' "$reqfile" | sed 's/^.*"type": *"\([^"]*\)".*$/\1/')
24 if [ "$type" == "configure" ]; then type=configuration; fi
25 if [ "$type" != "list" ]; then
26 echo "$json" |
27 sed 's/^.*"content"://' |
28 sed 's/}}$/}/' > "$reqfile"
29 validate "$reqfile" "${type}request"
30 fi
31 }
32
33 validate_response() {
34 local json="$1"
35 echo "$json" > "$respfile"
36 validate "$respfile" "response"
37 type=$(grep '"type":' "$respfile" | sed 's/^.*"type": "\([^"]*\)".*$/\1/')
38 if [ "$type" == "configure" ]; then type=configuration; fi
39 echo "$json" |
40 sed 's/^.*"content"://' |
41 sed 's/, "error.*$//' |
42 sed 's/, "success.*$//' > "$respfile"
43 validate "$respfile" "${type}response"
44 }
45
46 ( while read request ; do
47 validate_request "$request"
48 echo "$request"
49 done |
50 bin/vampipe-convert request -i json -o capnp |
51 VAMP_PATH=./vamp-plugin-sdk/examples bin/vampipe-server |
52 bin/vampipe-convert response -i capnp -o json |
53 while read response ; do
54 validate_response "$response"
55 done
9 ) <<EOF 56 ) <<EOF
10 {"type":"list"} 57 {"type":"list"}
11 {"type":"load","content": {"pluginKey":"vamp-example-plugins:percussiononsets","inputSampleRate":44100,"adapterFlags":["AdaptInputDomain","AdaptBufferSize"]}} 58 {"type":"load","content": {"pluginKey":"vamp-example-plugins:percussiononsets","inputSampleRate":44100,"adapterFlags":["AdaptInputDomain","AdaptBufferSize"]}}
12 {"type":"configure","content":{"pluginHandle":1,"configuration":{"blockSize": 8, "channelCount": 1, "parameterValues": {"sensitivity": 40, "threshold": 3}, "stepSize": 8}}} 59 {"type":"configure","content":{"pluginHandle":1,"configuration":{"blockSize": 8, "channelCount": 1, "parameterValues": {"sensitivity": 40, "threshold": 3}, "stepSize": 8}}}
13 {"type":"process","content": {"pluginHandle": 1, "processInput": { "timestamp": {"s": 0, "n": 0}, "inputBuffers": [{"values": [1,2,3,4,5,6,7,8]}]}}} 60 {"type":"process","content": {"pluginHandle": 1, "processInput": { "timestamp": {"s": 0, "n": 0}, "inputBuffers": [{"values": [1,2,3,4,5,6,7,8]}]}}}
14 {"type":"finish","content": {"pluginHandle": 1}} 61 {"type":"finish","content": {"pluginHandle": 1}}
15 EOF 62 EOF
16