!7 // TODO: wait with the test on boot until #1027019 has done its thing cmodule RebootConsciousness > DynPrintLog { DoubleRange typicalTimeToReboot = new(1000, 0); start-thread { theTest(); /*watchQuotedLog_future(rebootLogFile(), 1000, voidfunc(S s) { new Matches m; if "* Rebooting computer" predictReboot(); });*/ dm_vmBus_onMessage_q doingCleanReboot(r predictReboot); } void theTest { LS lastLines = unquoteAll(lastNLines(2, rebootLogFile())); pnl(lastLines); analyzeLines(lastLines); } void analyzeLines(LS lastLines) { if (empty(lastLines)) ret; if (l(lastLines) == 1) ret with confused("Only one event: " + lastLines); S line1 = first(lastLines), line2 = second(lastLines); new Matches m; new Matches m2; if (match("* Rebooting computer", line1, m) && match("* Boot timestamp changed from * to *", line2, m2)) { long ts1 = parseLong(m.get(0)), ts2 = parseLong(m2.get(2)); if (ts2 > ts1) { notConfused("All OK! A reboot happened after my reboot command"); double timeToReboot = toSeconds(ts2-ts1); setField(typicalTimeToReboot := DoubleRange( min(typicalTimeToReboot.start, timeToReboot), max(typicalTimeToReboot.end, timeToReboot)); } else confused("Timestamps are weird: " + lastLines); } else confused("Was expecting reboot cmd & then reboot effect: " + lastLines); } void confused(S msg) { printAndProgramLog("Confused: " + msg); } void notConfused(S msg) { printAndProgramLog("I am very satisfied. " + msg); } void predict(S msg) { printAndProgramLog("I predict: " + msg); dm_sayInEnglish(msg); } void predictReboot enter { predict("A reboot will happen in between " + formatDouble(typicalTimeToReboot.start, 1) + " and " + formatDouble(typicalTimeToReboot.end, 1) + " seconds"); } }