test(firmware): event_log boot recovery — partial fill and post-wrap
Exercises the slot-scan logic in event_log_init(): after a simulated reboot (RAM state cleared, NVS slots preserved) the module must resume with the correct head/cnt so newest-first read order is unchanged and subsequent writes continue the seq monotonically. Adds native-only event_log_test_simulate_reboot() helper. Lifts the slot-scan loop out of the #ifdef ARDUINO guard so the native stub exercises the same recovery path as production; the platform-specific NVS setup remains guarded.
This commit is contained in:
@@ -27,6 +27,11 @@
|
||||
g_head = 0;
|
||||
g_cnt = 0;
|
||||
}
|
||||
extern "C" void event_log_test_simulate_reboot() {
|
||||
// Simulate device reboot: clear in-RAM state, keep persistent slots.
|
||||
g_head = 0;
|
||||
g_cnt = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static const size_t SLOTS = 32;
|
||||
@@ -69,6 +74,7 @@ void event_log_init() {
|
||||
Serial.println("[evlog] NVS begin failed");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
// Scan all 32 slots; locate the one with the largest seq.
|
||||
// Empty log: every slot tag == 0 (not a valid EventLogTag, which starts at 1).
|
||||
uint32_t max_seq = 0;
|
||||
@@ -91,9 +97,6 @@ void event_log_init() {
|
||||
g_head = 0;
|
||||
g_cnt = 0;
|
||||
}
|
||||
#else
|
||||
// nothing
|
||||
#endif
|
||||
}
|
||||
|
||||
void event_log_write(EventLogTag tag, uint16_t data0, uint16_t data1) {
|
||||
|
||||
@@ -33,6 +33,7 @@ struct EventLogEntry {
|
||||
static_assert(sizeof(EventLogEntry) == 32, "EventLogEntry must be 32 bytes");
|
||||
|
||||
// NVS-backed 32-slot ring buffer. Safe to call before NTP sync.
|
||||
// Call exactly once from application setup, before any task writes events.
|
||||
void event_log_init();
|
||||
void event_log_write(EventLogTag tag, uint16_t data0 = 0, uint16_t data1 = 0);
|
||||
size_t event_log_read_recent(EventLogEntry* out, size_t max_entries);
|
||||
|
||||
Reference in New Issue
Block a user