Skip to content

Commit

Permalink
Added stub test framework
Browse files Browse the repository at this point in the history
  • Loading branch information
maniacbug committed Dec 16, 2011
1 parent 44e7980 commit fc43ebc
Show file tree
Hide file tree
Showing 8 changed files with 449 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/unit/Jamfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SubDir TOP ;

# Set up output directories
LOCATE_TARGET = $(SEARCH_SOURCE)/out/$(TOOLSET) ;
LOCATE_SOURCE = $(LOCATE_TARGET) ;

# Pull in local libraries
SKETCH_LIBS += RF24Network RF24 ;
HDRS += $(HOME)/Source/Arduino/libraries/$(SKETCH_LIBS) ;

# Main output executable
Maple $(SEARCH_SOURCE:B).elf : [ GLOB $(SEARCH_SOURCE) $(HOME)/Source/Arduino/libraries/$(SKETCH_LIBS) : $(MODULE_EXT) ] ;
237 changes: 237 additions & 0 deletions tests/unit/Jamrules
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
MCU = cortex-m3 ;
CHIP = STM32F103ZE ;
BOARD = maple_native ;

#CHIP = at91sam3u4 ;
#BOARD = sam3u-ek ;

if ! $(TOOLSET)
{
TOOLSET = mix ;
Echo "Assuming TOOLSET=mix" ;
}
else if $(TOOLSET) = cs
{
TOOLS_PATH = /opt/cs/arm/bin ;
TOOLS_ARCH = arm-none-eabi- ;
}
else if $(TOOLSET) = yagarto
{
TOOLS_PATH = ~/Source/yagarto-4.6.2/bin ;
TOOLS_ARCH = arm-none-eabi- ;
}
if $(TOOLSET) = yagarto-install
{
TOOLS_PATH = ~/Source/yagarto/install/bin ;
TOOLS_ARCH = arm-none-eabi- ;
}
else if $(TOOLSET) = devkit
{
TOOLS_PATH = /opt/devkitARM/bin ;
TOOLS_ARCH = arm-eabi- ;
}
else if $(TOOLSET) = maple
{
TOOLS_PATH = /opt/Maple/Resources/Java/hardware/tools/arm/bin ;
TOOLS_ARCH = arm-none-eabi- ;
LINK_DIR = /opt/Maple/Resources/Java/hardware/leaflabs/cores/maple ;
MAPLE_DIR = /opt/Maple/Resources/Java/hardware/leaflabs/cores/maple ;
MAPLE_SUBDIRS = . ;
}
else if $(TOOLSET) = mix
{
TOOLS_PATH = /opt/Maple/Resources/Java/hardware/tools/arm/bin ;
TOOLS_ARCH = arm-none-eabi- ;
LINKFLAGS += --print-gc-sections ;
}
else if $(TOOLSET) = ports
{
TOOLS_PATH = /opt/local/bin ;
TOOLS_ARCH = arm-none-eabi- ;
}

# Tool locations

CC = $(TOOLS_PATH)/$(TOOLS_ARCH)gcc ;
C++ = $(TOOLS_PATH)/$(TOOLS_ARCH)g++ ;
AS = $(TOOLS_PATH)/$(TOOLS_ARCH)gcc -c ;
LINK = $(TOOLS_PATH)/$(TOOLS_ARCH)g++ ;
OBJCOPY = $(TOOLS_PATH)/$(TOOLS_ARCH)objcopy ;
DFU = dfu-util ;

# Flags

DEFINES += VECT_TAB_FLASH BOARD_$(BOARD) MCU_$(CHIP) ERROR_LED_PORT=GPIOC ERROR_LED_PIN=15 STM32_HIGH_DENSITY MAPLE_IDE ;
OPTIM = -Os ;
MFLAGS = cpu=$(MCU) thumb arch=armv7-m ;
CCFLAGS = -Wall -m$(MFLAGS) -g -nostdlib -ffunction-sections -fdata-sections -Wl,--gc-sections ;
C++FLAGS = $(CCFLAGS) -fno-rtti -fno-exceptions ;
LINKFLAGS += -m$(MFLAGS) -Xlinker --gc-sections ;
DFUFLAGS = -a1 -d 0x1eaf:0x0003 -R ;

# Directories

MAPLE_DIR ?= /opt/libmaple ;
MAPLE_LIBS = Servo LiquidCrystal Wire FreeRTOS ;
MAPLE_SUBDIRS ?= libmaple libmaple/usb libmaple/usb/usb_lib wirish wirish/comm wirish/boards ;

SKETCH_DIR = $(HOME)/Source/Maple ;

CORE_DIRS = $(MAPLE_DIR)/$(MAPLE_SUBDIRS) $(MAPLE_DIR)/libraries/$(MAPLE_LIBS) ;
HDRS = $(CORE_DIRS) ;

# Modules
MODULE_EXT = *.c *.cpp *.S *.pde *.ino *.test ;
CORE_MODULES = [ GLOB $(CORE_DIRS) : $(MODULE_EXT) ] ;

# Unit test framework
CXXTEST_DIR = $(HOME)/Source/cxxtest ;
#CXXTEST_GEN = $(CXXTEST_DIR)/cxxtestgen.py ;
CXXTEST_GEN = $(CXXTEST_DIR)/python/scripts/cxxtestgen ;
HDRS += $(CXXTEST_DIR) ;

# Linker script
LINK_DIR ?= $(MAPLE_DIR)/support/ld ;
LINKSCRIPT = $(LINK_DIR)/$(BOARD)/flash.ld ;
LINKFLAGS += -T$(LINKSCRIPT) -L$(LINK_DIR) ;

rule Pde
{
Depends $(<) : $(>) ;
MakeLocate $(<) : $(LOCATE_SOURCE) ;
Clean clean : $(<) ;
}

if ( $(ARDUINO_VERSION) < 100 )
{
ARDUINO_H = WProgram.h ;
}
else
{
ARDUINO_H = Arduino.h ;
}

actions Pde
{
echo "#include <$(ARDUINO_H)>" > $(<)
echo "#line 1 \"$(>)\"" >> $(<)
cat $(>) >> $(<)
}

rule C++Pde
{
local _CPP = $(>:B).cpp ;
Pde $(_CPP) : $(>) ;
C++ $(<) : $(_CPP) ;
}

rule TestSuite
{
Depends $(<) : $(>) ;
MakeLocate $(<) : $(LOCATE_SOURCE) ;
Clean clean : $(<) ;
}

actions TestSuite
{
$(CXXTEST_GEN) --part $(>) > $(<)
}

rule TestRoot
{
MakeLocate $(<) : $(LOCATE_SOURCE) ;
}

actions TestRoot
{
$(CXXTEST_GEN) --root --error-printer > $(<)
}

rule C++TestSuite
{
local _CPP = $(>:B).cpp ;
TestSuite $(_CPP) : $(>) ;
C++ $(<) : $(_CPP) ;
}

rule Hex
{
Depends $(<) : $(>) ;
MakeLocate $(<) : $(LOCATE_TARGET) ;
Depends hex : $(<) ;
Clean clean : $(<) ;
}

actions Hex
{
$(OBJCOPY) -O ihex $(>) $(<)
}

rule Binary
{
Depends $(<) : $(>) ;
MakeLocate $(<) : $(LOCATE_TARGET) ;
Depends binary : $(<) ;
Clean clean : $(<) ;
}

actions Binary
{
$(OBJCOPY) -O binary $(>) $(<)
}

rule UserObject
{
switch $(>:S)
{
case .S : As $(<) : $(>) ;
case .ino : C++Pde $(<) : $(>) ;
case .pde : C++Pde $(<) : $(>) ;
case .test : C++TestSuite $(<) : $(>) ;
}
}

rule Upload
{
Depends up : $(<) ;
NotFile up ;
Always $(<) ;
Always up ;
}

actions Upload
{
$(DFU) $(DFUFLAGS) -D $(<)
}

# Override base objects rule, so all output can go in the output dir
rule Objects
{
local _i ;

for _i in [ FGristFiles $(<) ]
{
local _b = $(_i:B)$(SUFOBJ) ;
local _o = $(_b:G=$(SOURCE_GRIST:E)) ;
Object $(_o) : $(_i) ;
Depends obj : $(_o) ;
}
}

# Override base main rule, so all output can go in the output dir
rule Main
{
# Bring in the map
LINKFLAGS on $(<) = $(LINKFLAGS) -Wl,-Map=$(LOCATE_TARGET)/$(<:B).map ;

MakeLocate $(<) ;
MainFromObjects $(<) : $(>:B)$(SUFOBJ) ;
Objects $(>) ;
}

rule Maple
{
Main $(<) : $(>) $(CORE_MODULES) ;
Binary $(<:B).bin : $(<) ;
Upload $(<:B).bin ;
}
1 change: 1 addition & 0 deletions tests/unit/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
These unit tests only work on Maple.
19 changes: 19 additions & 0 deletions tests/unit/Template.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/

// STL headers
// C headers
// Framework headers
// Library headers
// Project headers
// This component's header
#include <Template.h>

/****************************************************************************/

// vim:cin:ai:sts=2 sw=2 ft=cpp
30 changes: 30 additions & 0 deletions tests/unit/Template.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/

#ifndef __TEMPLATE_H__
#define __TEMPLATE_H__

// STL headers
// C headers
// Framework headers
// Library headers
// Project headers

/**
* Example for how classes should be declared
*/

class Template
{
private:
protected:
public:
};

#endif // __TEMPLATE_H__
// vim:cin:ai:sts=2 sw=2 ft=cpp
42 changes: 42 additions & 0 deletions tests/unit/TemplateTest.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/

// STL headers
#include <vector>
#include <string>
#include <iostream>
// C headers
// Framework headers
// Library headers
#include <cxxtest/TestSuite.h>
// Project headers
// This component's header
#include <Template.h>

using namespace std;

class TemplateTestSuite: public CxxTest::TestSuite
{
Template* pTemplate ;
public:
void setUp()
{
pTemplate = new Template();
}

void tearDown()
{
delete pTemplate;
}

void testEmpty( void )
{
TS_ASSERT(pTemplate);
}
};
// vim:cin:ai:sts=2 sw=2 ft=cpp
Loading

0 comments on commit fc43ebc

Please sign in to comment.