[修改] 增加freeRTOS

1. 版本FreeRTOSv202212.01,命名为kernel;
This commit is contained in:
2023-05-06 16:43:01 +00:00
commit a345df017b
20944 changed files with 11094377 additions and 0 deletions

View File

@ -0,0 +1,135 @@
/*
* FreeRTOS V202212.01
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
/* XXX: this file will be processed by unifdef to generate new header files
* that can be mocked according to the configurations desired
* it has a few limitations on the format of this file such as:
* no config that spans more than one line
* no strings in config names
* for more info please check the man file with $ man unifdef
*/
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. See
* http://www.freertos.org/a00110.html
*----------------------------------------------------------*/
#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configUSE_TICKLESS_IDLE 1
#define configUSE_TIME_SLICING 1
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 1
#define configUSE_DAEMON_TASK_STARTUP_HOOK 1
#define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 70 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 52 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 12 )
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configCHECK_FOR_STACK_OVERFLOW 1
#define configUSE_RECURSIVE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 20
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_APPLICATION_TASK_TAG 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_ALTERNATIVE_API 0
#define configUSE_QUEUE_SETS 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configTASK_NOTIFICATION_ARRAY_ENTRIES 5
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 0
#define configINITIAL_TICK_COUNT ( ( TickType_t ) 0 ) /* For test. */
#define configSTREAM_BUFFER_TRIGGER_LEVEL_TEST_MARGIN 1 /* As there are a lot of tasks running. */
/* Software timer related configuration options. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
#define configTIMER_QUEUE_LENGTH 20
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
#define configMAX_PRIORITIES ( 9 )
/* Run time stats gathering configuration options. */
unsigned long ulGetRunTimeCounterValue( void ); /* Prototype of function that returns run time counter. */
void vConfigureTimerForRunTimeStats( void ); /* Prototype of function that initialises the run time counter. */
#define configGENERATE_RUN_TIME_STATS 0
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats()
#define portGET_RUN_TIME_COUNTER_VALUE() ulGetRunTimeCounterValue()
#define portUSING_MPU_WRAPPERS 0
#define portHAS_STACK_OVERFLOW_CHECKING 0
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5
#define portSTACK_GROWTH ( -1 )
#define configRECORD_STACK_HIGH_ADDRESS 1
/* This demo makes use of one or more example stats formatting functions. These
* format the raw data provided by the uxTaskGetSystemState() function in to human
* readable ASCII form. See the notes in the implementation of vTaskList() within
* FreeRTOS/Source/tasks.c for limitations. */
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
#define configSTACK_ALLOCATION_FROM_SEPARATE_HEAP 0
/* Set the following definitions to 1 to include the API function, or zero
* to exclude the API function. In most cases the linker will remove unused
* functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_uxTaskGetStackHighWaterMark 0
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xSemaphoreGetMutexHolder 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1
/* It is a good idea to define configASSERT() while developing. configASSERT()
* uses the same semantics as the standard C assert() macro. */
#define configASSERT( x )
#define portREMOVE_STATIC_QUALIFIER 1
#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0
#define configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES 0
#endif /* FREERTOS_CONFIG_H */

View File

@ -0,0 +1,135 @@
/*
* FreeRTOS V202212.01
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
/* XXX: this file will be processed by unifdef to generate new header files
* that can be mocked according to the configurations desired
* it has a few limitations on the format of this file such as:
* no config that spans more than one line
* no strings in config names
* for more info please check the man file with $ man unifdef
*/
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. See
* http://www.freertos.org/a00110.html
*----------------------------------------------------------*/
#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configUSE_TICKLESS_IDLE 1
#define configUSE_TIME_SLICING 1
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 1
#define configUSE_DAEMON_TASK_STARTUP_HOOK 1
#define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 70 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 52 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 12 )
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configCHECK_FOR_STACK_OVERFLOW 1
#define configUSE_RECURSIVE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 20
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_APPLICATION_TASK_TAG 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_ALTERNATIVE_API 0
#define configUSE_QUEUE_SETS 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configTASK_NOTIFICATION_ARRAY_ENTRIES 5
#define configSUPPORT_STATIC_ALLOCATION 0
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configINITIAL_TICK_COUNT ( ( TickType_t ) 0 ) /* For test. */
#define configSTREAM_BUFFER_TRIGGER_LEVEL_TEST_MARGIN 1 /* As there are a lot of tasks running. */
/* Software timer related configuration options. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
#define configTIMER_QUEUE_LENGTH 20
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
#define configMAX_PRIORITIES ( 9 )
/* Run time stats gathering configuration options. */
unsigned long ulGetRunTimeCounterValue( void ); /* Prototype of function that returns run time counter. */
void vConfigureTimerForRunTimeStats( void ); /* Prototype of function that initialises the run time counter. */
#define configGENERATE_RUN_TIME_STATS 0
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats()
#define portGET_RUN_TIME_COUNTER_VALUE() ulGetRunTimeCounterValue()
#define portUSING_MPU_WRAPPERS 0
#define portHAS_STACK_OVERFLOW_CHECKING 0
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5
#define portSTACK_GROWTH ( -1 )
#define configRECORD_STACK_HIGH_ADDRESS 1
/* This demo makes use of one or more example stats formatting functions. These
* format the raw data provided by the uxTaskGetSystemState() function in to human
* readable ASCII form. See the notes in the implementation of vTaskList() within
* FreeRTOS/Source/tasks.c for limitations. */
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
#define configSTACK_ALLOCATION_FROM_SEPARATE_HEAP 0
/* Set the following definitions to 1 to include the API function, or zero
* to exclude the API function. In most cases the linker will remove unused
* functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_uxTaskGetStackHighWaterMark 0
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xSemaphoreGetMutexHolder 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1
/* It is a good idea to define configASSERT() while developing. configASSERT()
* uses the same semantics as the standard C assert() macro. */
#define configASSERT( x )
#define portREMOVE_STATIC_QUALIFIER 1
#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0
#define configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES 0
#endif /* FREERTOS_CONFIG_H */

View File

@ -0,0 +1,190 @@
# Change according to what your unit test directory is.
# For example if testing queue.c your directory should be called queue
# 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 += $(KERNEL_DIR)/include/portable.h
MOCK_FILES_FP += $(PROJECT_DIR)/list_macros.h
MOCK_FILES_FP += $(UT_ROOT_DIR)/config/fake_assert.h
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
COVERAGE_OPTS := -fprofile-arcs -ftest-coverage -fprofile-generate
# build/generated/queue
SCRATCH_DIR := $(GENERATED_DIR)/$(PROJECT)
# 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 $(MOCK_DIRS))
$(shell for n in $(MOCK_DIRS) ; do touch -a $(n)/mock_dummy.c)
endif
EXEC_LIST := $(addprefix $(BIN_DIR)/,$(patsubst %.c,%,$(PROJ_SRC_LIST)))
EXEC_PATH := $(addsuffix _%_utest,$(addprefix $(BIN_DIR)/,$(PROJECT)))
PROJ_OBJ_LIST := $(EXEC_LIST)
.PHONY: all Makefile directories
.SECONDARY:
all : directories $(EXEC_LIST)
# 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 $@
# 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)/*
# 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
# 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
# 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 -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)
EXEC_PREFIX := $(PROJECT)
include ../coverage.mk

View File

@ -0,0 +1,105 @@
/*
* FreeRTOS V202212.01
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef GLOBAL_VARS_H
#define GLOBAL_VARS_H
#include "timers.h"
/* ====================== DEFINITIONS FROM timers.c ======================== */
#define tmrNO_DELAY ( TickType_t ) 0U
#define tmrSTATUS_IS_ACTIVE ( ( uint8_t ) 0x01 )
#define tmrSTATUS_IS_STATICALLY_ALLOCATED ( ( uint8_t ) 0x02 )
#define tmrSTATUS_IS_AUTORELOAD ( ( uint8_t ) 0x04 )
#define tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR ( ( BaseType_t ) -2 )
#define tmrCOMMAND_EXECUTE_CALLBACK ( ( BaseType_t ) -1 )
#define tmrCOMMAND_START_DONT_TRACE ( ( BaseType_t ) 0 )
#define tmrCOMMAND_START ( ( BaseType_t ) 1 )
#define tmrCOMMAND_RESET ( ( BaseType_t ) 2 )
#define tmrCOMMAND_STOP ( ( BaseType_t ) 3 )
#define tmrCOMMAND_CHANGE_PERIOD ( ( BaseType_t ) 4 )
#define tmrCOMMAND_DELETE ( ( BaseType_t ) 5 )
#define tmrFIRST_FROM_ISR_COMMAND ( ( BaseType_t ) 6 )
#define tmrCOMMAND_START_FROM_ISR ( ( BaseType_t ) 6 )
#define tmrCOMMAND_RESET_FROM_ISR ( ( BaseType_t ) 7 )
#define tmrCOMMAND_STOP_FROM_ISR ( ( BaseType_t ) 8 )
#define tmrCOMMAND_CHANGE_PERIOD_FROM_ISR ( ( BaseType_t ) 9 )
typedef struct tmrTimerControl /* The old naming convention is used to prevent breaking kernel aware debuggers. */
{
const char * pcTimerName; /*<< Text name. This is not used by the kernel, it is included simply to make debugging easier. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
ListItem_t xTimerListItem; /*<< Standard linked list item as used by all kernel features for event management. */
TickType_t xTimerPeriodInTicks; /*<< How quickly and often the timer expires. */
void * pvTimerID; /*<< An ID to identify the timer. This allows the timer to be identified when the same callback is used for multiple timers. */
TimerCallbackFunction_t pxCallbackFunction; /*<< The function that will be called when the timer expires. */
#if ( configUSE_TRACE_FACILITY == 1 )
UBaseType_t uxTimerNumber; /*<< An ID assigned by trace tools such as FreeRTOS+Trace */
#endif
uint8_t ucStatus; /*<< Holds bits to say if the timer was statically allocated or not, and if it is active or not. */
} xTIMER;
typedef xTIMER Timer_t;
typedef struct tmrTimerParameters
{
TickType_t xMessageValue; /*<< An optional value used by a subset of commands, for example, when changing the period of a timer. */
Timer_t * pxTimer; /*<< The timer to which the command will be applied. */
} TimerParameter_t;
typedef struct tmrCallbackParameters
{
PendedFunction_t pxCallbackFunction; /* << The callback function to execute. */
void * pvParameter1; /* << The value that will be used as the callback functions first parameter. */
uint32_t ulParameter2; /* << The value that will be used as the callback functions second parameter. */
} CallbackParameters_t;
typedef struct tmrTimerQueueMessage
{
BaseType_t xMessageID; /*<< The command being sent to the timer service task. */
union
{
TimerParameter_t xTimerParameters;
/* Don't include xCallbackParameters if it is not going to be used as
* it makes the structure (and therefore the timer queue) larger. */
#if ( INCLUDE_xTimerPendFunctionCall == 1 )
CallbackParameters_t xCallbackParameters;
#endif /* INCLUDE_xTimerPendFunctionCall */
} u;
} DaemonTaskMessage_t;
#define HOOK_DIAG() \
do { \
printf( "%s Called\n", __FUNCTION__ ); \
} while( 0 )
/*#undef HOOK_DIAG */
/*#idefine HOOK_DIAG() */
#endif /* ifndef GLOBAL_VARS_H */

View File

@ -0,0 +1,64 @@
/*
* FreeRTOS V202212.01
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef LIST_MACRO_H
#define LIST_MACRO_H
#include <FreeRTOS.h>
#include <task.h>
#include <portmacro.h>
#include <list.h>
#undef listLIST_IS_EMPTY
BaseType_t listLIST_IS_EMPTY( const List_t * pxList );
#undef listGET_OWNER_OF_HEAD_ENTRY
void * listGET_OWNER_OF_HEAD_ENTRY( const List_t * pxList );
#undef listIS_CONTAINED_WITHIN
BaseType_t listIS_CONTAINED_WITHIN( List_t * list,
const ListItem_t * listItem );
#undef listGET_LIST_ITEM_VALUE
TickType_t listGET_LIST_ITEM_VALUE( ListItem_t * listItem );
#undef listSET_LIST_ITEM_VALUE
void listSET_LIST_ITEM_VALUE( ListItem_t * listItem,
TickType_t itemValue );
#undef listLIST_ITEM_CONTAINER
List_t * listLIST_ITEM_CONTAINER( const ListItem_t * listItem );
#undef listCURRENT_LIST_LENGTH
UBaseType_t listCURRENT_LIST_LENGTH( List_t * list );
#undef listGET_ITEM_VALUE_OF_HEAD_ENTRY
TickType_t listGET_ITEM_VALUE_OF_HEAD_ENTRY( List_t * list );
#undef listGET_LIST_ITEM_OWNER
void * listGET_LIST_ITEM_OWNER( ListItem_t * listItem );
#endif /* ifndef LIST_MACRO_H */

View File

@ -0,0 +1,32 @@
:cmock:
:mock_prefix: mock_
:when_no_prototypes: :warn
:treat_externs: :include
:enforce_strict_ordering: TRUE
:plugins:
- :ignore
- :ignore_arg
- :expect_any_args
- :array
- :callback
- :return_thru_ptr
:callback_include_count: true # include a count arg when calling the callback
:callback_after_arg_check: false # check arguments before calling the callback
:treat_as:
uint8: HEX8
uint16: HEX16
uint32: UINT32
int8: INT8
bool: UINT8
:includes: # This will add these includes to each mock.
- <stdbool.h>
- "FreeRTOS.h"
:treat_externs: :exclude # Now the extern-ed functions will be mocked.
:weak: __attribute__((weak))
:verbosity: 3
:attributes:
- PRIVILEGED_FUNCTION
:strippables:
- PRIVILEGED_FUNCTION
- portDONT_DISCARD
:treat_externs: :include

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,482 @@
/*
* FreeRTOS V202212.01
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*! @file timers_utest.c */
/* Test includes. */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "portmacro.h"
#include "timers.h"
#include "global_vars.h"
#include "unity.h"
#include "unity_memory.h"
/* Mock includes. */
#include "mock_queue.h"
#include "mock_list.h"
#include "mock_list_macros.h"
#include "mock_fake_assert.h"
#include "mock_portable.h"
#include "mock_task.h"
/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
#include <pthread.h>
void stopTimers();
/* ============================ GLOBAL VARIABLES =========================== */
static uint16_t usMallocFreeCalls = 0;
static uint32_t critical_section_counter;
static bool port_yield_within_api_called = false;
static TickType_t saved_last_time = 0;
/* ============================= FUNCTION HOOKS =========================== */
void vFakePortEnterCriticalSection( void )
{
critical_section_counter++;
}
void vFakePortExitCriticalSection( void )
{
critical_section_counter--;
}
void vFakePortYieldWithinAPI()
{
HOOK_DIAG();
port_yield_within_api_called = true;
pthread_exit( NULL );
}
void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
StackType_t ** ppxTimerTaskStackBuffer,
uint32_t * pulTimerTaskStackSize )
{
static StaticTask_t xTimerTaskTCB;
static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
*ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
*ppxTimerTaskStackBuffer = uxTimerTaskStack;
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
}
void vApplicationDaemonTaskStartupHook( void )
{
HOOK_DIAG();
}
/* ========================== CALLBACK FUNCTIONS =========================== */
static void xCallback_Test( TimerHandle_t xTimer )
{
HOOK_DIAG();
}
static int32_t end_2_timer = 0;
static void xCallback_Test_2_end( TimerHandle_t xTimer )
{
HOOK_DIAG();
static int i = 2;
if( end_2_timer - 1 <= 0 )
{
pthread_exit( &i );
}
end_2_timer--;
}
static int32_t end_4_timer = 0;
static void pended_function_4_end( void * arg1,
uint32_t arg2 )
{
HOOK_DIAG();
static int i = 4;
if( end_4_timer - 1 <= 0 )
{
pthread_exit( &i );
}
end_4_timer--;
}
/* ============================ STATIC FUNCTIONS =========================== */
static void * timer_thread_function( void * args )
{
void * pvParameters = NULL;
portTASK_FUNCTION( prvTimerTask, pvParameters );
( void ) fool_static2; /* ignore unused variable warning */
/* API Call */
prvTimerTask( pvParameters );
return NULL;
}
/* ============================== UNITY FIXTURES ========================== */
void setUp( void )
{
vFakeAssert_Ignore();
port_yield_within_api_called = false;
/* Track calls to malloc / free */
UnityMalloc_StartTest();
critical_section_counter = 0;
end_2_timer = 0;
end_4_timer = 0;
stopTimers();
}
/*! called before each testcase */
void tearDown( void )
{
TEST_ASSERT_EQUAL_INT_MESSAGE( 0, usMallocFreeCalls,
"free is not called the same number of times as malloc,"
"you might have a memory leak!!" );
usMallocFreeCalls = 0;
UnityMalloc_EndTest();
}
/*! called at the beginning of the whole suite */
void suiteSetUp()
{
}
/*! called at the end of the whole suite */
int suiteTearDown( int numFailures )
{
return numFailures;
}
/* ============================== TEST FUNCTIONS ========================== */
/**
* @brief xTimerCreate happy path
*
*/
void test_xTimerCreateTimerTask_success( void )
{
BaseType_t ret_xtimer;
QueueHandle_t queue_handle = ( QueueHandle_t ) 3; /* not zero */
/* Setup */
/* Expectations */
vListInitialise_ExpectAnyArgs();
vListInitialise_ExpectAnyArgs();
xQueueGenericCreate_ExpectAnyArgsAndReturn( queue_handle );
vQueueAddToRegistry_ExpectAnyArgs();
xTaskCreate_ExpectAnyArgsAndReturn( pdTRUE );
/* API Call */
ret_xtimer = xTimerCreateTimerTask();
/* Validations */
TEST_ASSERT_TRUE( ret_xtimer );
}
/**
* @brief xTimerCreate happy path
*
*/
void test_xTimerCreate_success( void )
{
uint32_t ulID = 0;
TimerHandle_t xTimer = NULL;
Timer_t pxNewTimer;
QueueHandle_t queue_handle = ( QueueHandle_t ) 3; /* not zero */
pvPortMalloc_ExpectAndReturn( sizeof( Timer_t ), &pxNewTimer );
vListInitialise_ExpectAnyArgs();
vListInitialise_ExpectAnyArgs();
xQueueGenericCreate_ExpectAnyArgsAndReturn( queue_handle );
vQueueAddToRegistry_ExpectAnyArgs();
vListInitialiseItem_ExpectAnyArgs();
xTimer = xTimerCreate( "ut-timer",
pdMS_TO_TICKS( 1000 ),
pdTRUE,
&ulID,
xCallback_Test );
TEST_ASSERT_NOT_EQUAL( NULL, xTimer );
TEST_ASSERT_EQUAL_PTR( &pxNewTimer, xTimer );
TEST_ASSERT_EQUAL( tmrSTATUS_IS_AUTORELOAD, pxNewTimer.ucStatus );
TEST_ASSERT_EQUAL_STRING( "ut-timer", pxNewTimer.pcTimerName );
TEST_ASSERT_EQUAL( pdMS_TO_TICKS( 1000 ), pxNewTimer.xTimerPeriodInTicks );
TEST_ASSERT_EQUAL_PTR( &ulID, pxNewTimer.pvTimerID );
TEST_ASSERT_EQUAL_PTR( xCallback_Test, pxNewTimer.pxCallbackFunction );
}
void test_xTimerCreate_success_no_auto_reload( void )
{
uint32_t ulID = 0;
TimerHandle_t xTimer = NULL;
Timer_t pxNewTimer;
QueueHandle_t queue_handle = ( QueueHandle_t ) 3; /* not zero */
pvPortMalloc_ExpectAndReturn( sizeof( Timer_t ), &pxNewTimer );
vListInitialise_ExpectAnyArgs();
vListInitialise_ExpectAnyArgs();
xQueueGenericCreate_ExpectAnyArgsAndReturn( queue_handle );
vQueueAddToRegistry_ExpectAnyArgs();
vListInitialiseItem_ExpectAnyArgs();
xTimer = xTimerCreate( "ut-timer",
pdMS_TO_TICKS( 1000 ),
pdFALSE,
&ulID,
xCallback_Test );
TEST_ASSERT_EQUAL_PTR( &pxNewTimer, xTimer );
TEST_ASSERT_EQUAL( 0, pxNewTimer.ucStatus );
}
void test_xTimerCreate_success_twice( void )
{
uint32_t ulID = 0;
TimerHandle_t xTimer = NULL;
Timer_t pxNewTimer;
QueueHandle_t queue_handle = ( QueueHandle_t ) 3; /* not zero */
pvPortMalloc_ExpectAndReturn( sizeof( Timer_t ), &pxNewTimer );
/* prvInitialiseNewTimer */
/* prvCheckForValidListAndQueue */
vListInitialise_ExpectAnyArgs();
vListInitialise_ExpectAnyArgs();
xQueueGenericCreate_ExpectAnyArgsAndReturn( queue_handle );
vQueueAddToRegistry_ExpectAnyArgs();
/* back prvInitialiseNewTimer */
vListInitialiseItem_ExpectAnyArgs();
xTimer = xTimerCreate( "ut-timer",
pdMS_TO_TICKS( 1000 ),
pdTRUE,
&ulID,
xCallback_Test );
TEST_ASSERT_EQUAL_PTR( &pxNewTimer, xTimer );
TEST_ASSERT_EQUAL_PTR( &pxNewTimer, xTimer );
TEST_ASSERT_EQUAL( tmrSTATUS_IS_AUTORELOAD, pxNewTimer.ucStatus );
TEST_ASSERT_EQUAL_STRING( "ut-timer", pxNewTimer.pcTimerName );
TEST_ASSERT_EQUAL( pdMS_TO_TICKS( 1000 ), pxNewTimer.xTimerPeriodInTicks );
TEST_ASSERT_EQUAL_PTR( &ulID, pxNewTimer.pvTimerID );
TEST_ASSERT_EQUAL_PTR( xCallback_Test, pxNewTimer.pxCallbackFunction );
/* Second call to xTimerCreate */
pvPortMalloc_ExpectAndReturn( sizeof( Timer_t ), &pxNewTimer );
vListInitialiseItem_ExpectAnyArgs();
xTimer = xTimerCreate( "ut-timer",
pdMS_TO_TICKS( 1000 ),
pdTRUE,
&ulID,
xCallback_Test );
TEST_ASSERT_EQUAL_PTR( &pxNewTimer, xTimer );
}
void test_xTimerCreate_fail_timer_allocation( void )
{
uint32_t ulID = 0;
TimerHandle_t xTimer = NULL;
pvPortMalloc_ExpectAndReturn( sizeof( Timer_t ), NULL );
xTimer = xTimerCreate( "ut-timer",
pdMS_TO_TICKS( 1000 ),
pdTRUE,
&ulID,
xCallback_Test );
TEST_ASSERT_EQUAL( NULL, xTimer );
}
void test_xTimerCreate_fail_queue_allocation( void )
{
uint32_t ulID = 0;
Timer_t pxNewTimer;
TimerHandle_t xTimer = NULL;
/* Expectations */
pvPortMalloc_ExpectAndReturn( sizeof( Timer_t ), &pxNewTimer );
/* prvInitialiseNewTimer */
/* prvCheckForValidListAndQueue */
vListInitialise_ExpectAnyArgs();
vListInitialise_ExpectAnyArgs();
xQueueGenericCreate_ExpectAnyArgsAndReturn( NULL );
/* Back prvInitialiseNewTimer */
vListInitialiseItem_ExpectAnyArgs();
/* API Call */
xTimer = xTimerCreate( "ut-timer",
pdMS_TO_TICKS( 1000 ),
pdTRUE,
&ulID,
xCallback_Test );
/* Validations */
TEST_ASSERT_EQUAL( &pxNewTimer, xTimer );
}
void test_timer_function_success3_command_delete_dynamic( void )
{
Timer_t xTimer = { 0 };
Timer_t xTimer2 = { 0 };
pthread_t thread_id;
int * retVal;
DaemonTaskMessage_t xMessage;
DaemonTaskMessage_t xMessage2;
CallbackParameters_t callback_param;
end_2_timer = 2;
end_4_timer = 1;
/* Setup */
xTimer.ucStatus |= tmrSTATUS_IS_AUTORELOAD;
xTimer.ucStatus &= ~tmrSTATUS_IS_STATICALLY_ALLOCATED;
xTimer.ucStatus &= ~tmrSTATUS_IS_ACTIVE;
xTimer.pxCallbackFunction = xCallback_Test_2_end;
xTimer.xTimerPeriodInTicks = UINT32_MAX;
xTimer2.ucStatus |= tmrSTATUS_IS_AUTORELOAD;
xTimer2.pxCallbackFunction = xCallback_Test_2_end;
xTimer2.xTimerPeriodInTicks = saved_last_time;
callback_param.pxCallbackFunction = &pended_function_4_end;
callback_param.pvParameter1 = NULL;
callback_param.ulParameter2 = 0xa9a9a9a9;
xMessage.xMessageID = tmrCOMMAND_DELETE;
xMessage.u.xCallbackParameters = callback_param;
xMessage.u.xTimerParameters.pxTimer = &xTimer;
xMessage.u.xTimerParameters.xMessageValue = saved_last_time;
xMessage2.xMessageID = tmrCOMMAND_EXECUTE_CALLBACK; /* used to end the loop */
xMessage2.u.xCallbackParameters = callback_param;
/* Expectations */
/* prvGetNextExpireTime */
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
listGET_ITEM_VALUE_OF_HEAD_ENTRY_ExpectAnyArgsAndReturn( 3 );
/* prvProcessTimerOrBlockTask */
vTaskSuspendAll_Expect();
/* prvSampleTimeNow */
xTaskGetTickCount_ExpectAndReturn( saved_last_time ); /* time now / static last_time = 0 */
/* back to prvProcessTimerOrBlockTask */
vQueueWaitForMessageRestricted_ExpectAnyArgs();
xTaskResumeAll_ExpectAndReturn( pdTRUE );
/* prvProcessReceivedCommands */
xQueueReceive_ExpectAndReturn( NULL, NULL, tmrNO_DELAY, pdPASS );
xQueueReceive_IgnoreArg_xQueue();
xQueueReceive_IgnoreArg_pvBuffer();
xQueueReceive_ReturnMemThruPtr_pvBuffer( &xMessage, sizeof( DaemonTaskMessage_t ) );
listIS_CONTAINED_WITHIN_ExpectAnyArgsAndReturn( pdFALSE );
uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
/* prvSampleTimeNow*/
xTaskGetTickCount_ExpectAndReturn( saved_last_time ); /* time now / static last_time = 0 */
vPortFree_Expect( &xTimer ); /* testcase is testing this clause */
/* back to prvProcessReceivedCommands */
xQueueReceive_ExpectAndReturn( NULL, NULL, tmrNO_DELAY, pdPASS );
xQueueReceive_IgnoreArg_xQueue();
xQueueReceive_IgnoreArg_pvBuffer();
xQueueReceive_ReturnMemThruPtr_pvBuffer( &xMessage2, sizeof( DaemonTaskMessage_t ) );
/* API Call */
pthread_create( &thread_id, NULL, &timer_thread_function, NULL );
pthread_join( thread_id, ( void ** ) &retVal );
/* Validations */
TEST_ASSERT_EQUAL( 4, *retVal );
}
void test_timer_function_success3_command_delete_static( void )
{
Timer_t xTimer = { 0 };
Timer_t xTimer2 = { 0 };
pthread_t thread_id;
int * retVal;
DaemonTaskMessage_t xMessage;
DaemonTaskMessage_t xMessage2;
CallbackParameters_t callback_param;
end_2_timer = 2;
end_4_timer = 1;
/* Setup */
xTimer.ucStatus |= tmrSTATUS_IS_AUTORELOAD;
xTimer.ucStatus |= tmrSTATUS_IS_STATICALLY_ALLOCATED;
xTimer.ucStatus &= ~tmrSTATUS_IS_ACTIVE;
xTimer.pxCallbackFunction = xCallback_Test_2_end;
xTimer.xTimerPeriodInTicks = UINT32_MAX;
xTimer2.ucStatus |= tmrSTATUS_IS_AUTORELOAD;
xTimer2.pxCallbackFunction = xCallback_Test_2_end;
xTimer2.xTimerPeriodInTicks = saved_last_time;
callback_param.pxCallbackFunction = &pended_function_4_end;
callback_param.pvParameter1 = NULL;
callback_param.ulParameter2 = 0xa9a9a9a9;
xMessage.xMessageID = tmrCOMMAND_DELETE;
xMessage.u.xCallbackParameters = callback_param;
xMessage.u.xTimerParameters.pxTimer = &xTimer;
xMessage.u.xTimerParameters.xMessageValue = saved_last_time;
xMessage2.xMessageID = tmrCOMMAND_EXECUTE_CALLBACK; /* used to end the loop */
xMessage2.u.xCallbackParameters = callback_param;
/* Expectations */
/* prvGetNextExpireTime */
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
listGET_ITEM_VALUE_OF_HEAD_ENTRY_ExpectAnyArgsAndReturn( 3 );
/* prvProcessTimerOrBlockTask */
vTaskSuspendAll_Expect();
/* prvSampleTimeNow */
xTaskGetTickCount_ExpectAndReturn( saved_last_time ); /* time now / static last_time = 0 */
/* back to prvProcessTimerOrBlockTask */
vQueueWaitForMessageRestricted_ExpectAnyArgs();
xTaskResumeAll_ExpectAndReturn( pdTRUE );
/* prvProcessExpiredTimer */
/* prvInsertTimerInActiveList */
/* prvProcessReceivedCommands */
xQueueReceive_ExpectAndReturn( NULL, NULL, tmrNO_DELAY, pdPASS );
xQueueReceive_IgnoreArg_xQueue();
xQueueReceive_IgnoreArg_pvBuffer();
xQueueReceive_ReturnMemThruPtr_pvBuffer( &xMessage, sizeof( DaemonTaskMessage_t ) );
listIS_CONTAINED_WITHIN_ExpectAnyArgsAndReturn( pdFALSE );
uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
/* prvSampleTimeNow*/
xTaskGetTickCount_ExpectAndReturn( saved_last_time ); /* time now / static last_time = 0 */
/* back to prvProcessReceivedCommands */
xQueueReceive_ExpectAndReturn( NULL, NULL, tmrNO_DELAY, pdPASS );
xQueueReceive_IgnoreArg_xQueue();
xQueueReceive_IgnoreArg_pvBuffer();
xQueueReceive_ReturnMemThruPtr_pvBuffer( &xMessage2, sizeof( DaemonTaskMessage_t ) );
/* API Call */
pthread_create( &thread_id, NULL, &timer_thread_function, NULL );
pthread_join( thread_id, ( void ** ) &retVal );
/* Validations */
TEST_ASSERT_EQUAL( 4, *retVal );
TEST_ASSERT_FALSE( xTimer.ucStatus & tmrSTATUS_IS_ACTIVE );
}