serial.introduction
metal.serial
is an ultra light-weight unit-testing library for gcc, to be used with a serial port or any interface the provides a byte stream. It's purpose is to allow fast and simple unit-testing on embedded systems that do not provide debugger access.
- two test levels (assertion/expecation)
- log messages
- test cases
- human-readable-format or json output
- success indication through the exit-code
- C and C++ implementation
Here's a simple example of a test with metal.serial
:
#include <metal/serial.hpp>
#include <cstdio>
int main(int argc, char *argv[])
{
int i = 41;
i++;
METAL_SERIAL_INIT();
METAL_SERIAL_ASSERT_EQUAL(i, 42);
METAL_SERIAL_TEST_EXIT(); //report the result
return 0;
}
void write_metal_serial(char c) {std::putchar(c); }//implementation of the byte stream
Using the metal.serial
we execute the file (test
) and pipe the output into metal.serial
to validate them.
test | metal.serial test
This will generate a detailed report and cause metal.serial
to yield the exit_code expected from test
. It is of course much more likely that data will be received from a serial port (or any other interface) which can be achieved by reading directly from the hardware:
metal.serial test.elf < /dev/ttyUSB0
This works by outputting the location in the binary, using addr2line
to find the code-location and parse the line from the code.
- Overview
- Runner Introduction
- Runner Invocation
- Runner Plugins
- Runner Extender
- Runner FAQ
- Runner Reference
- Unit Introduction
- Unit Tutorial
- Unit FAQ
- Unit Reference
- Calltrace Introduction
- Calltrace Tutorial
- Calltrace FAQ
- Calltrace Plugin
- Calltrace Reference
- Serial Introduction
- Serial Tutorial
- Serial Invocation
- Serial Reference