comparison vamp-server/test.sh @ 158:0876b5e67afe

Improve error handling and extend tests for it
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 20 Jan 2017 22:24:44 +0000
parents bf8e3e7dd7de
children 2ada256e47e1
comparison
equal deleted inserted replaced
157:5699fca64251 158:0876b5e67afe
1 #!/bin/bash 1 #!/bin/bash
2 2
3 set -eu 3 set -eu
4 4
5 piperdir=../piper 5 mydir=$(dirname "$0")
6 vampsdkdir=../vamp-plugin-sdk 6
7 piperdir="$mydir"/../../piper
8 vampsdkdir="$mydir"/../../vamp-plugin-sdk
9 bindir="$mydir"/../bin
7 schemadir="$piperdir"/json/schema 10 schemadir="$piperdir"/json/schema
8 11
9 if [ ! -d "$schemadir" ]; then 12 if [ ! -d "$schemadir" ]; then
10 echo "WARNING: schema directory $schemadir not found, won't be validating JSON schema" 1>&2 13 echo "WARNING: schema directory $schemadir not found, won't be validating JSON schema" 1>&2
11 fi 14 fi
49 local json="$1" 52 local json="$1"
50 echo "$json" > "$respfile" 53 echo "$json" > "$respfile"
51 validate "$respfile" "rpcresponse" 54 validate "$respfile" "rpcresponse"
52 } 55 }
53 56
57 # NB this list of commands includes a couple that are expected to fail
58 # (process before configure, configure with nonexistent handle, finish
59 # same handle twice)
54 cat > "$input" <<EOF 60 cat > "$input" <<EOF
55 {"method":"list"} 61 {"method":"list"}
56 {"method":"list","params": {"from":["vamp-example-plugins","something-nonexistent"]}} 62 {"method":"list","params": {"from":["vamp-example-plugins","something-nonexistent"]}}
57 {"method":"list","params": {"from":["something-nonexistent"]}} 63 {"method":"list","params": {"from":["something-nonexistent"]}}
58 {"method":"load","id":6,"params": {"key":"vamp-example-plugins:percussiononsets","inputSampleRate":44100,"adapterFlags":["AdaptInputDomain","AdaptBufferSize"]}} 64 {"method":"load","id":6,"params": {"key":"vamp-example-plugins:percussiononsets","inputSampleRate":44100,"adapterFlags":["AdaptInputDomain","AdaptBufferSize"]}}
65 {"method":"process","params": {"handle": 1, "processInput": { "timestamp": {"s": 0, "n": 0}, "inputBuffers": [ [1,2,3,4,5,6,7,8] ]}}}
59 {"method":"configure","id":"weevil","params":{"handle":1,"configuration":{"blockSize": 8, "channelCount": 1, "parameterValues": {"sensitivity": 40, "threshold": 3}, "stepSize": 8}}} 66 {"method":"configure","id":"weevil","params":{"handle":1,"configuration":{"blockSize": 8, "channelCount": 1, "parameterValues": {"sensitivity": 40, "threshold": 3}, "stepSize": 8}}}
67 {"method":"configure","id":9,"params":{"handle":-9999,"configuration":{"blockSize": 8, "channelCount": 1, "parameterValues": {"sensitivity": 40, "threshold": 3}, "stepSize": 8}}}
60 {"method":"process","params": {"handle": 1, "processInput": { "timestamp": {"s": 0, "n": 0}, "inputBuffers": [ [1,2,3,4,5,6,7,8] ]}}} 68 {"method":"process","params": {"handle": 1, "processInput": { "timestamp": {"s": 0, "n": 0}, "inputBuffers": [ [1,2,3,4,5,6,7,8] ]}}}
61 {"method":"finish","params": {"handle": 1}} 69 {"method":"finish","params": {"handle": 1}}
70 {"method":"finish","id":"blah","params": {"handle": 1}}
62 EOF 71 EOF
63 72
64 # Expected output, apart from the plugin list which seems a bit 73 # Expected output, apart from the plugin list which seems a bit
65 # fragile to check here 74 # fragile to check here
66 cat > "$expected" <<EOF 75 cat > "$expected" <<EOF
67 {"id": 6, "jsonrpc": "2.0", "method": "load", "result": {"defaultConfiguration": {"blockSize": 1024, "channelCount": 1, "parameterValues": {"sensitivity": 40, "threshold": 3}, "stepSize": 1024}, "handle": 1, "staticData": {"basic": {"description": "Detect percussive note onsets by identifying broadband energy rises", "identifier": "percussiononsets", "name": "Simple Percussion Onset Detector"}, "basicOutputInfo": [{"description": "Percussive note onset locations", "identifier": "onsets", "name": "Onsets"}, {"description": "Broadband energy rise detection function", "identifier": "detectionfunction", "name": "Detection Function"}], "category": ["Time", "Onsets"], "copyright": "Code copyright 2006 Queen Mary, University of London, after Dan Barry et al 2005. Freely redistributable (BSD license)", "inputDomain": "TimeDomain", "key": "vamp-example-plugins:percussiononsets", "maker": "Vamp SDK Example Plugins", "maxChannelCount": 1, "minChannelCount": 1, "parameters": [{"basic": {"description": "Energy rise within a frequency bin necessary to count toward broadband total", "identifier": "threshold", "name": "Energy rise threshold"}, "defaultValue": 3, "extents": {"max": 20, "min": 0}, "unit": "dB", "valueNames": []}, {"basic": {"description": "Sensitivity of peak detector applied to broadband detection function", "identifier": "sensitivity", "name": "Sensitivity"}, "defaultValue": 40, "extents": {"max": 100, "min": 0}, "unit": "%", "valueNames": []}], "programs": [], "version": 2}}} 76 {"id": 6, "jsonrpc": "2.0", "method": "load", "result": {"defaultConfiguration": {"blockSize": 1024, "channelCount": 1, "parameterValues": {"sensitivity": 40, "threshold": 3}, "stepSize": 1024}, "handle": 1, "staticData": {"basic": {"description": "Detect percussive note onsets by identifying broadband energy rises", "identifier": "percussiononsets", "name": "Simple Percussion Onset Detector"}, "basicOutputInfo": [{"description": "Percussive note onset locations", "identifier": "onsets", "name": "Onsets"}, {"description": "Broadband energy rise detection function", "identifier": "detectionfunction", "name": "Detection Function"}], "category": ["Time", "Onsets"], "copyright": "Code copyright 2006 Queen Mary, University of London, after Dan Barry et al 2005. Freely redistributable (BSD license)", "inputDomain": "TimeDomain", "key": "vamp-example-plugins:percussiononsets", "maker": "Vamp SDK Example Plugins", "maxChannelCount": 1, "minChannelCount": 1, "parameters": [{"basic": {"description": "Energy rise within a frequency bin necessary to count toward broadband total", "identifier": "threshold", "name": "Energy rise threshold"}, "defaultValue": 3, "extents": {"max": 20, "min": 0}, "unit": "dB", "valueNames": []}, {"basic": {"description": "Sensitivity of peak detector applied to broadband detection function", "identifier": "sensitivity", "name": "Sensitivity"}, "defaultValue": 40, "extents": {"max": 100, "min": 0}, "unit": "%", "valueNames": []}], "programs": [], "version": 2}}}
77 {"error": {"code": 0, "message": "error in process request: plugin has not been configured"}, "jsonrpc": "2.0", "method": "process"}
68 {"id": "weevil", "jsonrpc": "2.0", "method": "configure", "result": {"handle": 1, "outputList": [{"basic": {"description": "Percussive note onset locations", "identifier": "onsets", "name": "Onsets"}, "configured": {"binCount": 0, "binNames": [], "hasDuration": false, "sampleRate": 44100, "sampleType": "VariableSampleRate", "unit": ""}}, {"basic": {"description": "Broadband energy rise detection function", "identifier": "detectionfunction", "name": "Detection Function"}, "configured": {"binCount": 1, "binNames": [""], "hasDuration": false, "quantizeStep": 1, "sampleRate": 86.1328125, "sampleType": "FixedSampleRate", "unit": ""}}]}} 78 {"id": "weevil", "jsonrpc": "2.0", "method": "configure", "result": {"handle": 1, "outputList": [{"basic": {"description": "Percussive note onset locations", "identifier": "onsets", "name": "Onsets"}, "configured": {"binCount": 0, "binNames": [], "hasDuration": false, "sampleRate": 44100, "sampleType": "VariableSampleRate", "unit": ""}}, {"basic": {"description": "Broadband energy rise detection function", "identifier": "detectionfunction", "name": "Detection Function"}, "configured": {"binCount": 1, "binNames": [""], "hasDuration": false, "quantizeStep": 1, "sampleRate": 86.1328125, "sampleType": "FixedSampleRate", "unit": ""}}]}}
79 {"error": {"code": 0, "message": "error in configure request: unknown plugin handle supplied to configure"}, "id": 9, "jsonrpc": "2.0", "method": "configure"}
69 {"jsonrpc": "2.0", "method": "process", "result": {"features": {}, "handle": 1}} 80 {"jsonrpc": "2.0", "method": "process", "result": {"features": {}, "handle": 1}}
70 {"jsonrpc": "2.0", "method": "finish", "result": {"features": {"detectionfunction": [{"featureValues": [0], "timestamp": {"n": 11609977, "s": 0}}]}, "handle": 1}} 81 {"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"}
71 EOF 83 EOF
72 84
73 # We run the whole test twice, once with the server in Capnp mode 85 # We run the whole test twice, once with the server in Capnp mode
74 # (converting to JSON using piper-convert) and once with it directly 86 # (converting to JSON using piper-convert) and once with it directly
75 # in JSON mode 87 # in JSON mode
76 88
77 #debugflag=-d 89 #debugflag=-d
78 debugflag= 90 debugflag=
79 91
80 for format in json capnp ; do 92 for format in json capnp ; do # nb must be json first: see comment at end of loop
81 93
82 ( export VAMP_PATH="$vampsdkdir"/examples ; 94 ( export VAMP_PATH="$vampsdkdir"/examples ;
83 while read request ; do 95 while read request ; do
84 validate_request "$request" 96 validate_request "$request"
85 echo "$request" 97 echo "$request"
86 done | 98 done |
87 if [ "$format" = "json" ]; then 99 if [ "$format" = "json" ]; then
88 bin/piper-vamp-simple-server $debugflag json 100 "$bindir"/piper-vamp-simple-server $debugflag json
89 else 101 else
90 bin/piper-convert request -i json -o capnp | 102 "$bindir"/piper-convert request -i json -o capnp |
91 bin/piper-vamp-simple-server $debugflag capnp | 103 "$bindir"/piper-vamp-simple-server $debugflag capnp |
92 bin/piper-convert response -i capnp -o json 104 "$bindir"/piper-convert response -i capnp -o json
93 fi | 105 fi |
94 while read response ; do 106 while read response ; do
95 echo "$response" >> "$allrespfile" 107 echo "$response" >> "$allrespfile"
96 validate_response "$response" 108 validate_response "$response"
97 done 109 done
100 # Skip plugin lists 112 # Skip plugin lists
101 tail -n +4 "$allrespfile" > "$obtained" 113 tail -n +4 "$allrespfile" > "$obtained"
102 114
103 echo "Checking response contents against expected contents..." 115 echo "Checking response contents against expected contents..."
104 if ! cmp "$obtained" "$expected"; then 116 if ! cmp "$obtained" "$expected"; then
105 diff -u1 "$obtained" "$expected" 117 diff -U 1 "$obtained" "$expected"
106 else 118 else
107 echo "OK" 119 echo "OK"
108 fi 120 fi
109 121
110 echo "Checking plugin counts from list responses..." 122 echo "Checking plugin counts from list responses..."
140 fi 152 fi
141 echo OK 153 echo OK
142 154
143 rm "$allrespfile" 155 rm "$allrespfile"
144 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"
145 done 160 done
146 161
147 echo "Tests succeeded" # set -e at top should ensure we don't get here otherwise 162 echo "Tests succeeded" # set -e at top should ensure we don't get here otherwise