[修改] 增加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 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 configENABLE_MPU 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,130 @@
/*
* 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 portSTACK_GROWTH ( 1 )
#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 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 0 /* diff config 1 */
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_RECURSIVE_MUTEXES 0
#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 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 ( 7 )
/* 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 configENABLE_MPU 0
#define portHAS_STACK_OVERFLOW_CHECKING 1
#define portCRITICAL_NESTING_IN_TCB 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 configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES 0
#endif /* FREERTOS_CONFIG_H */

View File

@ -0,0 +1,181 @@
# 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
PROJECT := tasks
#
# Test/CMock/tasks
PROJECT_DIR := $(abspath .)
PROJ_DIR := $(abspath .)
# List the dependency files you wish to mock
MOCK_FILES_FP := $(KERNEL_DIR)/include/timers.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
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))
# 1 2 3 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 \
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 $@
# 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) \
$(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,336 @@
/*
* 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 GBLOBAL_VARS_H
#define GBLOBAL_VARS_H
#include "task.h"
#include <stdbool.h>
typedef struct tskTaskControlBlock /* The old naming convention is used to prevent breaking kernel aware debuggers. */
{
volatile StackType_t * pxTopOfStack; /*< Points to the location of the last item placed on the tasks stack. THIS MUST BE THE FIRST MEMBER OF THE TCB STRUCT. */
#if ( portUSING_MPU_WRAPPERS == 1 )
xMPU_SETTINGS xMPUSettings; /*< The MPU settings are defined as part of the port layer. THIS MUST BE THE SECOND MEMBER OF THE TCB STRUCT. */
#endif
ListItem_t xStateListItem; /*< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). */
ListItem_t xEventListItem; /*< Used to reference a task from an event list. */
UBaseType_t uxPriority; /*< The priority of the task. 0 is the lowest priority. */
StackType_t * pxStack; /*< Points to the start of the stack. */
char pcTaskName[ configMAX_TASK_NAME_LEN ]; /*< Descriptive name given to the task when created. Facilitates debugging only. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
StackType_t * pxEndOfStack; /*< Points to the highest valid address for the stack. */
#endif
#if ( portCRITICAL_NESTING_IN_TCB == 1 )
UBaseType_t uxCriticalNesting; /*< Holds the critical section nesting depth for ports that do not maintain their own count in the port layer. */
#endif
#if ( configUSE_TRACE_FACILITY == 1 )
UBaseType_t uxTCBNumber; /*< Stores a number that increments each time a TCB is created. It allows debuggers to determine when a task has been deleted and then recreated. */
UBaseType_t uxTaskNumber; /*< Stores a number specifically for use by third party trace code. */
#endif
#if ( configUSE_MUTEXES == 1 )
UBaseType_t uxBasePriority; /*< The priority last assigned to the task - used by the priority inheritance mechanism. */
UBaseType_t uxMutexesHeld;
#endif
#if ( configUSE_APPLICATION_TASK_TAG == 1 )
TaskHookFunction_t pxTaskTag;
#endif
#if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
void * pvThreadLocalStoragePointers[ configNUM_THREAD_LOCAL_STORAGE_POINTERS ];
#endif
#if ( configGENERATE_RUN_TIME_STATS == 1 )
uint32_t ulRunTimeCounter; /*< Stores the amount of time the task has spent in the Running state. */
#endif
#if ( configUSE_NEWLIB_REENTRANT == 1 )
/* Allocate a Newlib reent structure that is specific to this task.
* Note Newlib support has been included by popular demand, but is not
* used by the FreeRTOS maintainers themselves. FreeRTOS is not
* responsible for resulting newlib operation. User must be familiar with
* newlib and must provide system-wide implementations of the necessary
* stubs. Be warned that (at the time of writing) the current newlib design
* implements a system-wide malloc() that must be provided with locks.
*
* See the third party link http://www.nadler.com/embedded/newlibAndFreeRTOS.html
* for additional information. */
struct _reent xNewLib_reent;
#endif
#if ( configUSE_TASK_NOTIFICATIONS == 1 )
volatile uint32_t ulNotifiedValue[ configTASK_NOTIFICATION_ARRAY_ENTRIES ];
volatile uint8_t ucNotifyState[ configTASK_NOTIFICATION_ARRAY_ENTRIES ];
#endif
/* See the comments in FreeRTOS.h with the definition of
* tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE. */
#if ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 !e9029 Macro has been consolidated for readability reasons. */
uint8_t ucStaticallyAllocated; /*< Set to pdTRUE if the task is a statically allocated to ensure no attempt is made to free the memory. */
#endif
#if ( INCLUDE_xTaskAbortDelay == 1 )
uint8_t ucDelayAborted;
#endif
#if ( configUSE_POSIX_ERRNO == 1 )
int iTaskErrno;
#endif
} tskTCB;
/* =========================== DEFINES CONSTANTS ========================== */
typedef tskTCB TCB_t;
typedef void (* port_yield_operation)( void );
/* =========================== GLOBAL VARIABLES =========================== */
/* ============================ MACRO FUNCTIONS ============================ */
#define ASSERT_IF_IN_ISR_CALLED() \
do { \
TEST_ASSERT_TRUE( port_assert_if_in_isr_called ); \
port_assert_if_in_isr_called = false; \
} while( 0 )
#define ASSERT_IF_IN_ISR_NOT_CALLED() \
do { \
TEST_ASSERT_FALSE( port_assert_if_in_isr_called ); \
} while( 0 )
#define ASSERT_SETUP_TCB_CALLED() \
do { \
TEST_ASSERT_TRUE( port_setup_tcb_called ); \
port_setup_tcb_called = false; \
} while( 0 )
#define ASSERT_SETUP_TCB_NOT_CALLED() \
do { \
TEST_ASSERT_FALSE( port_setup_tcb_called ); \
} while( 0 )
#define ASSERT_PORT_YIELD_CALLED() \
do { \
TEST_ASSERT_TRUE( port_yield_called ); \
port_yield_called = false; \
} while( 0 )
#define ASSERT_PORT_YIELD_NOT_CALLED() \
do { \
TEST_ASSERT_FALSE( port_yield_called ); \
} while( 0 )
#define ASSERT_PORT_ENABLE_INTERRUPT_CALLED() \
do { \
TEST_ASSERT_TRUE( port_enable_interrupts_called ); \
port_enable_interrupts_called = false; \
} while( 0 )
#define ASSERT_PORT_ENABLE_INTERRUPT_NOT_CALLED() \
do { \
TEST_ASSERT_FALSE( port_enable_interrupts_called ); \
} while( 0 )
#define ASSERT_PORT_DISABLE_INTERRUPT_CALLED() \
do { \
TEST_ASSERT_TRUE( port_disable_interrupts_called ); \
port_disable_interrupts_called = false; \
} while( 0 )
#define ASSERT_PORT_DISABLE_INTERRUPT_NOT_CALLED() \
do { \
TEST_ASSERT_FALSE( port_disable_interrupts_called ); \
} while( 0 )
#define ASSERT_PORT_YIELD_WITHIN_API_CALLED() \
do { \
TEST_ASSERT_TRUE( port_yield_within_api_called ); \
port_yield_within_api_called = false; \
} while( 0 )
#define ASSERT_PORT_YIELD_WITHIN_API_NOT_CALLED() \
do { \
TEST_ASSERT_FALSE( port_yield_within_api_called ); \
} while( 0 )
#define ASSERT_TASK_DELETE_CALLED() \
do { \
TEST_ASSERT_TRUE( vTaskDeletePre_called ); \
vTaskDeletePre_called = false; \
} while( 0 )
#define ASSERT_TASK_DELETE_NOT_CALLED() \
do { \
TEST_ASSERT_FALSE( vTaskDeletePre_called ); \
} while( 0 )
#define ASSERT_APP_TICK_HOOK_CALLED() \
do { \
TEST_ASSERT_TRUE( vApplicationTickHook_called ); \
vApplicationTickHook_called = false; \
} while( 0 )
#define ASSERT_APP_TICK_HOOK_NOT_CALLED() \
do { \
TEST_ASSERT_FALSE( vApplicationTickHook_called ); \
} while( 0 )
#define ASSERT_PORT_CLEAR_INTERRUPT_CALLED() \
do { \
TEST_ASSERT_TRUE( portClear_Interrupt_called ); \
portClear_Interrupt_called = false; \
} while( 0 )
#define ASSERT_PORT_CLEAR_INTERRUPT_NOT_CALLED() \
do { \
TEST_ASSERT_FALSE( portClear_Interrupt_called ); \
} while( 0 )
#define ASSERT_PORT_CLEAR_INTERRUPT_FROM_ISR_CALLED() \
do { \
TEST_ASSERT_TRUE( portClear_Interrupt_from_isr_called ); \
portClear_Interrupt_from_isr_called = false; \
} while( 0 )
#define ASSERT_PORT_CLEAR_INTERRUPT_FROM_ISR_NOT_CALLED() \
do { \
TEST_ASSERT_FALSE( portClear_Interrupt_from_isr_called ); \
} while( 0 )
#define ASSERT_PORT_SET_INTERRUPT_FROM_ISR_CALLED() \
do { \
TEST_ASSERT_TRUE( portSet_Interrupt_from_isr_called ); \
portSet_Interrupt_from_isr_called = false; \
} while( 0 )
#define ASSERT_PORT_SET_INTERRUPT_FROM_ISR_NOT_CALLED() \
do { \
TEST_ASSERT_FALSE( portSet_Interrupt_from_isr_called ); \
} while( 0 )
#define ASSERT_PORT_SET_INTERRUPT_CALLED() \
do { \
TEST_ASSERT_TRUE( portSet_Interrupt_called ); \
portSet_Interrupt_called = false; \
} while( 0 )
#define ASSERT_PORT_SET_INTERRUPT_NOT_CALLED() \
do { \
TEST_ASSERT_FALSE( portSet_Interrupt_called ); \
} while( 0 )
#define ASSERT_INVALID_INTERRUPT_PRIORITY_CALLED() \
do { \
TEST_ASSERT_TRUE( port_invalid_interrupt_called ); \
port_invalid_interrupt_called = false; \
} while( 0 )
#define ASSERT_APPLICATION_IDLE_HOOK_CALLED() \
do { \
TEST_ASSERT_TRUE( vApplicationIdleHook_called ); \
vApplicationIdleHook_called = false; \
} while( 0 )
#define ASSERT_APPLICATION_IDLE_HOOK_NOT_CALLED() \
do { \
TEST_ASSERT_FALSE( vApplicationIdleHook_called ); \
} while( 0 )
#define ASSERT_APPLICATION_MALLOC_FAILED_HOOK_CALLED() \
do { \
TEST_ASSERT_TRUE( vApplicationMallocFailedHook_called ); \
vApplicationMallocFailedHook_called = false; \
} while( 0 )
#define ASSERT_APPLICATION_MALLOC_FAILED_HOOK_NOT_CALLED() \
do { \
TEST_ASSERT_FALSE( vApplicationMallocFailedHook_called ); \
} while( 0 )
#define ASSERT_PORT_ALLOCATE_SECURE_CONTEXT_CALLED() \
do { \
TEST_ASSERT_TRUE( port_allocate_secure_context_called ); \
port_allocate_secure_context_called = false; \
} while( 0 )
#define ASSERT_PORT_ALLOCATE_SECURE_CONTEXT_NOT_CALLED() \
do { \
TEST_ASSERT_FALSE( port_allocate_secure_context_called ); \
} while( 0 )
#define ASSERT_APP_STACK_OVERFLOW_HOOK_CALLED() \
do { \
TEST_ASSERT_TRUE( vApplicationStackOverflowHook_called ); \
vApplicationStackOverflowHook_called = false; \
} while( 0 )
#define ASSERT_APP_STACK_OVERFLOW_HOOK_NOT_CALLED() \
do { \
TEST_ASSERT_FALSE( vApplicationStackOverflowHook_called ); \
} while( 0 )
#define ASSERT_GET_IDLE_TASK_MEMORY_CALLED() \
do { \
TEST_ASSERT_TRUE( getIddleTaskMemory_called ); \
getIddleTaskMemory_called = false; \
} while( 0 )
#define ASSERT_GET_IDLE_TASK_MEMORY_NOT_CALLED() \
do { \
TEST_ASSERT_FALSE( getIddleTaskMemory_called ); \
} while( 0 )
#define RESET_ALL_HOOKS() \
do { \
vApplicationTickHook_called = false; \
vTaskDeletePre_called = false; \
getIddleTaskMemory_called = false; \
port_yield_called = false; \
port_enable_interrupts_called = false; \
port_disable_interrupts_called = false; \
port_yield_within_api_called = false; \
port_setup_tcb_called = false; \
portClear_Interrupt_called = false; \
portSet_Interrupt_called = false; \
portClear_Interrupt_from_isr_called = false; \
portSet_Interrupt_from_isr_called = false; \
port_invalid_interrupt_called = false; \
vApplicationStackOverflowHook_called = false; \
port_allocate_secure_context_called = false; \
port_assert_if_in_isr_called = false; \
} while( 0 )
#define HOOK_DIAG() \
do { \
printf( "%s Called\n", __FUNCTION__ ); \
} while( 0 )
#undef HOOK_DIAG
#define HOOK_DIAG()
#endif /* ifndef GBLOBAL_VARS_H */

View File

@ -0,0 +1,75 @@
/*
* 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>
struct tskTaskControlBlock;
typedef struct tskTaskControlBlock TCB_t;
#undef listLIST_IS_EMPTY
BaseType_t listLIST_IS_EMPTY( const List_t * pxList );
#undef listGET_OWNER_OF_HEAD_ENTRY
TCB_t * 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
TCB_t * listGET_LIST_ITEM_OWNER( ListItem_t * listItem );
#undef listINSERT_END
void listINSERT_END( List_t * pxList,
ListItem_t * listItem );
#undef listREMOVE_ITEM
void listREMOVE_ITEM( 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
:treat_inlines: :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.
- "FreeRTOSConfig.h"
- "FreeRTOS.h"
- "task.h"
:weak: __attribute__((weak))
:verbosity: 3
:attributes:
- PRIVILEGED_FUNCTION
:strippables:
- PRIVILEGED_FUNCTION
- portDONT_DISCARD

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,758 @@
/*
* 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 tasks_utest_2.c */
/* Tasks includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "task.h"
#include "mock_list.h"
#include "mock_list_macros.h"
#include "mock_timers.h"
#include "mock_portable.h"
/* Test includes. */
#include "unity.h"
#include "global_vars.h"
/* C runtime includes. */
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
/* =========================== EXTERN VARIABLES =========================== */
extern TCB_t * volatile pxCurrentTCB;
extern List_t pxReadyTasksLists[ configMAX_PRIORITIES ];
extern List_t xDelayedTaskList1;
extern List_t xDelayedTaskList2;
extern List_t * volatile pxDelayedTaskList;
extern List_t * volatile pxOverflowDelayedTaskList;
extern List_t xPendingReadyList;
/* INCLUDE_vTaskDelete */
extern List_t xTasksWaitingTermination;
extern volatile UBaseType_t uxDeletedTasksWaitingCleanUp;
extern List_t xSuspendedTaskList;
extern volatile UBaseType_t uxCurrentNumberOfTasks;
extern volatile TickType_t xTickCount;
extern volatile UBaseType_t uxTopReadyPriority;
extern volatile BaseType_t xSchedulerRunning;
extern volatile TickType_t xPendedTicks;
extern volatile BaseType_t xYieldPending;
extern volatile BaseType_t xNumOfOverflows;
extern UBaseType_t uxTaskNumber;
extern volatile TickType_t xNextTaskUnblockTime;
extern TaskHandle_t xIdleTaskHandle;
extern volatile UBaseType_t uxSchedulerSuspended;
/* =========================== GLOBAL VARIABLES =========================== */
static StaticTask_t xIdleTaskTCB;
static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
static TCB_t * ptcb;
static StackType_t stack[ ( ( size_t ) 300 ) * sizeof( StackType_t ) ];
static TCB_t tcb[ 10 ]; /* simulate up to 10 tasks: add more if needed */
static bool getIddleTaskMemoryValid = false;
static uint32_t critical_section_counter = 0;
static bool is_first_task = true;
static uint32_t created_tasks = 0;
static uint32_t create_task_priority = 3;
static port_yield_operation py_operation;
static bool vTaskDeletePre_called = false;
static bool getIddleTaskMemory_called = false;
static bool vApplicationTickHook_called = false;
static bool port_yield_called = false;
static bool port_enable_interrupts_called = false;
static bool port_disable_interrupts_called = false;
static bool port_yield_within_api_called = false;
static bool port_setup_tcb_called = false;
static bool portClear_Interrupt_called = false;
static bool portSet_Interrupt_called = false;
static bool portClear_Interrupt_from_isr_called = false;
static bool portSet_Interrupt_from_isr_called = false;
static bool port_invalid_interrupt_called = false;
static bool vApplicationStackOverflowHook_called = false;
static bool vApplicationIdleHook_called = false;
static bool port_allocate_secure_context_called = false;
static bool port_assert_if_in_isr_called = false;
static bool vApplicationMallocFailedHook_called = false;
/* =========================== Static Functions =========================== */
static void start_scheduler()
{
vListInitialiseItem_ExpectAnyArgs();
vListInitialiseItem_ExpectAnyArgs();
/* set owner */
listSET_LIST_ITEM_VALUE_ExpectAnyArgs();
/* set owner */
pxPortInitialiseStack_ExpectAnyArgsAndReturn( uxIdleTaskStack );
if( is_first_task )
{
is_first_task = false;
for( int i = ( UBaseType_t ) 0U; i < ( UBaseType_t ) configMAX_PRIORITIES; i++ )
{
vListInitialise_ExpectAnyArgs();
}
/* Delayed Task List 1 */
vListInitialise_ExpectAnyArgs();
/* Delayed Task List 2 */
vListInitialise_ExpectAnyArgs();
/* Pending Ready List */
vListInitialise_ExpectAnyArgs();
/* INCLUDE_vTaskDelete */
vListInitialise_ExpectAnyArgs();
/* INCLUDE_vTaskSuspend */
vListInitialise_ExpectAnyArgs();
}
listINSERT_END_ExpectAnyArgs();
xTimerCreateTimerTask_ExpectAndReturn( pdPASS );
xPortStartScheduler_ExpectAndReturn( pdTRUE );
getIddleTaskMemoryValid = true;
vTaskStartScheduler();
ASSERT_GET_IDLE_TASK_MEMORY_CALLED();
TEST_ASSERT_TRUE( xSchedulerRunning );
TEST_ASSERT_EQUAL( configINITIAL_TICK_COUNT, xTickCount );
TEST_ASSERT_EQUAL( portMAX_DELAY, xNextTaskUnblockTime );
}
static TaskHandle_t create_task()
{
TaskFunction_t pxTaskCode = NULL;
const char * const pcName = { __FUNCTION__ };
const uint32_t usStackDepth = 300;
void * const pvParameters = NULL;
UBaseType_t uxPriority = create_task_priority;
TaskHandle_t taskHandle;
BaseType_t ret;
pvPortMalloc_ExpectAndReturn( sizeof( TCB_t ), &tcb[ created_tasks ] );
pvPortMalloc_ExpectAndReturn( usStackDepth * sizeof( StackType_t ), stack );
vListInitialiseItem_Expect( &( tcb[ created_tasks ].xStateListItem ) );
vListInitialiseItem_Expect( &( tcb[ created_tasks ].xEventListItem ) );
/* TODO: expect set owner */
listSET_LIST_ITEM_VALUE_ExpectAnyArgs();
/* TODO: expect set owner */
pxPortInitialiseStack_ExpectAnyArgsAndReturn( stack );
if( is_first_task )
{
/* prvInitialiseTaskLists */
for( int i = ( UBaseType_t ) 0U; i < ( UBaseType_t ) configMAX_PRIORITIES; i++ )
{
vListInitialise_ExpectAnyArgs();
}
/* Delayed Task List 1 */
vListInitialise_ExpectAnyArgs();
/* Delayed Task List 2 */
vListInitialise_ExpectAnyArgs();
/* Pending Ready List */
vListInitialise_ExpectAnyArgs();
/* INCLUDE_vTaskDelete */
vListInitialise_ExpectAnyArgs();
/* INCLUDE_vTaskSuspend */
vListInitialise_ExpectAnyArgs();
is_first_task = false;
}
/* prvAddTaskToReadyList */
listINSERT_END_ExpectAnyArgs();
ret = xTaskCreate( pxTaskCode,
pcName,
usStackDepth,
pvParameters,
uxPriority,
&taskHandle );
TEST_ASSERT_EQUAL( pdPASS, ret );
ASSERT_SETUP_TCB_CALLED();
created_tasks++;
return taskHandle;
}
/* ============================ HOOK FUNCTIONS ============================ */
static void dummy_operation()
{
HOOK_DIAG();
}
void vFakePortAssertIfISR( void )
{
port_assert_if_in_isr_called = true;
HOOK_DIAG();
}
void port_allocate_secure_context( BaseType_t stackSize )
{
HOOK_DIAG();
port_allocate_secure_context_called = true;
}
void vApplicationIdleHook( void )
{
HOOK_DIAG();
vApplicationIdleHook_called = true;
}
void vApplicationMallocFailedHook( void )
{
vApplicationMallocFailedHook_called = true;
HOOK_DIAG();
}
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
StackType_t ** ppxIdleTaskStackBuffer,
uint32_t * pulIdleTaskStackSize )
{
HOOK_DIAG();
if( getIddleTaskMemoryValid == true )
{
/* Pass out a pointer to the StaticTask_t structure in which the Idle task's
* state will be stored. */
*ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
/* Pass out the array that will be used as the Idle task's stack. */
*ppxIdleTaskStackBuffer = uxIdleTaskStack;
/* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
* Note that, as the array is necessarily of type StackType_t,
* configMINIMAL_STACK_SIZE is specified in words, not bytes. */
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
}
else
{
*ppxIdleTaskTCBBuffer = NULL;
*ppxIdleTaskStackBuffer = NULL;
*pulIdleTaskStackSize = 0;
}
getIddleTaskMemory_called = true;
}
void vConfigureTimerForRunTimeStats( void )
{
HOOK_DIAG();
}
long unsigned int ulGetRunTimeCounterValue( void )
{
HOOK_DIAG();
return 3;
}
void vApplicationTickHook()
{
HOOK_DIAG();
vApplicationTickHook_called = true;
}
void vPortCurrentTaskDying( void * pvTaskToDelete,
volatile BaseType_t * pxPendYield )
{
HOOK_DIAG();
vTaskDeletePre_called = true;
}
void vFakePortEnterCriticalSection( void )
{
HOOK_DIAG();
critical_section_counter++;
}
void vFakePortExitCriticalSection( void )
{
HOOK_DIAG();
critical_section_counter--;
}
void vFakePortYieldWithinAPI()
{
HOOK_DIAG();
port_yield_within_api_called = true;
py_operation();
}
void vFakePortYieldFromISR()
{
HOOK_DIAG();
}
void vFakePortDisableInterrupts()
{
port_disable_interrupts_called = true;
HOOK_DIAG();
}
void vFakePortEnableInterrupts()
{
port_enable_interrupts_called = true;
HOOK_DIAG();
}
void vFakePortYield()
{
HOOK_DIAG();
port_yield_called = true;
py_operation();
}
void portSetupTCB_CB( void * tcb )
{
HOOK_DIAG();
port_setup_tcb_called = true;
}
void vFakePortClearInterruptMask( UBaseType_t bt )
{
HOOK_DIAG();
portClear_Interrupt_called = true;
}
UBaseType_t ulFakePortSetInterruptMask( void )
{
HOOK_DIAG();
portSet_Interrupt_called = true;
return 1;
}
void vFakePortClearInterruptMaskFromISR( UBaseType_t bt )
{
HOOK_DIAG();
portClear_Interrupt_from_isr_called = true;
}
UBaseType_t ulFakePortSetInterruptMaskFromISR( void )
{
HOOK_DIAG();
portSet_Interrupt_from_isr_called = true;
return 1;
}
void vFakePortAssertIfInterruptPriorityInvalid( void )
{
HOOK_DIAG();
port_invalid_interrupt_called = true;
}
void vApplicationStackOverflowHook( TaskHandle_t xTask,
char * stack )
{
HOOK_DIAG();
vApplicationStackOverflowHook_called = true;
}
/* ============================ Unity Fixtures ============================ */
/*! called before each testcase */
void setUp( void )
{
RESET_ALL_HOOKS();
pxCurrentTCB = NULL;
memset( &tcb, 0x00, sizeof( TCB_t ) );
ptcb = NULL;
memset( &pxReadyTasksLists, 0x00, configMAX_PRIORITIES * sizeof( List_t ) );
memset( &xDelayedTaskList1, 0x00, sizeof( List_t ) );
memset( &xDelayedTaskList2, 0x00, sizeof( List_t ) );
/*
* pxDelayedTaskList = NULL;
* pxOverflowDelayedTaskList = NULL;
*/
memset( &xPendingReadyList, 0x00, sizeof( List_t ) );
memset( &xTasksWaitingTermination, 0x00, sizeof( List_t ) );
uxDeletedTasksWaitingCleanUp = 0;
memset( &xSuspendedTaskList, 0x00, sizeof( List_t ) );
uxCurrentNumberOfTasks = ( UBaseType_t ) 0U;
xTickCount = ( TickType_t ) 500; /* configINITIAL_TICK_COUNT */
uxTopReadyPriority = tskIDLE_PRIORITY;
xSchedulerRunning = pdFALSE;
xPendedTicks = ( TickType_t ) 0U;
xYieldPending = pdFALSE;
xNumOfOverflows = ( BaseType_t ) 0;
uxTaskNumber = ( UBaseType_t ) 0U;
xNextTaskUnblockTime = ( TickType_t ) 0U;
xIdleTaskHandle = NULL;
uxSchedulerSuspended = ( UBaseType_t ) 0;
/* ulTaskSwitchedInTime = 0UL; */
/*ulTotalRunTime = 0UL; */
is_first_task = true;
created_tasks = 0;
py_operation = dummy_operation;
}
/*! called after each testcase */
void tearDown( void )
{
TEST_ASSERT_EQUAL( 0, critical_section_counter );
}
/*! 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 Cases ============================== */
/*!
* @brief create a static new task with a success path
*/
void test_xTaskCreateStatic_success( void )
{
StackType_t puxStackBuffer[ 300 ];
StaticTask_t * pxTaskBuffer = malloc( sizeof( TCB_t ) );
TaskFunction_t pxTaskCode = NULL;
const char * const pcName = { __FUNCTION__ };
const uint32_t ulStackDepth = 300;
void * const pvParameters = NULL;
UBaseType_t uxPriority = 3;
TaskHandle_t ret;
/* Setup */
memset( puxStackBuffer, 0xa5U, ulStackDepth * sizeof( StackType_t ) );
/* Expectations */
vListInitialiseItem_ExpectAnyArgs();
vListInitialiseItem_ExpectAnyArgs();
listSET_LIST_ITEM_VALUE_ExpectAnyArgs();
pxPortInitialiseStack_ExpectAnyArgsAndReturn( puxStackBuffer );
for( int i = ( UBaseType_t ) 0U; i < ( UBaseType_t ) configMAX_PRIORITIES; i++ )
{
vListInitialise_ExpectAnyArgs();
}
/* Delayed Task List 1 */
vListInitialise_ExpectAnyArgs();
/* Delayed Task List 2 */
vListInitialise_ExpectAnyArgs();
/* Pending Ready List */
vListInitialise_ExpectAnyArgs();
/* INCLUDE_vTaskDelete */
vListInitialise_ExpectAnyArgs();
/* INCLUDE_vTaskSuspend */
vListInitialise_ExpectAnyArgs();
listINSERT_END_ExpectAnyArgs();
/* API Call */
ret = xTaskCreateStatic( pxTaskCode,
pcName,
ulStackDepth,
pvParameters,
uxPriority,
puxStackBuffer,
pxTaskBuffer );
ptcb = ( TCB_t * ) pxTaskBuffer;
/* Validations */
TEST_ASSERT_EQUAL_PTR( puxStackBuffer, ptcb->pxStack );
TEST_ASSERT_NOT_EQUAL( NULL, ret );
TEST_ASSERT_EQUAL( 2, ptcb->ucStaticallyAllocated );
TEST_ASSERT_EQUAL( 0,
memcmp( ptcb->pxStack,
puxStackBuffer,
ulStackDepth * sizeof( StackType_t ) ) );
TEST_ASSERT_EQUAL( ptcb->pxEndOfStack,
ptcb->pxStack + ( 300 - 1 ) );
TEST_ASSERT_EQUAL( 0, memcmp( ptcb->pcTaskName, pcName, configMAX_TASK_NAME_LEN - 1 ) );
TEST_ASSERT_EQUAL( ptcb->uxPriority, uxPriority );
TEST_ASSERT_EQUAL( 1, uxCurrentNumberOfTasks );
ASSERT_SETUP_TCB_CALLED();
free( pxTaskBuffer );
}
void test_xTaskCreate_success( void )
{
TaskFunction_t pxTaskCode = NULL;
const char * const pcName = NULL;
const uint32_t usStackDepth = 300;
void * const pvParameters = NULL;
UBaseType_t uxPriority = configMAX_PRIORITIES;
TaskHandle_t taskHandle;
BaseType_t ret;
StackType_t stack[ ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ];
/* Setup */
/* Expectations */
pvPortMalloc_ExpectAndReturn( sizeof( TCB_t ), &tcb[ 0 ] );
pvPortMalloc_ExpectAndReturn( usStackDepth * sizeof( StackType_t ), stack );
vListInitialiseItem_Expect( &( tcb[ 0 ].xStateListItem ) );
vListInitialiseItem_Expect( &( tcb[ 0 ].xEventListItem ) );
listSET_LIST_ITEM_VALUE_ExpectAnyArgs();
pxPortInitialiseStack_ExpectAnyArgsAndReturn( stack );
for( int i = ( UBaseType_t ) 0U; i < ( UBaseType_t ) configMAX_PRIORITIES; i++ )
{
vListInitialise_ExpectAnyArgs();
}
/* Delayed Task List 1 */
vListInitialise_ExpectAnyArgs();
/* Delayed Task List 2 */
vListInitialise_ExpectAnyArgs();
/* Pending Ready List */
vListInitialise_ExpectAnyArgs();
/* INCLUDE_vTaskDelete */
vListInitialise_ExpectAnyArgs();
/* INCLUDE_vTaskSuspend */
vListInitialise_ExpectAnyArgs();
listINSERT_END_ExpectAnyArgs();
/* API Call */
ret = xTaskCreate( pxTaskCode,
pcName,
usStackDepth,
pvParameters,
uxPriority,
&taskHandle );
/* Validations */
ptcb = ( TCB_t * ) taskHandle;
TEST_ASSERT_EQUAL( pdPASS, ret );
TEST_ASSERT_EQUAL( 0, tcb[ 0 ].ucStaticallyAllocated );
TEST_ASSERT_EQUAL_PTR( &tcb[ 0 ], ptcb );
TEST_ASSERT_EQUAL( stack, tcb[ 0 ].pxStack );
TEST_ASSERT_EQUAL( 1, uxCurrentNumberOfTasks );
TEST_ASSERT_EQUAL( configMAX_PRIORITIES - 1, ptcb->uxPriority );
TEST_ASSERT_EQUAL( NULL, ptcb->pcTaskName[ 0 ] );
ASSERT_SETUP_TCB_CALLED();
}
void test_xTaskCreate_fail_stack_malloc( void )
{
TaskFunction_t pxTaskCode = NULL;
const char * const pcName = { __FUNCTION__ };
const uint32_t usStackDepth = 300;
void * const pvParameters = NULL;
UBaseType_t uxPriority = 3;
TaskHandle_t taskHandle;
BaseType_t ret;
pvPortMalloc_ExpectAndReturn( sizeof( TCB_t ), NULL );
ret = xTaskCreate( pxTaskCode,
pcName,
usStackDepth,
pvParameters,
uxPriority,
&taskHandle );
TEST_ASSERT_EQUAL( errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY, ret );
TEST_ASSERT_EQUAL( 0, uxCurrentNumberOfTasks );
ASSERT_SETUP_TCB_NOT_CALLED();
}
void test_xTaskCreate_fail_tcb_malloc( void )
{
TaskFunction_t pxTaskCode = NULL;
const char * const pcName = { __FUNCTION__ };
const uint32_t usStackDepth = 300;
void * const pvParameters = NULL;
UBaseType_t uxPriority = 3;
TaskHandle_t taskHandle;
BaseType_t ret;
pvPortMalloc_ExpectAndReturn( sizeof( TCB_t ), &tcb[ 0 ] );
pvPortMalloc_ExpectAndReturn( usStackDepth * sizeof( StackType_t ), NULL );
vPortFree_Expect( &tcb[ 0 ] );
ret = xTaskCreate( pxTaskCode,
pcName,
usStackDepth,
pvParameters,
uxPriority,
&taskHandle );
TEST_ASSERT_EQUAL( errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY, ret );
TEST_ASSERT_EQUAL( 0, uxCurrentNumberOfTasks );
ASSERT_SETUP_TCB_NOT_CALLED();
}
void test_vTaskPrioritySet_success_gt_curr_prio( void )
{
TaskHandle_t taskHandle2;
TCB_t * ptcb;
create_task_priority = 3;
create_task();
create_task_priority = 4;
taskHandle2 = create_task();
ptcb = ( TCB_t * ) taskHandle2;
TEST_ASSERT_EQUAL_PTR( pxCurrentTCB, taskHandle2 );
listGET_LIST_ITEM_VALUE_ExpectAnyArgsAndReturn( 0 );
listSET_LIST_ITEM_VALUE_Expect( &( ptcb->xEventListItem ),
configMAX_PRIORITIES - 5 );
listIS_CONTAINED_WITHIN_ExpectAndReturn( &pxReadyTasksLists[ 5 ],
&( ptcb->xStateListItem ),
pdTRUE );
uxListRemove_ExpectAndReturn( &( ptcb->xStateListItem ), 0 );
/* port Reset ready priority */
/* add task to ready list macro */
listINSERT_END_Expect( &( pxReadyTasksLists[ 5 ] ),
&( ptcb->xStateListItem ) );
TEST_ASSERT_EQUAL( 4, ptcb->uxPriority );
vTaskPrioritySet( taskHandle2, create_task_priority + 1 );
TEST_ASSERT_EQUAL( 4 + 1, ptcb->uxPriority );
ASSERT_PORT_YIELD_NOT_CALLED();
}
/* ----------------- testing portCRITICAL_NESTING_IN_TCB ------------------- */
void vTaskEnterCritical( void );
void vTaskExitCritical( void );
void test_vTaskExitCritical_succes( void )
{
TaskHandle_t task_handle;
/* Setup */
task_handle = create_task();
start_scheduler();
/* Expectations */
/* API Call */
vTaskExitCritical();
/* Validations */
TEST_ASSERT_EQUAL( 0, task_handle->uxCriticalNesting );
ASSERT_PORT_ENABLE_INTERRUPT_NOT_CALLED();
}
void test_vTaskExitCritical_success_enable_interrupts( void )
{
TaskHandle_t task_handle;
/* Setup */
task_handle = create_task();
start_scheduler();
vTaskEnterCritical();
ASSERT_IF_IN_ISR_CALLED();
/* Expectations */
/* API Call */
vTaskExitCritical();
/* Validations */
TEST_ASSERT_EQUAL( 0, task_handle->uxCriticalNesting );
ASSERT_PORT_ENABLE_INTERRUPT_CALLED();
}
void test_vTaskExitCritical_success_enable_too_many_nests( void )
{
TaskHandle_t task_handle;
/* Setup */
task_handle = create_task();
start_scheduler();
vTaskEnterCritical();
ASSERT_IF_IN_ISR_CALLED();
vTaskEnterCritical();
/* Expectations */
/* API Call */
vTaskExitCritical();
/* Validations */
TEST_ASSERT_EQUAL( 1, task_handle->uxCriticalNesting );
ASSERT_PORT_ENABLE_INTERRUPT_NOT_CALLED();
}
void test_vTaskExitCritical_scheduler_off( void )
{
TaskHandle_t task_handle;
/* Setup */
task_handle = create_task();
/* Expectations */
/* API Call */
vTaskExitCritical();
/* Validations */
TEST_ASSERT_EQUAL( 0, task_handle->uxCriticalNesting );
ASSERT_PORT_ENABLE_INTERRUPT_NOT_CALLED();
}
void test_vTaskEnterCritical_succes( void )
{
TaskHandle_t task_handle;
/* Setup */
task_handle = create_task();
start_scheduler();
/* Expectations */
/* API Call */
vTaskEnterCritical();
/* Validations */
TEST_ASSERT_EQUAL( 1, task_handle->uxCriticalNesting );
ASSERT_IF_IN_ISR_CALLED();
}
void test_vTaskEnterCritical_succes_twice( void )
{
TaskHandle_t task_handle;
/* Setup */
task_handle = create_task();
start_scheduler();
/* Expectations */
/* API Call */
vTaskEnterCritical();
ASSERT_IF_IN_ISR_CALLED();
vTaskEnterCritical();
/* Validations */
TEST_ASSERT_EQUAL( 2, task_handle->uxCriticalNesting );
ASSERT_IF_IN_ISR_NOT_CALLED();
}
void test_vTaskEnterCritical_no_op_no_sched( void )
{
TaskHandle_t task_handle;
/* Setup */
task_handle = create_task();
/* Expectations */
/* API Call */
vTaskEnterCritical();
/* Validations */
TEST_ASSERT_EQUAL( 0, task_handle->uxCriticalNesting );
ASSERT_IF_IN_ISR_NOT_CALLED();
}