Skip to content

Commit

Permalink
Adding in Unity unit testing to Makefile and c files that implements …
Browse files Browse the repository at this point in the history
…tests (#69)
  • Loading branch information
nwdepatie committed Oct 15, 2023
1 parent 8200948 commit 4b315ed
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c
ASM_SOURCES = \
startup_stm32f405xx.s

# Test source files
TEST_SOURCE_FILES = \
Test/unity/tests/cerberus_test.c \
Test/unity/tests/can_handler_test.c
# Unity source files and includes
UNITY_DIR = Test/unity/src
UNITY_SOURCES = $(UNITY_DIR)/unity.c

#######################################
# binaries
Expand Down Expand Up @@ -151,6 +158,19 @@ C_INCLUDES = \
-IDrivers/CMSIS/Device/ST/STM32F4xx/Include \
-IDrivers/CMSIS/Include

# test includes
UNITY_INCLUDES = \
-I$(UNITY_DIR) \
-ITest/unity/tests \
-ICore/Src \
-ICore/Inc \
-IDrivers/Embedded-Base/platforms/stm32f405/include \
-IDrivers/Embedded-Base/general/include \
-IDrivers/Embedded-Base/middleware/include \
-IMiddlewares/Third_Party/FreeRTOS/Source/include \
-IMiddlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 \
-IMiddlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F

# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections

Expand Down Expand Up @@ -209,6 +229,15 @@ $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(BUILD_DIR):
mkdir $@

#######################################
# run unit tests
#######################################
test: $(BUILD_DIR)/test_$(TARGET)
./$(BUILD_DIR)/test_$(TARGET)
$(BUILD_DIR)/test_$(TARGET): $(TEST_SOURCE_FILES) $(UNITY_SOURCES) | $(BUILD_DIR)
gcc -D UNIT_TEST $(UNITY_INCLUDES) -o $@ $^
#######################################

#######################################
# clean up
#######################################
Expand Down
6 changes: 6 additions & 0 deletions Test/unity/tests/can_handler_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "unity.h"

void test_can_handler(void)
{
//TEST_ASSERT_NOT_NULL(getFunction(0x2010));
}
16 changes: 16 additions & 0 deletions Test/unity/tests/cerberus_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "unity.h"
#include "cerberus_test.h"

void setUp(void) {
// set stuff up here
}

void tearDown(void) {
// clean stuff up here
}

int main(void) {
UNITY_BEGIN();
RUN_TEST(test_can_handler);
return UNITY_END();
}
17 changes: 17 additions & 0 deletions Test/unity/tests/cerberus_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef CERBERUS_TEST_H
#define CERBERUS_TEST_H

/*
* ************** NOTE **************
* These test files are specifically
* for unit tests, developers can
* make sure that specific functions
* and APIs meet requirements set out.
* This should NOT be used for actually
* simulating drivers and hardware,
* that is what we are using Renode for
*/

void test_can_handler(void);

#endif // CERBERUS_TEST_H

0 comments on commit 4b315ed

Please sign in to comment.