Skip to content

Commit

Permalink
more reliable TEST=wiring/no_fixture_long_running for electron G350
Browse files Browse the repository at this point in the history
  • Loading branch information
technobly committed Apr 9, 2018
1 parent 5d5de36 commit e1e8564
Showing 1 changed file with 84 additions and 48 deletions.
132 changes: 84 additions & 48 deletions user/tests/wiring/no_fixture_long_running/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down

0 comments on commit e1e8564

Please sign in to comment.