From bbba8859cb907d2e38133ac009187c5bf3140897 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Sat, 11 May 2024 23:06:44 +0200 Subject: [PATCH 01/14] runapptests - Fix GadgetBridge test data creation --- bin/runapptests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/runapptests.js b/bin/runapptests.js index 17d2e9ce2..392636b9c 100755 --- a/bin/runapptests.js +++ b/bin/runapptests.js @@ -231,7 +231,7 @@ function runStep(step, subtest, test, state){ break; case "gb" : p = p.then(() => { - let obj = Object.apply({ + let obj = Object.assign({ src:'Messenger', t: 'notify', type: 'text', From 443362418314e35f58272059cb44e18aa948daf9 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Sat, 11 May 2024 23:07:24 +0200 Subject: [PATCH 02/14] runapptests - Log sleep time before actually sleeping --- bin/runapptests.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/runapptests.js b/bin/runapptests.js index 392636b9c..faf2384c7 100755 --- a/bin/runapptests.js +++ b/bin/runapptests.js @@ -310,9 +310,10 @@ function runStep(step, subtest, test, state){ break; case "sleep" : p = p.then(()=>{ + console.log("> SLEEP FOR", step.ms); return new Promise(resolve => { setTimeout(()=>{ - console.log("> WAITED FOR", step.ms); + if (verbose) console.log("> SLEPT FOR", step.ms); resolve(); }, step.ms); }) From 5172d8f8b3df93b17d025ac14aaa2519490a48f0 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Sat, 11 May 2024 23:08:43 +0200 Subject: [PATCH 03/14] android - Port remaining tests from js to new json format --- apps/android/test.js | 153 ----------------------------------------- apps/android/test.json | 59 +++++++++++++++- 2 files changed, 58 insertions(+), 154 deletions(-) delete mode 100644 apps/android/test.js diff --git a/apps/android/test.js b/apps/android/test.js deleted file mode 100644 index 007b06fc7..000000000 --- a/apps/android/test.js +++ /dev/null @@ -1,153 +0,0 @@ -let result = true; - -function assertTrue(condition, text) { - if (!condition) { - result = false; - print("FAILURE: " + text); - } else print("OK: " + text); -} - -function assertFalse(condition, text) { - assertTrue(!condition, text); -} - -function assertUndefinedOrEmpty(array, text) { - assertTrue(!array || array.length == 0, text); -} - -function assertNotEmpty(array, text) { - assertTrue(array && array.length > 0, text); -} - -let internalOn = () => { - return getPinMode((process.env.HWVERSION==2)?D30:D26) == "input"; -}; - -let sec = { - connected: false -}; - -NRF.getSecurityStatus = () => sec; -// add an empty starting point to make the asserts work -Bangle._PWR={}; - -let teststeps = []; - -teststeps.push(()=>{ - print("Not connected, should use internal GPS"); - assertTrue(!NRF.getSecurityStatus().connected, "Not connected"); - - assertUndefinedOrEmpty(Bangle._PWR.GPS, "No GPS"); - assertFalse(Bangle.isGPSOn(), "isGPSOn"); - - assertTrue(Bangle.setGPSPower(1, "test"), "Switch GPS on"); - - assertNotEmpty(Bangle._PWR.GPS, "GPS"); - assertTrue(Bangle.isGPSOn(), "isGPSOn"); - assertTrue(internalOn(), "Internal GPS on"); - - assertFalse(Bangle.setGPSPower(0, "test"), "Switch GPS off"); - - assertUndefinedOrEmpty(Bangle._PWR.GPS, "No GPS"); - assertFalse(Bangle.isGPSOn(), "isGPSOn"); - assertFalse(internalOn(), "Internal GPS off"); - -}); - -teststeps.push(()=>{ - print("Connected, should use GB GPS"); - sec.connected = true; - - assertTrue(NRF.getSecurityStatus().connected, "Connected"); - - assertUndefinedOrEmpty(Bangle._PWR.GPS, "No GPS"); - assertFalse(Bangle.isGPSOn(), "isGPSOn"); - assertFalse(internalOn(), "Internal GPS off"); - - - print("Internal GPS stays on until the first GadgetBridge event arrives"); - assertTrue(Bangle.setGPSPower(1, "test"), "Switch GPS on"); - - assertNotEmpty(Bangle._PWR.GPS, "GPS"); - assertTrue(Bangle.isGPSOn(), "isGPSOn"); - assertTrue(internalOn(), "Internal GPS on"); - - print("Send minimal GadgetBridge GPS event to trigger switch"); - GB({t:"gps"}); -}); - -teststeps.push(()=>{ - print("GPS should be on, internal off"); - - assertNotEmpty(Bangle._PWR.GPS, "GPS"); - assertTrue(Bangle.isGPSOn(), "isGPSOn"); - assertFalse(internalOn(), "Internal GPS off"); -}); - -teststeps.push(()=>{ - print("Switching GPS off turns both GadgetBridge as well as internal off"); - assertFalse(Bangle.setGPSPower(0, "test"), "Switch GPS off"); - - assertUndefinedOrEmpty(Bangle._PWR.GPS, "No GPS"); - assertFalse(Bangle.isGPSOn(), "isGPSOn"); - assertFalse(internalOn(), "Internal GPS off"); -}); - -teststeps.push(()=>{ - print("Wait for all timeouts to run out"); - return 12000; -}); - -teststeps.push(()=>{ - print("Check auto switch when no GPS event arrives"); - - assertTrue(Bangle.setGPSPower(1, "test"), "Switch GPS on"); - - assertNotEmpty(Bangle._PWR.GPS, "GPS"); - assertTrue(Bangle.isGPSOn(), "isGPSOn"); - assertTrue(internalOn(), "Internal GPS on"); - - print("Send minimal GadgetBridge GPS event to trigger switch"); - GB({t:"gps"}); - - print("Internal should be switched off now"); - - assertNotEmpty(Bangle._PWR.GPS, "GPS"); - assertTrue(Bangle.isGPSOn(), "isGPSOn"); - assertFalse(internalOn(), "Internal GPS off"); - - //wait on next test - return 12000; -}); - -teststeps.push(()=>{ - print("Check state and disable GPS, internal should be on"); - - assertNotEmpty(Bangle._PWR.GPS, "GPS"); - assertTrue(Bangle.isGPSOn(), "isGPSOn"); - assertTrue(internalOn(), "Internal GPS on"); - - assertFalse(Bangle.setGPSPower(0, "test"), "Switch GPS off"); -}); - -teststeps.push(()=>{ - print("Result Overall is " + (result ? "OK" : "FAIL")); -}); - -let wrap = (functions) => { - if (functions.length > 0) { - setTimeout(()=>{ - let waitingTime = functions.shift()(); - if (waitingTime){ - print("WAITING: ", waitingTime); - setTimeout(()=>{wrap(functions);}, waitingTime); - } else - wrap(functions); - },0); - } -}; - -setTimeout(()=>{ - wrap(teststeps); -}, 5000); - diff --git a/apps/android/test.json b/apps/android/test.json index 809fd012c..74d88a1e6 100644 --- a/apps/android/test.json +++ b/apps/android/test.json @@ -5,13 +5,22 @@ "steps" : [ {"t":"cmd", "js": "Bangle.setGPSPower=(isOn, appID)=>{if (!appID) appID='?';if (!Bangle._PWR) Bangle._PWR={};if (!Bangle._PWR.GPS) Bangle._PWR.GPS=[];if (isOn && !Bangle._PWR.GPS.includes(appID)) Bangle._PWR.GPS.push(appID);if (!isOn && Bangle._PWR.GPS.includes(appID)) Bangle._PWR.GPS.splice(Bangle._PWR.GPS.indexOf(appID),1);return Bangle._PWR.GPS.length>0;};", "text": "Fake the setGPSPower"}, {"t":"wrap", "fn": "Bangle.setGPSPower", "id": "gpspower"}, - {"t":"cmd", "js": "NRF.getSecurityStatus = () => { return { connected: false };}", "text": "Control the security status"}, {"t":"cmd", "js": "Serial1.println = () => { }", "text": "Fake the serial port println"}, {"t":"cmd", "js": "Bluetooth.println = () => { }", "text": "Fake the Bluetooth println"}, {"t":"cmd", "js": "Bangle._PWR={}", "text": "Prepare an empty _PWR for following asserts"}, {"t":"cmd", "js": "require('Storage').writeJSON('android.settings.json', {overwriteGps: true})", "text": "Enable GPS overwrite"}, {"t":"cmd", "js": "eval(require('Storage').read('android.boot.js'))", "text": "Load the boot code"} ] + },{ + "id": "connected", + "steps" : [ + {"t":"cmd", "js": "NRF.getSecurityStatus = () => { return { connected: true };}", "text": "Control the security status to be connected"} + ] + },{ + "id": "disconnected", + "steps" : [ + {"t":"cmd", "js": "NRF.getSecurityStatus = () => { return { connected: false };}", "text": "Control the security status to be disconnected"} + ] }], "tests" : [{ "description": "Check setGPSPower is replaced", @@ -26,6 +35,7 @@ "description": "Test switching hardware GPS on and off", "steps" : [ {"t":"setup", "id": "default"}, + {"t":"setup", "id": "connected"}, {"t":"assertArray", "js": "Bangle._PWR.GPS", "is":"undefinedOrEmpty", "text": "No GPS clients"}, {"t":"assert", "js": "Bangle.isGPSOn()", "is":"falsy", "text": "isGPSOn shows GPS as off"}, {"t":"assert", "js": "Bangle.setGPSPower(1, 'test')", "is":"truthy", "text": "setGPSPower returns truthy when switching on"}, @@ -37,5 +47,52 @@ {"t":"assert", "js": "Bangle.isGPSOn()", "is":"falsy", "text": "isGPSOn shows GPS as off"}, {"t":"assertCall", "id": "gpspower", "count": 2, "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 0 } ] , "text": "internal GPS switched off"} ] + },{ + "description": "Test switching when GB GPS is available, internal GPS active until GB GPS event arrives", + "steps" : [ + {"t":"setup", "id": "default"}, + {"t":"setup", "id": "connected"}, + {"t":"assertArray", "js": "Bangle._PWR.GPS", "is":"undefinedOrEmpty", "text": "No GPS clients"}, + {"t":"assert", "js": "Bangle.isGPSOn()", "is":"falsy", "text": "isGPSOn shows GPS as off"}, + + {"t":"assert", "js": "Bangle.setGPSPower(1, 'test')", "is":"truthy", "text": "setGPSPower returns truthy when switching on"}, + {"t":"assertArray", "js": "Bangle._PWR.GPS", "is":"notEmpty", "text": "GPS clients"}, + {"t":"assert", "js": "Bangle.isGPSOn()", "is":"truthy", "text": "isGPSOn shows GPS as on"}, + {"t":"assertCall", "id": "gpspower", "count": 1, "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 1 } ], "text": "internal GPS switched on"}, + + {"t":"gb", "obj":{"t":"gps"}}, + {"t":"assertArray", "js": "Bangle._PWR.GPS", "is":"notEmpty", "text": "GPS clients still there"}, + {"t":"assert", "js": "Bangle.isGPSOn()", "is":"truthy", "text": "isGPSOn still shows GPS as on"}, + {"t":"assertCall", "id": "gpspower", "count": 2, "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 0 } ], "text": "internal GPS switched off"} + ] + },{ + "description": "Test switching when GB GPS is available, internal stays off", + "steps" : [ + {"t":"setup", "id": "default"}, + {"t":"setup", "id": "connected"}, + + {"t":"assert", "js": "Bangle.setGPSPower(1, 'test')", "is":"truthy", "text": "setGPSPower returns truthy when switching on"}, + + {"t":"gb", "obj":{"t":"gps"}}, + {"t":"assertCall", "id": "gpspower", "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 0 } ], "text": "internal GPS switched off"}, + + {"t":"assert", "js": "Bangle.setGPSPower(0, 'test')", "is":"falsy", "text": "setGPSPower returns truthy when switching on"}, + {"t":"assertCall", "id": "gpspower", "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 0 } ], "text": "internal GPS still switched off"} + ] + },{ + "description": "Test switching when GB GPS is available, but no event arrives", + "steps" : [ + {"t":"setup", "id": "default"}, + {"t":"setup", "id": "connected"}, + + {"t":"assert", "js": "Bangle.setGPSPower(1, 'test')", "is":"truthy", "text": "setGPSPower returns truthy when switching on"}, + + {"t":"gb", "obj":{"t":"gps"}, "text": "trigger switch"}, + {"t":"assertCall", "id": "gpspower", "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 0 } ], "text": "internal GPS switched off"}, + + {"t":"sleep", "ms":"12000", "text": "wait for fallback"}, + + {"t":"assertCall", "id": "gpspower", "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 1 } ], "text": "internal GPS switched on caused by missing GB event"} + ] }] } From ead2a9449e7b041cc3b5be8c9221a6980058e264 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Sat, 11 May 2024 23:18:29 +0200 Subject: [PATCH 04/14] Remove lint exemption for no longer existing file --- apps/lint_exemptions.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/apps/lint_exemptions.js b/apps/lint_exemptions.js index 78f4c81a6..98a069664 100644 --- a/apps/lint_exemptions.js +++ b/apps/lint_exemptions.js @@ -1269,12 +1269,6 @@ module.exports = { "no-undef" ] }, - "android/test.js": { - "hash": "703dad907d9b17d281faca2ecd9099d9f127e7241b48c7617f9147978ddb7c43", - "rules": [ - "no-undef" - ] - }, "android/boot.js": { "hash": "a537b3f7772e11f44615d80d6c6bacfa69c1854c6da3c01666863bcae8a18059", "rules": [ From 4385d4b85c84e0b270e4217c7df83096e7803cbd Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Sat, 11 May 2024 23:38:54 +0200 Subject: [PATCH 05/14] runapptests - Fix logging for asserting a value --- bin/runapptests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/runapptests.js b/bin/runapptests.js index faf2384c7..5b32e3921 100755 --- a/bin/runapptests.js +++ b/bin/runapptests.js @@ -126,7 +126,7 @@ function assertArray(step){ } function assertValue(step){ - console.log("> ASSERT " + `\`${step.js}\``, "IS", step.is.toUpperCase(), step.to ? "TO " + `\`${step.js}\`` : "", step.text ? "- " + step.text : ""); + console.log("> ASSERT " + `\`${step.js}\``, "IS", step.is.toUpperCase() + (step.to !== undefined ? " TO " + `\`${step.to}\`` : ""), step.text ? "- " + step.text : ""); let isOK; switch (step.is.toLowerCase()){ case "truthy": isOK = getValue(`!!${step.js}`); break; From 39259346fe55946fb6c39c745df121b17c85697d Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Sat, 11 May 2024 23:39:23 +0200 Subject: [PATCH 06/14] runapptests - Log GadgetBridge commands --- bin/runapptests.js | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/runapptests.js b/bin/runapptests.js index 5b32e3921..da172259e 100755 --- a/bin/runapptests.js +++ b/bin/runapptests.js @@ -239,6 +239,7 @@ function runStep(step, subtest, test, state){ title:'title', body:'body' }, step.obj || {}); + console.log(`> GB with`, verbose ? "event " + JSON.stringify(obj, null, null) : "type " + obj.t); emu.tx(`GB(${JSON.stringify(obj)})\n`); }); break; From e248235e8461d0463fa1e3d10f7bc7b5c58f4b6c Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Sun, 12 May 2024 00:17:00 +0200 Subject: [PATCH 07/14] messagesoverlay - Adds a test for watch backgrounding --- apps/messagesoverlay/test.json | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/messagesoverlay/test.json b/apps/messagesoverlay/test.json index 40ac14a8b..77e12caa6 100644 --- a/apps/messagesoverlay/test.json +++ b/apps/messagesoverlay/test.json @@ -16,7 +16,7 @@ {"t":"assert", "js": "Bangle['#onswipe']", "is":"function", "text": "One swipe handler restored"} ] },{ - "description": "Test handler backgrounding with fastloading (setUI)", + "description": "Test swipe handler backgrounding with fastloading (setUI)", "steps" : [ {"t":"cmd", "js": "Bangle.on('swipe',print)", "text": "Create listener for swipes"}, {"t":"cmd", "js": "Bangle.setUI({mode: 'clock',remove: ()=>{}})", "text": "Init UI for clock"}, @@ -24,9 +24,17 @@ {"t":"assertArray", "js": "Bangle['#onswipe']", "is":"undefinedOrEmpty", "text": "No swipe handlers while message overlay is on screen"}, {"t":"cmd", "js": "Bangle.setUI()", "text": "Trigger removal of UI"}, {"t":"assertArray", "js": "Bangle['#onswipe']", "is":"undefinedOrEmpty", "text": "Still no swipe handlers"}, - {"t":"cmd", "js": "Bangle.on('touch', print)"}, {"t":"emit", "event":"touch", "paramsArray": [ 1, { "x": 10, "y": 10, "type": 0 } ], "text": "Close message"}, {"t":"assert", "js": "Bangle['#onswipe']", "is":"function", "text": "One swipe handler restored"} ] + },{ + "description": "Test watch backgrounding", + "steps" : [ + {"t":"cmd", "js": "setWatch(print,BTN)", "text": "Create watch"}, + {"t":"cmd", "js": "require('messagesoverlay').message('text', {src:'Messenger',t:'add',type:'text',id:Date.now().toFixed(0),title:'title',body:'body'})", "text": "Show a message overlay"}, + {"t":"assertArray", "js": "global[\"\\xff\"].watches", "is":"undefinedOrEmpty", "text": "No watches while message overlay is on screen"}, + {"t":"emit", "event":"touch", "paramsArray": [ 1, { "x": 10, "y": 10, "type": 0 } ], "text": "Close message"}, + {"t":"assert", "js": "global[\"\\xff\"].watches.length", "is":"equal", "to": "2", "text": "One watch restored, first entry is always empty"} + ] }] } From 409b8cbdfcc8113bff066a72ebb021acf4a708f7 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Mon, 13 May 2024 17:56:48 +0200 Subject: [PATCH 08/14] runapptests - Replaces sleep command by time jump on emulator --- bin/runapptests.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/bin/runapptests.js b/bin/runapptests.js index da172259e..8187d869d 100755 --- a/bin/runapptests.js +++ b/bin/runapptests.js @@ -312,12 +312,16 @@ function runStep(step, subtest, test, state){ case "sleep" : p = p.then(()=>{ console.log("> SLEEP FOR", step.ms); - return new Promise(resolve => { - setTimeout(()=>{ - if (verbose) console.log("> SLEPT FOR", step.ms); - resolve(); - }, step.ms); - }) + if (!subtest.wrappedDateNow){ + emu.tx(`Date.now = (o)=>{return ()=>{ + return o() + global.APPTESTS.timeOffset; + };}(Date.now);\n`); + subtest.wrappedDateNow = true; + } + emu.tx(`global.APPTESTS.timeOffset += ${step.ms}; + for(let c of global["\xff"].timers){ + if(c) c.time -= ${step.ms * 1000}; + }\n`); }); break; case "upload" : From 107727ce6bc9f8936e25273b6df0c46bcd2af580 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Mon, 13 May 2024 18:00:46 +0200 Subject: [PATCH 09/14] runapptests - Set an initial value for the timeOffset --- bin/runapptests.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/runapptests.js b/bin/runapptests.js index 8187d869d..5eefa4905 100755 --- a/bin/runapptests.js +++ b/bin/runapptests.js @@ -311,11 +311,12 @@ function runStep(step, subtest, test, state){ break; case "sleep" : p = p.then(()=>{ - console.log("> SLEEP FOR", step.ms); + console.log("> SLEEP FOR", step.ms + "ms"); if (!subtest.wrappedDateNow){ emu.tx(`Date.now = (o)=>{return ()=>{ return o() + global.APPTESTS.timeOffset; - };}(Date.now);\n`); + };}(Date.now); + global.APPTESTS.timeOffset = 0;\n`); subtest.wrappedDateNow = true; } emu.tx(`global.APPTESTS.timeOffset += ${step.ms}; From d10fe4b2fb99a96c19507d5965824a810b46d26e Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Mon, 13 May 2024 18:40:52 +0200 Subject: [PATCH 10/14] runapptests - Allow resetting the recorded calls --- bin/runapptests.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bin/runapptests.js b/bin/runapptests.js index 5eefa4905..4ac9cacf3 100755 --- a/bin/runapptests.js +++ b/bin/runapptests.js @@ -57,7 +57,9 @@ const DEMOTEST = { {"t":"assertArray", "js": "[1,2,3]", "is":"notEmpty", "text": "Evaluates the content of 'js' on the device and asserts if the result is an array with more than 0 entries"}, {"t":"cmd", "js": "global.testfunction(1)", "text": "Call function for the following asserts"}, {"t":"assertCall", "id": "testfunc", "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 1 } ] , "text": "Asserts if a wrapped function has been called with the expected arguments"}, - {"t":"assertCall", "id": "testfunc", "count": 1 , "text": "Asserts if a wrapped function has been called the expected number of times"} + {"t":"assertCall", "id": "testfunc", "count": 1 , "text": "Asserts if a wrapped function has been called the expected number of times"}, + {"t":"resetCall", "id": "testfunc", "text": "Reset the recorded calls"}, + {"t":"assertCall", "id": "testfunc", "count": 0 , "text": "Asserts if a wrapped function has been called the expected number of times"} ] }] } @@ -276,6 +278,11 @@ function runStep(step, subtest, test, state){ state.ok &= assertArray(step); }); break; + case "resetCall": + console.log(`> RESET CALL ${step.id}`); + emu.tx(`global.APPTESTS.funcCalls.${step.id} = 0;\n`); + emu.tx(`global.APPTESTS.funcArgs.${step.id} = undefined;\n`); + break; case "assertCall": p = p.then(() => { state.ok &= assertCall(step); From a2d2a34906f2ee18e34186afca7c576518690415 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Mon, 13 May 2024 18:41:47 +0200 Subject: [PATCH 11/14] android - Explicit expectation for new calls instead of accepting old ones --- apps/android/test.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/android/test.json b/apps/android/test.json index 74d88a1e6..8e9b6ced2 100644 --- a/apps/android/test.json +++ b/apps/android/test.json @@ -86,12 +86,13 @@ {"t":"setup", "id": "connected"}, {"t":"assert", "js": "Bangle.setGPSPower(1, 'test')", "is":"truthy", "text": "setGPSPower returns truthy when switching on"}, - + + {"t":"resetCall", "id": "gpspower"}, {"t":"gb", "obj":{"t":"gps"}, "text": "trigger switch"}, {"t":"assertCall", "id": "gpspower", "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 0 } ], "text": "internal GPS switched off"}, + {"t":"resetCall", "id": "gpspower"}, {"t":"sleep", "ms":"12000", "text": "wait for fallback"}, - {"t":"assertCall", "id": "gpspower", "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 1 } ], "text": "internal GPS switched on caused by missing GB event"} ] }] From db14c39c94c4c006e8f6accd16db6ad002fd166d Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Mon, 13 May 2024 18:57:51 +0200 Subject: [PATCH 12/14] runapptests - Log step text for resetCall --- bin/runapptests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/runapptests.js b/bin/runapptests.js index 4ac9cacf3..92d480c18 100755 --- a/bin/runapptests.js +++ b/bin/runapptests.js @@ -279,7 +279,7 @@ function runStep(step, subtest, test, state){ }); break; case "resetCall": - console.log(`> RESET CALL ${step.id}`); + console.log(`> RESET CALL ${step.id}`, step.text ? "- " + step.text : ""); emu.tx(`global.APPTESTS.funcCalls.${step.id} = 0;\n`); emu.tx(`global.APPTESTS.funcArgs.${step.id} = undefined;\n`); break; From 9814dd424c853932a04a995228ad9a05d9e48453 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Mon, 13 May 2024 19:00:01 +0200 Subject: [PATCH 13/14] runapptests - Rename sleep to advanceTime and add documentation --- apps/android/test.json | 2 +- bin/runapptests.js | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/android/test.json b/apps/android/test.json index 8e9b6ced2..1a1436ccd 100644 --- a/apps/android/test.json +++ b/apps/android/test.json @@ -92,7 +92,7 @@ {"t":"assertCall", "id": "gpspower", "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 0 } ], "text": "internal GPS switched off"}, {"t":"resetCall", "id": "gpspower"}, - {"t":"sleep", "ms":"12000", "text": "wait for fallback"}, + {"t":"advanceTime", "ms":"12000", "text": "wait for fallback"}, {"t":"assertCall", "id": "gpspower", "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 1 } ], "text": "internal GPS switched on caused by missing GB event"} ] }] diff --git a/bin/runapptests.js b/bin/runapptests.js index 92d480c18..6ac290fc2 100755 --- a/bin/runapptests.js +++ b/bin/runapptests.js @@ -57,10 +57,17 @@ const DEMOTEST = { {"t":"assertArray", "js": "[1,2,3]", "is":"notEmpty", "text": "Evaluates the content of 'js' on the device and asserts if the result is an array with more than 0 entries"}, {"t":"cmd", "js": "global.testfunction(1)", "text": "Call function for the following asserts"}, {"t":"assertCall", "id": "testfunc", "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 1 } ] , "text": "Asserts if a wrapped function has been called with the expected arguments"}, - {"t":"assertCall", "id": "testfunc", "count": 1 , "text": "Asserts if a wrapped function has been called the expected number of times"}, {"t":"resetCall", "id": "testfunc", "text": "Reset the recorded calls"}, {"t":"assertCall", "id": "testfunc", "count": 0 , "text": "Asserts if a wrapped function has been called the expected number of times"} ] + }, { + "description": "Emulator time can advanced by a given amount. This currently works for timeouts,intervals and Date.now() calls", + "steps": [ + {"t":"cmd", "js":"setTimeout(()=>{global.waited = true},60000)", "text": "Set a timeout for 60 seconds"}, + {"t":"assert", "js":"global.waited", "is": "falsy", "text": "Timeout has not yet fired"}, + {"t":"advanceTime", "ms":60000}, + {"t":"assert", "js":"global.waited", "is": "true", "text": "Timeout has fired"} + ] }] } @@ -316,9 +323,9 @@ function runStep(step, subtest, test, state){ } }); break; - case "sleep" : + case "advanceTime" : p = p.then(()=>{ - console.log("> SLEEP FOR", step.ms + "ms"); + console.log("> ADVANCE TIME BY", step.ms + "ms"); if (!subtest.wrappedDateNow){ emu.tx(`Date.now = (o)=>{return ()=>{ return o() + global.APPTESTS.timeOffset; From 12da4948e8011dae5717103b88108f7f377feb39 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Wed, 15 May 2024 17:46:31 +0200 Subject: [PATCH 14/14] runapptests - Only advance timers and not Date.now --- apps/android/test.json | 2 +- bin/runapptests.js | 18 +++++------------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/apps/android/test.json b/apps/android/test.json index 1a1436ccd..429fd70fe 100644 --- a/apps/android/test.json +++ b/apps/android/test.json @@ -92,7 +92,7 @@ {"t":"assertCall", "id": "gpspower", "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 0 } ], "text": "internal GPS switched off"}, {"t":"resetCall", "id": "gpspower"}, - {"t":"advanceTime", "ms":"12000", "text": "wait for fallback"}, + {"t":"advanceTimers", "ms":"12000", "text": "wait for fallback"}, {"t":"assertCall", "id": "gpspower", "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 1 } ], "text": "internal GPS switched on caused by missing GB event"} ] }] diff --git a/bin/runapptests.js b/bin/runapptests.js index 6ac290fc2..dcbf13c58 100755 --- a/bin/runapptests.js +++ b/bin/runapptests.js @@ -61,11 +61,11 @@ const DEMOTEST = { {"t":"assertCall", "id": "testfunc", "count": 0 , "text": "Asserts if a wrapped function has been called the expected number of times"} ] }, { - "description": "Emulator time can advanced by a given amount. This currently works for timeouts,intervals and Date.now() calls", + "description": "Emulator timers and intervals can advanced by a given time", "steps": [ {"t":"cmd", "js":"setTimeout(()=>{global.waited = true},60000)", "text": "Set a timeout for 60 seconds"}, {"t":"assert", "js":"global.waited", "is": "falsy", "text": "Timeout has not yet fired"}, - {"t":"advanceTime", "ms":60000}, + {"t":"advanceTimers", "ms":60000, "text": "Advance timers by 60000 ms to get the timer to fire in the next idle period"}, {"t":"assert", "js":"global.waited", "is": "true", "text": "Timeout has fired"} ] }] @@ -323,18 +323,10 @@ function runStep(step, subtest, test, state){ } }); break; - case "advanceTime" : + case "advanceTimers" : p = p.then(()=>{ - console.log("> ADVANCE TIME BY", step.ms + "ms"); - if (!subtest.wrappedDateNow){ - emu.tx(`Date.now = (o)=>{return ()=>{ - return o() + global.APPTESTS.timeOffset; - };}(Date.now); - global.APPTESTS.timeOffset = 0;\n`); - subtest.wrappedDateNow = true; - } - emu.tx(`global.APPTESTS.timeOffset += ${step.ms}; - for(let c of global["\xff"].timers){ + console.log("> ADVANCE TIMERS BY", step.ms + "ms"); + emu.tx(`for(let c of global["\xff"].timers){ if(c) c.time -= ${step.ms * 1000}; }\n`); });