Mercurial > hg > piper-cpp
comparison vamp-server/test.sh @ 150:bf8e3e7dd7de
Move some things around, and add overall test script
| author | Chris Cannam <cannam@all-day-breakfast.com> |
|---|---|
| date | Fri, 20 Jan 2017 17:45:54 +0000 |
| parents | |
| children | 0876b5e67afe |
comparison
equal
deleted
inserted
replaced
| 149:70bf40743d6a | 150:bf8e3e7dd7de |
|---|---|
| 1 #!/bin/bash | |
| 2 | |
| 3 set -eu | |
| 4 | |
| 5 piperdir=../piper | |
| 6 vampsdkdir=../vamp-plugin-sdk | |
| 7 schemadir="$piperdir"/json/schema | |
| 8 | |
| 9 if [ ! -d "$schemadir" ]; then | |
| 10 echo "WARNING: schema directory $schemadir not found, won't be validating JSON schema" 1>&2 | |
| 11 fi | |
| 12 | |
| 13 tmpdir=$(mktemp -d) | |
| 14 | |
| 15 if [ ! -d "$tmpdir" ]; then | |
| 16 echo "Temp directory creation failed" 1>&2 | |
| 17 exit 1 | |
| 18 fi | |
| 19 | |
| 20 trap "rm -rf $tmpdir" 0 | |
| 21 | |
| 22 reqfile="$tmpdir/req.json" | |
| 23 respfile="$tmpdir/resp.json" | |
| 24 allrespfile="$tmpdir/resp.all" | |
| 25 input="$tmpdir/input" | |
| 26 expected="$tmpdir/expected" | |
| 27 obtained="$tmpdir/obtained" | |
| 28 | |
| 29 validate() { | |
| 30 local file="$1" | |
| 31 local schemaname="$2" | |
| 32 if [ -d "$schemadir" ]; then | |
| 33 echo " * validating against schema $schemaname... " 1>&2 | |
| 34 jsonschema -i "$file" "$schemadir/$schemaname.json" 1>&2 && \ | |
| 35 echo " -> validated against schema $schemaname" 1>&2 || \ | |
| 36 echo " !! failed to validate $schemaname!" 1>&2 | |
| 37 else | |
| 38 echo "(schema directory $schemadir not found, skipping validation)" 1>&2 | |
| 39 fi | |
| 40 } | |
| 41 | |
| 42 validate_request() { | |
| 43 local json="$1" | |
| 44 echo "$json" > "$reqfile" | |
| 45 validate "$reqfile" "rpcrequest" | |
| 46 } | |
| 47 | |
| 48 validate_response() { | |
| 49 local json="$1" | |
| 50 echo "$json" > "$respfile" | |
| 51 validate "$respfile" "rpcresponse" | |
| 52 } | |
| 53 | |
| 54 cat > "$input" <<EOF | |
| 55 {"method":"list"} | |
| 56 {"method":"list","params": {"from":["vamp-example-plugins","something-nonexistent"]}} | |
| 57 {"method":"list","params": {"from":["something-nonexistent"]}} | |
| 58 {"method":"load","id":6,"params": {"key":"vamp-example-plugins:percussiononsets","inputSampleRate":44100,"adapterFlags":["AdaptInputDomain","AdaptBufferSize"]}} | |
| 59 {"method":"configure","id":"weevil","params":{"handle":1,"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] ]}}} | |
| 61 {"method":"finish","params": {"handle": 1}} | |
| 62 EOF | |
| 63 | |
| 64 # Expected output, apart from the plugin list which seems a bit | |
| 65 # fragile to check here | |
| 66 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}}} | |
| 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": ""}}]}} | |
| 69 {"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}} | |
| 71 EOF | |
| 72 | |
| 73 # 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 | |
| 75 # in JSON mode | |
| 76 | |
| 77 #debugflag=-d | |
| 78 debugflag= | |
| 79 | |
| 80 for format in json capnp ; do | |
| 81 | |
| 82 ( export VAMP_PATH="$vampsdkdir"/examples ; | |
| 83 while read request ; do | |
| 84 validate_request "$request" | |
| 85 echo "$request" | |
| 86 done | | |
| 87 if [ "$format" = "json" ]; then | |
| 88 bin/piper-vamp-simple-server $debugflag json | |
| 89 else | |
| 90 bin/piper-convert request -i json -o capnp | | |
| 91 bin/piper-vamp-simple-server $debugflag capnp | | |
| 92 bin/piper-convert response -i capnp -o json | |
| 93 fi | | |
| 94 while read response ; do | |
| 95 echo "$response" >> "$allrespfile" | |
| 96 validate_response "$response" | |
| 97 done | |
| 98 ) < "$input" | |
| 99 | |
| 100 # Skip plugin lists | |
| 101 tail -n +4 "$allrespfile" > "$obtained" | |
| 102 | |
| 103 echo "Checking response contents against expected contents..." | |
| 104 if ! cmp "$obtained" "$expected"; then | |
| 105 diff -u1 "$obtained" "$expected" | |
| 106 else | |
| 107 echo "OK" | |
| 108 fi | |
| 109 | |
| 110 echo "Checking plugin counts from list responses..." | |
| 111 | |
| 112 # Now check the plugin lists, but as the descriptions etc are | |
| 113 # probably a bit fragile, let's just count the number of plugins | |
| 114 | |
| 115 # First, with no "from" arg to the list call | |
| 116 list_no_from=$(head -n +1 "$allrespfile" | fmt -1 | grep '"key"' | wc -l) | |
| 117 | |
| 118 # Now with a "from" arg that includes the library that exists | |
| 119 list_with_good_from=$(tail -n +2 "$allrespfile" | head -n +1 | fmt -1 | | |
| 120 grep '"key"' | wc -l) | |
| 121 | |
| 122 # Now with a "from" arg that doesn't include any real library | |
| 123 list_with_bad_from=$(tail -n +3 "$allrespfile" | head -n +1 | fmt -1 | | |
| 124 grep '"key"' | wc -l) | |
| 125 | |
| 126 if [ "$list_no_from" != "6" ]; then | |
| 127 echo "Wrong number of plugins from list response without \"from\" arg" | |
| 128 echo "Expected 6, obtained $list_no_from" | |
| 129 false | |
| 130 fi | |
| 131 if [ "$list_with_good_from" != "6" ]; then | |
| 132 echo "Wrong number of plugins from list response with good \"from\" arg" | |
| 133 echo "Expected 6, obtained $list_with_good_from" | |
| 134 false | |
| 135 fi | |
| 136 if [ "$list_with_bad_from" != "0" ]; then | |
| 137 echo "Wrong number of plugins from list response with bad \"from\" arg" | |
| 138 echo "Expected 0, obtained $list_with_bad_from" | |
| 139 false | |
| 140 fi | |
| 141 echo OK | |
| 142 | |
| 143 rm "$allrespfile" | |
| 144 | |
| 145 done | |
| 146 | |
| 147 echo "Tests succeeded" # set -e at top should ensure we don't get here otherwise |
