From 7d4489ef7b71fd320d2e1c4e85e8dc66f827f508 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Tue, 7 May 2024 19:46:49 +0200 Subject: [PATCH] runapptests - Adds a step type for starting an interactive console --- bin/runapptests.js | 60 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/bin/runapptests.js b/bin/runapptests.js index 6e581d663..ffb6a4c30 100755 --- a/bin/runapptests.js +++ b/bin/runapptests.js @@ -280,6 +280,49 @@ function runStep(step, subtest, test, state){ } }); break; + case "console" : + p = p.then(()=>{ + return new Promise(resolve => { + if (process.stdin.isTTY){ + console.log("> STARTING INTERACTIVE CONSOLE"); + + let shutdownHandler = function (code) { + console.log(" STOPPING INTERACTIVE CONSOLE"); + process.stdin.removeListener("readable", stdinlistener) + process.stdin.setRawMode(false); + handleRx = ()=>{}; + handleConsoleOutput = handleConsoleOutputCurrent; + resolve(); + } + + let stdinlistener = () => { + while ((chunk = process.stdin.read()) !== null) { + if (chunk === '\x03') { + shutdownHandler(); + } + emu.tx(chunk.toString()); + } + }; + + handleRx = (c) => { + process.stdout.write(String.fromCharCode(c)); + } + + let handleConsoleOutputCurrent = handleConsoleOutput; + handleConsoleOutput = () => {}; + + process.stdin.setRawMode(true); + process.stdin.setEncoding('ASCII'); + process.stdin.on("readable", stdinlistener); + + process.stdout.write(">"); + } else { + console.log("> TERMINAL NEEDS TO BE A TTY FOR INTERACTIVE CONSOLE"); + resolve(); + } + }) + }); + break; default: ERROR("Unknown step type "+step.t); } p = p.then(()=> { @@ -339,11 +382,26 @@ function runTest(test, testState) { }); } + +let handleRx = ()=>{}; +let handleConsoleOutput = () => {}; +if (verbose){ + handleConsoleOutput = (d) => { + console.log("<", d); + } +} + let testState = []; emu.init({ EMULATOR : EMULATOR, - DEVICEID : DEVICEID + DEVICEID : DEVICEID, + rxCallback : (ch)=>{ + handleRx(ch); + }, + consoleOutputCallback: (d)=>{ + handleConsoleOutput(d); + } }).then(function() { // Emulator is now loaded console.log("Loading tests");