mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-11-20 15:52:12 +01:00
Move the board profile tests into the native Unity suite
The board tests ran through tools/test-board-profile.sh with their own stubs, assert() and a script that copied nine method bodies out of Transceiver.cpp, so they were outside pio test -e native and the coverage report. Pure decisions now live in units the native env builds: BoardProfile::usesPin is constexpr, RadioReadiness decides register validity, the receive-state outcome (ready, retry or unavailable, with one try today) and whether a queued job may transmit, and ShadeGpioGuard decides whether a shade's outputs touch a board pad. Transceiver and ShadeGpio call them with identical behaviour. New Unity suites cover the generic and LILYGO profiles (reserved pads, startup order, radio bring-up) and the readiness unit; the old harness, its script, CI step and stubs are deleted. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2b3d556729
commit
28af01195a
27 changed files with 595 additions and 517 deletions
|
|
@ -10,12 +10,64 @@
|
|||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <type_traits>
|
||||
|
||||
typedef uint8_t byte;
|
||||
|
||||
// Fixed so anything formatted from it is deterministic.
|
||||
inline unsigned long millis() { return 0; }
|
||||
// Starts at 0 and only moves when a test calls delay() or sets it, so anything
|
||||
// formatted from it is deterministic.
|
||||
inline unsigned long stubMillis = 0;
|
||||
inline unsigned long millis() { return stubMillis; }
|
||||
inline void delay(unsigned long ms) { stubMillis += ms; }
|
||||
|
||||
// A fake GPIO bank for board code. Every pin call is also logged in order
|
||||
// so tests can check the startup sequence, not only the final levels.
|
||||
constexpr int LOW = 0;
|
||||
constexpr int HIGH = 1;
|
||||
constexpr int INPUT = 0x01;
|
||||
constexpr int OUTPUT = 0x03;
|
||||
struct StubGpioEvent {
|
||||
enum Kind : char { Mode = 'M', Level = 'L', Write = 'W', SpiBegin = 'B', SpiEnd = 'E' };
|
||||
Kind kind;
|
||||
uint8_t pin;
|
||||
int value;
|
||||
};
|
||||
inline std::vector<StubGpioEvent> stubGpioLog;
|
||||
inline int stubPinLevel[64] = {};
|
||||
inline int stubPinMode[64] = {};
|
||||
inline int stubPinReadOverride[64] = {}; // -1 for none, set by stubGpioReset()
|
||||
inline void stubGpioReset() {
|
||||
stubGpioLog.clear();
|
||||
for(int i = 0; i < 64; i++) { stubPinLevel[i] = 0; stubPinMode[i] = 0; stubPinReadOverride[i] = -1; }
|
||||
stubMillis = 0;
|
||||
}
|
||||
// The ESP-IDF call that sets the output latch whatever the pin mode is.
|
||||
inline void stubSetLatch(uint8_t pin, int level) {
|
||||
stubPinLevel[pin] = level;
|
||||
stubGpioLog.push_back({StubGpioEvent::Level, pin, level});
|
||||
}
|
||||
inline void pinMode(uint8_t pin, uint8_t mode) {
|
||||
stubPinMode[pin] = mode;
|
||||
stubGpioLog.push_back({StubGpioEvent::Mode, pin, mode});
|
||||
}
|
||||
// Arduino 3 only accepts writes once pinMode has made the pin an output.
|
||||
inline void digitalWrite(uint8_t pin, uint8_t level) {
|
||||
if(stubPinMode[pin] != OUTPUT) return;
|
||||
stubPinLevel[pin] = level;
|
||||
stubGpioLog.push_back({StubGpioEvent::Write, pin, level});
|
||||
}
|
||||
inline int digitalRead(uint8_t pin) {
|
||||
return stubPinReadOverride[pin] >= 0 ? stubPinReadOverride[pin] : stubPinLevel[pin];
|
||||
}
|
||||
|
||||
// Serial output is discarded.
|
||||
struct StubSerial {
|
||||
template <typename... Args> void printf(const char *, Args...) {}
|
||||
void println(const char *) {}
|
||||
};
|
||||
inline StubSerial Serial;
|
||||
|
||||
// Tests that measure time set this.
|
||||
inline unsigned long stubMicros = 0;
|
||||
inline unsigned long micros() { return stubMicros; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue