How to use arguments and return codes#
Arguments and return codes are not really useful in a true embedded application, since a user is not present to provide them or react to them. However, they are particularly useful during unit and regression testing, as they allow tests to be configured and pass/fail results returned simply.
Note
The facility to use arguments and return codes is only available for a single tile application; an application with a main() function written in the C language.
It makes no sense for a multi-tile application (with an XC main() function) to use arguments and return codes, because there is no mechanism to define which is the ‘master’ tile, nor define how it should distribute the arguments and collate the return code. Therefore this tutorial is suited only to single tile testing.
To add command line arguments, create a main() function with the usual prototype:
#include <stdio.h>
int main(int argc, char* argv[])
{
for (int x = 0; x < argc; x++)
printf("Arg %d %s\n", x, argv[x]);
return argc;
}
Build with a non-zero value for xcc -fcmdline-buffer-bytes
:
$ xcc main.c -target=XCORE-200-EXPLORER -fcmdline-buffer-bytes=1024
Note
If you forget to the -fcmdline-buffer-bytes parameter, then a buffer of size zero will be allocated, and argc will always hold a value of zero. No error or warning will be raised. So don’t forget!
Run with using xrun --args
, and examine the return code:
$ xrun --io --args a.xe giraffe elephant
Arg 0 a.xe
Arg 1 giraffe
Arg 2 elephant
$ echo $?
3
Similar behaviour can be found using xsim --args
and
xgdb --args
.