Compile error during unittest with mbed on native platform

Hi,

I’d like to run unit tests using the mbed stub library under UNITTESTS/stubs.

However, when I add the core directory I get the following error:

*** Multiple ways to build the same target were specified for: C:\WorkDir\UniversalPlatform\WaterSense.pio\build\desktop\lib8c9\stubs\randLIB_stub.o (from [‘C:\users\andi\.platformio\packages\framework-mbed\UNITTESTS\stubs\randLIB_stub.c’] and from [‘C:\users\andi\.platformio\packages\framework-mbed\UNITTESTS\stubs\randLIB_stub.cpp’])
File “C:\users\andi.platformio\penv\lib\site-packages\platformio\builder\tools\platformio.py”, line 351, in BuildLibrary

My platformio.ini config:
[env:desktop]
platform = native
build_flags=
-std=c++11
lib_compat_mode = off
build_unflags = -fno-rtti
test_ignore = test_embedded
lib_extra_dirs =
$PROJECT_CORE_DIR/packages/framework-mbed/UNITTESTS

The only thing I figured is that when I leave lib_copat_mode to strict or soft, the library won’t be included.

Any help appreciated.

Thanks,
Andy

Welp, the build system is right…

There are both randLIB_stub.cpp and randLIB_stub.c which in the build process would become the randLIB_stub.o object file so there’s a name conflict there. It’s extremely bad that mbed-os names these file the same.

Looking at the content of these files, they also seem really non-sensical

void randLIB_seed_random(void)
{
}

uint16_t randLIB_get_random_in_range(uint16_t min, uint16_t max)
{
    return min;
}

random number generated for testing always returns the minimum range. Alrighty, what could possibly go wrong when testing like this…

@valeros can maybe have a look at this?

As a workaround one might be able to delete the e.g. cpp file and put those two functions in the test files so that the symbols still remain there.

Hey maxgerhardt,

thank you for your detailed reply. Makes sense now. I missed the part with the endings (.c and .cpp)because I didn’t look close enough or was too tired yesterday night. I’ll have a look and try to find a workaround.

I choose not to meddle with the mbed framework and build my application/OS on top of the rtos/ features with pio. Only for unit testing I’d be great to use the stubs. I used to use the mbed way of unit testing but want to streamline the process as the mbed way is kind of tedious.

In addition, I want to have both, unit testing and integration testing in pio since I really like the integration testing with real objects and not mocks/stubs etc.

I’m going to reply later on after I tried some things.

Best
Andy