Skip to content

Commit dc94c34

Browse files
committed
Start adding unit tests
1 parent 4a886f9 commit dc94c34

File tree

6 files changed

+394
-5
lines changed

6 files changed

+394
-5
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "unit_test/unity"]
2+
path = unit_test/unity
3+
url = https://github.com/ThrowTheSwitch/Unity

app_timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ app_timer_error_e app_timer_init(app_timer_hw_model_t *model)
559559

560560
if (NULL == model)
561561
{
562-
return APP_TIMER_INVALID_PARAM;
562+
return APP_TIMER_NULL_PARAM;
563563
}
564564

565565
if ((0u == model->max_count) ||

app_timer_api.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,11 @@ typedef void (*app_timer_handler_t)(void *);
148148
*/
149149
typedef enum
150150
{
151-
APP_TIMER_OK,
152-
APP_TIMER_INVALID_PARAM,
153-
APP_TIMER_INVALID_STATE,
154-
APP_TIMER_ERROR
151+
APP_TIMER_OK, ///< Operation successful
152+
APP_TIMER_NULL_PARAM, ///< NULL pointer passed as parameter
153+
APP_TIMER_INVALID_PARAM, ///< Invalid data passed as parameter
154+
APP_TIMER_INVALID_STATE, ///< Operation not allowed in current state (has app_timer_init been called?)
155+
APP_TIMER_ERROR ///< Unspecified internal error
155156
} app_timer_error_e;
156157

157158

unit_test/Makefile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
OUTPUT_DIR := build
2+
OBJ_DIR := $(OUTPUT_DIR)/obj
3+
4+
ifeq ($(OS),Windows_NT)
5+
# Windows-specific vars; if you did a custom install of MinGW, or if you are using some
6+
# other compiler, then you might need to change some of these values
7+
#BIN_DIR := C:/MinGW/bin
8+
BIN_DIR := C:/msys64/mingw64/bin
9+
GCC := $(BIN_DIR)/gcc
10+
LD := $(BIN_DIR)/ld
11+
MKDIR := mkdir -p
12+
RMDIR := rm -rf
13+
else
14+
ifeq ($(shell uname -s),Linux)
15+
# Linux-specific vars
16+
GCC := gcc
17+
LD := ld
18+
MKDIR := mkdir -p
19+
RMDIR := rm -rf
20+
endif
21+
endif
22+
23+
OUTPUT_DIR := build
24+
TEST_PROG := $(OUTPUT_DIR)/test_app_timer
25+
26+
SRC_FILES := ../app_timer.c test_app_timer.c unity/src/unity.c
27+
INCLUDES := -Iunity/src -I../
28+
29+
.PHONY: clean test
30+
31+
default: test
32+
33+
all: clean test
34+
35+
test: $(TEST_PROG)
36+
37+
$(TEST_PROG): $(OUTPUT_DIR)
38+
$(GCC) $(SRC_FILES) $(INCLUDES) -o $(TEST_PROG)
39+
./$(TEST_PROG)
40+
41+
$(OUTPUT_DIR):
42+
$(MKDIR) $(OUTPUT_DIR)
43+
44+
clean:
45+
@$(RMDIR) $(OUTPUT_DIR)
46+
@echo "Outputs removed"

0 commit comments

Comments
 (0)