From e1e856465217923b734e8c40a6f8fde55fd60e6b Mon Sep 17 00:00:00 2001 From: Technobly Date: Mon, 9 Apr 2018 18:34:49 -0500 Subject: [PATCH] more reliable TEST=wiring/no_fixture_long_running for electron G350 --- .../wiring/no_fixture_long_running/time.cpp | 132 +++++++++++------- 1 file changed, 84 insertions(+), 48 deletions(-) diff --git a/user/tests/wiring/no_fixture_long_running/time.cpp b/user/tests/wiring/no_fixture_long_running/time.cpp index 2181ea4fc8..82d0deb9dc 100644 --- a/user/tests/wiring/no_fixture_long_running/time.cpp +++ b/user/tests/wiring/no_fixture_long_running/time.cpp @@ -7,67 +7,103 @@ test(TIME_01_SyncTimeInAutomaticMode) { set_system_mode(AUTOMATIC); assertEqual(System.mode(),AUTOMATIC); Particle.connect(); - waitFor(Particle.connected, 120000); + if (!waitFor(Particle.connected, 120000)) { + Serial.println("Timed out waiting to connect!"); + fail(); + return; + } Particle.syncTime(); - waitFor(Particle.syncTimeDone, 10000); + if (!waitFor(Particle.syncTimeDone, 120000)) { + Serial.println("Timed out waiting for time sync!"); + fail(); + return; + } delay(4000); for(int x=0; x<2; x++) { - time_t syncedLastUnix, syncedCurrentUnix; - system_tick_t syncedCurrentMillis; - system_tick_t syncedLastMillis = Particle.timeSyncedLast(syncedLastUnix); - // Invalid time (year = 00) 2000/01/01 00:00:00 - Time.setTime(946684800); - // assertFalse(Time.isValid()); - Particle.disconnect(); - waitFor(Particle.disconnected, 60000); - // set_system_mode(AUTOMATIC); - // assertEqual(System.mode(),AUTOMATIC); - delay(20000); + time_t syncedLastUnix, syncedCurrentUnix; + system_tick_t syncedCurrentMillis; + system_tick_t syncedLastMillis = Particle.timeSyncedLast(syncedLastUnix); + // Invalid time (year = 00) 2000/01/01 00:00:00 + Time.setTime(946684800); + // assertFalse(Time.isValid()); + Particle.disconnect(); + if (!waitFor(Particle.disconnected, 120000)) { + Serial.println("Timed out waiting to disconnect!"); + fail(); + return; + } + // set_system_mode(AUTOMATIC); + // assertEqual(System.mode(),AUTOMATIC); + delay(20000); - Particle.connect(); - waitFor(Particle.connected, 120000); - // Just in case send sync time request (Electron might not send it after handshake if the session was resumed) - Particle.syncTime(); - waitFor(Particle.syncTimeDone, 60000); + Particle.connect(); + if (!waitFor(Particle.connected, 120000)) { + Serial.println("Timed out waiting to connect!"); + fail(); + return; + } + // Just in case send sync time request (Electron might not send it after handshake if the session was resumed) + Particle.syncTime(); + if (!waitFor(Particle.syncTimeDone, 120000)) { + Serial.println("Timed out waiting for time sync!"); + fail(); + return; + } - assertTrue(Time.isValid()); - syncedCurrentMillis = Particle.timeSyncedLast(syncedCurrentUnix); - // Serial.printlnf("sCU-sLU: %d, sCM-sLM: %d", - // syncedCurrentUnix-syncedLastUnix, syncedCurrentMillis-syncedLastMillis); - assertMore(syncedCurrentMillis, syncedLastMillis); - assertMore(syncedCurrentUnix, syncedLastUnix); + assertTrue(Time.isValid()); + syncedCurrentMillis = Particle.timeSyncedLast(syncedCurrentUnix); + // Serial.printlnf("sCU-sLU: %d, sCM-sLM: %d", + // syncedCurrentUnix-syncedLastUnix, syncedCurrentMillis-syncedLastMillis); + assertMore(syncedCurrentMillis, syncedLastMillis); + assertMore(syncedCurrentUnix, syncedLastUnix); } // for() } test(TIME_02_SyncTimeInManualMode) { for(int x=0; x<2; x++) { - time_t syncedLastUnix, syncedCurrentUnix; - system_tick_t syncedCurrentMillis; - system_tick_t syncedLastMillis = Particle.timeSyncedLast(syncedLastUnix); - // Invalid time (year = 00) 2000/01/01 00:00:00 - Time.setTime(946684800); - // assertFalse(Time.isValid()); - Particle.disconnect(); - waitFor(Particle.disconnected, 120000); - set_system_mode(MANUAL); - assertEqual(System.mode(),MANUAL); - delay(20000); + time_t syncedLastUnix, syncedCurrentUnix; + system_tick_t syncedCurrentMillis; + system_tick_t syncedLastMillis = Particle.timeSyncedLast(syncedLastUnix); + // Invalid time (year = 00) 2000/01/01 00:00:00 + Time.setTime(946684800); + // assertFalse(Time.isValid()); + // Serial.println("DISCONNECT"); + Particle.disconnect(); + if (!waitFor(Particle.disconnected, 120000)) { + Serial.println("Timed out waiting to disconnect!"); + fail(); + return; + } + set_system_mode(MANUAL); + assertEqual(System.mode(),MANUAL); + delay(20000); - Particle.connect(); - waitFor(Particle.connected, 60000); - // Just in case send sync time request (Electron might not send it after handshake if the session was resumed) - Particle.syncTime(); - if (!Time.isValid()) { - waitFor(Particle.syncTimeDone, 120000); - } - assertTrue(Time.isValid()); - syncedCurrentMillis = Particle.timeSyncedLast(syncedCurrentUnix); - // Serial.printlnf("sCU-sLU: %d, sCM-sLM: %d", - // syncedCurrentUnix-syncedLastUnix, syncedCurrentMillis-syncedLastMillis); - assertMore(syncedCurrentMillis, syncedLastMillis); - assertMore(syncedCurrentUnix, syncedLastUnix); + // Serial.println("CONNECT"); + Particle.connect(); + if (!waitFor(Particle.connected, 120000)) { + Serial.println("Timed out waiting to connect!"); + fail(); + return; + } + + // Just in case send sync time request (Electron might not send it after handshake if the session was resumed) + // Serial.println("SYNC TIME"); + Particle.syncTime(); + if (!Time.isValid()) { + if (!waitFor(Particle.syncTimeDone, 120000)) { + Serial.println("Timed out waiting for time sync!"); + fail(); + return; + } + } + assertTrue(Time.isValid()); + syncedCurrentMillis = Particle.timeSyncedLast(syncedCurrentUnix); + // Serial.printlnf("sCU-sLU: %d, sCM-sLM: %d", + // syncedCurrentUnix-syncedLastUnix, syncedCurrentMillis-syncedLastMillis); + assertMore(syncedCurrentMillis, syncedLastMillis); + assertMore(syncedCurrentUnix, syncedLastUnix); } // for() }