-
-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit testing impossible for frameworks including Unity themselves #3980
Comments
Hi @maxgerhardt ! Thanks for reporting. Indeed, the reasons for this behavior are obvious, but I'm not sure how we can solve this problem in a reasonable way. We cannot simply omit our |
There might be special cases where e.g the pre-compiled Unity version is "functionally correct" and would not differ from what PlatformIO would use. Or when there are frameworks which won't remove their internal Unity version. It would make sense to add a fallback option to the In the Arduino-mbed case (and probably for The ArduinoCore-mbed people will surely see a problem with removing Unity since then no Arduino IDE user can use Unity (if they did). They might resolve that though be refactoring Unity into a library and compile it from source. That would be a good alternative. |
Thanks for the report! See docs https://docs.platformio.org/en/latest/advanced/unit-testing/frameworks/custom/examples/custom_unity_library.html |
Custom unity framework not working with mbedOSI need help with running unit tests on platformio with mbedOS framework, I am using the custom unity test framework. Below is the platformio.ini config file While running the pio test Collected 1 tests (test_blink) ============================================================ An unexpected error occurred. Further steps:
============================================================ @valeros @ivankravets @maxgerhardt please help me out. |
@pratiksurgeonslab98, thanks, we fixed the development version of PlatformIO Core. Could you re-test with |
@ivankravets Thanks for the prompt response. This is the present output: roy@roy-XPS-15-9510:~/SG_Firmware_Gen_I/master/SG_Firmware_Gen_I/Blink_LED$ pio test Processing test_blink in nucleo_f411re environmentBuilding & Uploading... srst_only separate srst_nogate srst_open_drain connect_deassert_srst target halted due to debug-request, current mode: Thread None of test case results are printed. |
Did you press the reset button on the board? What's the exact project? |
@maxgerhardt yes, i pressed the reset button but still it didn't show any test result. void setUp(void) void tearDown(void) void simple_test(void) int main(int argc, char **argv) Nothing was printed |
Do regular |
Yes regular printf() works on fine on firmware. I am running on Nucleo f411re board After opening the serial terminal on putty to read stlink serial data, the test is running. The results are displayed, it is coming in a jumbled way like this. To replicate the steps,
On platform io terminal, this is the output I am getting: Please specify ============================================ SUMMARY ============================================ nucleo_f411re test_blink ERRORED 00:00:05.658 I am also attaching my project file in zipped format for further inspection.
Thank You. |
I followed the exact steps listed in Custom Unity Library — PlatformIO and tests don't pass on Arduino Nano 33 BLE board. PlatformIO version: 6.1.5a4 Project structure and content is same for all files as the documentation. The following error comes from running *********************************************************************************************************************************************************************************************************************************************************************************
If you like PlatformIO, please:
- follow us on Twitter to stay up-to-date on the latest project news > https://twitter.com/PlatformIO_Org
- star it on GitHub > https://github.com/platformio/platformio
- try PlatformIO IDE for embedded development > https://platformio.org/platformio-ide
*********************************************************************************************************************************************************************************************************************************************************************************
Verbosity level can be increased via `-v, -vv, or -vvv` option
Collected 1 tests
Platform Manager: Installing nordicnrf52
Downloading [####################################] 100%
Unpacking [####################################] 100%
Platform Manager: [email protected] has been installed!
Processing test_blink in nano33ble environment
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Building & Uploading...
Tool Manager: Installing platformio/toolchain-gccarmnoneeabi @ ~1.80201.0
Downloading [####################################] 100%
Unpacking [####################################] 100%
Tool Manager: [email protected] has been installed!
Tool Manager: Installing platformio/framework-arduino-mbed @ ~3.1.1
Downloading [####################################] 100%
Unpacking [####################################] 100%
Tool Manager: [email protected] has been installed!
Tool Manager: Installing platformio/tool-sreccat @ ~1.164.0
Downloading [####################################] 100%
Unpacking [####################################] 100%
Tool Manager: [email protected] has been installed!
Tool Manager: Installing platformio/tool-openocd @ ~2.1100.0
Downloading [####################################] 100%
Unpacking [####################################] 100%
Tool Manager: [email protected] has been installed!
Tool Manager: Installing platformio/tool-bossac-nordicnrf52 @ ~1.10901.0
Downloading [####################################] 100%
Unpacking [####################################] 100%
Tool Manager: [email protected] has been installed!
Tool Manager: Installing platformio/tool-scons @ ~4.40400.0
Downloading [####################################] 100%
Unpacking [####################################] 100%
Tool Manager: [email protected] has been installed!
unity.c:(.text.UnityDefaultTestRun+0x0): multiple definition of `UnityDefaultTestRun'; .pio/build/nano33ble/lib0fc/libUnity.a(unity.c.o):unity.c:(.text.UnityDefaultTestRun+0x0): first defined here
/home/dudeperf3ct/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: /home/dudeperf3ct/.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/lib0fc/libUnity.a(unity.c.o):unity.c:(.text.UnityBegin+0x0): first defined here
/home/dudeperf3ct/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: /home/dudeperf3ct/.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/lib0fc/libUnity.a(unity.c.o):unity.c:(.text.UnityEnd+0x0): first defined here
/home/dudeperf3ct/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: /home/dudeperf3ct/.platformio/packages/framework-arduino-mbed/variants/ARDUINO_NANO33BLE/libs/libmbed.a(unity.o):(.rodata.UnityStrErr64+0x0): multiple definition of `UnityStrErr64'; .pio/build/nano33ble/lib0fc/libUnity.a(unity.c.o):(.rodata.UnityStrErr64+0x0): first defined here
/home/dudeperf3ct/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: /home/dudeperf3ct/.platformio/packages/framework-arduino-mbed/variants/ARDUINO_NANO33BLE/libs/libmbed.a(unity.o):(.rodata.UnityStrErrDouble+0x0): multiple definition of `UnityStrErrDouble'; .pio/build/nano33ble/lib0fc/libUnity.a(unity.c.o):(.rodata.UnityStrErrDouble+0x0): first defined here
/home/dudeperf3ct/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: /home/dudeperf3ct/.platformio/packages/framework-arduino-mbed/variants/ARDUINO_NANO33BLE/libs/libmbed.a(unity.o):(.rodata.UnityStrErrFloat+0x0): multiple definition of `UnityStrErrFloat'; .pio/build/nano33ble/lib0fc/libUnity.a(unity.c.o):(.rodata.UnityStrErrFloat+0x0): first defined here
/home/dudeperf3ct/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: warning: size of symbol `Unity' changed from 132 in .pio/build/nano33ble/lib0fc/libUnity.a(unity.c.o) to 160 in /home/dudeperf3ct/.platformio/packages/framework-arduino-mbed/variants/ARDUINO_NANO33BLE/libs/libmbed.a(unity.o)
collect2: error: ld returned 1 exit status
*** [.pio/build/nano33ble/firmware.elf] Error 1
Uploading stage has failed, see errors above. Use `pio test -vvv` option to enable verbose output.
--------------------------------------------------------------------------------------------------------------- nano33ble:test_blink [ERRORED] Took 1.29 seconds ---------------------------------------------------------------------------------------------------------------
==================================================================================================================================== SUMMARY ====================================================================================================================================
Environment Test Status Duration
------------- ---------- -------- ------------
nano33ble test_blink ERRORED 00:00:01.285
=================================================================================================================== 1 test cases: 0 succeeded in 00:00:01.285 ===================================================================================================================
|
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? |
I was able to run the test using unity_tests.zip. Is it possible to perform the tests for TFLite library using platformIO? A sample test can be found here. |
Then something is wrong in your project. Adding the TFLite library also shouldn't magically pull Unity in. The error message is showing a conflict from the compiled libraries ( Do you have |
Removing 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. |
Hm. I am trying running unity as a custom task, however, the tests never "end", in that the results are never returned even through I am running the tests on a RasperryPi Pico W. Thing is that it works on all other platforms, Native, pure arduino, ESP-IDF, and so on. Config: |
Tried with the Earle Philhower core as well, alas, no luck, no unity-output. |
This issue is getting kind of flooded with different problems that may or not be related to the original problem. For the Pico, if you use the default USB serial, you might be running into the problem that PlatformIO choses the wrong serial port because the Pico has not yet initialized, like #3742. I'll test if I can reproduce this. |
A few observations: Using test code of #include <Arduino.h>
#include <unity.h>
void setUp(void) { }
void tearDown(void) { }
int addition_function_under_test(int a, int b)
{
return a + b;
}
void test_calculator_addition(void) {
TEST_ASSERT_EQUAL(32, addition_function_under_test(25, 7));
}
void setup() {
// wait until serial port has connected
while(!Serial) {}
Serial.println("UNIT TEST START!!");
UNITY_BEGIN();
RUN_TEST(test_calculator_addition);
UNITY_END();
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
} and opening a CLI with This leads to the conclusion that the Unity version included in ArduinoCore-mbed for the Pico is not outputting its content to the USB serial port at least, maybe the hardware UART, or not all. Not tested with Arduino-Pico yet, but in general that should be less of a headache since it shouldn't include Unity. |
Solved for ArduinoCore-mbed: Their Unity version is working once you add a magic declaration that stdio output is supposed to go to See arduino/ArduinoCore-mbed#174 So, using #include <Arduino.h>
#include <unity.h>
REDIRECT_STDOUT_TO(Serial); at the top of the test file makes it work with ArduinoCore-mbed. |
And as expected, Arduino-Pico (Earlephilhower) put up no fight at all, working instantly. I've created a project that is compatible to be tested with both cores, just using a https://github.com/maxgerhardt/pio-pico-unity-testing
|
WRT:
...I got a declared out of scope for REDIRECT_STDOUT_TO(Serial).
Thanks!! |
I sure would like this to work as " EASY as its says it is" _ am stuck and I am certain it is NOT becuase I do not want to learn this waste of time programming crap . I am not wasting my remaining time or life doing this dum shit. Especially when it is not me . this stupid vs code is what is so dysfunctional and insecure, and got all kinds of glitchs and malfunctions . thats why it never works the same was no matter how many times i open it. its always some different crap . also now why do i have to download this same crap 20 X per day ????? just make it so I can compile my firmware for my 3D printer without all the mental gymnaswtics would you please???_ |
I am afraid we can't. Feeling your pain, though, I would recommend you to share this rant with the manufacturer of your 3D-printer instead of posting it here. It should not be that complicated. |
I am still having the exact same issue as the OP for Arduino Nano 33 BLE. |
What kind of issue is this?
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.
platformio-core/platformio/builder/tools/piomisc.py
Lines 353 to 361 in 834c7b0
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
test\main.cpp
from belowActual 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
Expected Results
Running unit tests is possible
If problems with PlatformIO Build System:
The content of
platformio.ini
:Source file to reproduce issue:
test\main.cpp
Additional info
The text was updated successfully, but these errors were encountered: