Comments (3)
Hi @jerabaul29,
tldr;
I believe there are two issues at play.
Firstly, PlatformIO automatically includes the unity framework in the include path only when compiling the source files in the test directory. And the second is that unless you run have run the tests, you may not have the tool-unity
package installed.
The other thing I will note is that the core v2 behaves differently than expected because the unity test framework seems to already be included in its source files.
With both of these sorted, you can see it works fine for me:
To run the tests from vscode, in the PlatformIO Tab, under Project Tasks > Advanced select the Test option:
A cheeky work around is once you have the tool-unity
package installed you can add the following to your platformio.ini
file:
build_flags = -I/home/user/.platformio/packages/tool-unity
or for windows:
build_flags = -IC:/Users/user/.platformio/packages/tool-unity
Long Version
Here I demonstrate that an Apollo3 Core V1 project behaves the same as an Arduino Mega 2560 project with regards to the inclusion of the unity test framework.
Create a project:
$ mkdir test_project
$ cd test_project
$ pio init -b SparkFun_RedBoard_Artemis_ATP --ide vscode -O"[email protected]"
The current working directory /home/user/test_project will be used for the project.
The next files/directories have been created in /home/user/test_project
include - Put project header files here
lib - Put here project specific (private) libraries
src - Put project source files here
platformio.ini - Project Configuration File
Project has been successfully initialized including configuration files for `vscode` IDE.
Create a file in src/main.cpp
with the contents:
#include "Arduino.h"
#include <unity.h>
void setup()
{
Serial.begin(115200);
}
void loop()
{
Serial.println("Hello World!");
delay(1000);
}
Create a file in test/test_1.cpp
with the following contents:
#include "Arduino.h"
#include <unity.h>
void test_flash_init(void)
{
TEST_ASSERT_TRUE(true);
}
void setup()
{
Serial.begin(115200);
UNITY_BEGIN();
RUN_TEST(test_flash_init);
UNITY_END();
}
void loop()
{
}
Then compile:
$ pio run
Processing SparkFun_RedBoard_Artemis_ATP (platform: apollo3blue; board: SparkFun_RedBoard_Artemis_ATP; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/apollo3blue/SparkFun_RedBoard_Artemis_ATP.html
PLATFORM: Apollo 3 Blue (0.0.2) > SparkFun RedBoard Artemis ATP
HARDWARE: AMA3B1KK 48MHz, 384KB RAM, 960KB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES:
- framework-arduinoapollo3 1.2.3
- toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 9 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/src/main.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/FrameworkArduino/analog/ap3_analog.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/FrameworkArduino/analog/ap3_analog_structures.c.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/FrameworkArduino/ard_supers/IPAddress.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/FrameworkArduino/ard_supers/Print.cpp.o
src/main.cpp:2:10: fatal error: unity.h: No such file or directory
***************************************************************
* Looking for unity.h dependency? Check our library registry!
*
* CLI > platformio lib search "header:unity.h"
* Web > https://platformio.org/lib/search?query=header:unity.h
*
***************************************************************
2 | #include <unity.h>
| ^~~~~~~~~
compilation terminated.
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/FrameworkArduino/ard_supers/Stream.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/FrameworkArduino/ard_supers/WMath.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/FrameworkArduino/ard_supers/WString.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/FrameworkArduino/ard_supers/avr/dtostrf.c.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/FrameworkArduino/ard_supers/hooks.c.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/FrameworkArduino/ard_supers/itoa.c.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/FrameworkArduino/clock/ap3_clock_sources.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/FrameworkArduino/debugging/ap3_debugging.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/FrameworkArduino/gpio/ap3_gpio.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/FrameworkArduino/gpio/ap3_gpio_structures.c.o
*** [.pio/build/SparkFun_RedBoard_Artemis_ATP/src/main.cpp.o] Error 1
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/FrameworkArduino/gpio/ap3_shift.cpp.o
========================================================================== [FAILED] Took 0.89 seconds ==========================================================================
Which fails. However if you run the tests:
$ pio test
Verbose mode can be enabled via `-v, --verbose` option
Collected 1 items
Processing * in SparkFun_RedBoard_Artemis_ATP environment
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Building...
Uploading...
Warning! Your `/etc/udev/rules.d/99-platformio-udev.rules` are outdated. Please update or reinstall them.
More details: https://docs.platformio.org/page/faq.html#platformio-udev-rules
Testing...
If you don't see any output for the first 10 secs, please reset board (press reset button)
test/test_1.cpp:14:test_flash_init [PASSED]
-----------------------
1 Tests 0 Failures 0 Ignored
========================================================================== [PASSED] Took 3.07 seconds ==========================================================================
Test Environment Status Duration
------ ----------------------------- -------- ------------
* SparkFun_RedBoard_Artemis_ATP PASSED 00:00:03.070
========================================================================== 1 succeeded in 00:00:03.070 ==========================================================================
It compiles and runs fine.
Now if you try the same with another Arduino Board like the mega you get the same results:
$ pio init -b megaatmega2560 --ide vscode
.
.
.
$ pio run
Processing megaatmega2560 (platform: atmelavr; board: megaatmega2560; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/megaatmega2560.html
PLATFORM: Atmel AVR (3.3.0) > Arduino Mega or Mega 2560 ATmega2560 (Mega 2560)
HARDWARE: ATMEGA2560 16MHz, 8KB RAM, 248KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES:
- framework-arduino-avr 5.1.0
- toolchain-atmelavr 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio/build/megaatmega2560/src/main.cpp.o
Archiving .pio/build/megaatmega2560/libFrameworkArduinoVariant.a
Indexing .pio/build/megaatmega2560/libFrameworkArduinoVariant.a
src/main.cpp:2:10: fatal error: unity.h: No such file or directory
***************************************************************
* Looking for unity.h dependency? Check our library registry!
*
* CLI > platformio lib search "header:unity.h"
* Web > https://platformio.org/lib/search?query=header:unity.h
*
***************************************************************
Compiling .pio/build/megaatmega2560/FrameworkArduino/CDC.cpp.o
#include <unity.h>
^~~~~~~~~
compilation terminated.
Compiling .pio/build/megaatmega2560/FrameworkArduino/HardwareSerial.cpp.o
Compiling .pio/build/megaatmega2560/FrameworkArduino/HardwareSerial0.cpp.o
Compiling .pio/build/megaatmega2560/FrameworkArduino/HardwareSerial1.cpp.o
Compiling .pio/build/megaatmega2560/FrameworkArduino/HardwareSerial2.cpp.o
Compiling .pio/build/megaatmega2560/FrameworkArduino/HardwareSerial3.cpp.o
Compiling .pio/build/megaatmega2560/FrameworkArduino/IPAddress.cpp.o
Compiling .pio/build/megaatmega2560/FrameworkArduino/PluggableUSB.cpp.o
Compiling .pio/build/megaatmega2560/FrameworkArduino/Print.cpp.o
Compiling .pio/build/megaatmega2560/FrameworkArduino/Stream.cpp.o
Compiling .pio/build/megaatmega2560/FrameworkArduino/Tone.cpp.o
Compiling .pio/build/megaatmega2560/FrameworkArduino/USBCore.cpp.o
Compiling .pio/build/megaatmega2560/FrameworkArduino/WInterrupts.c.o
*** [.pio/build/megaatmega2560/src/main.cpp.o] Error 1
Compiling .pio/build/megaatmega2560/FrameworkArduino/WMath.cpp.o
====================================================================================== [FAILED] Took 0.44 seconds ======================================================================================
It also fails, however the tests run fine:
$ pio test
Verbose mode can be enabled via `-v, --verbose` option
Collected 1 items
Processing * in megaatmega2560 environment
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Building...
Uploading...
Warning! Your `/etc/udev/rules.d/99-platformio-udev.rules` are outdated. Please update or reinstall them.
More details: https://docs.platformio.org/page/faq.html#platformio-udev-rules
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.01s
avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: reading input file ".pio/build/megaatmega2560/firmware.hex"
avrdude: writing flash (3204 bytes):
Writing | ################################################## | 100% 0.53s
avrdude: 3204 bytes of flash written
avrdude: verifying flash memory against .pio/build/megaatmega2560/firmware.hex:
avrdude: load data flash data from input file .pio/build/megaatmega2560/firmware.hex:
avrdude: input file .pio/build/megaatmega2560/firmware.hex contains 3204 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 0.38s
avrdude: verifying ...
avrdude: 3204 bytes of flash verified
avrdude: safemode: Fuses OK (E:FD, H:D8, L:FF)
avrdude done. Thank you.
Testing...
If you don't see any output for the first 10 secs, please reset board (press reset button)
test/test_1.cpp:14:test_flash_init [PASSED]
-----------------------
1 Tests 0 Failures 0 Ignored
========================================================================== [PASSED] Took 3.46 seconds ==========================================================================
Test Environment Status Duration
------ -------------- -------- ------------
* megaatmega2560 PASSED 00:00:03.460
========================================================================== 1 succeeded in 00:00:03.460 ==========================================================================
The part where it gets confusing is if we change our Apollo3 example to use the Core_V2 framework by changing the platform package line from:
platform_packages = [email protected]
to:
platform_packages = [email protected]
And then clean and compile:
$ pio run -t clean
.
.
.
$ pio run
Processing SparkFun_RedBoard_Artemis_ATP (platform: apollo3blue; board: SparkFun_RedBoard_Artemis_ATP; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/apollo3blue/SparkFun_RedBoard_Artemis_ATP.html
PLATFORM: Apollo 3 Blue (0.0.2) > SparkFun RedBoard Artemis ATP
HARDWARE: AMA3B1KK 48MHz, 384KB RAM, 960KB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES:
- framework-arduinoapollo3 2.1.0
- toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 9 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/src/main.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/variant/config/pins.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/variant/variant.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/mbed_bridge/bridge/pins.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/mbed_bridge/core-api/api/Common.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/mbed_bridge/core-api/api/IPAddress.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/mbed_bridge/core-api/api/PluggableUSB.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/mbed_bridge/core-api/api/Print.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/mbed_bridge/core-api/api/Stream.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/mbed_bridge/core-api/api/String.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/mbed_bridge/core-implement/CommonAnalog.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/mbed_bridge/core-implement/CommonDigital.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/mbed_bridge/core-implement/CommonInit.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/mbed_bridge/core-implement/CommonInterrupt.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/mbed_bridge/core-implement/CommonMath.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/mbed_bridge/core-implement/CommonPulse.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/mbed_bridge/core-implement/CommonTiming.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/mbed_bridge/core-implement/HardwareSerial.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/mbed_bridge/core-implement/Yield.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/mbed_bridge/core-implement/itoa.c.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/mbed_bridge/main.cpp.o
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/core-implement/CommonAnalog.cpp.o
Archiving .pio/build/SparkFun_RedBoard_Artemis_ATP/libvariant.a
Compiling .pio/build/SparkFun_RedBoard_Artemis_ATP/core-implement/CommonPulse.cpp.o
Indexing .pio/build/SparkFun_RedBoard_Artemis_ATP/libvariant.a
Archiving .pio/build/SparkFun_RedBoard_Artemis_ATP/libmbed_bridge.a
Indexing .pio/build/SparkFun_RedBoard_Artemis_ATP/libmbed_bridge.a
Archiving .pio/build/SparkFun_RedBoard_Artemis_ATP/libcore-implement.a
Indexing .pio/build/SparkFun_RedBoard_Artemis_ATP/libcore-implement.a
Linking .pio/build/SparkFun_RedBoard_Artemis_ATP/program
Checking size .pio/build/SparkFun_RedBoard_Artemis_ATP/program
arm-none-eabi-objcopy -O binary .pio/build/SparkFun_RedBoard_Artemis_ATP/program .pio/build/SparkFun_RedBoard_Artemis_ATP/firmware.bin
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [= ] 7.5% (used 29384 bytes from 393216 bytes)
Flash: [= ] 12.0% (used 117540 bytes from 983040 bytes)
====================================================================================== [SUCCESS] Took 2.71 seconds ======================================================================================
The bloody thing compiles fine.
This is because it would appear that the core v2 framework has the unity file already in it:
$ cd ~/.platformio/packages/[email protected]/
$ find . | grep unity.h
./cores/mbed-os/features/frameworks/unity/unity/unity.h
./cores/mbed-os/features/frameworks/utest/source/unity_handler.cpp
./cores/mbed-os/features/frameworks/utest/utest/unity_handler.h
from platform-apollo3blue.
Many thanks for the in-depth debugging :) . Definitely something strange going on.
Interesting :) . Actually it looks like this has gotten solved "all by itself", I cannot see the squiggles any longer.
A few points regarding the error I had:
- I do not import unity in any file in my "src folder code", only in my "test folder code", so I think I am doing this correctly :) . The screenshot was maybe not so clear, but was I showed actually lived in the "test folder" (this is visible from the initial error message, that names that this lives in a sub folder of the test folder).
- I am able to compile both the "src code" and the "test folder", so this means that, when building stuff, all is fine, and the needed unity stuff is well present on my machine (confirmed by checking that
~/.platformio/packages/tool-unity
does exist and is well on my machine) - probably an additional confirmation that I am setting stuff right.
The strange thing is that, this morning, the squiggles are gone...
I wonder if unity was not installed by default by PlatformIO, and got installed only the first time I run the command, or if the autodetect of the packages was re-run when I re-opened PlatformIO this morning, or something like that... That could explain why I had squiggles initially, and now they are not here any longer.
Sorry for the noise, but definitely something a bit weird going on... May be well possible that this is only a "platformio warmup issue that requests to run tests once, and re load, to be enabled". Weird. Wonder if this is maybe a platformio-core issue then, in which case maybe we should report it? :) What do you think? :) .
from platform-apollo3blue.
Ok, I did some tests on another computer, and it does look like this is some "IntelliSense warmup issues". I think that there may be a need to run a test one and then restart platformio or something like this for getting all up and going. I think the confusion may come from these differences between core v1 and core v2, the warmup etc.
So after some warmup etc all seems to be fine... Thanks for the help and the discussion, sorry for the noise!
from platform-apollo3blue.
Related Issues (20)
- brainstorming: releasing as a "all-parts-included", "turn-key" container? HOT 6
- attempting to compile compiles but also tries to upload (and fails if no board available) HOT 3
- very different amounts of memory used by i) Arduino IDE 1.8 vs ii) this platformio core HOT 6
- caching of compilation? HOT 2
- brainstorming: how would you recommend to compile / "install" an external non arduino library HOT 5
- Inconsistent Boards Names
- The solution to the lack of ‘tool-jlink’ after the Manual installation of Sparkfun/Arduino_Apollo3 on MacOS 10.12.6. HOT 1
- Error building any application with artemis boards HOT 9
- Build with custom linker script fails when project directory has a space
- Libraries in lib/ are not included in build process HOT 2
- new warning: "No baud rate specified. Using default svl baud rate of 921600" HOT 4
- Cannot build for boards that are not in boards-sfe HOT 6
- Add ability to set swo clock in swo viewer HOT 3
- Some dependency issues with the libraries HOT 4
- bug: strange include failure for /lib code HOT 2
- Make BOARD_VARIANTS_DIR customizable HOT 2
- Build fails in PlatformIO HOT 5
- Missing headers for Edge & Edge 2 with Ambiq HOT 1
- How to set -Os instead of default -O0? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from platform-apollo3blue.