BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Utilities: Unit Test

The <bsp430/utility/unittest.h> header provides a simple way to provide unit tests on MSP430. The core functionality provides a standard header emitted to the console, execution of code interspersed with validation of expected results, and a standard footer. External scripts can be used to automate the test infrastructure. In addition to text output, pass and fail states are demonstrated using LEDs.

Output from the following example is:

# sync...
# sync...
# sync...
# sync...
# sync...
FAIL [29]: unconditional
pass [31]: 1 == 1
pass [32]: 1 != 2
pass [33]: NOT 1 != 1
pass [34]: NOT 1 == 2
FAIL [37]: 1==rv: 1 != 42
# FAIL 2 pass 4
# ...done
# ...done
# ...done
# ...done
# ...done

When compiled using:

make PLATFORM=exp430f5438 realclean EXT_CPPFLAGS=-DAPP_ONLY_PASSING install

the output is:

# sync...
# sync...
# sync...
# sync...
# sync...
pass [31]: 1 == 1
pass [32]: 1 != 2
pass [33]: NOT 1 != 1
pass [34]: NOT 1 == 2
# PASSED 4
# ...done
# ...done
# ...done
# ...done
# ...done

main.c

#include <bsp430/clock.h>
#ifndef APP_ONLY_PASSING
#define APP_ONLY_PASSING 0
#endif /* APP_ONLY_PASSING */
void main ()
{
int rv;
(void)rv;
#if ! APP_ONLY_PASSING
BSP430_UNITTEST_FAIL("unconditional");
#endif /* APP_ONLY_PASSING */
#if ! APP_ONLY_PASSING
rv = 42;
#endif /* APP_ONLY_PASSING */
}

bsp430_config.h

/* Use a crystal if one is installed. Much more accurate timing
* results. */
#define BSP430_PLATFORM_BOOT_CONFIGURE_LFXT1 1
/* Application does output: support spin-for-jumper */
#define configBSP430_PLATFORM_SPIN_FOR_JUMPER 1
/* Support console output */
#define configBSP430_CONSOLE 1
/* Monitor uptime and provide generic ACLK-driven timer */
#define configBSP430_UPTIME 1
/* Support the unit-test framework */
#define configBSP430_UNITTEST 1
/* Get platform defaults */

Makefile

PLATFORM ?= exp430fr5739
MODULES=$(MODULES_PLATFORM)
MODULES += $(MODULES_UPTIME)
MODULES += $(MODULES_CONSOLE)
MODULES += utility/unittest
SRC=main.c
include $(BSP430_ROOT)/make/Makefile.common