From eed5cfda90deaa0624ca90c20b0e6093b537a78c Mon Sep 17 00:00:00 2001 From: Eric Severance Date: Wed, 25 Dec 2024 14:54:57 -0800 Subject: [PATCH 1/2] Include log messages in unit tests --- src/DebugConfiguration.h | 2 +- test/TestUtil.cpp | 10 ++++++++++ test/TestUtil.h | 4 ++++ test/test_crypto/test_main.cpp | 2 ++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/TestUtil.cpp create mode 100644 test/TestUtil.h diff --git a/src/DebugConfiguration.h b/src/DebugConfiguration.h index 55453ea1e7..7987e7fa14 100644 --- a/src/DebugConfiguration.h +++ b/src/DebugConfiguration.h @@ -45,7 +45,7 @@ #define LOG_CRIT(...) SEGGER_RTT_printf(0, __VA_ARGS__) #define LOG_TRACE(...) SEGGER_RTT_printf(0, __VA_ARGS__) #else -#if defined(DEBUG_PORT) && !defined(DEBUG_MUTE) && !defined(PIO_UNIT_TESTING) +#if defined(DEBUG_PORT) && !defined(DEBUG_MUTE) #define LOG_DEBUG(...) DEBUG_PORT.log(MESHTASTIC_LOG_LEVEL_DEBUG, __VA_ARGS__) #define LOG_INFO(...) DEBUG_PORT.log(MESHTASTIC_LOG_LEVEL_INFO, __VA_ARGS__) #define LOG_WARN(...) DEBUG_PORT.log(MESHTASTIC_LOG_LEVEL_WARN, __VA_ARGS__) diff --git a/test/TestUtil.cpp b/test/TestUtil.cpp new file mode 100644 index 0000000000..eda4ce6f7a --- /dev/null +++ b/test/TestUtil.cpp @@ -0,0 +1,10 @@ +#include "TestUtil.h" +#include "SerialConsole.h" +#include "concurrency/OSThread.h" + +void initializeTestEnvironment() +{ + concurrency::hasBeenSetup = true; + concurrency::OSThread::setup(); + consoleInit(); +} \ No newline at end of file diff --git a/test/TestUtil.h b/test/TestUtil.h new file mode 100644 index 0000000000..ce021e459e --- /dev/null +++ b/test/TestUtil.h @@ -0,0 +1,4 @@ +#pragma once + +// Initialize testing environment. +void initializeTestEnvironment(); \ No newline at end of file diff --git a/test/test_crypto/test_main.cpp b/test/test_crypto/test_main.cpp index 652d5dbcbc..a89ef3e249 100644 --- a/test/test_crypto/test_main.cpp +++ b/test/test_crypto/test_main.cpp @@ -1,5 +1,6 @@ #include "CryptoEngine.h" +#include "TestUtil.h" #include void HexToBytes(uint8_t *result, const std::string hex, size_t len = 0) @@ -170,6 +171,7 @@ void setup() delay(10); delay(2000); + initializeTestEnvironment(); UNITY_BEGIN(); // IMPORTANT LINE! RUN_TEST(test_SHA256); RUN_TEST(test_ECB_AES256); From ae84b6d8690c575778ab70ced934be0dc5a34493 Mon Sep 17 00:00:00 2001 From: Eric Severance Date: Wed, 25 Dec 2024 16:40:55 -0800 Subject: [PATCH 2/2] Provide an initial time value --- test/TestUtil.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/TestUtil.cpp b/test/TestUtil.cpp index eda4ce6f7a..b470b8ce88 100644 --- a/test/TestUtil.cpp +++ b/test/TestUtil.cpp @@ -1,10 +1,18 @@ -#include "TestUtil.h" #include "SerialConsole.h" #include "concurrency/OSThread.h" +#include "gps/RTC.h" + +#include "TestUtil.h" void initializeTestEnvironment() { concurrency::hasBeenSetup = true; - concurrency::OSThread::setup(); consoleInit(); +#if ARCH_PORTDUINO + struct timeval tv; + tv.tv_sec = time(NULL); + tv.tv_usec = 0; + perhapsSetRTC(RTCQualityNTP, &tv); +#endif + concurrency::OSThread::setup(); } \ No newline at end of file