Hi Mikhail,

On Wed, Dec 12, 2018 at 02:22:28PM +0000, Mikhail Efroimson wrote:
> I am writing my first MyNewt unit test package and I was hoping that
> someone could help me resolve an issue that I'm having. It seems that
> I have to include the project BSP as a dependency in my unit test
> package but when I do that and try to run it using newt test, the
> compiler complains that "Settings defined by multiple packages:
> MCU_FLASH_MIN_WRITE_SIZE" which is defined for under syscfg.defs of
> different MCU families in apache-mynewt-core/hw/mcu. How can I avoid
> this multiple definitions issue which only occurs when I try to run
> the unit tests?

The `newt test` command runs unit tests in the simulator.  To ensure
the simulator environment is available, newt automatically pulls in the
`hw/bsp/native` package and all its dependencies.

Only one BSP package is allowed per Mynewt build.  So, when building
something for the simulated environment, you must not include any
"real" BSP or MCU packages.  In other words, it is not possible to test
BSP or other "hardware" code in the simulator.

To test code meant for real hardware, you need to forego the simulator.
Instead, you create an app which runs the unit tests, and create a
target which ties that app to your BSP.  Unfortunately, it seems we
don't have any documentation on running unit tests on native hardware,
but a good way to get started is to take a look at the `apps/testbench`
app.  Specifically, you'll want to:

1. Create a new target for your unit test build (`newt target create`)
2. Set the target's app to `@apache-mynewt-core/apps/testbench` and
   the BSP to your BSP package.
3. Modify the testbench app to run your desired tests:
    a. Add dependencies to `pkg.yml` for your unit test packages.
    b. Modify `main.c`: Add an invocation of `TEST_SUITE_REGISTER()`
       for each unit test the app needs to run.

When the build is running on hardware, you can invoke tests using the
newtmgr tool, specifically the `run` command
(http://mynewt.apache.org/latest/newtmgr/command_list/newtmgr_run.html).
The test results get recorded to "testlog" log, also accessible via
newtmgr.

Chris

Reply via email to