changeset 129:19fb654630e7

Permit running test with only one arg (picking up first plugin as default), check for successful response, etc
author Chris Cannam <c.cannam@qmul.ac.uk>
date Thu, 10 Nov 2016 17:07:35 +0000
parents baa3ddcb0dce
children 225f0eb33154
files test/node-load-test.js
diffstat 1 files changed, 38 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/test/node-load-test.js	Thu Nov 10 15:07:24 2016 +0000
+++ b/test/node-load-test.js	Thu Nov 10 17:07:35 2016 +0000
@@ -4,14 +4,19 @@
     console.log(blah);
 }
 
-if (process.argv.length < 4) {
-    note("\nUsage: " + process.argv[0] + " <LibraryPath> <pluginKey>");
+if (process.argv.length < 3 || process.argv.length > 4) {
+    note("\nUsage: " + process.argv[0] + " <librarypath> [<pluginkey>]");
+    note("e.g. " + process.argv[0] + " ./VampExamplePlugins.js");
     note("e.g. " + process.argv[0] + " ./VampExamplePlugins.js vamp-example-plugins:zerocrossing");
-    throw "Wrong number of command-line args (2 expected)"
+    throw "Wrong number of command-line args (1 or 2 expected)"
 }
 
 var libraryPath = process.argv[2];
-var pluginKey = process.argv[3];
+
+var pluginKey = "";
+if (process.argv.length > 3) {
+    pluginKey = process.argv[3];
+}
 
 var base64 = require("./base64");
 
@@ -141,12 +146,32 @@
     return features;
 }
 
+function checkSuccess(response) {
+    if (response.error) {
+	console.log("Request type " + response.method + " failed: " +
+		    response.error.message);
+	throw response.error.message;
+    }
+}
+
 function test() {
 
     const rate = 44100;
+
+    note("Listing plugins...");
+    let response = request({
+	method: "list"
+    });
+    checkSuccess(response);
+
+    if (pluginKey === "") {
+	pluginKey = response.result.available[0].key;
+	note("Loading first plugin \"" + pluginKey + "\"...");
+    } else {
+	note("Loading requested plugin \"" + pluginKey + "\"...");
+    }
     
-    note("Loading plugin \"" + pluginKey + "\"...");
-    let response = request({
+    response = request({
         method: "load",
         params: {
             key: pluginKey,
@@ -154,8 +179,10 @@
             adapterFlags: ["AdaptAllSafe"]
         }
     });
+    checkSuccess(response);
 
-    const blockSize = 1024;
+    const blockSize = response.result.defaultConfiguration.blockSize;
+    const stepSize = response.result.defaultConfiguration.stepSize;
 
     response = request({
         method: "configure",
@@ -163,11 +190,12 @@
             handle: 1,
             configuration: {
                 blockSize: blockSize,
-                channelCount: 1,
-                stepSize: blockSize
+                stepSize: stepSize,
+                channelCount: 1
             }
         }
     });
+    checkSuccess(response);
 
     const nblocks = 1000;
 
@@ -196,7 +224,6 @@
         for (let featureList of features.values()) {
             featureCount += featureList.length;
         }
-        console.log(i);
     }
 
     note("Cleaning up the plugin and getting any remaining features...");
@@ -206,6 +233,7 @@
             handle: 1
         }
     });
+    checkSuccess(response);
 
     let features = responseToFeatureSet(response);
     for (let featureList of features.values()) {