Unit testing impossible for frameworks including Unity themselves
See original GitHub issueWhat kind of issue is this?
- [X ] PlatformIO Core. If you’ve found a bug, please provide an information below.
You can erase any parts of this template not applicable to your Issue.
Configuration
Operating system: Windows 10 x64
PlatformIO Version (platformio --version
): version 5.2.0a6
Description of problem
The PlatformIO “test” procedure is such that PlatformIO adds its own Unity library to the build.
this however directly conflicts with any framework which already has Unity compiled into it. Such is the case with the https://github.com/arduino/ArduinoCore-mbed in which the precompiled mbed-os library (libmbed.a
) has the Unity object files.
Thus it is impossible to e.g. run unit tests with a board = nano33ble
framework = arduino
configuration without modifications.
Refer to the community topic here
Steps to Reproduce
- Create a new Arduino Nano 33 BLE project
- Add
test\main.cpp
from below - Run the “Test” project task
Actual Results
A bazillion linker errors due a conflict with .pio\build\nano33ble\libUnityTestLib.a
and .platformio\packages\framework-arduino-mbed\variants\ARDUINO_NANO33BLE\libs\libmbed.a
c:/users/max/.platformio/packages/toolchain-gccarmnoneeabi@1.80201.190214/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\Max\.platformio\packages\framework-arduino-mbed\variants\ARDUINO_NANO33BLE\libs\libmbed.a(unity.o): in function `UnityBegin':
unity.c:(.text.UnityBegin+0x0): multiple definition of `UnityBegin'; .pio\build\nano33ble\libUnityTestLib.a(unity.c.o):unity.c:(.text.UnityBegin+0x0): first defined here
c:/users/max/.platformio/packages/toolchain-gccarmnoneeabi@1.80201.190214/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\Max\.platformio\packages\framework-arduino-mbed\variants\ARDUINO_NANO33BLE\libs\libmbed.a(unity.o): in function `UnityEnd':
unity.c:(.text.UnityEnd+0x0): multiple definition of `UnityEnd'; .pio\build\nano33ble\libUnityTestLib.a(unity.c.o):unity.c:(.text.UnityEnd+0x0): first defined here
c:/users/max/.platformio/packages/toolchain-gccarmnoneeabi@1.80201.190214/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\Max\.platformio\packages\framework-arduino-mbed\variants\ARDUINO_NANO33BLE\libs\libmbed.a(unity.o):(.rodata.UnityStrErr64+0x0): multiple definition of `UnityStrErr64'; .pio\build\nano33ble\libUnityTestLib.a(unity.c.o):(.rodata.UnityStrErr64+0x0): first defined here
c:/users/max/.platformio/packages/toolchain-gccarmnoneeabi@1.80201.190214/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\Max\.platformio\packages\framework-arduino-mbed\variants\ARDUINO_NANO33BLE\libs\libmbed.a(unity.o):(.rodata.UnityStrErrDouble+0x0): multiple definition of `UnityStrErrDouble'; .pio\build\nano33ble\libUnityTestLib.a(unity.c.o):(.rodata.UnityStrErrDouble+0x0): first defined here
c:/users/max/.platformio/packages/toolchain-gccarmnoneeabi@1.80201.190214/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\Max\.platformio\packages\framework-arduino-mbed\variants\ARDUINO_NANO33BLE\libs\libmbed.a(unity.o):(.rodata.UnityStrErrFloat+0x0): multiple definition of `UnityStrErrFloat'; .pio\build\nano33ble\libUnityTestLib.a(unity.c.o):(.rodata.UnityStrErrFloat+0x0): first defined here
c:/users/max/.platformio/packages/toolchain-gccarmnoneeabi@1.80201.190214/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: size of symbol `Unity' changed from 132 in .pio\build\nano33ble\libUnityTestLib.a(unity.c.o) to 160 in C:\Users\Max\.platformio\packages\framework-arduino-mbed\variants\ARDUINO_NANO33BLE\libs\libmbed.a(unity.o)
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\nano33ble\firmware.elf] Error 1
Expected Results
Running unit tests is possible
If problems with PlatformIO Build System:
The content of platformio.ini
:
[env:nano33ble]
platform = nordicnrf52
board = nano33ble
framework = arduino
Source file to reproduce issue:
test\main.cpp
#include <Arduino.h>
#include <unity.h>
void simple_test(void) {
TEST_ASSERT_EQUAL(33, 33);
}
void setup() {
delay(2000);
UNITY_BEGIN();
RUN_TEST(simple_test);
UNITY_END();
}
void loop() {
delay(1000);
}
Additional info
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:15 (8 by maintainers)
Unable to reproduce.
Core: 6.1.5a4, Nordic nRF52: 9.4.0.
Grab the project file, unpack it, and run the same above as me in the CLI. Does it still show an error?
unity_tests.zip
Removing
.pio
folder seemed to do the trick. Thanks! It works in my project as well. I have the same content as mentioned in the documentation for bothplatformio.ini
andtest
folder. I use 2 libraries TFLite and TinyMLx for running ML models on Arduino.Is it possible to perform the unit testing for TFLite library using platformIO? A sample unit test can be found here or here for reference.
I wonder if GoogleTest Runner can be of help in this case.