Mercurial > hg > piper-cpp
comparison test/test-server.sh @ 75:81e1c48e97f9
Rearrange and rename to Piper C++ structure
| author | Chris Cannam <c.cannam@qmul.ac.uk> |
|---|---|
| date | Mon, 10 Oct 2016 16:31:09 +0100 |
| parents | |
| children | d15cb1151d76 |
comparison
equal
deleted
inserted
replaced
| 74:d45cfa25aaad | 75:81e1c48e97f9 |
|---|---|
| 1 #!/bin/bash | |
| 2 | |
| 3 set -eu | |
| 4 | |
| 5 piperdir=../piper | |
| 6 vampsdkdir=../vamp-plugin-sdk | |
| 7 schemadir="$piperdir"/json/schema | |
| 8 | |
| 9 reqfile="/tmp/$$.req.json" | |
| 10 respfile="/tmp/$$.resp.json" | |
| 11 allrespfile="/tmp/$$.resp.all" | |
| 12 expected="/tmp/$$.expected" | |
| 13 obtained="/tmp/$$.obtained" | |
| 14 trap "rm -f $reqfile $respfile $allrespfile $obtained $expected" 0 | |
| 15 | |
| 16 validate() { | |
| 17 local file="$1" | |
| 18 local schemaname="$2" | |
| 19 jsonschema -i "$file" "$schemadir/$schemaname.json" 1>&2 && \ | |
| 20 echo "validated $schemaname" 1>&2 || \ | |
| 21 echo "failed to validate $schemaname" 1>&2 | |
| 22 } | |
| 23 | |
| 24 validate_request() { | |
| 25 local json="$1" | |
| 26 echo "$json" > "$reqfile" | |
| 27 validate "$reqfile" "rpcrequest" | |
| 28 } | |
| 29 | |
| 30 validate_response() { | |
| 31 local json="$1" | |
| 32 echo "$json" > "$respfile" | |
| 33 validate "$respfile" "rpcresponse" | |
| 34 } | |
| 35 | |
| 36 ( while read request ; do | |
| 37 validate_request "$request" | |
| 38 echo "$request" | |
| 39 done | | |
| 40 bin/piper-convert request -i json -o capnp | | |
| 41 VAMP_PATH="$vampsdkdir"/examples bin/piper-vamp-server | | |
| 42 bin/piper-convert response -i capnp -o json | | |
| 43 while read response ; do | |
| 44 echo "$response" >> "$allrespfile" | |
| 45 validate_response "$response" | |
| 46 done | |
| 47 ) <<EOF | |
| 48 {"method":"list"} | |
| 49 {"method":"load","id":6,"params": {"key":"vamp-example-plugins:percussiononsets","inputSampleRate":44100,"adapterFlags":["AdaptInputDomain","AdaptBufferSize"]}} | |
| 50 {"method":"configure","id":"weevil","params":{"handle":1,"configuration":{"blockSize": 8, "channelCount": 1, "parameterValues": {"sensitivity": 40, "threshold": 3}, "stepSize": 8}}} | |
| 51 {"method":"process","params": {"handle": 1, "processInput": { "timestamp": {"s": 0, "n": 0}, "inputBuffers": [ [1,2,3,4,5,6,7,8] ]}}} | |
| 52 {"method":"finish","params": {"handle": 1}} | |
| 53 EOF | |
| 54 | |
| 55 # Expected output, apart from the plugin list which seems a bit | |
| 56 # fragile to check here | |
| 57 cat > "$expected" <<EOF | |
| 58 {"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}}} | |
| 59 {"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": ""}}]}} | |
| 60 {"jsonrpc": "2.0", "method": "process", "result": {"features": {}, "handle": 1}} | |
| 61 {"jsonrpc": "2.0", "method": "finish", "result": {"features": {"detectionfunction": [{"featureValues": [0], "timestamp": {"n": 11609977, "s": 0}}]}, "handle": 1}} | |
| 62 EOF | |
| 63 | |
| 64 # Skip plugin list | |
| 65 tail -n +2 "$allrespfile" > "$obtained" | |
| 66 | |
| 67 echo "Checking response contents against expected contents..." | |
| 68 if ! cmp "$obtained" "$expected"; then | |
| 69 diff -u1 "$obtained" "$expected" | |
| 70 else | |
| 71 echo "OK" | |
| 72 fi | |
| 73 |
