Skip to content

Conversation

@kolod
Copy link
Contributor

@kolod kolod commented Jul 30, 2025

Pull Request: Fix PlatformIO Native Build and Improve Context Tests

Summary

This pull request addresses build issues with the PlatformIO native environment and improves the reliability and clarity of context reset tests in the ArduinoFake project.

Changes

  1. PlatformIO Build Fix

    • Updated [env:native] in platformio.ini to add -Wa,-mbig-obj to build_flags, resolving "too many sections" and "file too big" errors on Windows with large test binaries.
  2. Test Main Improvements

    • Added a tearDown() function stub to test/main.cpp for completeness.
    • Fixed the return value of main() to properly return the result of UNITY_END().
  3. Context Test Enhancements

    • In test/test_context.h, improved the test for context reset:
      • Explicitly broke pointers in ArduinoFakeInstances to ensure the reset is effective.
      • Added assertions to check that pointers are null after manual breakage and before reset.
      • Added a comment explaining why pointer comparison is not a reliable way to check for new instance creation, referencing allocator behavior and object identity.

Example (from context test)

// 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_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 reliable because memory allocators can reuse the same address for new objects after deletion.
// To properly verify a new instance, you should check object identity or state, not just pointer values.

Note:
Previous CI testing on Ubuntu did not reveal the problem in test_context, as the issue with pointer reuse and large object files is specific to the Windows toolchain and memory allocator behavior. The new changes ensure the tests are robust and portable across both Ubuntu and Windows environments.

@kolod
Copy link
Contributor Author

kolod commented Jul 30, 2025

I’ve decided to close it for now, as I need more time to better understand the build process and CI configuration with GitHub Actions. I’ll revisit and update this contribution once I have a clearer understanding. Thanks for your feedback and patience!

@kolod kolod closed this Jul 30, 2025
@FabioBatSilva
Copy link
Owner

No worries, Let me know if i can help.

It hasn't been updated in a while I appreciate the support .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants