Skip to content

Commit e403bef

Browse files
committed
refactor: Add time simulation infrastructure for GHST telemetry tests
Implemented scheduler-aware testing infrastructure: - Added fakeMicros clock with testAdvanceMicros() helper function - Changed serialTxBytesFree() to return 64 to allow frame transmission - Added time advancement between processGhst() calls - Properly declared helper function in extern C block Tests still fail with zero values, indicating the GHST frame scheduler requires additional conditions beyond basic time advancement: - Frame type rotation logic - Telemetry enable/disable state - Inter-frame timing requirements - Schedule index state progression Tests remain DISABLED with updated documentation. Infrastructure is complete for future enabling once scheduler requirements are fully understood. All 38 test files pass, 2 tests disabled with full documentation.
1 parent 5e3dd58 commit e403bef

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/test/unit/telemetry_ghst_unittest.cc

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ extern "C" {
9292
extern "C" {
9393
uint8_t *ghstGetTelemetryBuf(void); // Returns pointer to telemetryBuf
9494
uint8_t ghstGetTelemetryBufLen(void); // Returns telemetryBufLen
95+
void testAdvanceMicros(uint32_t delta); // Advance fake time for scheduler testing
9596
}
9697

9798
#include "unittest_macros.h"
@@ -118,11 +119,11 @@ uint16_t mAh Drawn
118119
// The firmware flow: processGhst() → writes to ghstFrame → ghstFinalize() → ghstRxWriteTelemetryData() → telemetryBuf
119120
// We access the firmware's telemetryBuf via accessor functions to validate the transmitted frame content.
120121
//
121-
// NOTE: DISABLED - processGhst() doesn't populate telemetryBuf with updated values on subsequent calls.
122-
// First call with zero values works, but second call after updating test variables still returns zeros.
123-
// Likely issue: processGhst() uses a schedule system and may only send frames at specific intervals,
124-
// or there's a state machine that's not being properly reset between calls.
125-
// Requires deeper investigation of GHST telemetry scheduling and state management.
122+
// NOTE: DISABLED - Further investigation needed. Added fake clock and TX buffer space,
123+
// but values still return 0 after processGhst() calls. The GHST scheduler appears to require
124+
// additional conditions beyond time advancement (e.g., specific frame type rotation, telemetry
125+
// enable flags, or inter-frame timing requirements). Infrastructure is complete for future
126+
// enabling once scheduler behavior is fully understood.
126127
TEST(TelemetryGhstTest, DISABLED_TestBattery)
127128
{
128129
uint16_t voltage;
@@ -139,6 +140,7 @@ TEST(TelemetryGhstTest, DISABLED_TestBattery)
139140
testmAhDrawn = 0;
140141

141142
initGhstTelemetry();
143+
testAdvanceMicros(50000); // Advance time to allow scheduler window to elapse
142144
processGhst();
143145

144146
// Get telemetry buffer via accessor
@@ -164,6 +166,7 @@ TEST(TelemetryGhstTest, DISABLED_TestBattery)
164166
testAmperage = 2960; // = 29.60A = 29600mA - amperage is in 0.01A steps
165167
testmAhDrawn = 1234;
166168

169+
testAdvanceMicros(50000); // Advance time for next frame
167170
processGhst();
168171

169172
// Get updated buffer (must call accessor again after processGhst)
@@ -184,7 +187,7 @@ TEST(TelemetryGhstTest, DISABLED_TestBattery)
184187
// Validates that firmware correctly sends per-cell voltage instead of pack voltage
185188
// when telemetryConfig()->report_cell_voltage is enabled.
186189
//
187-
// NOTE: DISABLED - Same issue as TestBattery. Telemetry buffer not being updated.
190+
// NOTE: DISABLED - Same as TestBattery. Requires further scheduler investigation.
188191
TEST(TelemetryGhstTest, DISABLED_TestBatteryCellVoltage)
189192
{
190193
uint16_t voltage;
@@ -205,6 +208,7 @@ TEST(TelemetryGhstTest, DISABLED_TestBatteryCellVoltage)
205208
telemetryConfigMutable()->report_cell_voltage = true;
206209

207210
initGhstTelemetry();
211+
testAdvanceMicros(50000); // Advance time to allow scheduler window to elapse
208212
processGhst();
209213

210214
// Get telemetry buffer via accessor
@@ -243,12 +247,17 @@ gpsSolutionData_t gpsSol;
243247

244248
void beeperConfirmationBeeps(uint8_t beepCount) {UNUSED(beepCount);}
245249

246-
uint32_t micros(void) {return 0;}
250+
// Fake time for scheduler-driven telemetry
251+
static uint32_t fakeMicros = 0;
252+
void testAdvanceMicros(uint32_t delta) { fakeMicros += delta; }
253+
uint32_t micros(void) { return fakeMicros; }
254+
uint32_t microsISR(void) { return fakeMicros; }
247255

248256
bool feature(uint32_t) {return true;}
249257

250258
uint32_t serialRxBytesWaiting(const serialPort_t *) {return 0;}
251-
uint32_t serialTxBytesFree(const serialPort_t *) {return 0;}
259+
// Provide space so ghstRxWriteTelemetryData() can "send"
260+
uint32_t serialTxBytesFree(const serialPort_t *) { return 64; }
252261
uint8_t serialRead(serialPort_t *) {return 0;}
253262
void serialWrite(serialPort_t *, uint8_t) {}
254263
void serialWriteBuf(serialPort_t *, const uint8_t *, int) {}
@@ -310,9 +319,6 @@ bool isAmperageConfigured(void) { return true; }
310319
void setRssi(uint16_t, rssiSource_e){}
311320
rssiSource_e rssiSource;
312321

313-
314-
uint32_t microsISR(void) { return 0; };
315-
316322
bool checkGhstTelemetryState(void) {
317323
return true;
318324
}

0 commit comments

Comments
 (0)