pointer length conflict in Unity tests with native_sim

Hello,

In my efforts to upgrade my project from NCS 2.3.0 (with Zephyr 3.2.99) to NCS 2.6.1 (with Zephyr 3.5.99), I'm running into various build issues with Unity unit tests.

I'm running the unit tests with the native_sim board. I'm running this in a WSL environment on a Windows 10 machine.

One thing I'm running into is a width mismatch in TEST_ASSERT_EQUAL() macros on struct device pointers (or probably any pointers), e.g.:

struct device const * const my_pointer = some_value;

TEST_ASSERT_EQUAL(DEVICE_DT_GET(DT_NODELABEL(some_node)), my_pointer);

I get a "cast from pointer to integer of different size" build error, on both of the values being tested against each other.
This is because TEST_ASSERT_EQUAL() casts both values to UNITY_INT.
And, I've ascertained that UNITY_INT in my environment resolves to 64 bits, while the pointers are 32 bits.

How do I resolve this?

Thanks!

Parents Reply Children
  • A clarification: The definition/assignment of my_pointer is inside one of my test functions. In other words, it's kind of like:

    void test_my_feature(void) {

    struct device const * const my_pointer = function_that_I_want_to_test(some_value);

    TEST_ASSERT_EQUAL(DEVICE_DT_GET(DT_NODELABEL(some_node)), my_pointer);

    }

    So, the static keyword is not of use here.

    But I did try changing the line to your suggestion, for the fun of it. It still gave the "cast from pointer to integer of different size" error (not surprisingly, I think - it doesn't address the width difference), and furthermore, gave "initializer element is not constant" due to the static.

    Also for the fun of it, I tried changing to:

    struct device const * my_pointer = function_that_I_want_to_test(some_value);

    (i.e., dropped the second "const" - i.e., just a pointer to a const, not a const pointer to a const). Still got "cast from pointer to integer of different size".

Related