-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create unit test framework by reusing embunit in RIOT submodule.
- Loading branch information
Showing
8 changed files
with
157 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <embUnit/embUnit.h> | ||
|
||
TestRef NanocoapTest_tests(void); | ||
|
||
int main (int argc, const char* argv[]) | ||
{ | ||
TestRunner_start(); | ||
TestRunner_runTest(NanocoapTest_tests()); | ||
TestRunner_end(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
CC = gcc | ||
CFLAGS = -O | ||
INCLUDES = -I.. -I../riot/sys/embunit -I../riot/sys/include | ||
LIBS = embunit | ||
RM = rm | ||
TARGET = tests | ||
NANO_DIR = ../nanocoap/bin | ||
NANO_OBJS = $(NANO_DIR)/nanocoap.o $(NANO_DIR)/handler.o | ||
OBJS = AllTests.o nanocoapTest.o | ||
RIOTBASE = $(CURDIR)/../riot | ||
|
||
all: $(TARGET) | ||
|
||
$(TARGET): nano_objs $(OBJS) | ||
$(CC) -o $@ $(OBJS) $(NANO_OBJS) -L$(LIBS) -lembUnit | ||
|
||
.c.o: | ||
$(CC) \ | ||
-DRIOT_FILE_RELATIVE=\"$(patsubst $(RIOTBASE)/%,%,$(abspath $<))\" \ | ||
$(CFLAGS) $(INCLUDES) -c $< | ||
|
||
nano_objs: | ||
-@cd ../nanocoap;$(MAKE) objs | ||
|
||
clean: | ||
-$(RM) -f $(TARGET) $(OBJS) | ||
|
||
.PHONY: clean all nano_objs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
all: | ||
$(MAKE) -f Makefile.embunit | ||
$(MAKE) -f Makefile.textui | ||
|
||
clean: | ||
$(MAKE) -f Makefile.embunit clean | ||
$(MAKE) -f Makefile.textui clean | ||
|
||
.PHONY: clean all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
CC = gcc | ||
CFLAGS = -O | ||
AR = ar | ||
ARFLAGS = ru | ||
RANLIB = ranlib | ||
RM = rm | ||
SRC = ../../riot/sys/embunit | ||
INCLUDES = -I../../riot/sys/embunit -I../../riot/sys/include/embUnit | ||
OUTPUT = ./ | ||
TARGET = libembUnit.a | ||
OBJS = AssertImpl.o RepeatedTest.o stdImpl.o TestCaller.o TestCase.o TestResult.o TestRunner.o TestSuite.o | ||
|
||
all: $(TARGET) | ||
|
||
$(TARGET): $(OBJS) | ||
$(AR) $(ARFLAGS) $(OUTPUT)$@ $(OBJS) | ||
$(RANLIB) $(OUTPUT)$@ | ||
|
||
%.o: $(SRC)/%.c | ||
$(CC) $(CFLAGS) $(INCLUDES) -c $< | ||
|
||
clean: | ||
-$(RM) $(OBJS) $(TARGET) | ||
|
||
.PHONY: clean all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
CC = gcc | ||
CFLAGS = -O | ||
INCLUDES = .. | ||
LIBS = ../lib | ||
AR = ar | ||
ARFLAGS = ru | ||
RANLIB = ranlib | ||
RM = rm | ||
SRC = ../../riot/sys/embunit | ||
INCLUDES = -I../../riot/sys/embunit -I../../riot/sys/include/embUnit -I../../riot/sys/include | ||
OUTPUT = ./ | ||
TARGET = libtextui.a | ||
OBJS = TextUIRunner.o XMLOutputter.o TextOutputter.o CompilerOutputter.o | ||
|
||
all: $(TARGET) | ||
|
||
$(TARGET): $(OBJS) | ||
$(AR) $(ARFLAGS) $(OUTPUT)$@ $(OBJS) | ||
$(RANLIB) $(OUTPUT)$@ | ||
|
||
%.o: $(SRC)/%.c | ||
$(CC) $(CFLAGS) -I$(INCLUDES) -c $< | ||
|
||
clean: | ||
-$(RM) $(TARGET) $(OBJS) | ||
|
||
.PHONY: clean all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <embUnit/embUnit.h> | ||
#include "nanocoap/nanocoap.h" | ||
|
||
/* | ||
* Parses a basic NON GET request for '/cli/stats'. Includes a 2-byte token. | ||
*/ | ||
static void testParseGetReq(void) | ||
{ | ||
coap_pkt_t pdu; | ||
|
||
uint8_t buf[] = { | ||
0x52, 0x01, 0xd3, 0x06, 0x35, 0x61, 0xb3, 0x63, | ||
0x6c, 0x69, 0x05, 0x73, 0x74, 0x61, 0x74, 0x73 | ||
}; | ||
|
||
int res = coap_parse(&pdu, &buf[0], sizeof(buf)); | ||
|
||
TEST_ASSERT_EQUAL_INT(0, res); | ||
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code(&pdu)); | ||
TEST_ASSERT_EQUAL_INT(2, coap_get_token_len(&pdu)); | ||
TEST_ASSERT_EQUAL_INT(4 + 2, coap_get_total_hdr_len(&pdu)); | ||
TEST_ASSERT_EQUAL_INT(COAP_TYPE_NON, coap_get_type(&pdu)); | ||
TEST_ASSERT_EQUAL_INT(0, pdu.payload_len); | ||
TEST_ASSERT_EQUAL_STRING("/cli/stats", (char *) &pdu.url[0]); | ||
} | ||
|
||
TestRef NanocoapTest_tests(void) | ||
{ | ||
EMB_UNIT_TESTFIXTURES(fixtures) { | ||
new_TestFixture(testParseGetReq), | ||
}; | ||
EMB_UNIT_TESTCALLER(NanocoapTest, NULL, NULL, fixtures); | ||
|
||
return (TestRef)&NanocoapTest; | ||
} |