Refactor test utilities to use portable delay function and include necessary headers

This commit is contained in:
Ben Meadors
2026-02-08 09:42:05 -06:00
parent a43ce34143
commit 370f62a8c9
3 changed files with 24 additions and 3 deletions
+16
View File
@@ -4,6 +4,13 @@
#include "TestUtil.h"
#if defined(ARDUINO)
#include <Arduino.h>
#else
#include <chrono>
#include <thread>
#endif
void initializeTestEnvironment()
{
concurrency::hasBeenSetup = true;
@@ -15,4 +22,13 @@ void initializeTestEnvironment()
perhapsSetRTC(RTCQualityNTP, &tv);
#endif
concurrency::OSThread::setup();
}
void testDelay(unsigned long ms)
{
#if defined(ARDUINO)
::delay(ms);
#else
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
#endif
}
+4 -1
View File
@@ -1,4 +1,7 @@
#pragma once
// Initialize testing environment.
void initializeTestEnvironment();
void initializeTestEnvironment();
// Portable delay for tests (Arduino or host).
void testDelay(unsigned long ms);
+4 -2
View File
@@ -1,6 +1,8 @@
#include <string.h>
#include <unity.h>
#include "TestUtil.h"
/**
* Get actual string length for nanopb char array fields.
* Nanopb stores strings as fixed-size char arrays that may contain embedded nulls.
@@ -202,8 +204,8 @@ void setup()
{
// NOTE!!! Wait for >2 secs
// if board doesn't support software reset via Serial.DTR/RTS
delay(10);
delay(2000);
testDelay(10);
testDelay(2000);
UNITY_BEGIN();
RUN_TEST(test_normal_string);