diff --git a/Makefile b/Makefile index aeaffae76..518110427 100644 --- a/Makefile +++ b/Makefile @@ -51,11 +51,9 @@ check: ## Run tests using the current binary executable build (meson/ninja) ninja -C meson test check-js: ## Run tests using a wasm build for nodejs - yarn --cwd bindings/javascript - yarn --cwd bindings/javascript build yarn --cwd bindings/javascript test - @echo "#!/bin/sh\nnode test/zenroom_exec.js src/zenroom.js \$$@\n" \ - > test/zenroom && chmod +x test/zenroom + @sed 's@=ROOT=@'"${pwd}"'@' test/zexe_js_wrapper.sh > zenroom + @chmod +x zenroom install: destbin=${DESTDIR}${PREFIX}/bin install: destdocs=${DESTDIR}${PREFIX}/share/zenroom diff --git a/test/zencode_exec.js b/test/zencode_exec.js new file mode 100644 index 000000000..eaf5243e4 --- /dev/null +++ b/test/zencode_exec.js @@ -0,0 +1,40 @@ +const fs = require('fs') +const util = require('util') + +const C = require(process.argv[2])() // 1st arg is path to WASM zenroom.js + + +const zencodeExec = function(script, conf = null, keys = null, data = null) { + C.then(function(Module){ + Module.exec_ok = () => 0 + Module.exec_error = () => 0 + Module.print = text => console.log(text) + Module.printErr = text => console.error(text) + Module.ccall( + 'zencode_exec', + 'number', + ['string', 'string', 'string', 'string', 'number'], + [script, conf, keys, data] + ) + }) +} +const zencode = function(script_file, conf_string=null, keys_file=null, data_file=null) { + const enc = { encoding: 'utf8' } + const script = fs.readFileSync(script_file, enc) + const conf = conf_string + const keys = (keys_file) ? fs.readFileSync(keys_file, enc) : null + const data = (data_file) ? fs.readFileSync(data_file, enc) : null + return zencodeExec(script, conf, keys, data) +} + +// console.log("[JS] zenroom %s %s %s %s", +// process.argv[3], // script file +// process.argv[4], // conf string +// process.argv[5], // keys file +// process.argv[6], // data file +// ) + +// console.time(process.argv[3]) +zencode(process.argv[3],process.argv[4],process.argv[5],process.argv[6]) +// console.timeEnd(process.argv[3]) +// console.log("@", "=".repeat(40), "@\n") diff --git a/test/zenroom_exec.js b/test/zenroom_exec.js index f1b8c4368..94a0d6c91 100644 --- a/test/zenroom_exec.js +++ b/test/zenroom_exec.js @@ -4,7 +4,7 @@ const util = require('util') // but it is not recommended as stated in https://github.com/kripken/emscripten/issues/2537 // fs.writeFileSync('zenroom.js.mem', fs.readFileSync('src/zenroom.js.mem')); -const C = require(process.argv[2])() +const C = require(process.argv[2])() // 1st arg is path to WASM zenroom.js const zenroomExec = function(script, conf = null, keys = null, data = null) { @@ -12,7 +12,7 @@ const zenroomExec = function(script, conf = null, keys = null, data = null) { Module.exec_ok = () => 0 Module.exec_error = () => 0 Module.print = text => console.log(text) - Module.printErr = text => console.log(text) + Module.printErr = text => console.error(text) Module.ccall( 'zenroom_exec', 'number', @@ -21,22 +21,23 @@ const zenroomExec = function(script, conf = null, keys = null, data = null) { ) }) } - -const zenroom = function(script_file, conf_file=null, keys_file=null, data_file=process.argv[4]) { +const zenroom = function(script_file, conf_string=null, keys_file=null, data_file=null) { const enc = { encoding: 'utf8' } const script = fs.readFileSync(script_file, enc) - const conf = (conf_file) ? fs.readFileSync(conf_file, enc) : null + const conf = conf_string const keys = (keys_file) ? fs.readFileSync(keys_file, enc) : null const data = (data_file) ? fs.readFileSync(data_file, enc) : null - return zenroomExec(script, conf, keys, data) } -console.log("[JS] zenroom_exec %s %s", - process.argv[2], - process.argv[3]) +console.log("[JS] zenroom %s %s %s %s", + process.argv[3], // script file + process.argv[4], // conf string + process.argv[5], // keys file + process.argv[6], // data file + ) console.time(process.argv[3]) -zenroom(process.argv[3]) +zenroom(process.argv[3],process.argv[4],process.argv[5],process.argv[6]) console.timeEnd(process.argv[3]) console.log("@", "=".repeat(40), "@\n") diff --git a/test/zexe_js_wrapper.sh b/test/zexe_js_wrapper.sh new file mode 100644 index 000000000..280779b12 --- /dev/null +++ b/test/zexe_js_wrapper.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# template: %PATH% has to be subsituted with absolute path +# this is processed by check-js to create a zenroom wrapper + +conf=${conf:-"logfmt=text,debug=0"} + +while getopts "zc:k:a:" arg; do + case $arg in + z) ;; # autodetected from script name + k) keys="${OPTARG}" ;; + a) data="${OPTARG}" ;; + c) conf="${OPTARG},logfmt=text,debug=0" ;; + esac +done +shift $((OPTIND-1)) + +if [[ $1 == *.lua ]]; then + node =ROOT=/test/zenroom_exec.js \ + =ROOT=/bindings/javascript/dist/main/zenroom.js $1 $conf $keys $data +elif [[ $1 == *.zen ]]; then + node =ROOT=/test/zencode_exec.js \ + =ROOT=/bindings/javascript/dist/main/zenroom.js $1 $conf $keys $data +else + echo "Unsupported script: $1" +fi