Skip to content

Adds native unit test support, initial test coverage of Utils and Identity#1065

Open
aqua wants to merge 30 commits intomeshcore-dev:devfrom
aqua:testing
Open

Adds native unit test support, initial test coverage of Utils and Identity#1065
aqua wants to merge 30 commits intomeshcore-dev:devfrom
aqua:testing

Conversation

@aqua
Copy link
Copy Markdown

@aqua aqua commented Nov 5, 2025

This is an expanded form of PR #925 to address issue #1059 . They overlap but are easily reconciled -- either could be merged and the other updated to adjust for it. This fixes native compilation of almost the entire MC firmware, adds address sanitization, and adds slightly more test coverage. #925 has a couple extra tests I didn't think of, a couple more mocks we might want to merge in for convenient use, and adds a github workflow to run the tests (which is a good idea if maintainers are willing to accept that into the merge workflow -- I'd have done it but held off for feedback.)

Devin Carraway added 22 commits November 3, 2025 00:30
Libraries vary on whether they accept a no-argument println(),
but they all accept a single string value.
There aren't any standard mocks for these and our code
invokes the adafruit LittleFS library and RTC library
calls which assume they exist.
Doesn't really add any value over `pio test -e native` but stays
consistent with the current build procedure and any -D defines that
may become mandatory later.
Uses the native platform, which compiles with the host system's
compilers.  This was tested on MacOS' GNU c++.

Use the skaygin/ArduinoNative libdep for the Arduino platform
library dependencies; it's the most complete native mock
currently available in PlatformIO and covers almost everything
we use.

Reuses the preexisting stm32 clone of Adafruit's LittleFS for our
filesystem dependency, which seemed to be the easiest path
(though it's also the most demanding of the SPI interface.) Uses
private mocks of SPI and Wire.

The initial two sets of unit tests are fairly trivial, covering
our SHA256 library and mesh::Utils::toHex(), just to show that
everything's working.
Found the first bug, in fromHex() :)
- printHex (demonstrates a mock/spy stream)
- 2-part sha256
It's fast enough (and the current set of tests is small enough) to turn
on for the main native env, but not all local compilers will support it
so I made it a separate target.

Usage: pio test -e native-asan

Current tests all pass asan checks.
@446564
Copy link
Copy Markdown
Contributor

446564 commented Apr 24, 2026

@aqua sorry can you check these conflicts as well?

@aqua
Copy link
Copy Markdown
Author

aqua commented Apr 25, 2026

@446564 Done. Not having gotten any response on the PR I haven't been trying to chase upstream.

@446564
Copy link
Copy Markdown
Contributor

446564 commented Apr 27, 2026

Thanks, reviews should start flowing for the next few months.

@446564
Copy link
Copy Markdown
Contributor

446564 commented Apr 27, 2026

Which environment should these pass in?

I tried with native and RAK_4631_repeater and both fail. Just pio test -e native -v for example.

Devin Carraway added 4 commits April 28, 2026 21:44
- NATIVE_PLATFORM needs the same filesystem open() args as STM32 and
  NRF52
- Not all Stream implementations have a printf() (fix is simpler anyway)
SensorManager as a virtual interface is fine for testing, but
CayenneLPP makes assumptions about Arduino which aren't valid
for ArduinoNative and sets up clashes between ArduinoNative
and the native C++ libraries (in particular, ArduinoNative
wants to #define round, which appears as a symbol in some
STL implementations which CayenneLPP will try to fall back
on.)

Since we're not exercising SensorManager in tests yet, the
short-term workaround is to hide the header and forward-declare
the class.  If we do get to the point of exercising it for
testing, the right fix would probably be to send a PR against
ArduinoNative to remove that #define as the mainline Arduino
libraries did a few years ago.
@aqua
Copy link
Copy Markdown
Author

aqua commented Apr 28, 2026

@446564 pio test -e native is usually the easy way. We picked up some test breakers in the last six months. Commits above fix the ones that surface for me (where "native" means MacOS clang).

@446564
Copy link
Copy Markdown
Contributor

446564 commented Apr 28, 2026

@446564 pio test -e native is usually the easy way. We picked up some test breakers in the last six months. Commits above fix the ones that surface for me (where "native" means MacOS clang).

tests are still failing with your most recent commit.

@aqua
Copy link
Copy Markdown
Author

aqua commented Apr 28, 2026

Can you paste your build/test output somewhere (pio test -e native -vvv -- verbosity not normally needed but helpful if we're chasing a compiler-specific issue), and the platform/environment you're testing on?

(I might not respond for a couple days, going to be busy for a bit)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants