Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

unit.faq

Klemens David Morgenstern edited this page Apr 4, 2018 · 1 revision

Is this library only for gcc?

No, this library itself works with all compilers, which follow the language standards (C89, C++11). But, the debugger-runner is currently only available for gdb. What that means is, that the in-depth analysis and output of the values tested are only available when the program can be run through the gdb. We do however have plans to extend that, the next addition would be the lldb.

Why does the critical check not cancel the execution?

Given a test like this

void test_case()
{
   METAL_CRITICAL(METAL_ASSERT(false));
   METAL_LOG("Should not be executed");
}

the second line will be executed if not in hosted mode. The reason is, that the execution control will be done by the debugger. There is no implementation of that in the code; even though it would be possible (e.g. with exceptions) it would amount to a lot of code, which is just not necessary with the debugger. In order to take that into account, you will have to cancel manually, possible with return.

void test_case()
{
   METAL_CRITICAL(METAL_ASSERT(false));
   if (METAL_ERROR())
	   return;
   METAL_LOG("Should not be executed");
}

This will then yield the similar behaviour in hosted as in standalone mode. Please keep in mind, that the standalone mode is not meant as the usual use-case, but as a solution for time-critical builds.

Can I use it for a release build?

The test+library can be used without the debugger altogether, which means that the METAL_REPORT will indicate the success. Additionally a form of hybrid is possible if the test implementation is differnet. That is METAL_NO_IMPLEMENT_INCLUDE must be defined and and a source file including metal/unit.ipp must be added. Then only the function which is used by the breakpoint will have debug symbols.

Can I get the coverage from the test execution?

Yes, this is possible with gcov. GCov requires you to compile and link with the --coverage flag set. Gcov will then attempt to use the syscalls to write files, which of course will do nothing in a bare-metal environment. If you are using the newlib in your project, we provide code, so those calls can be redirected through the runner.

Can I record the coverage seperately for each case?

Theoretically it is possible to call __gcov_flush anywhere in the program so the whole data gets dumped. But to make that work, you would also need to move the files with the generated test data. We will research this, and hopefully provide a solution, which will then be provided as a seperate plugin.