Harden USB logging and persist watchdog events in management reports
This commit is contained in:
1 parent
bd55369aa9
commit
3add4695cc
98 files changed
+7207
-372
No files matched your search
+42
-3
@@ -6,6 +6,11 @@
|
||||
#include <string>
|
||||
using namespace mesh;
|
||||
using namespace mesh::management;
|
||||
namespace mesh {
|
||||
UsbLoggingStatus test_usb_status;
|
||||
unsigned usb_status_calls = 0;
|
||||
UsbLoggingStatus usbLoggingStatus() { ++usb_status_calls; return test_usb_status; }
|
||||
}
|
||||
struct Fixture {
|
||||
MemoryFS fs;
|
||||
Mesh mesh;
|
||||
@@ -16,7 +21,7 @@ struct Fixture {
|
||||
CommonCLI cli;
|
||||
CommonCLICallbacks callbacks;
|
||||
std::unique_ptr<ManagementReporter> reporter;
|
||||
Fixture() { test_millis = 0; reboot(); }
|
||||
Fixture() { test_millis = 0; test_usb_status = UsbLoggingStatus(); usb_status_calls = 0; reboot(); }
|
||||
void reboot() { reporter.reset(); test_millis = 0; reporter.reset(new ManagementReporter(mesh, board, sensors, acl, prefs, callbacks, cli, &fs)); }
|
||||
std::string cmd(const char* text, bool ok = true) {
|
||||
char b[200], reply[160] = {}; strcpy(b, text);
|
||||
@@ -100,23 +105,57 @@ int main() {
|
||||
{
|
||||
Fixture f;
|
||||
for (unsigned i = 0; i < 36; ++i) { ClientInfo c; c.id.pub_key[0] = i; f.acl.clients.push_back(c); }
|
||||
f.configure(false); f.advance(21 * DAY + 600); assert(f.mesh.packets.size() == 6);
|
||||
for (unsigned i = 0; i < 6; ++i) {
|
||||
test_usb_status.supported = true; test_usb_status.watchdog_enabled = true;
|
||||
test_usb_status.host_connected = test_usb_status.reader_connected = true;
|
||||
test_usb_status.stalled = true; test_usb_status.retry_seconds = 7200;
|
||||
test_usb_status.inactive_seconds = 3600; test_usb_status.backoff_step = 1;
|
||||
test_usb_status.last_event.reasons = UsbLoggingWatchdogEvent::TX_STALLED;
|
||||
test_usb_status.last_event.action = UsbLoggingWatchdogEvent::REENUMERATE;
|
||||
test_usb_status.last_event.sequence = 17; test_usb_status.last_event.uptime_seconds = 300;
|
||||
test_usb_status.last_event.persisted = true;
|
||||
f.configure(false); f.advance(21 * DAY + 600); assert(f.mesh.packets.size() == 9);
|
||||
assert(usb_status_calls == 1);
|
||||
for (unsigned i = 0; i < 9; ++i) {
|
||||
const auto& p = f.mesh.packets[i]; assert(validPage(p.payload, p.payload_len));
|
||||
assert(p.payload[78] == i && p.payload[80] == 36 && p.flood);
|
||||
assert(!memcmp(p.payload, "MGR3", 4) && read16(p.payload + HEADER) == 61);
|
||||
assert(!(read16(p.payload + HEADER) & 1024)); // an open reader is not an active logger
|
||||
assert(read32(p.payload + HEADER + 3) == 7200);
|
||||
assert(read32(p.payload + HEADER + 7) == 3600);
|
||||
UsbLoggingWatchdogEvent event;
|
||||
assert(decodeUsbWatchdogEvent(p.payload + WATCHDOG_EVENT_OFFSET, event));
|
||||
assert(event.reasons == UsbLoggingWatchdogEvent::TX_STALLED && event.action == UsbLoggingWatchdogEvent::REENUMERATE);
|
||||
assert(event.sequence == 17 && event.uptime_seconds == 300 && event.persisted && event.epoch == 0);
|
||||
assert(floodSize(p.payload_len) <= 179);
|
||||
}
|
||||
}
|
||||
{
|
||||
Fixture f;
|
||||
for (unsigned i = 0; i < 7; ++i) { ClientInfo c; c.id.pub_key[0] = i; f.acl.clients.push_back(c); }
|
||||
f.configure(false); f.advance(21 * DAY); assert(f.mesh.packets.size() == 1);
|
||||
assert(!memcmp(f.mesh.packets[0].payload, "MGR3", 4));
|
||||
assert(read16(f.mesh.packets[0].payload + HEADER) == 0); // unsupported is explicit
|
||||
test_usb_status.supported = true; test_usb_status.retry_seconds = 999;
|
||||
test_usb_status.watchdog_auto = true; test_usb_status.auto_connected_seconds = 100;
|
||||
test_usb_status.host_connected = test_usb_status.reader_connected = test_usb_status.logger_active = true;
|
||||
test_usb_status.last_event.reasons = UsbLoggingWatchdogEvent::CLIENT_INACTIVE;
|
||||
test_usb_status.last_event.action = UsbLoggingWatchdogEvent::SOFT_RECOVERY;
|
||||
test_usb_status.last_event.sequence = 1; test_usb_status.last_event.epoch = 1700000001;
|
||||
f.board.voltage = 2900; f.board.temperature = 60; f.advance(60);
|
||||
assert(f.mesh.packets.size() == 2);
|
||||
assert(read16(f.mesh.packets[1].payload + HEADER) == 0); // frozen report snapshot
|
||||
assert(read32(f.mesh.packets[1].payload + HEADER + 11) == 0);
|
||||
assert(read32(f.mesh.packets[1].payload + WATCHDOG_EVENT_OFFSET + 9) == 0);
|
||||
assert(usb_status_calls == 1);
|
||||
// The low reading was not in the first snapshot and must survive into the next one.
|
||||
f.board.voltage = 3740; f.board.temperature = 24; f.advance(21 * DAY + 3600);
|
||||
assert(f.mesh.packets.size() == 4);
|
||||
assert(read16(f.mesh.packets.back().payload + 66) == 2900);
|
||||
assert(f.mesh.packets.back().payload[69] == temperature(60));
|
||||
assert(read16(f.mesh.packets.back().payload + HEADER) == 1561);
|
||||
assert(read32(f.mesh.packets.back().payload + HEADER + 11) == 100);
|
||||
assert(read32(f.mesh.packets.back().payload + WATCHDOG_EVENT_OFFSET + 9) == 1);
|
||||
assert(usb_status_calls == 2);
|
||||
}
|
||||
{
|
||||
Fixture f; f.configure(false); f.mesh.temp = true; f.advance(22 * DAY); assert(f.mesh.packets.empty());
|
||||
|
||||
Reference in new issue
Block a user