Running native test using Ardunio code

Hi all,
please forgive me if I chose the wrong forum section or if the answer is obvious! I did spent quite a while researching, that is why I asking here now.

So I am working on a project using the Teesy 4.1 and the corresponding audio shild. I am trying to run a test natively on my desktop machine. It is supposed to unit test some code that has very little interaction with the board (no i/o etc.) but does some number crunching and transforming instead. Never the less it includes <Ardunio.h>. I have tried using the following code in my platformio.ini:

platform = native
board = teensy41
framework = arduino

This results in the error: Error: Unknown board ID 'teensy41' when run using pio test -e native_test_env.

So I am wondering, how can I run a test that include Ardunio (Teensy) code natively on my desktop machine?

All of these three things are contradictory. If you are running natively, your “board” is your local computer, most likely an x86 machine. There doesn’t exist a functional Arduino framework for a regular computer (because it would also make no sense). However there are mocking Arduino libraries which are meant exactly for unit testing – ArduinoFake. This works as demonstrated in the official platformio-examples/unit-testing/arduino-mock at develop · platformio/platformio-examples · GitHub example. This will give you an environment in which you have Arduino.h (and e.g., basic String classes etc.) available, and you will have to setup yourself what the Arduino API functions (like pinMode(), digitalRead()) will be returning. That’s what mocking is all abot.

You will however need to change the environment in your platformio.ini to

1 Like

Thank you very much for the quick answer! I was hoping there would be a way to test my code without having a board connected! But as soon as I sent my question (like you do) I realized that I am using platform specific functions like arm_rfft_fast_f32, so I guess I have to run the tests on the board anyway in order for them to be meaningful…

But thanks a lot for your explanation, it did help me understand the context a bit better :slight_smile:

You can always go the emulator route of using Renode. Compile your unit-test firmware for a supported ARM board (if all it matters that it’s ARM Cortex-M7, e.g., an STM32F7), throw it into Renode, get the results. Easy.