mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-12-08 12:45:22 -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
|
|
@ -35,7 +35,7 @@ MOCK_OBJ := $(addprefix mock_,$(MOCK_FILES:.h=.o))
|
|||
MOCK_HDR_LIST := $(addprefix $(MOCKS_DIR)/,$(MOCK_HDR))
|
||||
MOCK_SRC_LIST := $(addprefix $(MOCKS_DIR)/,$(MOCK_SRC))
|
||||
MOCK_OBJ_LIST := $(addprefix $(SCRATCH_DIR)/,$(MOCK_OBJ))
|
||||
CFLAGS += -I$(MOCKS_DIR)
|
||||
CPPFLAGS += -I$(MOCKS_DIR)
|
||||
|
||||
# Kernel files under test
|
||||
PROJ_SRC_LIST := $(addprefix $(KERNEL_DIR)/,$(PROJECT_SRC))
|
||||
|
|
@ -53,10 +53,6 @@ SF_OBJ_LIST := $(addprefix $(SCRATCH_DIR)/sf_,$(SUITE_SUPPORT_SRC:.c=.o))
|
|||
DEPS_OBJ_LIST := $(addprefix $(SCRATCH_DIR)/dep_,$(PROJECT_DEPS_SRC:.c=.o))
|
||||
EXECS := $(addprefix $(EXEC_PREFIX)_,$(SUITE_UT_SRC:.c=))
|
||||
EXEC_LIST := $(addprefix $(BIN_DIR)/,$(EXECS))
|
||||
LCOV_LIST := $(addsuffix .info,$(addprefix $(SCRATCH_DIR)/,$(SUITE_UT_SRC:.c=)))
|
||||
COVINFO_INITIAL := $(SCRATCH_DIR)/$(EXEC_PREFIX)_initial.info
|
||||
COVINFO_COMBINE := $(SCRATCH_DIR)/$(EXEC_PREFIX)_combined.info
|
||||
COVINFO := $(abspath $(SCRATCH_DIR)/..)/$(EXEC_PREFIX).info
|
||||
LIBS_LIST := $(foreach lib, $(LIBS), $(LIB_DIR)/$(lib).so)
|
||||
|
||||
# Coverage related options
|
||||
|
|
@ -70,64 +66,14 @@ COV_REPORT_DIR := $(SCRATCH_DIR)/coverage
|
|||
NO_DELETE : $(MOCK_HDR_LIST) $(MOCK_SRC_LIST) $(MOCK_OBJ_LIST) \
|
||||
$(DEPS_OBJ_LIST) $(SF_OBJ_LIST) $(EXEC_LIST) \
|
||||
$(PROJ_PP_LIST) $(PROJ_OBJ_LIST) $(PROJ_GCDA_LIST) \
|
||||
$(SUITE_OBJ_LIST) $(RUNNER_SRC_LIST) $(RUNNER_OBJ_LIST) \
|
||||
$(COVINFO) $(LCOV_LIST)
|
||||
|
||||
# Cases that run test binaries cannot be run in parallel.
|
||||
.NOTPARALLEL : $(COVINFO) $(LCOV_LIST) $(PROJ_GCDA_LIST)
|
||||
$(SUITE_OBJ_LIST) $(RUNNER_SRC_LIST) $(RUNNER_OBJ_LIST)
|
||||
|
||||
.DEFAULT_GOAL := run
|
||||
|
||||
# Generate gcov files by default
|
||||
run : gcov
|
||||
|
||||
gcov : $(PROJ_GCDA_LIST)
|
||||
|
||||
clean:
|
||||
rm -rf $(SCRATCH_DIR)
|
||||
rm -rf $(EXEC_LIST)
|
||||
rm -rf $(COVINFO)
|
||||
|
||||
$(LIBS_LIST) :
|
||||
make -C $(UT_ROOT_DIR) libs
|
||||
|
||||
define run-test
|
||||
$(1)
|
||||
|
||||
endef
|
||||
|
||||
# Run and append to gcov data files
|
||||
$(PROJ_GCDA_LIST) : $(EXEC_LIST)
|
||||
rm -f $(PROJ_DIR)/*.gcda
|
||||
mkdir -p $(BIN_DIR)
|
||||
# run each test case
|
||||
$(foreach bin,$^,$(call run-test,$(bin)))
|
||||
|
||||
# Run and generate lcov
|
||||
lcov: $(COVINFO)
|
||||
|
||||
lcovhtml : $(COVINFO)
|
||||
mkdir -p $(COV_REPORT_DIR)
|
||||
genhtml $(COVINFO) $(LCOV_OPTS) --output-directory $(COV_REPORT_DIR)
|
||||
|
||||
bin: $(EXEC_LIST)
|
||||
|
||||
# Generate _mock.c / .h files
|
||||
$(MOCK_HDR_LIST) $(MOCK_SRC_LIST) : $(PROJECT_DIR)/$(PROJECT).yml $(MOCK_FILES_FP)
|
||||
mkdir -p $(SCRATCH_DIR) $(MOCKS_DIR)
|
||||
cd $(SCRATCH_DIR) && \
|
||||
ruby $(CMOCK_EXEC_DIR)/cmock.rb -o$(PROJECT_DIR)/$(PROJECT).yml \
|
||||
$(MOCK_FILES_FP)
|
||||
|
||||
# Generate callgraph for coverage filtering
|
||||
$(PROJ_DIR)/callgraph.json : $(PROJ_SRC_LIST)
|
||||
mkdir -p $(PROJ_DIR)
|
||||
python3 $(UT_ROOT_DIR)/tools/callgraph.py --out $@ $^
|
||||
|
||||
# preprocess proj files to expand macros for coverage
|
||||
$(PROJ_DIR)/%.i : $(KERNEL_DIR)/%.c
|
||||
mkdir -p $(PROJ_DIR)
|
||||
$(CC) -E $< $(CPPFLAGS) $(CFLAGS) -o $@
|
||||
$(CC) -E $< $(CPPFLAGS) -o $@
|
||||
|
||||
# compile the project objects with coverage instrumented
|
||||
$(PROJ_DIR)/%.o : $(PROJ_DIR)/%.i
|
||||
|
|
@ -173,39 +119,15 @@ $(EXEC_LIST) : $(BIN_DIR)/$(EXEC_PREFIX)_%_utest : $(SCRATCH_DIR)/%_utest.o
|
|||
$(CC) $< $(subst .o,_runner.o,$<) $(SF_OBJ_LIST) $(DEPS_OBJ_LIST) \
|
||||
$(MOCK_OBJ_LIST) $(PROJ_OBJ_LIST) $(LDFLAGS) -o $@
|
||||
|
||||
# Generate baseline inital coverage data from .gcno file
|
||||
$(SCRATCH_DIR)/$(EXEC_PREFIX)_initial.info : $(PROJ_OBJ_LIST)
|
||||
lcov $(LCOV_OPTS) --capture --initial --directory $(PROJ_DIR) -o $@
|
||||
# Generate _mock.c / .h files
|
||||
$(MOCK_HDR_LIST) $(MOCK_SRC_LIST) : $(PROJECT_DIR)/$(PROJECT).yml $(MOCK_FILES_FP)
|
||||
mkdir -p $(SCRATCH_DIR) $(MOCKS_DIR)
|
||||
cd $(SCRATCH_DIR) && \
|
||||
ruby $(CMOCK_EXEC_DIR)/cmock.rb -o$(PROJECT_DIR)/$(PROJECT).yml \
|
||||
$(MOCK_FILES_FP)
|
||||
|
||||
# Run the test runner and genrate a filtered gcov.json.gz file
|
||||
$(SCRATCH_DIR)/%_utest.info : $(BIN_DIR)/$(EXEC_PREFIX)_%_utest \
|
||||
$(PROJ_DIR)/callgraph.json
|
||||
# Remove any existing coverage data
|
||||
rm -f $(PROJ_DIR)/*.gcda
|
||||
|
||||
# run the testrunner
|
||||
$<
|
||||
$(LIBS_LIST) :
|
||||
make -C $(UT_ROOT_DIR) libs
|
||||
|
||||
# Gather coverage into a json.gz file
|
||||
gcov $(GCOV_OPTS) $(foreach src,$(PROJECT_SRC),$(PROJ_DIR)/$(src:.c=.gcda)) \
|
||||
--json-format --stdout | gzip > $(subst .info,.json.gz,$@)
|
||||
|
||||
# Filter coverage based on tags in unit test file
|
||||
$(TOOLS_DIR)/filtercov.py --in $(subst .info,.json.gz,$@) \
|
||||
--map $(PROJ_DIR)/callgraph.json \
|
||||
--test $(SUITE_DIR)/$*_utest.c \
|
||||
--format lcov \
|
||||
--out $@
|
||||
-lcov $(LCOV_OPTS) --summary $@
|
||||
|
||||
# Remove temporary files
|
||||
rm -f $(subst .info,.json.gz,$@)
|
||||
rm -f $(PROJ_GCDA_LIST)
|
||||
|
||||
# Combine lcov from each test bin into one lcov info file for the suite
|
||||
$(COVINFO_COMBINE) : $(LCOV_LIST)
|
||||
lcov $(LCOV_OPTS) -o $@ $(foreach cov,$(LCOV_LIST),--add-tracefile $(cov) )
|
||||
|
||||
# Add baseline / initial coverage generated by gcc to point out untagged functions
|
||||
$(COVINFO) : $(COVINFO_COMBINE) $(COVINFO_INITIAL)
|
||||
lcov $(LCOV_OPTS) -o $@ --add-tracefile $(COVINFO_INITIAL) --add-tracefile $(COVINFO_COMBINE)
|
||||
include $(UT_ROOT_DIR)/coverage.mk
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue