How to run a Unit-Test for ESP32 without flashing it? - c++

Knowing from other languages and platforms we want to use Unit-Testing during the Build-Process BEFORE the code is flashed to the hardware. This should be possible for simple functions tests which have no need for the ESP32 hardware.
But as we understand yet the C++ code is compiled (and linked) for the ESP32 chip and shall not run on the developing system or in a CI/CD pipeline.
Is there any way to emulate ESP32 (for C++) or run Unit-Tests on any other way on another systems?
note: We are using 'platformio' for the build.

It is possible to do this with the qemu_esp32 emulator. You can compile your test runner and run it directly on the emulator instead of flashing it to a real esp32 chip.
Here is an example of how to do this (adapted from esp32_qemu_unity_test_action):
Compile the test runner like you normally would. Before you proceed you might want to actually flash this just to know your test runner and tests are working.
idf.py build
cd build
Normally when you flash a esp32, you're writing several binary files to specific locations. This command merges all those into a single full binary image.
esptool.py --chip esp32 merge_bin --fill-flash-size 4MB -o flash_image.bin #flash_args
Run the esp32 emulator and provide the full binary flash image.
/opt/qemu/bin/qemu-system-xtensa -nographic -no-reboot -machine esp32 -drive file=flash_image.bin,if=mtd,format=raw -serial file:output.log
By specifying -no-reboot, the emulator will simply exit instead of rebooting.

Related

Run application without GUI on iOS?

I have a C++ library that I want to include into my iOS application. It has unit tests. If I put it simply, it's something like:
#include <cstdio>
int main()
{
printf("Test result\n");
}
Is it possible to run such an application that uses only stdin/stdout on an arm64 based iOS device to make sure that all compiles and works correctly?
I can do it on a real android device with adb push/adb shell, so I wonder, is it possible to do the same on iOS based devices?
It's not completely clear what are you trying to archive. But let me guess:
There is a third-party library you don't have control over.
There're tests in this library. The tests are a separate console app.
And you're looking for a way to run this app in some kind of shell on iOS that can run an arbitrary executables. And you can't because of all the security.
But if you have the source code of unit tests, then with some small changes you can compile them as a library, not as an executable. And call them from a "shell" you can write yourself - a small host app the sole purpose of which is to call these tests (and probably send their results via any kind of connection that suits you).
More on this you can read here
Yes, this host app will have a GUI, but I don't really understand why do you against it... if you really are.
Also these may be helpfull:
debug bridge for iPhone / shell command prompt
ADB equivalent for iOS device

How to combine multiple sensors into one project with separate drivers?

I am creating an application that requires a Ximea camera and a sensor which is connected to a driver. Both are C++ compatible. The problem is that the Ximea camera only builds in x86 on Visual Studio and the sensor builds on x64. I would like to run both from the same project, and I believe that I need to use MSBuild or some sort of Batch Build to configure both so that they can both run at the same time. I essentially want to take images from the camera to steer the sensor, so they both need to be running at the same time.
Here is a link to the API I am using for the camera.
(This is my first time working heavily in C++ so any advice/references/resources would be great!)
I would like to run both from the same project, and I believe that I
need to use MSBuild or some sort of Batch Build to configure both so
that they can both run at the same time.
Run and build means different things, you can use msbuild or batch scripts to build Ximea camera project in X86 and the sensor project in X64 when you build the whole solution.
In VS you can right-click Solution in Solution Explorer=>Configuration Manager to control this behavior. See:
Then when you choose Solution Platform x86, it actually builds the project A and B in X64, and C in X86. This is what msbuild can do for you. But I can't make sure if there will be compatibility issue when you run it.

Need ideas for automating on-chip testing on Cortex-M4 using gdb and semihosting

I'm working on safety-critical software that requires extensive testing. The target processor, a Cortex-M4, has rich resources for the application but the unit and integration tests, if aggregated, would be much larger than the on-board FLASH/RAM. They are designed to be run from gdb while using semi-hosting to off-load the test results. What's needed is a way to automate the testing so it can be run without per-test human intervention.
The test programs run fine from Eclipse using both OpenOCD and Segger debugger front-ends. These require per-test configurations and then manual starting of the tests. There will be 30-50 test programs so this isn't really viable for continuous integration or simple batch runs.
I've been looking around for possible ways to do this. There are a few tricky bits to consider. The first is supporting the semihosting of the output. That uses the breakpoint system to have the I/O from the host. In this use, a couple of files get opened on the host computer for logs. Another issue is ending the program being tested and loading the next. The programs can take a long time to run and drop into an infinite loop when the main() is exited. And the development platform is Windows 10.
The two basic ideas I've had are to use the gdb client library from cygwin to create a custom program or to use OpenOCD. Running through multiple tests could be done inside the application or from a Makefile.
Question: is the semihosting done in the gdb client or server?
So... Looking for some suggestions or experiences in creating what I picture as a custom gdb client in Win10.

How to run C++ test on visual studio online

I have test cases that are executable (*.exe files). There is no user interface involved.
How do I use Team center /visual studio online to run these test cases on server.
For now, either on demand running or scheduled running will work for me.
(Currently I have no test case that runs on server. So you may mention the basic setup. )
I have written some test cases (they are exe files). I can run them locally line any other exe file.
My code is in C++.
My test cases are in C++.
You could run them as part of your build. Just configure a build in VSO for your solution, and then modify the msbuild project file to call your tests and send the output to the build folder so it gets uploaded as part of the drop. If you are using VS, you would get a better experience using the VS unit testing support (i.e., get results in VS): http://www.visualstudio.com/get-started/run-tests-with-builds-vs.

OCUnit: How to run tests without launching iPhone simulator?

I'm following iOS Development Guide: Unit Testing Applications. However, when I attempt to build (Command+B) the LogicTests target (step 8 of "Setting Up Logic Testing"), I get the error: "The selected run destination is not valid for this action."
Since I added my application target to LogicTests's target dependencies, I'm able to run the unit tests with Command+U, but this also launches the iPhone Simulator.
To save time & resources, is it possible to run the OCUnit tests (both logic & application tests) without launching the iPhone Simulator?
I understand the annoyance of the simulator popping up in unit tests. The best remedy I've been able to find is to do Command + U, followed by Command + H when launching unit tests. (Control + H hides the simulator after it appears.) Since it appears nearly instantaneously, this can be an effective way of getting it out of your range of vision.
I've managed to run my unit tests which test my model classes without the simulator being launched as follows:
I didn't set any bundle loader or test host build settings, instead I just added the .m files I was unit testing to the Build Phases Compile Sources.
I then ran the unit tests from the command line using:
xcodebuild -verbose -target TheElementsUnitTests -configuration Debug -sdk iphonesimulator5.0 clean build
Not really sure why this didn't launch the simulator, but it definitely didn't!
Here's a small AppleScript that I set to run for Generates output in Testing behaviour configuration:
#!/usr/bin/osascript
activate application "Xcode"
It brings Xcode back immediately after pressing command + U.
P.S. I also opened a bug and Apple marked it as a duplicate. So, they're aware.
How much time/resources? Rather than focusing on reducing those, I'd focus on expanding your tests to go far beyond Apple's original "Logic Test" guidelines. Those guidelines were limiting, and written before Xcode 4. Now you can write tests without thinking, "Is this a logic test or an application test?" -- just test everything.