mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-12-09 13:15:15 -05:00
Kernel timers.c tasks.c Unit Test (#539)
* Test: add multi config ability to build system * Remove Tests that are not implemented yet from the makefile * Fix header check * Test: Unit Test tasks.c * UnitTest: tasks.c Save progress * saving some work 70% coverage * coverage 77% * tasks.c coverage 90% * tasks.c coverage 95% * Cleanup and common header * Cover some extra branches, no_mutex +stack growth * Fix Makefile not to use modified version of c-preprocessor * Remove c-preprocessor errros * Rebase and add some tests * Fortify_source=1 and O0 are mutually exclusive * Style: Uncrustify code * Style: Fix indent * Fix Header checks * Add prototypes * Build: use unifdef instead of the c-preprocessor to generate different configurations * Build: fix makefile cflags * Fix UT after upgrading kernel version * Resolve conflicts and test failures * Comment fix version number * Fix build error * Update FreeRTOS/Test/CMock/Makefile Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>
This commit is contained in:
parent
c00078e729
commit
1ac492d6aa
30 changed files with 9949 additions and 398 deletions
|
|
@ -3,74 +3,188 @@
|
|||
# and the project name should be queue
|
||||
# if testing list.c your directory should be called list
|
||||
# and the project name should be list
|
||||
|
||||
include ../makefile.in
|
||||
|
||||
.PRECIOUS:
|
||||
|
||||
PROJECT := timers
|
||||
#
|
||||
# Test/CMock/tasks
|
||||
PROJECT_DIR := $(abspath .)
|
||||
PROJ_DIR := $(abspath .)
|
||||
|
||||
# List the dependency files you wish to mock
|
||||
MOCK_FILES_FP := $(KERNEL_DIR)/include/task.h
|
||||
MOCK_FILES_FP += $(KERNEL_DIR)/include/queue.h
|
||||
MOCK_FILES_FP += $(KERNEL_DIR)/include/list.h
|
||||
MOCK_FILES_FP += $(UT_ROOT_DIR)/config/fake_assert.h
|
||||
MOCK_FILES_FP := $(KERNEL_DIR)/include/task.h
|
||||
MOCK_FILES_FP += $(KERNEL_DIR)/include/queue.h
|
||||
MOCK_FILES_FP += $(KERNEL_DIR)/include/list.h
|
||||
MOCK_FILES_FP += $(KERNEL_DIR)/include/portable.h
|
||||
MOCK_FILES_FP += $(PROJECT_DIR)/list_macros.h
|
||||
MOCK_FILES_FP += $(UT_ROOT_DIR)/config/fake_assert.h
|
||||
|
||||
# List the options the compilation would need
|
||||
CPPFLAGS += -DconfigSUPPORT_DYNAMIC_ALLOCATION=1
|
||||
CPPFLAGS += -DconfigSUPPORT_STATIC_ALLOCATION=1
|
||||
UNDEF_MOCKED_HEADER_MACROS := -UlistLIST_IS_EMPTY -UlistGET_OWNER_OF_HEAD_ENTRY\
|
||||
-UlistIS_CONTAINED_WITHIN -UlistGET_LIST_ITEM_VALUE \
|
||||
-UlistSET_LIST_ITEM_VALUE \
|
||||
-UlistLIST_ITEM_CONTAINER -UlistCURRENT_LIST_LENGTH
|
||||
|
||||
# List special compilation flags for this module
|
||||
CFLAGS += -Wno-unused-function
|
||||
|
||||
# List special preprocessing flags for this module
|
||||
CPPFLAGS +=
|
||||
|
||||
# List special linking flags for this module
|
||||
LDFLAGS +=
|
||||
|
||||
# Makefile Debug Flags (if needed)
|
||||
#MAKEFLAGS += -rR
|
||||
|
||||
# Try not to edit beyond this line
|
||||
MOCK_FILES := $(notdir $(MOCK_FILES_FP))
|
||||
MOCK_OBJ := $(addprefix mock_,$(MOCK_FILES:.h=.o))
|
||||
MOCK_SRC := $(addprefix mock_,$(MOCK_FILES:.h=.c))
|
||||
EXEC := $(PROJECT)_utest
|
||||
PROJECT_DIR := $(abspath .)
|
||||
|
||||
COVERAGE_OPTS := -fprofile-arcs -ftest-coverage -fprofile-generate
|
||||
|
||||
# build/generated/queue
|
||||
SCRATCH_DIR := $(GENERATED_DIR)/$(PROJECT)
|
||||
PROJ_LIB_DIR := $(SCRATCH_DIR)/lib
|
||||
MOCK_OBJ_LIST := $(addprefix $(PROJ_LIB_DIR)/,$(MOCK_OBJ))
|
||||
MOCKS_DIR := $(SCRATCH_DIR)/mocks
|
||||
MOCK_SRC_LIST := $(addprefix $(MOCKS_DIR)/,$(MOCK_SRC))
|
||||
CFLAGS += -I$(MOCKS_DIR)
|
||||
COVERAGE_OPTS := -fprofile-arcs -ftest-coverage -fprofile-generate
|
||||
|
||||
# list.h timers.h portable.h
|
||||
MOCK_FILES := $(notdir $(MOCK_FILES_FP))
|
||||
|
||||
# ...tasks/%/mocks/mock_list.o tasks/%/mocks/mock_timers.o
|
||||
MOCK_OBJS := $(addprefix $(SCRATCH_DIR)/%/mocks/mock_,$(MOCK_FILES:.h=.o))
|
||||
|
||||
# ...tasks/%/mocks/mock_list.c tasks/%/mocks/mock_timers.c
|
||||
MOCK_SRC_LIST := $(addprefix $(SCRATCH_DIR)/%/mocks/,$(addprefix mock_,$(MOCK_FILES:.h=.c)))
|
||||
|
||||
# tasks/%/cpp/timers.h tasks/%/cpp/list.h
|
||||
CPP_FILES := $(addprefix $(SCRATCH_DIR)/%/cpp/,$(notdir $(MOCK_FILES_FP)))
|
||||
DEP_FILES := $(addsuffix .d,$(addprefix $(SCRATCH_DIR)/%/cpp/,$(notdir $(MOCK_FILES_FP))))
|
||||
|
||||
# tasks_1_utest.c tasks_2_utest.c ...
|
||||
PROJ_SRC_LIST := $(sort $(wildcard $(PROJECT)_*_utest.c))
|
||||
|
||||
# 1_utest.c dynamic_utest.c
|
||||
SUITE_UT_SRC := $(subst $(PROJECT)_,,$(PROJ_SRC_LIST))
|
||||
|
||||
# timers_1_utest.c -> 1 timers_dynamic_utest -> dynamic config1 assert ...
|
||||
DISCRIMINATOR := $(subst _utest,,$(subst .c,,$(subst $(PROJECT)_,,$(PROJ_SRC_LIST))))
|
||||
|
||||
# tasks/1/mocks tasks/2/mocks
|
||||
MOCK_DIRS := $(addsuffix /mocks,$(addprefix $(SCRATCH_DIR)/,$(DISCRIMINATOR)))
|
||||
# queue/1/cpp queue/2/cpp
|
||||
CPP_DIRS := $(addsuffix /cpp,$(addprefix $(SCRATCH_DIR)/,$(DISCRIMINATOR)))
|
||||
# tasks/1/include tasks/2/include
|
||||
INCLUDE_DIRS := $(addsuffix /include,$(addprefix $(SCRATCH_DIR)/,$(DISCRIMINATOR)))
|
||||
#list/1 list/2 ....
|
||||
CONFIG_DIRS := $(addprefix $(SCRATCH_DIR)/,$(DISCRIMINATOR))
|
||||
|
||||
ifeq ($(MOCK_FILES_FP),)
|
||||
$(shell mkdir -p $(MOCKS_DIR))
|
||||
$(shell touch -a $(MOCKS_DIR)/mock_dummy.c)
|
||||
$(shell mkdir -p $(MOCK_DIRS))
|
||||
$(shell for n in $(MOCK_DIRS) ; do touch -a $(n)/mock_dummy.c)
|
||||
endif
|
||||
|
||||
$(MOCKS_DIR)/mock_%.c : Makefile $(PROJECT_DIR)/$(PROJECT).yml | directories
|
||||
cd $(SCRATCH_DIR) && \
|
||||
ruby $(CMOCK_EXEC_DIR)/cmock.rb -o$(PROJECT_DIR)/$(PROJECT).yml \
|
||||
$(MOCK_FILES_FP)
|
||||
EXEC_LIST := $(addprefix $(BIN_DIR)/,$(patsubst %.c,%,$(PROJ_SRC_LIST)))
|
||||
EXEC_PATH := $(addsuffix _%_utest,$(addprefix $(BIN_DIR)/,$(PROJECT)))
|
||||
PROJ_OBJ_LIST := $(EXEC_LIST)
|
||||
|
||||
$(PROJ_LIB_DIR)/mock_%.o : $(MOCKS_DIR)/mock_%.c
|
||||
$(CC) -c $< -fPIC $(CFLAGS) -o $@
|
||||
.PHONY: all Makefile directories
|
||||
|
||||
$(BIN_DIR)/$(EXEC) : $(SCRATCH_DIR)/test_runner.o \
|
||||
$(SCRATCH_DIR)/$(PROJECT).o \
|
||||
$(SCRATCH_DIR)/$(PROJECT)_utest.o \
|
||||
$(MOCK_OBJ_LIST)
|
||||
$(CC) $+ $(LDFLAGS) -o $@
|
||||
.SECONDARY:
|
||||
all : directories $(EXEC_LIST)
|
||||
|
||||
$(SCRATCH_DIR)/test_runner.o : $(SCRATCH_DIR)/test_runner.c \
|
||||
$(SCRATCH_DIR)/$(PROJECT).o
|
||||
$(CC) -c $< $(CPPFLAGS) $(CFLAGS) -o $@
|
||||
# Build the executables 1 per configuration
|
||||
$(EXEC_PATH) : $(MOCK_OBJS) \
|
||||
$(SCRATCH_DIR)/%/test_runner.o \
|
||||
$(SCRATCH_DIR)/%/$(PROJECT).o \
|
||||
$(SCRATCH_DIR)/%/$(PROJECT)_utest.o \
|
||||
| libs directories
|
||||
$(CC) $+ $(LDFLAGS) -o $@
|
||||
|
||||
$(SCRATCH_DIR)/$(PROJECT)_utest.o : $(PROJECT_DIR)/$(PROJECT)_utest.c \
|
||||
$(MOCKS_DIR)/mock_*.c \
|
||||
| directories
|
||||
$(CC) -c $< $(CPPFLAGS) $(CFLAGS) -o $@
|
||||
# Mock All preprocessed header files
|
||||
$(MOCK_SRC_LIST) : $(CPP_FILES) \
|
||||
Makefile \
|
||||
$(PROJECT_DIR)/$(PROJECT).yml \
|
||||
| directories
|
||||
cd $(@D) && cd .. && \
|
||||
ruby $(CMOCK_EXEC_DIR)/cmock.rb -o$(PROJECT_DIR)/$(PROJECT).yml \
|
||||
$(<D)/*
|
||||
|
||||
$(SCRATCH_DIR)/$(PROJECT).o : $(KERNEL_DIR)/$(PROJECT).c
|
||||
$(CC) -c $< $(CPPFLAGS) $(CFLAGS) $(COVERAGE_OPTS) -o $@
|
||||
# Copy FreeRTOSConfig_$(DISCRIMINATOR).h to the apropriate directory and remove
|
||||
# its guard ( FREERTOS_CONFIG_H ) to be able to be ingested into unifdef
|
||||
$(CPP_FILES) : | directories
|
||||
cp $(PROJECT_DIR)/FreeRTOSConfig_$*.h $(SCRATCH_DIR)/$*/include/FreeRTOSConfig.h
|
||||
cp $(PROJECT_DIR)/FreeRTOSConfig_$*.h $(SCRATCH_DIR)/$*/include/FreeRTOSConfig.def
|
||||
sed -i '/#ifndef FREERTOS_CONFIG_H/d' $(SCRATCH_DIR)/$*/include/FreeRTOSConfig.def
|
||||
sed -i '/#define FREERTOS_CONFIG_H/d' $(SCRATCH_DIR)/$*/include/FreeRTOSConfig.def
|
||||
sed -i '/#endif/d' $(SCRATCH_DIR)/$*/include/FreeRTOSConfig.def
|
||||
for h_file in $(MOCK_FILES_FP) ; do \
|
||||
unifdef -f $(SCRATCH_DIR)/$*/include/FreeRTOSConfig.def $$h_file \
|
||||
> $(SCRATCH_DIR)/$*/cpp/$$(basename $$h_file) ; \
|
||||
done
|
||||
|
||||
$(SCRATCH_DIR)/test_runner.c : $(SCRATCH_DIR)/$(PROJECT)_utest.o \
|
||||
Makefile | directories
|
||||
ruby $(UNITY_BIN_DIR)/generate_test_runner.rb $(EXEC).c \
|
||||
$(PROJECT_DIR)/$(PROJECT).yml $@
|
||||
# Build ALL the mock objects for the config
|
||||
# This target is called ONLY once per configuration pattern (%)
|
||||
$(MOCK_OBJS) : $(MOCK_SRC_LIST)
|
||||
$(eval INCLUDE = -I$(SCRATCH_DIR)/$*/include)
|
||||
$(eval INCLUDE += -I$(SCRATCH_DIR)/$*/mocks) \
|
||||
$(eval INCLUDE += -I$(KERNEL_DIR)/include) \
|
||||
for files in $^ ; do \
|
||||
new_name=$${files%.c}.o; \
|
||||
$(CC) -c $$files $(INCLUDE) $(CPPFLAGS) $(CFLAGS) -fPIC \
|
||||
-DUNITY_EXCLUDE_MATH_H -DUNITY_EXCLUDE_STDINT_H \
|
||||
-DUNITY_OUTPUT_CHAR -o $$new_name ; \
|
||||
done
|
||||
|
||||
.PHONY: directories
|
||||
# Build test_runner.o from test_runner.c
|
||||
$(SCRATCH_DIR)/%/test_runner.o : $(SCRATCH_DIR)/%/test_runner.c \
|
||||
$(SCRATCH_DIR)/%/$(PROJECT).o
|
||||
$(eval INCLUDE = -I$(SCRATCH_DIR)/$*/include)
|
||||
$(eval INCLUDE += -I$(SCRATCH_DIR)/$*/mocks)
|
||||
$(eval INCLUDE += -I$(KERNEL_DIR)/include)
|
||||
$(CC) -c $< $(INCLUDE) $(CPPFLAGS) $(CFLAGS) -o $@
|
||||
|
||||
# Build tasks_utest.o from tasks_utest_%.c
|
||||
$(SCRATCH_DIR)/%/$(PROJECT)_utest.o : $(PROJECT_DIR)/$(PROJECT)_%_utest.c \
|
||||
$(MOCK_OBJS) \
|
||||
global_vars.h \
|
||||
| directories
|
||||
$(eval INCLUDE = -I$(SCRATCH_DIR)/$*/include)
|
||||
$(eval INCLUDE += -I$(SCRATCH_DIR)/$*/mocks)
|
||||
$(eval INCLUDE += -I$(KERNEL_DIR)/include)
|
||||
$(CC) -c $< $(INCLUDE) $(CPPFLAGS) $(CFLAGS) -o $@
|
||||
|
||||
# Build tasks.o from tasks.i with the custom FreeRTOSConfig.h and place it in
|
||||
# its configuration directory
|
||||
$(SCRATCH_DIR)/%/$(PROJECT).o : $(SCRATCH_DIR)/%/$(PROJECT).i | directories
|
||||
$(CC) -c $< $(CFLAGS) $(COVERAGE_OPTS) -o $@
|
||||
|
||||
RESET_TIMER_FUNCTION := void stopTimers() { xTimerQueue = NULL; xTimerTaskHandle = NULL; }
|
||||
|
||||
# Build tasks.i from tasks.c with the custom FreeRTOSConfig.h and place it in
|
||||
# its configuration directory
|
||||
$(SCRATCH_DIR)/%/$(PROJECT).i : $(KERNEL_DIR)/$(PROJECT).c | directories
|
||||
$(eval INCLUDE = -I$(SCRATCH_DIR)/$*/include)
|
||||
$(eval INCLUDE += -I$(SCRATCH_DIR)/$*/mocks) \
|
||||
$(eval INCLUDE += -I$(KERNEL_DIR)/include) \
|
||||
grep -q '$(RESET_TIMER_FUNCTION)' $< || \
|
||||
sed -i -e '$$a$(RESET_TIMER_FUNCTION)' $<
|
||||
$(CC) -E $< $(INCLUDE) $(CPPFLAGS) -include list_macros.h -o $@
|
||||
|
||||
# Generate test_runner.c which contains the main function from the test file
|
||||
$(SCRATCH_DIR)/%/test_runner.c : $(PROJECT_DIR)/$(PROJECT)_%_utest.c \
|
||||
Makefile | directories
|
||||
ruby $(UNITY_BIN_DIR)/generate_test_runner.rb "--use_param_tests=1" \
|
||||
$(PROJECT)_$*_utest.c $(PROJECT_DIR)/$(PROJECT).yml $@
|
||||
|
||||
# Create needed directories
|
||||
directories :
|
||||
-mkdir $(SCRATCH_DIR)
|
||||
-mkdir $(MOCKS_DIR)
|
||||
-mkdir $(PROJ_LIB_DIR)
|
||||
-mkdir -p $(SCRATCH_DIR)
|
||||
-mkdir -p $(CONFIG_DIRS)
|
||||
-mkdir -p $(MOCK_DIRS)
|
||||
-mkdir -p $(CPP_DIRS)
|
||||
-mkdir -p $(INCLUDE_DIRS)
|
||||
-mkdir -p $(BIN_DIR)
|
||||
-mkdir -p $(LIB_DIR)
|
||||
|
||||
# prevent deletion by chain of implicit rules
|
||||
NO_DELETE: $(MOCK_SRC_LIST)
|
||||
EXEC_PREFIX := $(PROJECT)
|
||||
|
||||
include ../coverage.mk
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue