Skip to content

Letting Arduino/arduino-cli compile unittests #147

Open
@matthijskooijman

Description

@matthijskooijman

While thinking about #146 (compiler flags), I realized that the regular Arduino builds potentially use different flags for C and C++ files. Then there is #113 (compile object files separately), which would require complicating the build process further. Then I realized that some libraries are intended to be compiled with "dot_a_linkage", which we might be able to ignore since it is rarely used, but still.

Anyway, the bottom line is that for compiling unittests, you would ideally mimic the regular Arduino build process as close as possible. Then I realized: Maybe Arduino can actually just do the build, using regular gcc, producing a binary? This could be done by making an Arduino Platform/core that just contains the mocked code, and then each unittest would just be a separate sketch.

Looking around to see if there is any existing such core, I found only ncore which has not been updated since 2012 and is still written for Arduino 1.0, so probably not a good starting point.

With this approach, the current arduino_ci code could be split: One part would be an Arduino core, along with a unit-test library, that could be installed as a normal Arduino core and also used from the Arduino IDE directly (where maybe "upload" would just run the generated program, showing output in the IDE console). Then the second part would be the sketch-compile-test and unit-test-compile-and-run driver, that uses Arduino to do the grunt work.

A related observation is that using the Java IDE to compile things, as is done now, is a bit heavy. A good alternative would be to use arduino-cli, maybe you already saw that? It's a somewhat recently introduce commandline tool that can do pretty much everything the IDE can (building sketches, instaling libraries, cores, getting info about all kinds of things), but with a proper CLI interface. I think it's currently used as the backend for the new (alpha) Arduino Pro IDE, and is intended to become the backend for the Java IDE as well at some point.

All this would be quite an invasive change, that puts arduino_ci pretty much upside down, but at first glance it does look like an interesting direction...

Metadata

Metadata

Assignees

No one assigned

    Labels

    arduino mocksCompilation mocks for the Arduino libraryenhancementNew feature or requestsome OSesOnly affects some OSes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions