From f11b2d84ba829af408e51cdf946c41606bea771c Mon Sep 17 00:00:00 2001 From: Oleksandr Kolodkin Date: Wed, 30 Jul 2025 18:52:51 +0300 Subject: [PATCH 1/4] fix `pio test` build process --- platformio.ini | 4 +++- test/main.cpp | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/platformio.ini b/platformio.ini index 6952f64..eb6da95 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,5 +10,7 @@ [env:native] platform = native -build_flags = -std=gnu++17 +build_flags = + -std=gnu++17 + -Wa,-mbig-obj test_build_src = yes diff --git a/test/main.cpp b/test/main.cpp index a308066..0cf895e 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -29,6 +29,11 @@ void setUp(void) ArduinoFakeReset(); } +void tearDown(void) +{ + // Nothing to do here +} + int main(int argc, char **argv) { UNITY_BEGIN(); @@ -46,9 +51,7 @@ int main(int argc, char **argv) RUN_TEST_GROUP(ClientTest); RUN_TEST_GROUP(IncludeTest); - UNITY_END(); - - return 0; + return UNITY_END(); } #endif From 85bfb7a51cb05bfd13dc01f1948d1a4b86ebe665 Mon Sep 17 00:00:00 2001 From: Oleksandr Kolodkin Date: Wed, 30 Jul 2025 19:18:21 +0300 Subject: [PATCH 2/4] fix test_reset --- test/test_context.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/test/test_context.h b/test/test_context.h index 1ae3b02..c11bc74 100644 --- a/test/test_context.h +++ b/test/test_context.h @@ -18,9 +18,28 @@ namespace ArduinoContextTest ArduinoFakeContext* context = getArduinoFakeContext(); ArduinoFakeInstances* instances = context->Instances; + // Broke pointers for testing purposes + context->Instances->Serial = nullptr; + context->Instances->SPI = nullptr; + + TEST_ASSERT_NULL(context->Instances->Serial); + TEST_ASSERT_NULL(context->Instances->SPI); + ArduinoFakeReset(); - TEST_ASSERT_NOT_EQUAL(context->Instances, instances); + // After reset, a new instance of ArduinoFakeInstances should be created + // and the previous instance should be deleted. + // The Serial and SPI instances should also be reset to nullptr. + TEST_ASSERT_NOT_NULL(context->Instances); + TEST_ASSERT_NOT_NULL(context->Instances->Serial); + TEST_ASSERT_NOT_NULL(context->Instances->SPI); + + // A simple pointer comparison like TEST_ASSERT_NOT_EQUAL(context->Instances, instances); + // is not a reliable way to check if a new instance was created, because + // memory allocators can reuse the same address for new objects after deletion. + // This means a new instance could be created at the same memory location as the old one, + // causing the test to fail even though the instance is actually new. + // To properly verify a new instance, you should check object identity or state, not just pointer values. } void test_function_mock(void) From 5636318a691cb7e6e1689e960f8a19a9992d45e1 Mon Sep 17 00:00:00 2001 From: Oleksandr Kolodkin Date: Wed, 30 Jul 2025 19:35:40 +0300 Subject: [PATCH 3/4] Add pio test job and windows-latest --- .github/workflows/check.yaml | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 193b22b..59ee09b 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -1,6 +1,14 @@ name: Check -on: [push, pull_request] +on: + push: + branches: + - main + - master + pull_request: + branches: + - main + - master jobs: build: @@ -8,11 +16,11 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-22.04] + os: [ubuntu-22.04, windows-latest] steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Tests run: make @@ -27,7 +35,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - uses: actions/cache@v3 with: @@ -43,5 +51,8 @@ jobs: name: Install PlatformIO Core run: pip install --upgrade platformio - - name: Tests + name: Build example run: pio test -d examples/wiring-blink/ + - + name: Build Tests + run: pio test \ No newline at end of file From 99ac23cf335d4e752a27d3c958bc898ec760f600 Mon Sep 17 00:00:00 2001 From: Oleksandr Kolodkin Date: Wed, 30 Jul 2025 20:12:53 +0300 Subject: [PATCH 4/4] Update cmakelists --- external/fakeit/CMakeLists.txt | 18 +++++++++--------- external/unity/CMakeLists.txt | 19 +++++++++---------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/external/fakeit/CMakeLists.txt b/external/fakeit/CMakeLists.txt index ed87fcb..f0ce360 100644 --- a/external/fakeit/CMakeLists.txt +++ b/external/fakeit/CMakeLists.txt @@ -1,18 +1,18 @@ -cmake_minimum_required(VERSION 3.2.2) +cmake_minimum_required(VERSION 3.14) project(fakeit VERSION 2.4.0 LANGUAGES CXX) -include(git-download) +include(FetchContent) -set(REPO_DIR ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}-repo) - -download_repo( - URL "https://github.com/eranpeer/FakeIt.git" - TAG ${PROJECT_VERSION} - CLONE_DIR ${REPO_DIR} +FetchContent_Declare( + fakeit_repo + GIT_REPOSITORY https://github.com/eranpeer/FakeIt.git + GIT_TAG ${PROJECT_VERSION} ) +FetchContent_MakeAvailable(fakeit_repo) + add_library(${PROJECT_NAME} INTERFACE) target_include_directories(${PROJECT_NAME} INTERFACE - ${REPO_DIR}/single_header/standalone/ + ${fakeit_repo_SOURCE_DIR}/single_header/standalone/ ) diff --git a/external/unity/CMakeLists.txt b/external/unity/CMakeLists.txt index 9070698..84766cf 100644 --- a/external/unity/CMakeLists.txt +++ b/external/unity/CMakeLists.txt @@ -1,20 +1,19 @@ -cmake_minimum_required(VERSION 3.2.2) +cmake_minimum_required(VERSION 3.14) project(unity VERSION 2.4.1 LANGUAGES C) -include(git-download) +include(FetchContent) -set(REPO_DIR ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}-repo) - -download_repo( - URL "https://github.com/ThrowTheSwitch/Unity.git" - TAG v${PROJECT_VERSION} - CLONE_DIR ${REPO_DIR} +FetchContent_Declare( + unity_repo + GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git + GIT_TAG v${PROJECT_VERSION} ) +FetchContent_MakeAvailable(unity_repo) add_library(${PROJECT_NAME} STATIC - ${REPO_DIR}/src/unity.c + ${unity_repo_SOURCE_DIR}/src/unity.c ) target_include_directories(${PROJECT_NAME} PUBLIC - ${REPO_DIR}/src + ${unity_repo_SOURCE_DIR}/src )