Add queue.c CMock unit test (#552)

* Disregard coverage data without a function_name field set

* Fix calling make on subdirectories

* Undefine FORTIFY_SOURCE when running without ENABLE_SANITIZERS

* Add queue and semaphore unit tests

* Update FreeRTOS-Kernel submodule revision
This commit is contained in:
Paul Bartell 2021-04-20 15:45:52 -07:00 committed by GitHub
parent 53af0ec62e
commit 7a695784bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
60 changed files with 13147 additions and 135 deletions

@ -1 +1 @@
Subproject commit 99295c9ae8f40a1be7fd23de9171f820b6a42db6
Subproject commit 71f5af4e0f8d5fad2c4d83c43aa6748eb6cfaaf9

View file

@ -8,7 +8,7 @@ export LD ?= /usr/local/bin/ld
# Add units here when adding a new unit test directory with the same name
UNITS += list
#UNITS += queue
UNITS += queue
#UNITS += timers
UNITS += stream_buffer
UNITS += message_buffer
@ -111,8 +111,7 @@ $(COVINFO) : $(LCOV_LIST)
# Generate lcov for each suite
$(LCOV_LIST) : zero_coverage
$(foreach unit,$(UNITS),\
make -C $(unit) lcov;)
make -C $(subst .info,,$(@F)) lcov
lcovhtml : $(COVINFO)
mkdir -p $(COVERAGE_DIR)

View file

@ -126,7 +126,7 @@ void vConfigureTimerForRunTimeStats( void ); /* Prototype of function that in
{ \
vFakeAssert( false, __FILE__, __LINE__ ); \
} \
} while ( 0 );
} while ( 0 )
#define mtCOVERAGE_TEST_MARKER() __asm volatile ( "NOP" )

View file

@ -41,11 +41,13 @@ CPPFLAGS :=
# Compiler flags
CFLAGS := $(INCLUDE_DIR) -O0 -ggdb -pthread --std=c99 -Werror -Wall
CFLAGS += -fstack-protector-all
CFLAGS += -Wformat -Werror=format-security -Werror=array-bounds
CFLAGS += -D_FORTIFY_SOURCE=2
ifeq ($(ENABLE_SANITIZER),1)
CFLAGS += -fstack-protector-all
CFLAGS += -Wformat -Werror=format-security -Werror=array-bounds
CFLAGS += -D_FORTIFY_SOURCE=2
CFLAGS += -fsanitize=address,undefined -fsanitize-recover=address
else
CFLAGS += -U_FORTIFY_SOURCE
endif
# Linker flags

View file

@ -5,7 +5,12 @@ MAKEFILE_ABSPATH := $(abspath $(lastword $(MAKEFILE_LIST)))
include ../makefile.in
# SUITES lists the suites contained in subdirectories of this directory
SUITES += two_tests
SUITES += generic
SUITES += dynamic
SUITES += static
SUITES += semaphore
SUITES += sets
SUITES += tracing
# PROJECT and SUITE variables are determined based on path like so:
# $(UT_ROOT_DIR)/$(PROJECT)/$(SUITE)

View file

@ -0,0 +1,141 @@
/*
* FreeRTOS V202012.00
* 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
#include "fake_assert.h"
/*-----------------------------------------------------------
* 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_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 0
#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 0
#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 ( 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 1
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats()
#define portGET_RUN_TIME_COUNTER_VALUE() ulGetRunTimeCounterValue()
/* Co-routine related configuration options. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* 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 1
/* 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 1
#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 ) \
do \
{ \
if( x ) \
{ \
vFakeAssert( true, __FILE__, __LINE__ ); \
} \
else \
{ \
vFakeAssert( false, __FILE__, __LINE__ ); \
} \
} while ( 0 )
#define mtCOVERAGE_TEST_MARKER() __asm volatile ( "NOP" )
#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0
#if ( configINCLUDE_MESSAGE_BUFFER_AMP_DEMO == 1 )
extern void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer );
#define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )
#endif /* configINCLUDE_MESSAGE_BUFFER_AMP_DEMO */
#endif /* FREERTOS_CONFIG_H */

View file

@ -0,0 +1,48 @@
# Indent with spaces
.RECIPEPREFIX := $(.RECIPEPREFIX) $(.RECIPEPREFIX)
# Do not move this line below the include
MAKEFILE_ABSPATH := $(abspath $(lastword $(MAKEFILE_LIST)))
include ../../makefile.in
# PROJECT_SRC lists the .c files under test
PROJECT_SRC += queue.c
# PROJECT_DEPS_SRC list the .c file that are dependencies of PROJECT_SRC files
# Files in PROJECT_DEPS_SRC are excluded from coverage measurements
PROJECT_DEPS_SRC += list.c
# PROJECT_HEADER_DEPS: headers that should be excluded from coverage measurements.
PROJECT_HEADER_DEPS += FreeRTOS.h
# SUITE_UT_SRC: .c files that contain test cases (must end in _utest.c)
SUITE_UT_SRC += queue_create_dynamic_utest.c
SUITE_UT_SRC += queue_delete_dynamic_utest.c
# SUITE_SUPPORT_SRC: .c files used for testing that do not contain test cases.
# Paths are relative to PROJECT_DIR
SUITE_SUPPORT_SRC += queue_utest_common.c
SUITE_SUPPORT_SRC += td_task.c
SUITE_SUPPORT_SRC += td_port.c
# List the headers used by PROJECT_SRC that you would like to mock
MOCK_FILES_FP += $(KERNEL_DIR)/include/task.h
MOCK_FILES_FP += $(UT_ROOT_DIR)/config/fake_assert.h
MOCK_FILES_FP += $(UT_ROOT_DIR)/config/fake_port.h
# List any addiitonal flags needed by the preprocessor
CPPFLAGS += -DportUSING_MPU_WRAPPERS=0
# List any addiitonal flags needed by the compiler
CFLAGS +=
# Try not to edit beyond this line unless necessary.
# Project / Suite are determined based on path: $(UT_ROOT_DIR)/$(PROJECT)/$(SUITE)
PROJECT := $(lastword $(subst /, ,$(dir $(abspath $(MAKEFILE_ABSPATH)/../))))
SUITE := $(lastword $(subst /, ,$(dir $(MAKEFILE_ABSPATH))))
# Make variables available to included makefile
export
include ../../testdir.mk

View file

@ -0,0 +1 @@
../generic/queue_create_dynamic_utest.c

View file

@ -0,0 +1 @@
../generic/queue_delete_dynamic_utest.c

View file

@ -0,0 +1,140 @@
/*
* FreeRTOS V202012.00
* 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
#include "fake_assert.h"
/*-----------------------------------------------------------
* 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_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 0
#define configUSE_RECURSIVE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 0
#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 0
#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 1
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats()
#define portGET_RUN_TIME_COUNTER_VALUE() ulGetRunTimeCounterValue()
/* Co-routine related configuration options. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* 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 1
/* 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 1
#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 ) \
do \
{ \
if( x ) \
{ \
vFakeAssert( true, __FILE__, __LINE__ ); \
} \
else \
{ \
vFakeAssert( false, __FILE__, __LINE__ ); \
} \
} while ( 0 )
#define mtCOVERAGE_TEST_MARKER() __asm volatile ( "NOP" )
#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0
#if ( configINCLUDE_MESSAGE_BUFFER_AMP_DEMO == 1 )
extern void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer );
#define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )
#endif /* configINCLUDE_MESSAGE_BUFFER_AMP_DEMO */
#endif /* FREERTOS_CONFIG_H */

View file

@ -0,0 +1,56 @@
# Indent with spaces
.RECIPEPREFIX := $(.RECIPEPREFIX) $(.RECIPEPREFIX)
# Do not move this line below the include
MAKEFILE_ABSPATH := $(abspath $(lastword $(MAKEFILE_LIST)))
include ../../makefile.in
# PROJECT_SRC lists the .c files under test
PROJECT_SRC += queue.c
# PROJECT_DEPS_SRC list the .c file that are dependencies of PROJECT_SRC files
# Files in PROJECT_DEPS_SRC are excluded from coverage measurements
PROJECT_DEPS_SRC += list.c
# PROJECT_HEADER_DEPS: headers that should be excluded from coverage measurements.
PROJECT_HEADER_DEPS += FreeRTOS.h
# SUITE_UT_SRC: .c files that contain test cases (must end in _utest.c)
SUITE_UT_SRC += queue_create_dynamic_utest.c
SUITE_UT_SRC += queue_create_static_utest.c
SUITE_UT_SRC += queue_delete_dynamic_utest.c
SUITE_UT_SRC += queue_delete_static_utest.c
SUITE_UT_SRC += queue_reset_utest.c
SUITE_UT_SRC += queue_receive_nonblocking_utest.c
SUITE_UT_SRC += queue_receive_blocking_utest.c
SUITE_UT_SRC += queue_send_nonblocking_utest.c
SUITE_UT_SRC += queue_send_blocking_utest.c
SUITE_UT_SRC += queue_status_utest.c
# SUITE_SUPPORT_SRC: .c files used for testing that do not contain test cases.
# Paths are relative to PROJECT_DIR
SUITE_SUPPORT_SRC += queue_utest_common.c
SUITE_SUPPORT_SRC += td_task.c
SUITE_SUPPORT_SRC += td_port.c
# List the headers used by PROJECT_SRC that you would like to mock
MOCK_FILES_FP += $(KERNEL_DIR)/include/task.h
MOCK_FILES_FP += $(UT_ROOT_DIR)/config/fake_assert.h
MOCK_FILES_FP += $(UT_ROOT_DIR)/config/fake_port.h
# List any addiitonal flags needed by the preprocessor
CPPFLAGS += -DportUSING_MPU_WRAPPERS=0
# List any addiitonal flags needed by the compiler
CFLAGS += -O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-exceptions
# Try not to edit beyond this line unless necessary.
# Project / Suite are determined based on path: $(UT_ROOT_DIR)/$(PROJECT)/$(SUITE)
PROJECT := $(lastword $(subst /, ,$(dir $(abspath $(MAKEFILE_ABSPATH)/../))))
SUITE := $(lastword $(subst /, ,$(dir $(MAKEFILE_ABSPATH))))
# Make variables available to included makefile
export
include ../../testdir.mk

View file

@ -0,0 +1,324 @@
/*
* FreeRTOS V202012.00
* 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 queue_create_dynamic_utest.c */
/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "../queue_utest_common.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "queue.h"
/* ============================ GLOBAL VARIABLES =========================== */
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* ========================== Helper functions =========================== */
static void test_long_queue( QueueHandle_t xQueue,
uint32_t maxItems )
{
/* Veify that queue is empty */
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
queue_common_add_sequential_to_queue( xQueue, maxItems );
/* Veify that queue is full */
TEST_ASSERT_EQUAL( 0, uxQueueSpacesAvailable( xQueue ) );
queue_common_receive_sequential_from_queue( xQueue, maxItems, maxItems, 0 );
/* Veify that queue is empty */
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
}
/* ========================== Test Cases =========================== */
/**
* @brief Test xQueueCreate when calls to malloc fail
* @coverage xQueueGenericCreate
*/
void test_macro_xQueueCreate_malloc_fail( void )
{
UnityMalloc_MakeMallocFailAfterCount( 0 );
QueueHandle_t xQueue = INVALID_PTR;
xQueue = xQueueCreate( 1, 1 );
TEST_ASSERT_EQUAL( NULL, xQueue );
}
/**
* @brief Test xQueueCreate with uxQueueLength=0, uxItemSize=0
* @details This is an invalid queue configuration and causes a failed configASSERT.
* @coverage xQueueGenericCreate
*/
void test_macro_xQueueCreate_zeroQueueLength_zeroItemSize()
{
/* Expect that xQueueCreate will assert because a length of 0 is invalid */
fakeAssertExpectFail();
QueueHandle_t xQueue = xQueueCreate( 0, 0 );
/* validate returned queue handle */
TEST_ASSERT_NOT_EQUAL( NULL, xQueue );
/* verify that configASSERT was called */
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Veify that queue is empty */
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
/* Veify that queue is also full */
TEST_ASSERT_EQUAL( 0, uxQueueSpacesAvailable( xQueue ) );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueCreate with uxQueueLength=0, uxItemSize=1
* @details This is an invalid queue configuration and causes a failed configASSERT.
* @coverage xQueueGenericCreate
*/
void test_macro_xQueueCreate_zeroQueueLength_oneItemSize( void )
{
/* Expect that xQueueCreate will assert because a length of 0 is invalid */
fakeAssertExpectFail();
QueueHandle_t xQueue = xQueueCreate( 0, 1 );
/* validate returned queue handle */
TEST_ASSERT_NOT_EQUAL( NULL, xQueue );
/* verify that configASSERT was called */
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Veify that new queue is empty */
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
/* Valdiate that the queue is full */
TEST_ASSERT_EQUAL( 0, uxQueueSpacesAvailable( xQueue ) );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueCreate with uxQueueLength=1, uxItemSize=0
* @details This configuration is equivalent to a binary semaphore.
* @coverage xQueueGenericCreate
*/
void test_macro_xQueueCreate_oneItem_zeroLength( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, 0 );
/* validate returned queue handle */
TEST_ASSERT_NOT_EQUAL( NULL, xQueue );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Veify that new queue is empty */
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
/* Valdiate that the queue has 1 space remaining */
TEST_ASSERT_EQUAL( 1, uxQueueSpacesAvailable( xQueue ) );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueCreate with uxQueueLength=1, uxItemSize=1
* @details This configuration is equivalent to a 1 byte mailbox.
* @coverage xQueueGenericCreate
*/
void test_macro_xQueueCreate_oneItem_oneLength( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, 1 );
/* validate returned queue handle */
TEST_ASSERT_NOT_EQUAL( NULL, xQueue );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE + 1, getLastMallocSize() );
/* Veify that new queue is empty */
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
uint8_t testval = ( uint8_t ) getNextMonotonicTestValue();
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, &testval, 0 ) );
/* Veify that queue is full */
TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( 0, uxQueueSpacesAvailable( xQueue ) );
uint8_t testVal2 = 0xFF;
/* Receive from the queue */
TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueue, &testVal2, 0 ) );
TEST_ASSERT_EQUAL( testval, testVal2 );
/* Veify that queue is empty */
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( 1, uxQueueSpacesAvailable( xQueue ) );
vQueueDelete( xQueue );
}
/*!
* @brief Test xQueueCreate with uxQueueLength=1, uxItemSize=[2,16]
* @details End to end test with varied mailbox sizes from 2 to 16 bytes.
* @coverage xQueueGenericCreate
*/
void test_macro_xQueueCreate_oneItem_multiLength( void )
{
uint8_t testVal[ MAX_MULTI_LEN ];
/* Generate test pattern to send to the queue (re-used for each iteration) */
for( int i = 0; i < MAX_MULTI_LEN; i++ )
{
testVal[ i ] = ( uint8_t ) getNextMonotonicTestValue();
}
for( uint8_t i = 2; i <= MAX_MULTI_LEN; i++ )
{
QueueHandle_t xQueue = xQueueCreate( 1, i );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE + i, getLastMallocSize() );
/* Veify that queue is empty */
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
/* Mask off the bytes we won't use */
uint8_t testValCompare[ MAX_MULTI_LEN ];
for( int j = 0; j < MAX_MULTI_LEN; j++ )
{
if( j < i )
{
testValCompare[ j ] = testVal[ j ];
}
else
{
testValCompare[ j ] = 0xFF;
}
}
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, &testVal, 0 ) );
/* Veify that queue is also full */
TEST_ASSERT_EQUAL( 0, uxQueueSpacesAvailable( xQueue ) );
uint8_t testValCheck[ MAX_MULTI_LEN ];
memset( testValCheck, 0xFF, MAX_MULTI_LEN );
/* Receive from the queue */
TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueue, &testValCheck, 0 ) );
TEST_ASSERT_EQUAL_MEMORY( testValCompare, testValCheck, MAX_MULTI_LEN );
/* Veify that queue is empty */
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
vQueueDelete( xQueue );
}
}
/*!
* @brief xQueueCreate with a large queue.
* @coverage xQueueCreate
*/
void test_LargeQueueRunThrough( void )
{
QueueHandle_t xQueue = xQueueCreate( MAX_QUEUE_ITEMS, sizeof( uint32_t ) );
test_long_queue( xQueue, MAX_QUEUE_ITEMS );
vQueueDelete( xQueue );
}
/**
* @brief xQueueCreate where uxQueueLength * uxItemSize results in integer overflow
* @details In this test case xQueueSizeInBytes > MAX(size_t), but individually
* uxQueueLength and uxItemSize are each less than MAX(size_t).
* @coverage xQueueGenericCreate
*/
void test_macro_xQueueCreate_multiplication_overflow( void )
{
/* Calculate a test value = 2^( sizeof(size_t) * 8 bits / 2)
* For a 64 bit size_t, this is 2^(8*8/2) = 2^(32) */
size_t factor = 1ULL << ( sizeof( size_t ) * 4 );
EXPECT_ASSERT_BREAK( xQueueCreate( factor, factor ) );
}
/*!
* @brief xQueueCreate where adding xQueueSizeInBytes and sizeof(StaticQueue_t)
* results in integer overflow.
* @details This test case satisfies the following constraints given that:
* xQueueSizeInBytes = (uxQueueLength * uxItemSize),
* xQueueSizeInBytes <= MAX(size_t) and
* ( xQueueSizeInBytes + sizeof(StaticQueue_t) ) > MAX(size_t)
* @coverage xQueueGenericCreate
*/
void test_macro_xQueueCreate_addiiton_overflow( void )
{
/* Based on the formula:
* ( 2^x - 1 ) == ( 2^( x/2 ) + 1 ) * ( 2^( x/2 ) - 1 ) */
size_t powTwo = 1ULL << ( sizeof( size_t ) * 4 );
size_t factorA = powTwo - 1;
size_t factorB = powTwo + 1;
EXPECT_ASSERT_BREAK( xQueueCreate( factorA, factorB ) );
}

View file

@ -0,0 +1,232 @@
/*
* FreeRTOS V202012.00
* 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 queue_create_static_utest.c */
/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "../queue_utest_common.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "queue.h"
/* ============================ GLOBAL VARIABLES =========================== */
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* ========================== Helper functions =========================== */
static void test_long_queue( QueueHandle_t xQueue,
uint32_t maxItems )
{
/* Veify that queue is empty */
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
queue_common_add_sequential_to_queue( xQueue, maxItems );
/* Veify that queue is full */
TEST_ASSERT_EQUAL( 0, uxQueueSpacesAvailable( xQueue ) );
queue_common_receive_sequential_from_queue( xQueue, maxItems, maxItems, 0 );
/* Veify that queue is empty */
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
}
/* ========================== Test Cases =========================== */
/**
* @brief xQueueCreateStatic with a NULL pointer for queueStorage
* @coverage xQueueGenericCreateStatic
*/
void test_macro_xQueueCreateStatic_null_QueueStorage_fail( void )
{
/* Expect that xQueueCreate will assert */
fakeAssertExpectFail();
StaticQueue_t queueBuffer;
QueueHandle_t xQueue = xQueueCreateStatic( MAX_QUEUE_ITEMS, sizeof( uint32_t ), NULL, &queueBuffer );
/* Validate the queue handle */
TEST_ASSERT_EQUAL( &queueBuffer, xQueue );
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
}
/**
* @brief xQueueCreateStatic with a NULL pointer for queueBuffer
* @coverage xQueueGenericCreateStatic
*/
void test_macro_xQueueCreateStatic_null_queueBuffer_fail( void )
{
/* Expect that xQueueCreate will assert */
fakeAssertExpectFail();
uint32_t queueStorage[ MAX_QUEUE_ITEMS ];
QueueHandle_t xQueue = INVALID_PTR;
xQueue = xQueueCreateStatic( MAX_QUEUE_ITEMS, sizeof( uint32_t ), ( void * ) queueStorage, NULL );
/* Validate that the queue handle is NULL */
TEST_ASSERT_EQUAL( NULL, xQueue );
/* Check that configASSERT was called */
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
}
/**
* @brief Test xQueueCreateStatic with a NULL buffer, uxQueueLength=1, uxItemSize=0
* @details This configuration is equivalent to a binary semaphore.
* @coverage xQueueGenericCreateStatic
*/
void test_macro_xQueueCreateStatic_nullQueueStorage_oneItem_zeroLength( void )
{
StaticQueue_t queueBuffer;
QueueHandle_t xQueue = xQueueCreateStatic( 1, 0, NULL, &queueBuffer );
/* validate returned queue handle */
TEST_ASSERT_NOT_EQUAL( NULL, xQueue );
/* Veify that new queue is empty */
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
/* Valdiate that the queue has 1 space remaining */
TEST_ASSERT_EQUAL( 1, uxQueueSpacesAvailable( xQueue ) );
/* Send a test value */
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, NULL, 0 ) );
/* Test receive */
TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueue, NULL, 0 ) );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueCreateStatic with uxQueueLength=0, uxItemSize=0
* @details This configuration is invalid and causes a configASSERT.
* @coverage xQueueGenericCreateStatic
*/
void test_macro_xQueueCreateStatic_validQueueStorage_zeroItem_zeroLength( void )
{
StaticQueue_t queueBuffer;
/* Expect that xQueueCreateStatic will assert becasue a zero length queue is invalid */
fakeAssertExpectFail();
QueueHandle_t xQueue = xQueueCreateStatic( 0, 0, NULL, &queueBuffer );
/* verify that configASSERT was called */
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
/* validate returned queue handle */
TEST_ASSERT_NOT_EQUAL( NULL, xQueue );
/* Veify that new queue is empty */
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
/* Valdiate that the queue has 0 space remaining */
TEST_ASSERT_EQUAL( 0, uxQueueSpacesAvailable( xQueue ) );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueCreateStatic with a valid buffer, uxQueueLength=1, uxItemSize=0
* @details This configuration is equivalent to a binary semaphore.
* @coverage xQueueGenericCreateStatic
*/
void test_macro_xQueueCreateStatic_validQueueStorage_oneItem_zeroLength( void )
{
StaticQueue_t queueBuffer;
uint32_t queueData;
/* Expect that xQueueCreateStatic will assert because data storage is not
* necessary for a zero itemLength queue */
fakeAssertExpectFail();
QueueHandle_t xQueue = xQueueCreateStatic( 1, 0, ( void * ) &queueData, &queueBuffer );
/* verify that configASSERT was called */
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
/* validate returned queue handle */
TEST_ASSERT_NOT_EQUAL( NULL, xQueue );
/* Veify that new queue is empty */
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
/* Valdiate that the queue has 1 space remaining */
TEST_ASSERT_EQUAL( 1, uxQueueSpacesAvailable( xQueue ) );
/* Send a test value */
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, NULL, 0 ) );
/* Test receive */
TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueue, NULL, 0 ) );
vQueueDelete( xQueue );
}
/**
* @brief xQueueCreateStatic with a large queue.
* @coverage xQueueGenericCreateStatic
*/
void test_macro_xQueueCreateStatic_large( void )
{
uint32_t queueStorage[ MAX_QUEUE_ITEMS ];
StaticQueue_t queueBuffer;
QueueHandle_t xQueue = xQueueCreateStatic( MAX_QUEUE_ITEMS, sizeof( uint32_t ), ( void * ) queueStorage, &queueBuffer );
test_long_queue( xQueue, MAX_QUEUE_ITEMS );
vQueueDelete( xQueue );
}

View file

@ -0,0 +1,131 @@
/*
* FreeRTOS V202012.00
* 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 queue_delete_dynamic_utest.c */
/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "../queue_utest_common.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "queue.h"
#include "mock_fake_port.h"
/* ============================ GLOBAL VARIABLES =========================== */
/* =========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* =========================== Helper functions ============================ */
/* ============================== Test Cases =============================== */
/**
* @brief Test vQueueDelete with an invalid QueueHandle
* @coverage vQueueDelete
*/
void test_vQueueDelete_invalid_handle( void )
{
EXPECT_ASSERT_BREAK( vQueueDelete( NULL ) );
}
/**
* @brief Test vQueueDelete with a statically allocated queue of size 6 x 4 bytes
* @coverage vQueueDelete
*/
void test_vQueueDelete_empty( void )
{
QueueHandle_t xQueue = xQueueCreate( 6, sizeof( uint32_t ) );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE + ( 6 * 4 ), getLastMallocSize() );
vQueueDelete( xQueue );
TEST_ASSERT_EQUAL_PTR( ( void * ) xQueue, getLastFreedAddress() );
}
/**
* @brief Test vQueueDelete with a half-full queue of size 6 x 4 bytes
* @coverage vQueueDelete
*/
void test_vQueueDelete_half_full( void )
{
QueueHandle_t xQueue = xQueueCreate( 6, sizeof( uint32_t ) );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE + ( 6 * 4 ), getLastMallocSize() );
for( uint32_t i = 0; i < 3; i++ )
{
xQueueSend( xQueue, &i, 0 );
}
vQueueDelete( xQueue );
TEST_ASSERT_EQUAL_PTR( ( void * ) xQueue, getLastFreedAddress() );
}
/**
* @brief Test vQueueDelete with a full queue of size 6 x 4 bytes
* @coverage vQueueDelete
*/
void test_vQueueDelete_full( void )
{
QueueHandle_t xQueue = xQueueCreate( 6, sizeof( uint32_t ) );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE + ( 6 * 4 ), getLastMallocSize() );
for( uint32_t i = 0; i < 6; i++ )
{
xQueueSend( xQueue, &i, 0 );
}
vQueueDelete( xQueue );
TEST_ASSERT_EQUAL_PTR( ( void * ) xQueue, getLastFreedAddress() );
}

View file

@ -0,0 +1,151 @@
/*
* FreeRTOS V202012.00
* 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 queue_delete_static_utest.c */
/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "../queue_utest_common.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "queue.h"
#include "mock_fake_port.h"
/* ============================ GLOBAL VARIABLES =========================== */
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* ========================== Helper functions =========================== */
/* ============================= Test Cases ============================== */
/**
* @brief Test vQueueDelete with an invalid QueueHandle
* @coverage vQueueDelete
*/
void test_vQueueDelete_invalid_handle( void )
{
EXPECT_ASSERT_BREAK( vQueueDelete( NULL ) );
}
/**
* @brief Test vQueueDelete with a statically allocated queue of size 6 x 4 bytes
* @coverage vQueueDelete
*/
void test_vQueueDelete_empty( void )
{
void * queueBuffer = malloc( sizeof( StaticQueue_t ) );
void * queueData = malloc( 6 * sizeof( uint32_t ) );
QueueHandle_t xQueue = xQueueCreateStatic( 6, sizeof( uint32_t ), queueData, queueBuffer );
/* Verify that no call to malloc occured */
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
vQueueDelete( xQueue );
/* Veirfy that free was not called */
TEST_ASSERT_EQUAL_PTR( NULL, getLastFreedAddress() );
free( queueBuffer );
free( queueData );
}
/**
* @brief Test vQueueDelete with a half-full queue of size 6 x 4 bytes
* @coverage vQueueDelete
*/
void test_vQueueDelete_half_full( void )
{
void * queueBuffer = malloc( sizeof( StaticQueue_t ) );
void * queueData = malloc( 6 * sizeof( uint32_t ) );
QueueHandle_t xQueue = xQueueCreateStatic( 6, sizeof( uint32_t ), queueData, queueBuffer );
/* Verify that no call to malloc occured */
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
for( uint32_t i = 0; i < 3; i++ )
{
xQueueSend( xQueue, &i, 0 );
}
vQueueDelete( xQueue );
/* Veirfy that free was not called */
TEST_ASSERT_EQUAL_PTR( NULL, getLastFreedAddress() );
free( queueBuffer );
free( queueData );
}
/**
* @brief Test vQueueDelete with a full queue of size 6 x 4 bytes
* @coverage vQueueDelete
*/
void test_vQueueDelete_full( void )
{
void * queueBuffer = malloc( sizeof( StaticQueue_t ) );
void * queueData = malloc( 6 * sizeof( uint32_t ) );
QueueHandle_t xQueue = xQueueCreateStatic( 6, sizeof( uint32_t ), queueData, queueBuffer );
/* Verify that no call to malloc occured */
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
for( uint32_t i = 0; i < 6; i++ )
{
xQueueSend( xQueue, &i, 0 );
}
vQueueDelete( xQueue );
/* Veirfy that free was not called */
TEST_ASSERT_EQUAL_PTR( NULL, getLastFreedAddress() );
free( queueBuffer );
free( queueData );
}

View file

@ -0,0 +1,656 @@
/*
* FreeRTOS V202012.00
* 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 queue_receive_blocking_utest.c */
/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "../queue_utest_common.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "queue.h"
#include "mock_fake_port.h"
/* ============================ GLOBAL VARIABLES =========================== */
/* Used to share a QueueHandle_t between a test case and it's callbacks */
static QueueHandle_t xQueueHandleStatic;
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
vFakePortAssertIfInterruptPriorityInvalid_Ignore();
xQueueHandleStatic = NULL;
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* ========================== Helper functions =========================== */
/* ============================= Test Cases ============================== */
/**
* @brief Callback for test_xQueueReceive_blocking_success_locked_no_pending
* which adds an item to it's test queue.
*/
static BaseType_t xQueueReceive_xTaskCheckForTimeOutCB( TimeOut_t * const pxTimeOut,
TickType_t * const pxTicksToWait,
int cmock_num_calls )
{
BaseType_t xReturnValue = td_task_xTaskCheckForTimeOutStub( pxTimeOut, pxTicksToWait, cmock_num_calls );
if( cmock_num_calls == NUM_CALLS_TO_INTERCEPT )
{
uint32_t testVal = getNextMonotonicTestValue();
TEST_ASSERT_TRUE( xQueueSendFromISR( xQueueHandleStatic, &testVal, NULL ) );
TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueueHandleStatic ) );
}
return xReturnValue;
}
/**
* @brief Test a blocking call to xQueueReceive with a locked queue.
* @details Test a blocking call to xQueueReceive with a locked queue with no
* tasks in the queue WaitingToReceiveFrom event list.
* @coverage xQueueReceive prvUnlockQueue
*/
void test_xQueueReceive_blocking_success_locked_no_pending( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
/* Export for callbacks */
xQueueHandleStatic = xQueue;
xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB );
xTaskResumeAll_Stub( &td_task_xTaskResumeAllStub );
uint32_t checkVal = INVALID_UINT32;
TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
vQueueDelete( xQueue );
}
/**
* @brief Test a blocking call to xQueuePeek with a locked queue.
* @details Test a blocking call to xQueuePeek with a locked queue with no tasks
* in the queue WaitingToReceiveFrom event list.
* @coverage xQueuePeek prvUnlockQueue
*/
void test_xQueuePeek_blocking_success_locked_no_pending( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
/* Export for callbacks */
xQueueHandleStatic = xQueue;
xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB );
xTaskResumeAll_Stub( &td_task_xTaskResumeAllStub );
uint32_t checkVal = INVALID_UINT32;
TEST_ASSERT_EQUAL( pdTRUE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
vQueueDelete( xQueue );
}
/**
* @brief Callback for xTaskResumeAll used by tests for blocking calls to
* xQueueReceive and xQueuePeek
*/
static BaseType_t xQueueReceive_xTaskResumeAllCallback( int cmock_num_calls )
{
BaseType_t xReturnValue = td_task_xTaskResumeAllStub( cmock_num_calls );
/* If td_task_xTaskResumeAllStub returns pdTRUE, a higher priority task is pending
* Receive from an ISR to block */
if( pdTRUE == xReturnValue )
{
if( cmock_num_calls == NUM_CALLS_TO_INTERCEPT )
{
uint32_t checkValue = INVALID_UINT32;
TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueueHandleStatic ) );
TEST_ASSERT_TRUE( xQueueReceiveFromISR( xQueueHandleStatic, &checkValue, NULL ) );
TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkValue );
}
}
return xReturnValue;
}
/**
* @brief Test a blocking call to xQueueReceive with a locked queue.
* @details Test a blocking call to xQueueReceive with a locked queue with a
* higher priority task in the queue WaitingToReceiveFrom event list.
* @coverage xQueueReceive prvUnlockQueue
*/
void test_xQueueReceive_blocking_timeout_locked_high_prio_pending( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
/* Export for callbacks */
xQueueHandleStatic = xQueue;
xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB );
xTaskResumeAll_Stub( &xQueueReceive_xTaskResumeAllCallback );
td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 );
td_task_addFakeTaskWaitingToReceiveFromQueue( xQueue );
uint32_t checkVal = INVALID_UINT32;
TEST_ASSERT_EQUAL( pdFALSE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT + 1, td_task_getCount_YieldFromTaskResumeAll() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT - 1, td_task_getCount_vPortYieldWithinAPI() );
TEST_ASSERT_EQUAL( 1, td_task_getCount_vTaskMissedYield() );
TEST_ASSERT_EQUAL( INVALID_UINT32, checkVal );
vQueueDelete( xQueue );
}
/**
* @brief Test a blocking call to xQueuePeek with a locked queue.
* @details Test a blocking call to xQueuePeek with a locked queue with a
* higher priority task in the queue WaitingToReceiveFrom event list.
* @coverage xQueuePeek prvUnlockQueue
*/
void test_xQueuePeek_blocking_timeout_locked_high_prio_pending( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
/* Export for callbacks */
xQueueHandleStatic = xQueue;
xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB );
xTaskResumeAll_Stub( &xQueueReceive_xTaskResumeAllCallback );
td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 );
td_task_addFakeTaskWaitingToReceiveFromQueue( xQueue );
uint32_t checkVal = INVALID_UINT32;
TEST_ASSERT_EQUAL( pdFALSE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT + 1, td_task_getCount_YieldFromTaskResumeAll() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT - 1, td_task_getCount_vPortYieldWithinAPI() );
TEST_ASSERT_EQUAL( 1, td_task_getCount_vTaskMissedYield() );
TEST_ASSERT_EQUAL( INVALID_UINT32, checkVal );
vQueueDelete( xQueue );
}
/**
* @brief Test a blocking call to xQueueReceive with a locked queue.
* @details Test a blocking call to xQueueReceive with a locked queue with a
* lower priority task in the queue WaitingToReceiveFrom event list.
* @coverage xQueueReceive prvUnlockQueue
*/
void test_xQueueReceive_blocking_success_locked_low_prio_pending( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
/* Export for callbacks */
xQueueHandleStatic = xQueue;
xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB );
xTaskResumeAll_Stub( &xQueueReceive_xTaskResumeAllCallback );
td_task_setFakeTaskPriority( DEFAULT_PRIORITY - 1 );
td_task_addFakeTaskWaitingToReceiveFromQueue( xQueue );
uint32_t checkVal = INVALID_UINT32;
TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
vQueueDelete( xQueue );
}
/**
* @brief Test a blocking call to xQueuePeek with a locked queue.
* @details Test a blocking call to xQueuePeek with a locked queue with a
* lower priority task in the queue WaitingToReceiveFrom event list.
* @coverage xQueuePeek prvUnlockQueue
*/
void test_xQueuePeek_blocking_success_locked_low_prio_pending( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
/* Export for callbacks */
xQueueHandleStatic = xQueue;
xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB );
xTaskResumeAll_Stub( &xQueueReceive_xTaskResumeAllCallback );
td_task_setFakeTaskPriority( DEFAULT_PRIORITY - 1 );
td_task_addFakeTaskWaitingToReceiveFromQueue( xQueue );
uint32_t checkVal = INVALID_UINT32;
TEST_ASSERT_EQUAL( pdTRUE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueuePeek with taskSCHEDULER_SUSPENDED and timeout=10
* @details This should cause xQueuePeek to configASSERT becuase it would
* block forever when the queue is empty.
* @coverage xQueuePeek
*/
void test_xQueuePeek_blocking_suspended_assert( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
td_task_setSchedulerState( taskSCHEDULER_SUSPENDED );
vTaskSuspendAll_Stub( td_task_vTaskSuspendAllStubNoCheck );
uint32_t checkVal = INVALID_UINT32;
fakeAssertExpectFail();
TEST_ASSERT_EQUAL( pdFALSE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( pdTRUE, fakeAssertGetFlagAndClear() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
td_task_setSchedulerState( taskSCHEDULER_RUNNING );
vQueueDelete( xQueue );
}
/**
* @brief Callback which adds and item to it's test queue.
* @details Used in test_xQueuePeek_blocking_success and test_xQueueReceive_blocking_sucess.
*/
static BaseType_t blocking_success_xTaskCheckForTimeOut_cb( TimeOut_t * const pxTimeOut,
TickType_t * const pxTicksToWait,
int cmock_num_calls )
{
BaseType_t xReturnValue = td_task_xTaskCheckForTimeOutStub( pxTimeOut, pxTicksToWait, cmock_num_calls );
if( cmock_num_calls == NUM_CALLS_TO_INTERCEPT )
{
uint32_t testVal = getNextMonotonicTestValue();
xQueueSend( xQueueHandleStatic, &testVal, 0 );
TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueueHandleStatic ) );
}
return xReturnValue;
}
/**
* @brief Test xQueuePeek in blocking mode with a queue that is initially empty,
* but later becomes full.
* @coverage xQueuePeek
*/
void test_xQueuePeek_blocking_success( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
/* Export for blocking_success_xTaskCheckForTimeOut_cb callback */
xQueueHandleStatic = xQueue;
xTaskCheckForTimeOut_Stub( &blocking_success_xTaskCheckForTimeOut_cb );
uint32_t checkVal = INVALID_UINT32;
TEST_ASSERT_EQUAL( pdTRUE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
vQueueDelete( xQueue );
}
/**
* @brief Callback which adds and item to it's test queue.
* @details used in test_xQueuePeek_blocking_success_last_chance and
* test_xQueueReceive_blocking_success_last_chance.
*/
static BaseType_t blocking_success_last_chance_xTaskCheckForTimeOut_cb( TimeOut_t * const pxTimeOut,
TickType_t * const pxTicksToWait,
int cmock_num_calls )
{
BaseType_t xReturnValue = td_task_xTaskCheckForTimeOutStub( pxTimeOut, pxTicksToWait, cmock_num_calls );
if( cmock_num_calls == TICKS_TO_WAIT )
{
uint32_t testVal = getNextMonotonicTestValue();
xQueueSend( xQueueHandleStatic, &testVal, 0 );
}
return xReturnValue;
}
/**
* @brief Test xQueuePeek in blocking mode with a queue that is initially empty,
* but becomes full right before the last chance to remove data from the queue.
* @coverage xQueuePeek
*/
void test_xQueuePeek_blocking_success_last_chance( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
/* Export for blocking_success_xTaskCheckForTimeOut_cb callback */
xQueueHandleStatic = xQueue;
xTaskCheckForTimeOut_Stub( &blocking_success_last_chance_xTaskCheckForTimeOut_cb );
uint32_t checkVal = INVALID_UINT32;
TEST_ASSERT_EQUAL( pdTRUE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueuePeek in blocking mode with an empty queue.
* @coverage xQueuePeek
*/
void test_xQueuePeek_blocking_timeout( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
uint32_t checkVal = INVALID_UINT32;
TEST_ASSERT_EQUAL( pdFALSE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueReceive with taskSCHEDULER_SUSPENDED and timeout=10
* @details This should cause xQueueReceive to configASSERT becuase it would
* block forever when the queue is empty.
* @coverage xQueueReceive
*/
void test_xQueueReceive_blocking_suspended_assert( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
uint32_t checkVal = INVALID_UINT32;
fakeAssertExpectFail();
td_task_setSchedulerState( taskSCHEDULER_SUSPENDED );
vTaskSuspendAll_Stub( td_task_vTaskSuspendAllStubNoCheck );
TEST_ASSERT_EQUAL( pdFALSE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( pdTRUE, fakeAssertGetFlagAndClear() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
td_task_setSchedulerState( taskSCHEDULER_RUNNING );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueReceive in blocking mode with an occupied queue
* @coverage xQueueReceive
*/
void test_xQueueReceive_blocking_success( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
/* Export for blocking_success_xTaskCheckForTimeOut_cb callback */
xQueueHandleStatic = xQueue;
xTaskCheckForTimeOut_Stub( &blocking_success_xTaskCheckForTimeOut_cb );
uint32_t checkVal = INVALID_UINT32;
TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueReceive in blocking mode with a queue that is initially empty,
* but becomes full right before the last chance to remove data from the queue.
* @coverage xQueueReceive
*/
void test_xQueueReceive_blocking_success_last_chance( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
/* Export for blocking_success_xTaskCheckForTimeOut_cb callback */
xQueueHandleStatic = xQueue;
xTaskCheckForTimeOut_Stub( &blocking_success_last_chance_xTaskCheckForTimeOut_cb );
uint32_t checkVal = INVALID_UINT32;
TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueReceive in blocking mode with an empty queue
* @coverage xQueueReceive
*/
void test_xQueueReceive_blocking_timeout( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
uint32_t checkVal = INVALID_UINT32;
TEST_ASSERT_EQUAL( pdFALSE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueReceive in blocking mode with an empty locked queue.
* @details This test case verifies a situation that should never occur
* ( xQueueReceive called on a locked queue ).
* @coverage xQueueReceive
*/
void test_xQueueReceive_blocking_locked( void )
{
/* Create a new binary Queue */
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
/* Set private lock counters */
vSetQueueRxLock( xQueue, queueLOCKED_UNMODIFIED );
vSetQueueTxLock( xQueue, queueLOCKED_UNMODIFIED );
uint32_t checkVal = INVALID_UINT32;
/* Run xQueueReceive in blocking mode with the queue locked */
TEST_ASSERT_EQUAL( pdFALSE, xQueueReceive( xQueue, &checkVal, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
/* Verify that the queue is now unlocked */
TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueRxLock( xQueue ) );
TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueTxLock( xQueue ) );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueuePeek in blocking mode with an empty locked queue.
* @details This test case verifies a situation that should never occur
* ( xQueuePeek called on a locked queue ).
* @coverage xQueuePeek
*/
void test_xQueuePeek_blocking_locked( void )
{
/* Create a new binary Queue */
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
/* Set private lock counters */
vSetQueueRxLock( xQueue, queueLOCKED_UNMODIFIED );
vSetQueueTxLock( xQueue, queueLOCKED_UNMODIFIED );
uint32_t checkVal = INVALID_UINT32;
/* Run xQueueReceive in blocking mode with the queue locked */
TEST_ASSERT_EQUAL( pdFALSE, xQueuePeek( xQueue, &checkVal, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
/* Verify that the queue is now unlocked */
TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueRxLock( xQueue ) );
TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueTxLock( xQueue ) );
vQueueDelete( xQueue );
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,201 @@
/*
* FreeRTOS V202012.00
* 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 queue_reset_utest.c */
/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "../queue_utest_common.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "queue.h"
#include "mock_fake_port.h"
/* ============================ GLOBAL VARIABLES =========================== */
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* ========================== Helper functions =========================== */
/* ========================== Test Cases =========================== */
/**
* @brief Test xQueueReset with an invalid queue handle
* @coverage xQueueGenericReset
*/
void test_macro_xQueueReset_invalid_handle( void )
{
EXPECT_ASSERT_BREAK( xQueueReset( NULL ) );
}
/**
* @brief Test xQueueReset with an empty queue of size 6 x 4 bytes
* @coverage xQueueGenericReset
*/
void test_macro_xQueueReset_empty( void )
{
QueueHandle_t xQueue = xQueueCreate( 6, sizeof( uint32_t ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( pdPASS, xQueueReset( xQueue ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueReset with a half-full queue of size 6 x 4 bytes
* @coverage xQueueGenericReset
*/
void test_macro_xQueueReset_half_full( void )
{
QueueHandle_t xQueue = xQueueCreate( 6, sizeof( uint32_t ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
for( uint32_t i = 0; i < 3; i++ )
{
xQueueSend( xQueue, &i, 0 );
}
TEST_ASSERT_EQUAL( 3, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( pdPASS, xQueueReset( xQueue ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueReset with a full queue of size 6 x 4 bytes
* @coverage xQueueGenericReset
*/
void test_macro_xQueueReset_full( void )
{
QueueHandle_t xQueue = xQueueCreate( 6, sizeof( uint32_t ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
for( uint32_t i = 0; i < 6; i++ )
{
xQueueSend( xQueue, &i, 0 );
}
TEST_ASSERT_EQUAL( 6, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( pdPASS, xQueueReset( xQueue ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueReset with a queue of size 6 x 4 bytes
* and a simulated higher priority task that is blocked waiting send to the queue.
* @coverage xQueueGenericReset
*/
void test_macro_xQueueReset_tasks_waiting_higher_priority( void )
{
QueueHandle_t xQueue = xQueueCreate( 6, sizeof( uint32_t ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
/* Fill the queue */
for( uint32_t i = 0; i < 6; i++ )
{
xQueueSend( xQueue, &i, 0 );
}
/* Insert an item into the event list */
td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 );
td_task_addFakeTaskWaitingToSendToQueue( xQueue );
TEST_ASSERT_EQUAL( pdTRUE, xQueueReset( xQueue ) );
TEST_ASSERT_EQUAL( 1, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( 1, td_task_getCount_vPortYieldWithinAPI() );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueReset with a queue of size 6 x 4 bytes
* and a simulated lower priority task that is blocked waiting to send to the queue.
* xTasksWaitingToSend
* @coverage xQueueGenericReset
*/
void test_macro_xQueueReset_tasks_waiting_lower_priority( void )
{
QueueHandle_t xQueue = xQueueCreate( 6, sizeof( uint32_t ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
/* Fill the queue */
for( uint32_t i = 0; i < 6; i++ )
{
xQueueSend( xQueue, &i, 0 );
}
/* Insert an item into the event list */
td_task_setFakeTaskPriority( DEFAULT_PRIORITY - 1 );
td_task_addFakeTaskWaitingToSendToQueue( xQueue );
TEST_ASSERT_EQUAL( pdTRUE, xQueueReset( xQueue ) );
vQueueDelete( xQueue );
}

View file

@ -0,0 +1,339 @@
/*
* FreeRTOS V202012.00
* 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 queue_send_blocking_utest.c */
/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "../queue_utest_common.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "queue.h"
#include "mock_fake_port.h"
/* ============================ GLOBAL VARIABLES =========================== */
/* Used to share a QueueHandle_t between a test case and it's callbacks */
static QueueHandle_t xQueueHandleStatic;
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
vFakePortAssertIfInterruptPriorityInvalid_Ignore();
xQueueHandleStatic = NULL;
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* ========================== Helper functions =========================== */
/* ============================= Test Cases ============================== */
/**
* @brief Callback for test_macro_xQueueSend_blocking_success which empties it's test queue.
*/
static BaseType_t xQueueSend_locked_xTaskCheckForTimeOutCB( TimeOut_t * const pxTimeOut,
TickType_t * const pxTicksToWait,
int cmock_num_calls )
{
BaseType_t xReturnValue = td_task_xTaskCheckForTimeOutStub( pxTimeOut, pxTicksToWait, cmock_num_calls );
if( cmock_num_calls == NUM_CALLS_TO_INTERCEPT )
{
uint32_t checkVal = INVALID_UINT32;
( void ) xQueueReceiveFromISR( xQueueHandleStatic, &checkVal, NULL );
TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
}
return xReturnValue;
}
/**
* @brief Test xQueueSend with timeout=10 on a full queue which is locked and
* has no tasks on it's WaitingToSend event list.
* @coverage prvUnlockQueue
*/
void test_macro_xQueueSend_blocking_success_locked_no_pending( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
/* Export for callbacks */
xQueueHandleStatic = xQueue;
uint32_t testVal = getNextMonotonicTestValue();
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, &testVal, 0 ) );
TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
xTaskCheckForTimeOut_Stub( &xQueueSend_locked_xTaskCheckForTimeOutCB );
xTaskResumeAll_Stub( &td_task_xTaskResumeAllStub );
uint32_t testVal2 = getLastMonotonicTestValue() + 12345;
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, &testVal2, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
/* Check that vPortYieldWithinAPI was called and would have yielded */
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
/* Check that vTaskMissedYield was not called */
TEST_ASSERT_EQUAL( 0, td_task_getCount_vTaskMissedYield() );
vQueueDelete( xQueue );
}
/**
* @brief Callback used for xQueueSend blocking_locked tests.
*/
static BaseType_t xQueueSend_xTaskResumeAllCallback( int cmock_num_calls )
{
BaseType_t xReturnValue = td_task_xTaskResumeAllStub( cmock_num_calls );
/* If td_task_xTaskResumeAllStub returns pdTRUE, a higher priority task is pending
* Send from an ISR to block */
if( pdTRUE == xReturnValue )
{
if( cmock_num_calls == NUM_CALLS_TO_INTERCEPT )
{
uint32_t testVal = getNextMonotonicTestValue();
( void ) xQueueSendFromISR( xQueueHandleStatic, &testVal, NULL );
}
}
return xReturnValue;
}
/**
* @brief Test xQueueSend with timeout=10 on a full queue which is locked and
* has a higher priority task on it's WaitingToSend event list.
* @coverage prvUnlockQueue
*/
void test_macro_xQueueSend_blocking_fail_locked_high_prio_pending( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
/* Export for callbacks */
xQueueHandleStatic = xQueue;
uint32_t testVal = getNextMonotonicTestValue();
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, &testVal, 0 ) );
xTaskCheckForTimeOut_Stub( &xQueueSend_locked_xTaskCheckForTimeOutCB );
xTaskResumeAll_Stub( &xQueueSend_xTaskResumeAllCallback );
/* this task is lower priority than the pending task */
td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 );
td_task_addFakeTaskWaitingToSendToQueue( xQueue );
uint32_t testVal2 = getLastMonotonicTestValue() + 12345;
TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( pdFALSE, xQueueSend( xQueue, &testVal2, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
/* Check that xTaskResumeAll was called and would have yielded */
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT + 1, td_task_getCount_YieldFromTaskResumeAll() );
/* Check that vPortYieldWithinAPI was called and would have yielded */
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT - 1, td_task_getCount_vPortYieldWithinAPI() );
/* Check that vTaskMissedYield was called */
TEST_ASSERT_EQUAL( 1, td_task_getCount_vTaskMissedYield() );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueSend with timeout=10 on a full queue which is locked and
* has a lower priority task on it's WaitingToSend event list.
* @coverage prvUnlockQueue
*/
void test_macro_xQueueSend_blocking_success_locked_low_prio_pending( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
/* Export for callbacks */
xQueueHandleStatic = xQueue;
uint32_t testVal = getNextMonotonicTestValue();
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, &testVal, 0 ) );
xTaskCheckForTimeOut_Stub( &xQueueSend_locked_xTaskCheckForTimeOutCB );
xTaskResumeAll_Stub( &xQueueSend_xTaskResumeAllCallback );
/* The pending task is lower priority */
td_task_setFakeTaskPriority( DEFAULT_PRIORITY - 1 );
td_task_addFakeTaskWaitingToSendToQueue( xQueue );
uint32_t testVal2 = getLastMonotonicTestValue() + 12345;
TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, &testVal2, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
/* Check that vPortYieldWithinAPI was called and would have yielded */
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
/* Check that vTaskMissedYield was not called */
TEST_ASSERT_EQUAL( 0, td_task_getCount_vTaskMissedYield() );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueSend with taskSCHEDULER_SUSPENDED and timeout=10
* @details This should cause xQueueSend to configASSERT becuase it would
* block forever when the queue is full.
* @coverage xQueueGenericSend
*/
void test_macro_xQueueSend_blocking_suspended_assert( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
uint32_t testVal = getNextMonotonicTestValue();
fakeAssertExpectFail();
td_task_setSchedulerState( taskSCHEDULER_SUSPENDED );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, &testVal, 10 ) );
TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( pdTRUE, fakeAssertGetFlagAndClear() );
td_task_setSchedulerState( taskSCHEDULER_RUNNING );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueSend with taskSCHEDULER_RUNNING and timeout=10 on a full queue.
* @coverage xQueueGenericSend
*/
void test_macro_xQueueSend_blocking_timeout( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
uint32_t testVal = getNextMonotonicTestValue();
/* Fill up the queue */
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, &testVal, 0 ) );
TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( errQUEUE_FULL, xQueueSend( xQueue, &testVal, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
/* Check that vPortYieldWithinAPI was called and would have yielded */
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
/* Check that vTaskMissedYield was not called */
TEST_ASSERT_EQUAL( 0, td_task_getCount_vTaskMissedYield() );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueSend in blocking mode with a full locked queue.
* @details This test case verifies a situation that should never occur ( xQueueSend called on a locked queue ).
* @coverage xQueueGenericSend
*/
void test_macro_xQueueSend_blocking_locked( void )
{
/* Create a new binary Queue */
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
uint32_t testVal1 = getNextMonotonicTestValue();
/* Fill the queue */
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, &testVal1, TICKS_TO_WAIT ) );
/* Set private lock counters */
vSetQueueRxLock( xQueue, queueLOCKED_UNMODIFIED );
vSetQueueTxLock( xQueue, queueLOCKED_UNMODIFIED );
uint32_t testVal2 = getNextMonotonicTestValue();
TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
/* Call xQueueSend in blocking mode with the queue locked */
TEST_ASSERT_EQUAL( pdFALSE, xQueueSend( xQueue, &testVal2, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xQueue ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
/* Verify that the queue is now unlocked */
TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueRxLock( xQueue ) );
TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueTxLock( xQueue ) );
vQueueDelete( xQueue );
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,328 @@
/*
* FreeRTOS V202012.00
* 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 queue_status_utest.c */
/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "../queue_utest_common.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "queue.h"
/* ============================ GLOBAL VARIABLES =========================== */
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* ========================== Helper functions =========================== */
/* ============================= Test Cases ============================== */
/**
* @brief Test uxQueueMessagesWaiting with an invalid QueueHandle
* @coverage uxQueueMessagesWaiting
*/
void test_uxQueueMessagesWaiting_invalid_handle( void )
{
EXPECT_ASSERT_BREAK( uxQueueMessagesWaiting( NULL ) );
}
/**
* @brief Test uxQueueMessagesWaiting with a queue of size 5 x 4 bytes
* @details Test uxQueueMessagesWaiting with a typical queue when empty and occupied.
* @coverage uxQueueMessagesWaiting
*/
void test_uxQueueMessagesWaiting_empty_occupied( void )
{
QueueHandle_t xQueue = xQueueCreate( 5, sizeof( uint32_t ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueue ) );
for( uint32_t i = 0; i < 5; i++ )
{
xQueueSend( xQueue, &i, 0 );
TEST_ASSERT_EQUAL( i + 1, uxQueueMessagesWaiting( xQueue ) );
}
vQueueDelete( xQueue );
}
/**
* @brief Test uxQueueMessagesWaitingFromISR with an invalid Queue Handle
* @coverage uxQueueMessagesWaitingFromISR
*/
void test_uxQueueMessagesWaitingFromISR_invalid_handle( void )
{
EXPECT_ASSERT_BREAK( uxQueueMessagesWaitingFromISR( NULL ) );
}
/**
* @brief Test uxQueueMessagesWaitingFromISR with a queue of size 5 x 4 bytes
* @details Test uxQueueMessagesWaitingFromISR with a typical queue when empty and occupied.
* @coverage uxQueueMessagesWaitingFromISR
*/
void test_uxQueueMessagesWaitingFromISR_empty_occupied( void )
{
QueueHandle_t xQueue = xQueueCreate( 5, sizeof( uint32_t ) );
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaitingFromISR( xQueue ) );
for( uint32_t i = 0; i < 5; i++ )
{
xQueueSend( xQueue, &i, 0 );
TEST_ASSERT_EQUAL( i + 1, uxQueueMessagesWaitingFromISR( xQueue ) );
}
vQueueDelete( xQueue );
}
/**
* @brief Test uxQueueSpacesAvailable with an invalid QueueHandle
* @coverage uxQueueSpacesAvailable
*/
void test_uxQueueSpacesAvailable_invalid_handle( void )
{
EXPECT_ASSERT_BREAK( uxQueueSpacesAvailable( NULL ) );
}
/**
* @brief Test uxQueueSpacesAvailable with a queue of size 5 x 4 bytes
* @details Test uxQueueSpacesAvailable with a typical queue when empty and occupied.
* @coverage uxQueueSpacesAvailable
*/
void test_uxQueueSpacesAvailable_empty_occupied( void )
{
QueueHandle_t xQueue = xQueueCreate( 5, sizeof( uint32_t ) );
TEST_ASSERT_EQUAL( 5, uxQueueSpacesAvailable( xQueue ) );
for( uint32_t i = 0; i < 5; i++ )
{
xQueueSend( xQueue, &i, 0 );
TEST_ASSERT_EQUAL( 4 - i, uxQueueSpacesAvailable( xQueue ) );
}
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueIsQueueEmptyFromISR with an invalid QueueHandle
* @coverage xQueueIsQueueEmptyFromISR
*/
void test_xQueueIsQueueEmptyFromISR_invalid_handle( void )
{
EXPECT_ASSERT_BREAK( xQueueIsQueueEmptyFromISR( NULL ) );
}
/**
* @brief Test xQueueIsQueueEmptyFromISR with a queue of size 5 x 4 bytes
* @details Test xQueueIsQueueEmptyFromISR with a typical queue when empty and occupied.
* @coverage xQueueIsQueueEmptyFromISR
*/
void test_xQueueIsQueueEmptyFromISR_empty_occupied( void )
{
QueueHandle_t xQueue = xQueueCreate( 5, sizeof( uint32_t ) );
TEST_ASSERT_EQUAL( pdTRUE, xQueueIsQueueEmptyFromISR( xQueue ) );
for( uint32_t i = 0; i < 5; i++ )
{
xQueueSend( xQueue, &i, 0 );
TEST_ASSERT_EQUAL( pdFALSE, xQueueIsQueueEmptyFromISR( xQueue ) );
}
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueIsQueueFullFromISR with an invalid QueueHandle
* @coverage xQueueIsQueueFullFromISR
*/
void test_xQueueIsQueueFullFromISR_invalid_handle( void )
{
EXPECT_ASSERT_BREAK( xQueueIsQueueFullFromISR( NULL ) );
}
/**
* @brief Test xQueueIsQueueFullFromISR with a queue of size 5 x 4 bytes
* @details Test xQueueIsQueueFullFromISR with a typical queue when empty and occupied.
* @coverage xQueueIsQueueFullFromISR
*/
void test_xQueueIsQueueFullFromISR_empty_occupied( void )
{
QueueHandle_t xQueue = xQueueCreate( 5, sizeof( uint32_t ) );
for( uint32_t i = 0; i < 5; i++ )
{
TEST_ASSERT_EQUAL( pdFALSE, xQueueIsQueueFullFromISR( xQueue ) );
xQueueSend( xQueue, &i, 0 );
}
TEST_ASSERT_EQUAL( pdTRUE, xQueueIsQueueFullFromISR( xQueue ) );
vQueueDelete( xQueue );
}
/**
* @brief Test vQueueWaitForMessageRestricted with an empty queue.
* @details Test vQueueWaitForMessageRestricted with various values for
* xTicksToWait and xWaitIndefinitely.
* @coverage vQueueWaitForMessageRestricted
*/
void test_vQueueWaitForMessageRestricted_empty( void )
{
QueueHandle_t xQueue = xQueueCreate( 5, sizeof( uint32_t ) );
struct
{
TickType_t xTicksToWait;
BaseType_t xWaitIndefinitely;
}
xTestCaseArray[] =
{
{ 0, pdFALSE },
{ 0, pdTRUE },
{ 1, pdFALSE },
{ 1, pdTRUE },
{ 10, pdFALSE },
{ 10, pdTRUE },
{ 65536, pdTRUE }
};
List_t * pxTasksWaitingToReceive = pxGetTasksWaitingToReceiveFromQueue( xQueue );
for( uint32_t i = 0; i < ( sizeof( xTestCaseArray ) / sizeof( xTestCaseArray[ 0 ] ) ); i++ )
{
vTaskPlaceOnEventListRestricted_Expect( pxTasksWaitingToReceive,
xTestCaseArray[ i ].xTicksToWait,
xTestCaseArray[ i ].xWaitIndefinitely );
/* call api function */
vQueueWaitForMessageRestricted( xQueue,
xTestCaseArray[ i ].xTicksToWait,
xTestCaseArray[ i ].xWaitIndefinitely );
}
vQueueDelete( xQueue );
}
/**
* @brief Test vQueueWaitForMessageRestricted with an occupied queue.
* @details Test vQueueWaitForMessageRestricted with various values for
* xTicksToWait and xWaitIndefinitely.
* @coverage vQueueWaitForMessageRestricted
*/
void test_vQueueWaitForMessageRestricted_occupied( void )
{
QueueHandle_t xQueue = xQueueCreate( 5, sizeof( uint32_t ) );
uint32_t testVal = getNextMonotonicTestValue();
xQueueSend( xQueue, &testVal, 0 );
const struct
{
TickType_t xTicksToWait;
BaseType_t xWaitIndefinitely;
}
xTestCaseArray[] =
{
{ 0, pdFALSE },
{ 0, pdTRUE },
{ 1, pdFALSE },
{ 1, pdTRUE },
{ 10, pdFALSE },
{ 10, pdTRUE },
{ 65536, pdTRUE }
};
for( uint32_t i = 0; i < ( sizeof( xTestCaseArray ) / sizeof( xTestCaseArray[ 0 ] ) ); i++ )
{
/* call api function */
vQueueWaitForMessageRestricted( xQueue,
xTestCaseArray[ i ].xTicksToWait,
xTestCaseArray[ i ].xWaitIndefinitely );
/* Do not expect a call to vTaskPlaceOnEventListRestricted */
}
vQueueDelete( xQueue );
}
/**
* @brief Test vQueueWaitForMessageRestricted on an empty locked queue.
* @details This test case verifies a situation that should never occur ( vQueueWaitForMessageRestricted called on a locked queue ).
* @coverage vQueueWaitForMessageRestricted
*/
void test_vQueueWaitForMessageRestricted_locked( void )
{
/* Create a new binary Queue */
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
/* Set private lock counters */
vSetQueueRxLock( xQueue, queueLOCKED_UNMODIFIED );
vSetQueueTxLock( xQueue, queueLOCKED_UNMODIFIED );
List_t * pxTasksWaitingToReceive = pxGetTasksWaitingToReceiveFromQueue( xQueue );
vTaskPlaceOnEventListRestricted_Expect( pxTasksWaitingToReceive,
10,
pdFALSE );
/* Run vQueueWaitForMessageRestricted with the queue locked */
vQueueWaitForMessageRestricted( xQueue, 10, pdFALSE );
/* Verify that the queue is now unlocked */
TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueRxLock( xQueue ) );
TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueTxLock( xQueue ) );
vQueueDelete( xQueue );
}

View file

@ -13,11 +13,13 @@
: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
uint8: HEX8
uint16: HEX16
uint32: UINT32
int8: INT8
bool: UINT8
UBaseType_t: UINT32
BaseType_t: UINT32
:includes: # This will add these includes to each mock.
- <stdbool.h>
- "FreeRTOS.h"

View file

@ -1,113 +0,0 @@
/*
* FreeRTOS V202012.00
* 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 queue_utest.c */
/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "queue.h"
/* Test includes. */
#include "unity.h"
#include "unity_memory.h"
/* Mock includes. */
#include "mock_task.h"
#include "mock_list.h"
#include "mock_fake_assert.h"
#include "mock_fake_port.h"
/* ============================ GLOBAL VARIABLES =========================== */
/* ========================== CALLBACK FUNCTIONS =========================== */
void * pvPortMalloc( size_t xSize )
{
return unity_malloc( xSize );
}
void vPortFree( void * pv )
{
return unity_free( pv );
}
/*******************************************************************************
* Unity fixtures
******************************************************************************/
void setUp( void )
{
mock_task_Init();
mock_fake_assert_Init();
mock_fake_port_Init();
vFakeAssert_Ignore();
vFakePortEnterCriticalSection_Ignore();
vFakePortExitCriticalSection_Ignore();
/* Track calls to malloc / free */
UnityMalloc_StartTest();
}
/*! called before each testcase */
void tearDown( void )
{
UnityMalloc_EndTest();
mock_task_Verify();
mock_task_Destroy();
mock_fake_assert_Verify();
mock_fake_assert_Destroy();
mock_fake_port_Verify();
mock_fake_port_Destroy();
}
/*! called at the beginning of the whole suite */
void suiteSetUp()
{
}
/*! called at the end of the whole suite */
int suiteTearDown( int numFailures )
{
return numFailures;
}
/*!
* @brief xQueueCreate happy path.
* @coverage xQueueGenericCreate
*/
void test_xQueueCreate_Success( void )
{
vListInitialise_Ignore();
QueueHandle_t xQueue = xQueueCreate( 1, 1 );
TEST_ASSERT_NOT_EQUAL( NULL, xQueue );
vQueueDelete(xQueue);
}

View file

@ -0,0 +1,323 @@
/*
* FreeRTOS V202012.00
* 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 queue_utest_common.c */
#include "queue_utest_common.h"
/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
/* Test includes. */
#include "unity.h"
#include "unity_memory.h"
/* Mock includes. */
#include "mock_task.h"
#include "mock_fake_assert.h"
#include "mock_fake_port.h"
/* ============================ GLOBAL VARIABLES =========================== */
static uint32_t ulMonotonicTestValue = 0xFFFF;
#if defined( configASSERT )
static bool xMaskAssert = false;
static BaseType_t xNumAssertsMasked = 0;
bool xMaskAssertAndAbort = false;
#endif
static size_t uxLastMallocSize = 0;
static void * pLastFreedAddress = 0;
static uint32_t ulNumMallocCalls = 0;
/* ========================== CALLBACK FUNCTIONS =========================== */
void * pvPortMalloc( size_t xSize )
{
uxLastMallocSize = xSize;
ulNumMallocCalls++;
return unity_malloc( xSize );
}
void vPortFree( void * pv )
{
pLastFreedAddress = pv;
return unity_free( pv );
}
#if defined( configASSERT )
void fakeAssertCallback( bool assertion,
char * file,
int line,
int num_calls )
{
if( !assertion && xMaskAssertAndAbort )
{
Throw( configASSERT_E );
}
else if( !assertion && !xMaskAssert )
{
printf( "ASSERT: File: %s line: %d\n", file, line );
TEST_FAIL();
}
else if( !assertion )
{
xNumAssertsMasked++;
}
}
#endif /* if defined( configASSERT ) */
/* ============================= Unity Fixtures ============================= */
void commonSetUp( void )
{
mock_task_Init();
mock_fake_assert_Init();
mock_fake_port_Init();
/* Map configAssert to a local callback */
vFakeAssert_Stub( fakeAssertCallback );
/* Reset globals for vFakeAssert() */
#if defined( configASSERT )
xMaskAssert = false;
xNumAssertsMasked = 0;
xMaskAssertAndAbort = false;
#endif
/* Reset malloc related globals */
uxLastMallocSize = false;
pLastFreedAddress = false;
ulNumMallocCalls = 0;
td_task_register_stubs();
td_port_register_stubs();
/* Track calls to malloc / free */
UnityMalloc_StartTest();
}
void commonTearDown( void )
{
#if defined( configASSERT )
TEST_ASSERT_EQUAL_MESSAGE( 0, xNumAssertsMasked,
"An unexpected configASSERT was called in this test case." );
#endif
td_task_teardown_check();
td_port_teardown_check();
mock_task_Verify();
mock_task_Destroy();
mock_fake_assert_Verify();
mock_fake_assert_Destroy();
mock_fake_port_Verify();
mock_fake_port_Destroy();
UnityMalloc_EndTest();
}
void commonSuiteSetUp()
{
}
int commonSuiteTearDown( int numFailures )
{
return numFailures;
}
/* ========================== Helper functions =========================== */
uint32_t getNextMonotonicTestValue()
{
return ++ulMonotonicTestValue;
}
uint32_t getLastMonotonicTestValue()
{
return ulMonotonicTestValue;
}
void fakeAssertExpectFail( void )
{
#if defined( configASSERT )
/* Verify that there are no pending assertions */
TEST_ASSERT_TRUE( xNumAssertsMasked == 0 );
/* Set flag */
xMaskAssert = true;
#endif
}
bool fakeAssertGetFlagAndClear( void )
{
#if defined( configASSERT )
bool xRetVal = ( xNumAssertsMasked > 0 );
/* Verify that only one assertion failed since flags were last handled */
TEST_ASSERT_TRUE_MESSAGE( xNumAssertsMasked <= 1, "Number of asserts > 1 in fakeAssertGetFlagAndClear." );
/* Reset globals */
xMaskAssert = false;
xNumAssertsMasked = 0;
return xRetVal;
#else
return true;
#endif /* if defined( configASSERT ) */
}
BaseType_t fakeAssertGetNumAssertsAndClear( void )
{
#if defined( configASSERT )
BaseType_t xRetVal = xNumAssertsMasked;
/* Reset globals */
xMaskAssert = false;
xNumAssertsMasked = 0;
return xRetVal;
#else
return 0;
#endif
}
void fakeAssertVerifyNumAssertsAndClear( uint32_t ulNumAssertsExpected )
{
#if defined( configASSERT )
TEST_ASSERT_EQUAL( ulNumAssertsExpected, xNumAssertsMasked );
/* Reset globals */
xMaskAssert = false;
xNumAssertsMasked = 0;
#endif
}
size_t getLastMallocSize( void )
{
return uxLastMallocSize;
}
void * getLastFreedAddress( void )
{
return pLastFreedAddress;
}
size_t getNumberMallocCalls( void )
{
return ulNumMallocCalls;
}
List_t * pxGetTasksWaitingToSendToQueue( QueueHandle_t xQueue )
{
StaticQueue_t * pxQueue = ( StaticQueue_t * ) xQueue;
List_t * pxTasksWaitingToSend = ( List_t * ) &( pxQueue->xDummy3[ 0 ] );
return pxTasksWaitingToSend;
}
List_t * pxGetTasksWaitingToReceiveFromQueue( QueueHandle_t xQueue )
{
StaticQueue_t * pxQueue = ( StaticQueue_t * ) xQueue;
List_t * pxTasksWaitingToReceive = ( List_t * ) &( pxQueue->xDummy3[ 1 ] );
return pxTasksWaitingToReceive;
}
int8_t cGetQueueRxLock( QueueHandle_t xQueue )
{
/* Access private lock counter */
StaticQueue_t * pxQueue = ( StaticQueue_t * ) xQueue;
int8_t * pcRxLock = ( int8_t * ) &( pxQueue->ucDummy5[ 0 ] );
return *pcRxLock;
}
int8_t cGetQueueTxLock( QueueHandle_t xQueue )
{
/* Access private lock counter */
StaticQueue_t * pxQueue = ( StaticQueue_t * ) xQueue;
int8_t * pcTxLock = ( int8_t * ) &( pxQueue->ucDummy5[ 1 ] );
return *pcTxLock;
}
void vSetQueueRxLock( QueueHandle_t xQueue,
int8_t value )
{
/* Access private lock counter */
StaticQueue_t * pxQueue = ( StaticQueue_t * ) xQueue;
int8_t * pcRxLock = ( int8_t * ) &( pxQueue->ucDummy5[ 0 ] );
*pcRxLock = value;
}
void vSetQueueTxLock( QueueHandle_t xQueue,
int8_t value )
{
/* Access private lock counter */
StaticQueue_t * pxQueue = ( StaticQueue_t * ) xQueue;
int8_t * pcTxLock = ( int8_t * ) &( pxQueue->ucDummy5[ 1 ] );
*pcTxLock = value;
}
/**
* @brief Helper function to call xQueueSend with sequential values
* @param xQueue The handle to the queue to be tested
* @param numberOfItems Number of sequential items to add to the queue under test.
*/
void queue_common_add_sequential_to_queue( QueueHandle_t xQueue,
uint32_t numberOfItems )
{
for( uint32_t i = 0; i < numberOfItems; i++ )
{
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, &i, 0 ) );
TEST_ASSERT_EQUAL_UINT32( i + 1, uxQueueMessagesWaiting( xQueue ) );
}
}
/**
* @brief Helper function to call xQueueReceive and verify sequential values are received
* @param xQueue The handle to the queue to be tested
* @param maxItems Maximum number of items the queue supports
* @param numberOfItems Number of sequential items to receive from the queue under test.
* @param expectedFirstValue The first value to expect to receive from the queue
*/
void queue_common_receive_sequential_from_queue( QueueHandle_t xQueue,
uint32_t maxItems,
uint32_t numberOfItems,
uint32_t expectedFirstValue )
{
for( uint32_t i = 0; i < numberOfItems; i++ )
{
uint32_t testVal = 0xFFFFFFFF;
TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueue, &testVal, 0 ) );
TEST_ASSERT_EQUAL( expectedFirstValue + i, testVal );
TEST_ASSERT_EQUAL_UINT32( i + 1, uxQueueSpacesAvailable( xQueue ) );
TEST_ASSERT_EQUAL_UINT32( maxItems - i - 1, uxQueueMessagesWaiting( xQueue ) );
}
}

View file

@ -0,0 +1,394 @@
/*
* FreeRTOS V202012.00
* 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 queue_utest_common.h */
#ifndef QUEUE_UTEST_COMMON_H
#define QUEUE_UTEST_COMMON_H
/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
/* Test includes. */
#include "unity.h"
#include "unity_memory.h"
#include "CException.h"
/* FreeRTOS includes */
#include "FreeRTOS.h"
#include "queue.h"
/* Mock includes. */
#include "mock_task.h"
#include "mock_fake_assert.h"
/* ================================ CONSTANTS ===============================*/
#define MAX_MULTI_LEN 16
#define MAX_QUEUE_ITEMS 500
#define QUEUE_T_SIZE sizeof( StaticQueue_t )
#define B_SEMPHR_AVAILABLE 1
#define B_SEMPHR_TAKEN 0
#define INVALID_UINT32 0xFFFFFFFF
#define INVALID_PTR ( ( void * ) INVALID_UINT32 )
#define configASSERT_E 0xAA101
#define queueUNLOCKED ( ( int8_t ) -1 )
#define queueLOCKED_UNMODIFIED ( ( int8_t ) 0 )
#define DEFAULT_PRIORITY 5
#define TICKS_TO_WAIT 10
#define NUM_CALLS_TO_INTERCEPT TICKS_TO_WAIT / 2
/* ============================ GLOBAL VARIABLES =========================== */
bool xMaskAssertAndAbort;
/* ================================= MACROS ================================ */
/**
* @brief Expect a configASSERT from the funciton called.
* Break out of the called function when this occurs.
* @details Use this macro when the call passsed in as a parameter is expected
* to cause invalid memory access.
*/
#define EXPECT_ASSERT_BREAK( call ) \
do \
{ \
xMaskAssertAndAbort = true; \
CEXCEPTION_T e = CEXCEPTION_NONE; \
Try \
{ \
call; \
TEST_FAIL(); \
} \
Catch( e ) \
TEST_ASSERT_EQUAL( configASSERT_E, e ); \
} while ( 0 )
/* ========================== CALLBACK FUNCTIONS =========================== */
/**
* @brief defines malloc() for this test and redirects it to unity_malloc
* @param xSize size of memory block to be allocated
* @return pointer to the allocated memory on success.
* @return NULL if the memory could not be allocated.
*/
void * pvPortMalloc( size_t xSize );
/**
* @brief defines free() for this test and redirects it to unity_free
* @param pv pointer to the block to be freed
*/
void vPortFree( void * pv );
/**
* @brief Callback function for calls to configASSERT
* @details This callback function will cause a unit test to fail if the
* provided assertion is false and the fakeAssertExpectFail()
* function was not called prior to the assertion.
* @param assertion Boolean assertion passed into the configASSERT() macro
* @param file Name of the file in which the assert occured
* @param line Line number of the assertion
* @param num_calls Number of times configASSERT() was called
*/
void fakeAssertCallback( bool assertion,
char * file,
int line,
int num_calls );
/* ========================== Unity fixtures =========================== */
/**
* @brief Setup function called before each test case.
*/
void setUp( void );
/**
* @brief Teardown function called after each test case.
*/
void tearDown( void );
/**
* @brief Setup function called before this test suite (file).
*/
void suiteSetUp();
/**
* @brief Setup function called afer this test suite (file) has completed.
*/
int suiteTearDown( int numFailures );
/* ========================== Helper functions =========================== */
/**
* @brief Common test case setup function for queue tests.
*/
void commonSetUp( void );
/**
* @brief Common test case teardown function for queue tests.
*/
void commonTearDown( void );
/**
* @brief Common test suite setup function for queue test suites.
*/
void commonSuiteSetUp();
/**
* @brief Common test suite teardown function for queue test suites.
*/
int commonSuiteTearDown( int numFailures );
/**
* @brief Get a monotonically increasing test value (somewhat random).
*/
uint32_t getNextMonotonicTestValue();
/**
* @brief Get the test value provided by the last call to getNextMonotonicTestValue().
*/
uint32_t getLastMonotonicTestValue();
/**
* @brief Mask subsquent failing assertions until next test case.
*/
void fakeAssertExpectFail( void );
/**
* @brief Determine if a configASSERT occurred and clear the assertion flag.
* @return true if an assert occureed since the start of the test suite or
* the last call to fakeAssertGetFlagAndClear.
* @return false if no assert was triggered.
*/
bool fakeAssertGetFlagAndClear( void );
/**
* @brief get the size of the last heap memory allocation via pvPortMalloc()
* @return The parameter given during the last call to pvPortMalloc()
*/
size_t getLastMallocSize( void );
/**
* @brief get the address of the last heap memory deallocation via pvPortFree()
* @return The parameter given during the last call to pvPortFree()
*/
void * getLastFreedAddress( void );
/**
* @brief get the number of malloc calls made in the current test case.
* @return number of malloc calls made since the start of the test case.
*/
size_t getNumberMallocCalls( void );
/**
* @return A pointer to the given queue's xTasksWaitingToSend event list.
*/
List_t * pxGetTasksWaitingToSendToQueue( QueueHandle_t xQueue );
/**
* @return A pointer to the given queue's xTasksWaitingToReceive event list.
*/
List_t * pxGetTasksWaitingToReceiveFromQueue( QueueHandle_t xQueue );
/**
* @return The value of a given queue's cRxLock.
*/
int8_t cGetQueueRxLock( QueueHandle_t xQueue );
/**
* @return The value of a given queue's cTxLock.
*/
int8_t cGetQueueTxLock( QueueHandle_t xQueue );
/**
* @brief Set the value of a given queue's cRxLock to the specified value.
*/
void vSetQueueRxLock( QueueHandle_t xQueue,
int8_t value );
/**
* @brief Set the value of a given queue's cTxLock to the specified value.
*/
void vSetQueueTxLock( QueueHandle_t xQueue,
int8_t value );
/**
* @brief Get the number of asserts that have occurred since the last call to this function in a given test case.
*/
BaseType_t fakeAssertGetNumAssertsAndClear( void );
/**
* @brief Check that the number of failed configASSERTs that have occured in this test case equals the given number.
*/
void fakeAssertVerifyNumAssertsAndClear( uint32_t ulNumAssertsExpected );
/**
* @brief Receives a given number of items from the given queue and verifies that the items contain sequential values.
*/
void queue_common_receive_sequential_from_queue( QueueHandle_t xQueue,
uint32_t maxItems,
uint32_t numberOfItems,
uint32_t expectedFirstValue );
/**
* @brief Adds a given number of itesm to the given queue with sequential values in each item.
*/
void queue_common_add_sequential_to_queue( QueueHandle_t xQueue,
uint32_t numberOfItems );
/**
* @brief Register the stubs contained in td_port.c using the relevant CMock _Stub calls.
* @details This function should be called before every test case.
*/
void td_port_register_stubs( void );
/**
* @brief Validate ending state of td_port related variables.
* @details This function should be called after every test case.
* It verifies the state of the variables used by td_port funcitons and
* frees resources used by CMock.
*/
void td_port_teardown_check( void );
/**
* @return pdTRUE if the simulated "port" a critical section/.
*/
BaseType_t td_port_isInCriticalSection( void );
/**
* @brief Register the stubs contained in td_task.c using the relevant CMock _Stub calls.
* @details This function should be called before every test case.
*/
void td_task_register_stubs( void );
/**
* @brief Validate ending state of td_task related variables.
* @details This function should be called after every test case.
* It verifies the state of the variables used by td_task functions and
* frees resources used by CMock.
*/
void td_task_teardown_check( void );
/**
* @brief Sets the scheduler state used by the task test double.
*/
void td_task_setSchedulerState( BaseType_t state );
/**
* @brief Sets the priority of the fake / simulated task used by td_task.c.
*/
void td_task_setFakeTaskPriority( TickType_t priority );
/**
* @brief Sets the priority of the fake / simulated task used by td_task.c.
*/
TickType_t td_task_getFakeTaskPriority( void );
/**
* @brief Adds the td_task.c fake task to the given queue's WaitingToSend event list.
*/
void td_task_addFakeTaskWaitingToSendToQueue( QueueHandle_t xQueue );
/**
* @brief Adds the td_task.c fake task to the given queue's WaitingToReceive event list.
*/
void td_task_addFakeTaskWaitingToReceiveFromQueue( QueueHandle_t xQueue );
/**
* @brief Test double for xTaskCheckForTimeOut
*/
BaseType_t td_task_xTaskCheckForTimeOutStub( TimeOut_t * const pxTimeOut,
TickType_t * const pxTicksToWait,
int cmock_num_calls );
/**
* @brief Test double for xTaskResumeAll
*/
BaseType_t td_task_xTaskResumeAllStub( int cmock_num_calls );
/**
* @brief Test double for vTaskSuspendAll which does not check the scheduler state when called.
*/
void td_task_vTaskSuspendAllStubNoCheck( int cmock_num_calls );
/**
* @brief Test double for vPortYieldWithinAPI
*/
void td_task_vPortYieldWithinAPIStub( int cmock_num_calls );
/**
* @brief Get the number of calls to all yield related functions.
*/
BaseType_t td_task_getYieldCount( void );
/**
* @brief Get the number of times vPortYield was called and clear the counter.
* @return number of times vPortYield was called during the current test case.
*/
BaseType_t td_task_getCount_vPortYield( void );
/**
* @brief Get the number of times vPortYieldFromISR was called and clear the counter.
* @return number of times vPortYieldFromISR was called during the current test case.
*/
BaseType_t td_task_getCount_vPortYieldFromISR( void );
/**
* @brief Get the number of times vPortYieldWithinAPI was called and clear the counter.
* @return number of times vPortYieldWithinAPI was called during the current test case.
*/
BaseType_t td_task_getCount_vPortYieldWithinAPI( void );
/**
* @brief Get the number of times vTaskMissedYield was called and clear the counter.
* @return number of times vTaskMissedYield was called during the current test case.
*/
BaseType_t td_task_getCount_vTaskMissedYield( void );
/**
* @brief Get the number of times xTaskResumeAll and resulted in a yield.
* @return number of times xTaskResumeAll was called and resulted in a yield
* during the current test case. Also clears the counter before returning
* the previous value.
*/
BaseType_t td_task_getCount_YieldFromTaskResumeAll( void );
/**
* @brief Get the current state of the xYieldPending variable.
* @return pdTRUE when a yield is pending due to a call to vTaskMissedYield
* or xTaskRemoveFromEventList
*/
BaseType_t td_task_getYieldPending( void );
#endif /* QUEUE_UTEST_COMMON_H */

View file

@ -0,0 +1,140 @@
/*
* FreeRTOS V202012.00
* 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
#include "fake_assert.h"
/*-----------------------------------------------------------
* 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_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 0
#define configUSE_RECURSIVE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 0
#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 0
#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 1
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats()
#define portGET_RUN_TIME_COUNTER_VALUE() ulGetRunTimeCounterValue()
/* Co-routine related configuration options. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* 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 1
/* 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 1
#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 ) \
do \
{ \
if( x ) \
{ \
vFakeAssert( true, __FILE__, __LINE__ ); \
} \
else \
{ \
vFakeAssert( false, __FILE__, __LINE__ ); \
} \
} while ( 0 )
#define mtCOVERAGE_TEST_MARKER() __asm volatile ( "NOP" )
#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0
#if ( configINCLUDE_MESSAGE_BUFFER_AMP_DEMO == 1 )
extern void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer );
#define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )
#endif /* configINCLUDE_MESSAGE_BUFFER_AMP_DEMO */
#endif /* FREERTOS_CONFIG_H */

View file

@ -0,0 +1,52 @@
# Indent with spaces
.RECIPEPREFIX := $(.RECIPEPREFIX) $(.RECIPEPREFIX)
# Do not move this line below the include
MAKEFILE_ABSPATH := $(abspath $(lastword $(MAKEFILE_LIST)))
include ../../makefile.in
# PROJECT_SRC lists the .c files under test
PROJECT_SRC += queue.c
# PROJECT_DEPS_SRC list the .c file that are dependencies of PROJECT_SRC files
# Files in PROJECT_DEPS_SRC are excluded from coverage measurements
PROJECT_DEPS_SRC += list.c
# PROJECT_HEADER_DEPS: headers that should be excluded from coverage measurements.
PROJECT_HEADER_DEPS += FreeRTOS.h
# SUITE_UT_SRC: .c files that contain test cases (must end in _utest.c)
SUITE_UT_SRC += semaphore_create_utest.c
SUITE_UT_SRC += binary_semaphore_utest.c
SUITE_UT_SRC += counting_semaphore_utest.c
SUITE_UT_SRC += semaphore_common_utest.c
SUITE_UT_SRC += mutex_utest.c
SUITE_UT_SRC += recursive_mutex_utest.c
# SUITE_SUPPORT_SRC: .c files used for testing that do not contain test cases.
# Paths are relative to PROJECT_DIR
SUITE_SUPPORT_SRC += queue_utest_common.c
SUITE_SUPPORT_SRC += td_task.c
SUITE_SUPPORT_SRC += td_port.c
# List the headers used by PROJECT_SRC that you would like to mock
MOCK_FILES_FP += $(KERNEL_DIR)/include/task.h
MOCK_FILES_FP += $(UT_ROOT_DIR)/config/fake_assert.h
MOCK_FILES_FP += $(UT_ROOT_DIR)/config/fake_port.h
# List any addiitonal flags needed by the preprocessor
CPPFLAGS += -DportUSING_MPU_WRAPPERS=0
# List any addiitonal flags needed by the compiler
CFLAGS +=
# Try not to edit beyond this line unless necessary.
# Project / Suite are determined based on path: $(UT_ROOT_DIR)/$(PROJECT)/$(SUITE)
PROJECT := $(lastword $(subst /, ,$(dir $(abspath $(MAKEFILE_ABSPATH)/../))))
SUITE := $(lastword $(subst /, ,$(dir $(MAKEFILE_ABSPATH))))
# Make variables available to included makefile
export
include ../../testdir.mk

View file

@ -0,0 +1,889 @@
/*
* FreeRTOS V202012.00
* 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 binary_semaphore_utest.c */
#include "../queue_utest_common.h"
#include "mock_fake_port.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "semphr.h"
/* =============================== CONSTANTS =============================== */
/* ============================ GLOBAL VARIABLES =========================== */
/* Used to share a semaphore handle between a test case and callback */
static SemaphoreHandle_t xSemaphoreHandleStatic;
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* ========================== Helper functions =========================== */
/* ============================= Test Cases ============================== */
/**
* @brief Test xSemaphoreTake with a Binary Semaphore
* @details Create a binary semaphore using xSemaphoreCreateBinary
* and verify that an immediate call to xSemaphoreTake fails.
* @coverage xQueueSemaphoreTake
*/
void test_macro_xSemaphoreTake_xSemaphoreCreateBinary_fail( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Verify that an immediate xSemaphoreTake operation fails */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, 0 ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGive with xSemaphoreCreateBinary
* @details Create a binary semaphore using xSemaphoreCreateBinary
* and verify that an immediate call to xSemaphoreGive succeeds.
* @coverage xQueueGenericSend
*/
void test_macro_xSemaphoreGive_xSemaphoreCreateBinary_success( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Verify that an immediate xSemaphoreGive operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGive( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @deprecated
* @brief Test xSemaphoreTake with vSemaphoreCreateBinary
* @details Create a semaphore using vSemaphoreCreateBinary and verify that a
* subsequent call to xSemaphoreTake succeeds.
* @coverage xQueueSemaphoreTake
*/
void test_macro_xSemaphoreTake_vSemaphoreCreateBinary_success( void )
{
SemaphoreHandle_t xSemaphore = NULL;
vSemaphoreCreateBinary( xSemaphore );
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Verify that an immediate xSemaphoreTake operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @deprecated
* @brief Test xSemaphoreGive with vSemaphoreCreateBinary
* @details Create a semaphore using vSemaphoreCreateBinary and verify that a
* subsequent call to xSemaphoreGive fails.
* @coverage xQueueGenericSend
*/
void test_macro_xSemaphoreGive_vSemaphoreCreateBinary_fail( void )
{
SemaphoreHandle_t xSemaphore = NULL;
vSemaphoreCreateBinary( xSemaphore );
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Verify that an immediate xSemaphoreGive operation fails */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGive( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGive and xSemaphoreTake with xSemaphoreCreateBinary
* @details Create a binary semaphore using xSemaphoreCreateBinary
* and verify that an immediate call to xSemaphoreGive succeeds and a subsequent
* call to xSemaphoreTake succeeds.
* @coverage xQueueGenericSend xQueueSemaphoreTake
*/
void test_macro_xSemaphoreGive_xSemaphoreTake_success( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Verify that an immediate xSemaphoreGive operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGive( xSemaphore ) );
/* Verify that a subsequent xSemaphoreTake operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGive multiple times on a Binary Semaphore
* @details Create a binary semaphore using xSemaphoreCreateBinary
* and verify that an immediate call to xSemaphoreGive succeeds and a subsequent
* call to xSemaphoreGive fails.
* @coverage xQueueGenericSend
*/
void test_macro_xSemaphoreGive_multiple_fail( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Verify that an immediate xSemaphoreGive operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGive( xSemaphore ) );
/* Verify that the second xSemaphoreGive operation fails */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGive( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake multiple times on a Binary Semaphore
* @details Create a binary semaphore using xSemaphoreCreateBinary,
* verify that an immediate call to xSemaphoreGive succeeds, a subsequent
* call to xSemaphoreTake succeds, but a second call to xSemaphoreTake fails.
* @coverage xQueueSemaphoreTake
*/
void test_macro_xSemaphoreTake_multiple_fail( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Verify that an immediate xSemaphoreGive operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGive( xSemaphore ) );
/* Verify that a subsequent xSemaphoreTake operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
/* Verify that a second xSemaphoreTake operation fails */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, 0 ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test uxSemaphoreGetCount with a Binary Semaphore
* @details Create a binary semaphore using vSemaphoreCreateBinary.
* validate the return value of uxSemaphoreGetCount(),
* call xSemaphoreTake() and validate the return value of uxSemaphoreGetCount()
* @coverage uxQueueMessagesWaiting
*/
void test_macro_uxSemaphoreGetCount( void )
{
SemaphoreHandle_t xSemaphore = NULL;
vSemaphoreCreateBinary( xSemaphore );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
( void ) xSemaphoreTake( xSemaphore, 0 );
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTakeFromISR with a Binary Semaphore
* @coverage xQueueReceiveFromISR
**/
void test_macro_xSemaphoreTakeFromISR_success( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
vFakePortAssertIfInterruptPriorityInvalid_Expect();
/* Give the Binary Semaphore */
( void ) xSemaphoreGive( xSemaphore );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTakeFromISR( xSemaphore, NULL ) );
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief xSemaphoreGiveFromISR with an empty queue
* @coverage xQueueGiveFromISR
*/
void test_macro_xSemaphoreGiveFromISR_success( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
vFakePortAssertIfInterruptPriorityInvalid_Expect();
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveFromISR( xSemaphore, NULL ) );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/*!
* @brief xSemaphoreGiveFromISR with a full queue
* @coverage xQueueGiveFromISR
*/
void test_macro_xSemaphoreGiveFromISR_fail( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
vFakePortAssertIfInterruptPriorityInvalid_Expect();
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveFromISR( xSemaphore, NULL ) );
vFakePortAssertIfInterruptPriorityInvalid_Expect();
TEST_ASSERT_EQUAL( errQUEUE_FULL, xSemaphoreGiveFromISR( xSemaphore, NULL ) );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGiveFromISR with a higher priority task waiting and a null pointer for pxHigherPriorityTaskWoken
* @details Test xSemaphoreGiveFromISR with a higher priority task waiting and
* verifies that a null pxHigherPriorityTaskWoken is handled correctly.
* @coverage xQueueGiveFromISR
*/
void test_macro_xSemaphoreGiveFromISR_high_priority_pending_null_ptr( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
vFakePortAssertIfInterruptPriorityInvalid_Expect();
/* Insert an item into the event list */
td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 );
td_task_addFakeTaskWaitingToReceiveFromQueue( xSemaphore );
/* Give the Binary Semaphore */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveFromISR( xSemaphore, NULL ) );
TEST_ASSERT_EQUAL( pdTRUE, td_task_getYieldPending() );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGiveFromISR with a higher priority task waiting
* @details Test xSemaphoreGiveFromISR with a higher priority task waiting and
* verify that xHigherPriorityTaskWoken is set accoridngly.
* @coverage xQueueGiveFromISR
*/
void test_macro_xSemaphoreGiveFromISR_high_priority_pending( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
vFakePortAssertIfInterruptPriorityInvalid_Expect();
/* Insert an item into the event list */
td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 );
td_task_addFakeTaskWaitingToReceiveFromQueue( xSemaphore );
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
/* Give the semaphore */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken ) );
TEST_ASSERT_EQUAL( pdTRUE, xHigherPriorityTaskWoken );
TEST_ASSERT_EQUAL( pdTRUE, td_task_getYieldPending() );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGiveFromISR with a lower priority task waiting
* @details Test xSemaphoreGiveFromISR with a lower priority task waiting and
* verify that xHigherPriorityTaskWoken is not modified.
* @coverage xQueueGiveFromISR
*/
void test_macro_xSemaphoreGiveFromISR_low_priority_pending( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
vFakePortAssertIfInterruptPriorityInvalid_Expect();
/* Insert an item into the event list */
td_task_setFakeTaskPriority( DEFAULT_PRIORITY - 1 );
td_task_addFakeTaskWaitingToReceiveFromQueue( xSemaphore );
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
/* Give the semaphore */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken ) );
TEST_ASSERT_EQUAL( pdFALSE, xHigherPriorityTaskWoken );
TEST_ASSERT_EQUAL( pdFALSE, td_task_getYieldPending() );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGiveFromISR with no tasks waiting
* @details Test xSemaphoreGiveFromISR with no tasks waiting and verify that xHigherPriorityTaskWoken is not modified.
* @coverage xQueueGiveFromISR
*/
void test_macro_xSemaphoreGiveFromISR_no_pending( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
vFakePortAssertIfInterruptPriorityInvalid_Expect();
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
/* Give the semaphore */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken ) );
TEST_ASSERT_EQUAL( pdFALSE, xHigherPriorityTaskWoken );
TEST_ASSERT_EQUAL( pdFALSE, td_task_getYieldPending() );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGiveFromISR on a semaphore that is locked
* @coverage xQueueGiveFromISR
*/
void test_xSemaphoreGiveFromISR_locked( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
/* Set private lock counters */
vSetQueueRxLock( xSemaphore, queueLOCKED_UNMODIFIED );
vSetQueueTxLock( xSemaphore, queueLOCKED_UNMODIFIED );
vFakePortAssertIfInterruptPriorityInvalid_Expect();
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveFromISR( xSemaphore, NULL ) );
/* Verify that the cRxLock counter has not changed */
TEST_ASSERT_EQUAL( queueLOCKED_UNMODIFIED, cGetQueueRxLock( xSemaphore ) );
/* Verify that the cTxLock counter has been incremented */
TEST_ASSERT_EQUAL( queueLOCKED_UNMODIFIED + 1, cGetQueueTxLock( xSemaphore ) );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGiveFromISR on a semaphore that is locked and cRxLock overflows.
* @coverage xQueueGiveFromISR
*/
void test_xSemaphoreGiveFromISR_locked_overflow( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
/* Set private lock counters */
vSetQueueRxLock( xSemaphore, INT8_MAX );
vSetQueueTxLock( xSemaphore, INT8_MAX );
vFakePortAssertIfInterruptPriorityInvalid_Expect();
/* Expect an assertion since the cTxLock value has overflowed */
fakeAssertExpectFail();
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveFromISR( xSemaphore, NULL ) );
/* Verify that the cRxLock counter has not changed */
TEST_ASSERT_EQUAL( INT8_MAX, cGetQueueRxLock( xSemaphore ) );
/* Verify that the cTxLock counter has been incremented */
TEST_ASSERT_EQUAL( INT8_MIN, cGetQueueTxLock( xSemaphore ) );
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake with an occupied semaphore with higher priority tasks waiting
* @coverage xQueueSemaphoreTake
*/
void test_xSemaphoreTake_tasks_waiting_higher_priority( void )
{
/* Create a new binary semaphore */
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
( void ) xSemaphoreGive( xSemaphore );
/* Insert an item into the event list */
td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 );
td_task_addFakeTaskWaitingToSendToQueue( xSemaphore );
/* take the semaphore */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
TEST_ASSERT_EQUAL( 1, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( 1, td_task_getCount_vPortYieldWithinAPI() );
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake with an occupied semaphore with an equal priority task waiting
* @coverage xQueueSemaphoreTake
*/
void test_xSemaphoreTake_tasks_waiting_equal_priority( void )
{
/* Create a new binary semaphore */
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
( void ) xSemaphoreGive( xSemaphore );
/* Insert an item into the event list */
td_task_setFakeTaskPriority( DEFAULT_PRIORITY );
td_task_addFakeTaskWaitingToSendToQueue( xSemaphore );
/* take the semaphore */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
TEST_ASSERT_EQUAL( 0, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( 0, td_task_getCount_vPortYieldWithinAPI() );
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake with an occupied semaphore with lower priority tasks waiting.
* @coverage xQueueSemaphoreTake
*/
void test_xSemaphoreTake_tasks_waiting_lower_priority( void )
{
/* Create a new binary semaphore */
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
( void ) xSemaphoreGive( xSemaphore );
/* Insert an item into the event list */
td_task_setFakeTaskPriority( DEFAULT_PRIORITY - 1 );
td_task_addFakeTaskWaitingToSendToQueue( xSemaphore );
/* take the semaphore */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
TEST_ASSERT_EQUAL( 0, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( 0, td_task_getCount_vPortYieldWithinAPI() );
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake with taskSCHEDULER_SUSPENDED and timeout=10
* @details This should cause xSemaphoreTake to configASSERT becuase it would
* block forever when the semaphore is empty.
* @coverage xQueueSemaphoreTake
*/
void test_xSemaphoreTake_blocking_suspended_assert( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
fakeAssertExpectFail();
vTaskSuspendAll_Stub( td_task_vTaskSuspendAllStubNoCheck );
td_task_setSchedulerState( taskSCHEDULER_SUSPENDED );
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
TEST_ASSERT_EQUAL( pdTRUE, fakeAssertGetFlagAndClear() );
td_task_setSchedulerState( taskSCHEDULER_RUNNING );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake with taskSCHEDULER_SUSPENDED and timeout=0
* @details This should not cause xSemaphoreTake to configASSERT becuase
* xSemaphoreTake is non-blocking when timeout=0.
* @coverage xQueueSemaphoreTake
*/
void test_xSemaphoreTake_nonblocking_suspended_noassert( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
td_task_setSchedulerState( taskSCHEDULER_SUSPENDED );
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, 0 ) );
td_task_setSchedulerState( taskSCHEDULER_RUNNING );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Callback which calls xSemaphoreGive on xSemaphoreHandleStatic
*/
static BaseType_t blocking_success_xTaskCheckForTimeOut_cb( TimeOut_t * const pxTimeOut,
TickType_t * const pxTicksToWait,
int cmock_num_calls )
{
BaseType_t xReturnValue = td_task_xTaskCheckForTimeOutStub( pxTimeOut, pxTicksToWait, cmock_num_calls );
if( cmock_num_calls == NUM_CALLS_TO_INTERCEPT )
{
( void ) xSemaphoreGiveFromISR( xSemaphoreHandleStatic, NULL );
}
return xReturnValue;
}
/**
* @brief Test xSemaphoreTake in blocking mode with a taken Binary Semaphore
* which becomes available while a call to xSemaphoreTake is blocking.
* @coverage xQueueSemaphoreTake
*/
void test_xSemaphoreTake_blocking_sucess( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
/* Export for blocking_success_xTaskCheckForTimeOut_cb callback */
xSemaphoreHandleStatic = xSemaphore;
vFakePortAssertIfInterruptPriorityInvalid_Ignore();
xTaskCheckForTimeOut_Stub( &blocking_success_xTaskCheckForTimeOut_cb );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Callback which calls xSemaphoreGive on xSemaphoreHandleStatic when
* cmock_num_calls == TICKS_TO_WAIT
*/
static BaseType_t blocking_last_chance_xTaskCheckForTimeOut_cb( TimeOut_t * const pxTimeOut,
TickType_t * const pxTicksToWait,
int cmock_num_calls )
{
BaseType_t xReturnValue = td_task_xTaskCheckForTimeOutStub( pxTimeOut, pxTicksToWait, cmock_num_calls );
if( cmock_num_calls == TICKS_TO_WAIT )
{
( void ) xSemaphoreGiveFromISR( xSemaphoreHandleStatic, NULL );
return pdTRUE;
}
return xReturnValue;
}
/**
* @brief Test xSemaphoreTake in blocking mode with a Binary Semaphore that is initially taken,
* but becomes available at the end of the blocking time period.
* @coverage xQueueSemaphoreTake
*/
void test_xSemaphoreTake_blocking_success_last_chance( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
/* Export for blocking_success_xTaskCheckForTimeOut_cb callback */
xSemaphoreHandleStatic = xSemaphore;
vFakePortAssertIfInterruptPriorityInvalid_Expect();
xTaskCheckForTimeOut_Stub( &blocking_last_chance_xTaskCheckForTimeOut_cb );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake in blocking mode with a taken binary semaphore
* @coverage xQueueSemaphoreTake
*/
void test_xSemaphoreTake_blocking_timeout( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake in blocking mode with a taken locked semaphore
* @details This test case verifies a situation that should never occur
* ( xSemaphoreTake called on a locked semaphore ).
* @coverage xQueueSemaphoreTake
*/
void test_xSemaphoreTake_blocking_locked( void )
{
/* Create a new binary semaphore */
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
/* Set private lock counters */
vSetQueueRxLock( xSemaphore, queueLOCKED_UNMODIFIED );
vSetQueueTxLock( xSemaphore, queueLOCKED_UNMODIFIED );
/* Run xSemaphoreTake in blocking mode with the semaphore locked */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
/* Verify that the semaphore is now unlocked */
TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueRxLock( xSemaphore ) );
TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueTxLock( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Callback for test_xSemaphoreTake_blocking_success_locked_no_pending
* which adds an item to it's test queue.
*/
static BaseType_t xSemaphoreTake_xTaskCheckForTimeOutCB( TimeOut_t * const pxTimeOut,
TickType_t * const pxTicksToWait,
int cmock_num_calls )
{
BaseType_t xReturnValue = td_task_xTaskCheckForTimeOutStub( pxTimeOut, pxTicksToWait, cmock_num_calls );
if( cmock_num_calls == NUM_CALLS_TO_INTERCEPT )
{
TEST_ASSERT_TRUE( xSemaphoreGiveFromISR( xSemaphoreHandleStatic, NULL ) );
TEST_ASSERT_EQUAL( 1, uxQueueMessagesWaiting( xSemaphoreHandleStatic ) );
}
return xReturnValue;
}
/**
* @brief Test a blocking call to xSemaphoreTake with a locked binary semaphore.
* @details Test a blocking call to xSemaphoreTake with a locked binary semaphore with no
* tasks in the binary semaphore WaitingToReceiveFrom event list.
* @coverage xQueueSemaphoreTake prvUnlockQueue
*/
void test_xSemaphoreTake_blocking_success_locked_no_pending( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
vFakePortAssertIfInterruptPriorityInvalid_Ignore();
/* Export for callbacks */
xSemaphoreHandleStatic = xSemaphore;
xTaskCheckForTimeOut_Stub( &xSemaphoreTake_xTaskCheckForTimeOutCB );
xTaskResumeAll_Stub( &td_task_xTaskResumeAllStub );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
vQueueDelete( xSemaphore );
}
/**
* @brief Callback for xTaskResumeAll used by tests for blocking calls to
* xSemaphoreTake
*/
static BaseType_t xSemaphoreTake_xTaskResumeAllCallback( int cmock_num_calls )
{
BaseType_t xReturnValue = td_task_xTaskResumeAllStub( cmock_num_calls );
/* If td_task_xTaskResumeAllStub returns pdTRUE, a higher priority task is pending
* Receive from an ISR to block */
if( pdTRUE == xReturnValue )
{
if( cmock_num_calls == NUM_CALLS_TO_INTERCEPT )
{
TEST_ASSERT_EQUAL( 1, uxSemaphoreGetCount( xSemaphoreHandleStatic ) );
TEST_ASSERT_TRUE( xSemaphoreTakeFromISR( xSemaphoreHandleStatic, NULL ) );
}
}
return xReturnValue;
}
/**
* @brief Test a blocking call to xSemaphoreTake with a locked binary semaphore.
* @details Test a blocking call to xSemaphoreTake with a locked binary semaphore with a
* higher priority task in the binary semaphore WaitingToReceiveFrom event list.
* @coverage xQueueSemaphoreTake prvUnlockQueue
*/
void test_xSemaphoreTake_blocking_timeout_locked_high_prio_pending( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
vFakePortAssertIfInterruptPriorityInvalid_Ignore();
/* Export for callbacks */
xSemaphoreHandleStatic = xSemaphore;
xTaskCheckForTimeOut_Stub( &xSemaphoreTake_xTaskCheckForTimeOutCB );
xTaskResumeAll_Stub( &xSemaphoreTake_xTaskResumeAllCallback );
td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 );
td_task_addFakeTaskWaitingToReceiveFromQueue( xSemaphore );
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT + 1, td_task_getCount_YieldFromTaskResumeAll() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT - 1, td_task_getCount_vPortYieldWithinAPI() );
TEST_ASSERT_EQUAL( 1, td_task_getCount_vTaskMissedYield() );
vQueueDelete( xSemaphore );
}
/**
* @brief Test a blocking call to xSemaphoreTake with a locked binary semaphore.
* @details Test a blocking call to xSemaphoreTake with a locked binary semaphore with a
* lower priority task in the semaphore WaitingToReceiveFrom event list.
* @coverage xQueueSemaphoreTake prvUnlockQueue
*/
void test_xSemaphoreTake_blocking_success_locked_low_prio_pending( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
vFakePortAssertIfInterruptPriorityInvalid_Ignore();
/* Export for callbacks */
xSemaphoreHandleStatic = xSemaphore;
xTaskCheckForTimeOut_Stub( &xSemaphoreTake_xTaskCheckForTimeOutCB );
xTaskResumeAll_Stub( &xSemaphoreTake_xTaskResumeAllCallback );
td_task_setFakeTaskPriority( DEFAULT_PRIORITY - 1 );
td_task_addFakeTaskWaitingToReceiveFromQueue( xSemaphore );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
vQueueDelete( xSemaphore );
}

View file

@ -0,0 +1,894 @@
/*
* FreeRTOS V202012.00
* 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 counting_semaphore_utest.c */
#include "../queue_utest_common.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "semphr.h"
#include "mock_fake_port.h"
/* ============================ GLOBAL VARIABLES =========================== */
static SemaphoreHandle_t xSemaphoreHandleStatic;
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
xSemaphoreHandleStatic = NULL;
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* =========================== Helper functions ============================ */
/* ============================== Test Cases =============================== */
/**
* @brief Test xSemaphoreTake with an invalid counting semaphore
* @details Verify that a call to xSemaphoreTake fails on a counting
* semaphore created with uxMaxCount=0 and uxInitialCount=0
* @coverage xQueueSemaphoreTake
*/
void test_macro_xSemaphoreTake_CountingSemaphore_zero_zero_fail( void )
{
/* Expect that xSemaphoreCreateCounting will assert because uxMaxCount=0 is invalid */
fakeAssertExpectFail();
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 0, 0 );
fakeAssertGetNumAssertsAndClear();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Verify that an xSemaphoreTake fails */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, 0 ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGive with an invalid counting semaphore
* @details Verify that a call to xSemaphoreGive fails on a counting
* semaphore created with uxMaxCount=0 and uxInitialCount=0
* @coverage xQueueGenericSend
*/
void test_macro_xSemaphoreGive_CountingSemaphore_zero_zero_fail( void )
{
/* Expect that xSemaphoreCreateCounting will assert because uxMaxCount=0 is invalid */
fakeAssertExpectFail();
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 0, 0 );
fakeAssertGetNumAssertsAndClear();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Verify that an xSemaphoreGive fails */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGive( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGive with xSemaphoreCreateCounting( 1, 2 )
* @details Test xSemaphoreGive with an invalid counting semaphore where
* uxInitialCount > xMaxCount
* @coverage xQueueGenericSend
*/
void test_macro_xSemaphoreGive_with_CountingSemaphore_one_two_fail( void )
{
/* Expect that xSemaphoreCreateCounting will assert because
* uxInitialCount > xMaxCount is invalid */
fakeAssertExpectFail();
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 1, 2 );
fakeAssertGetFlagAndClear();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Verify that an xSemaphoreGive fails */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGive( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake with xSemaphoreCreateCounting( 1, 2 )
* @details Test xSemaphoreTake with an invalid counting semaphore where
* uxInitialCount > xMaxCount
* @coverage xQueueSemaphoreTake
*/
void test_macro_xSemaphoreTake_with_CountingSemaphore_one_two_success( void )
{
/* Expect that xSemaphoreCreateCounting will assert because
* uxInitialCount > xMaxCount is invalid */
fakeAssertExpectFail();
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 1, 2 );
fakeAssertGetFlagAndClear();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Verify that an xSemaphoreTake succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake and xSemaphoreGive with xSemaphoreCreateCounting( 1, 2 )
* @details Test xSemaphoreTake and xSemaphoreGive with an invalid counting
* semaphore where uxInitialCount > xMaxCount.
* @coverage xQueueSemaphoreTake xQueueGenericSend
*/
void test_macro_xSemaphoreTake_xSemaphoreGive_with_CountingSemaphore_one_two_success( void )
{
/* Expect that xSemaphoreCreateCounting will assert because
* uxInitialCount > xMaxCount is invalid */
fakeAssertExpectFail();
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 1, 2 );
fakeAssertGetFlagAndClear();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Verify that an xSemaphoreTake succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
/* Verify that a second xSemaphoreTake succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
/* Verify that an xSemaphoreGive succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGive( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake with xSemaphoreCreateCounting( 1, 0 )
* @details Test xSemaphoreTake with a binary semaphore constructed with
* xSemaphoreCreateCounting.
* @coverage xQueueSemaphoreTake
*/
void test_macro_xSemaphoreTake_CountingSemaphore_one_zero_fail( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 1, 0 );
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Verify that an xSemaphoreTake fails */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, 0 ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGive with xSemaphoreCreateCounting( 1, 0 )
* @details Test xSemaphoreGive with a binary semaphore constructed with
* xSemaphoreCreateCounting.
* @coverage xQueueGenericSend
*/
void test_macro_xSemaphoreGive_CountingSemaphore_one_zero_success( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 1, 0 );
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Verify that an xSemaphoreGive succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGive( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGive and xSemaphoreTake with xSemaphoreCreateCounting( 1, 0 )
* @details Test xSemaphoreGive and xSemaphoreTake with a binary semaphore
* constructed with xSemaphoreCreateCounting.
* @coverage xQueueGenericSend xQueueSemaphoreTake
*/
void test_macro_xSemaphoreGive_xSemaphoreTake_CountingSemaphore_one_zero_success( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 1, 0 );
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Verify that an xSemaphoreGive succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGive( xSemaphore ) );
/* Verify that an xSemaphoreTake succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
/* Verify that an xSemaphoreGive succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGive( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGive with xSemaphoreCreateCounting( 100, 50 )
* @details Test multiple xSemaphoreGive calls on a counting semaphore
* @coverage xQueueGenericSend
*/
void test_macro_xSemaphoreGive_CountingSemaphore_100_50( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 100, 50 );
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Call xSemaphoreGive 50 times and verify success */
for( int i = 0; i < 50; i++ )
{
/* Verify that an xSemaphoreGive operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGive( xSemaphore ) );
}
/* Check the count */
TEST_ASSERT_EQUAL( 100, uxSemaphoreGetCount( xSemaphore ) );
/* Veirfy that a subsequent call to xSemaphoreGive fails */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGive( xSemaphore ) );
/* Verify that an xSemaphoreTake operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
/* Check the count */
TEST_ASSERT_EQUAL( 99, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake with xSemaphoreCreateCounting( 100, 50 )
* @details Test multiple xSemaphoreTake calls on a counting semaphore
* @coverage xQueueSemaphoreTake
*/
void test_macro_xSemaphoreTake_CountingSemaphore_100_50( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 100, 50 );
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Call xSemaphoreTake 50 times and verify success */
for( int i = 0; i < 50; i++ )
{
/* Verify that an xSemaphoreTake operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
}
/* Check the count */
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
/* Veirfy that a subsequent call to xSemaphoreGive fails */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, 0 ) );
/* Verify that an xSemaphoreGive operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGive( xSemaphore ) );
/* Check the count */
TEST_ASSERT_EQUAL( 1, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Verify that this test case is running on a 64 bit platform.
*/
void test_size_of_UBaseType_is_64_bits( void )
{
if( TEST_PROTECT() )
{
/* Check that UBaseType_t is 64 bits on this platform */
TEST_ASSERT_EQUAL( sizeof( uint64_t ), sizeof( UBaseType_t ) );
}
}
/**
* @brief Test xSemaphoreGive with xSemaphoreCreateCounting( UINT64_MAX, UINT64_MAX-1 )
* @details Test xSemaphoreGive with a counting semaphore with uxMaxCount=UINT64_MAX and
* uxInitialCount=UINT64_MAX-1
* @coverage xQueueGenericSend
*/
void test_macro_xSemaphoreGive_CountingSemaphore_upper_bound( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( UINT64_MAX, UINT64_MAX - 1 );
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Check the initial count */
TEST_ASSERT_EQUAL( UINT64_MAX - 1, uxSemaphoreGetCount( xSemaphore ) );
/* Verify that a xSemaphoreGive operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGive( xSemaphore ) );
/* Check the count */
TEST_ASSERT_EQUAL( UINT64_MAX, uxSemaphoreGetCount( xSemaphore ) );
/* Verify that the next xSemaphoreGive operation fails */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGive( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake with xSemaphoreCreateCounting( UINT64_MAX, UINT64_MAX )
* @details Test xSemaphoreTake with a counting semaphore with uxMaxCount=UINT64_MAX and
* uxInitialCount=UINT64_MAX
* @coverage xQueueSemaphoreTake
*/
void test_macro_xSemaphoreTake_CountingSemaphore_upper_bound( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( UINT64_MAX, UINT64_MAX );
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
/* Verify that a xSemaphoreTake operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
TEST_ASSERT_EQUAL( UINT64_MAX - 1, uxSemaphoreGetCount( xSemaphore ) );
/* Verify that a subsequent xSemaphoreGive operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGive( xSemaphore ) );
/* Check the count */
TEST_ASSERT_EQUAL( UINT64_MAX, uxSemaphoreGetCount( xSemaphore ) );
/* Verify that the next xSemaphoreGive operation fails */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGive( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief xSemaphoreTake with xSemaphoreCreateCounting( UINT64_MAX, 1)
* @details Test xSemaphoreTake with a counting semaphore with uxMaxCount=UINT64_MAX and
* uxInitialCount=1
* @coverage xQueueSemaphoreTake
*/
void test_macro_xSemaphoreTake_CountingSemaphore_lower_bound( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( UINT64_MAX, 1 );
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
/* Check the initial count */
TEST_ASSERT_EQUAL( 1, uxSemaphoreGetCount( xSemaphore ) );
/* Verify that a xSemaphoreTake operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
/* Check the count */
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
/* Verify that the next xSemaphoreTake operation fails */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, 0 ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief xSemaphoreGive with xSemaphoreCreateCounting( UINT64_MAX, 0)
* @details Test xSemaphoreGive with a counting semaphore with uxMaxCount=UINT64_MAX and
* uxInitialCount=0
* @coverage xQueueGenericSend
*/
void test_macro_xSemaphoreGive_CountingSemaphore_lower_bound( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( UINT64_MAX, 0 );
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
/* Check the initial count */
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
/* Verify that a xSemaphoreGive operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGive( xSemaphore ) );
/* Check the count */
TEST_ASSERT_EQUAL( 1, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGive with xSemaphoreCreateCounting( UINT64_MAX - 1, UINT64_MAX )
* @details Test xSemaphoreGive with a counting semaphore with uxMaxCount=UINT64_MAX-1 and
* uxInitialCount=UINT64_MAX
* @coverage xQueueGenericSend
*/
void test_macro_xSemaphoreGive_CountingSemaphore_over_upper_bound( void )
{
/* Expect that xSemaphoreCreateCounting will configASSERT because
* uxInitialCount > xMaxCount is invalid */
fakeAssertExpectFail();
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( UINT64_MAX - 1, UINT64_MAX );
/* verify that configASSERT was called */
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Check the count */
TEST_ASSERT_EQUAL( UINT64_MAX, uxSemaphoreGetCount( xSemaphore ) );
/* Verify that an xSemaphoreGive operation fails */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGive( xSemaphore ) );
/* Check that the count has not changed */
TEST_ASSERT_EQUAL( UINT64_MAX, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGive with a counting semaphore where uxInitialCount > uxMaxCount
* @details Test xSemaphoreGive with a counting semaphore with uxMaxCount=1 and
* uxInitialCount=2
* @coverage xQueueGenericSend
*/
void test_macro_xSemaphoreGive_count_higher_than_max( void )
{
/* Expect that xSemaphoreCreateCounting will assert because
* uxInitialCount > xMaxCount is invalid */
fakeAssertExpectFail();
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 1, 2 );
fakeAssertGetFlagAndClear();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Check that the count was initialized correctly */
TEST_ASSERT_EQUAL( 2, uxSemaphoreGetCount( xSemaphore ) );
/* Verify that an xSemaphoreGive fails (would cause the count to increase) */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGive( xSemaphore ) );
/* Verify that an xSemaphoreTake succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
/* Check that the count has decreased */
TEST_ASSERT_EQUAL( 1, uxSemaphoreGetCount( xSemaphore ) );
/* Verify that an xSemaphoreGive fails (would cause the count to increase beyond 2) */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGive( xSemaphore ) );
/* Verify that an xSemaphoreTake succeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
/* Check that the count has decreased */
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
/* Verify that an xSemaphoreGive succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGive( xSemaphore ) );
/* Check that the count is now 1 */
TEST_ASSERT_EQUAL( 1, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake with taskSCHEDULER_SUSPENDED and timeout=10
* @details This should cause xSemaphoreTake to configASSERT becuase it would
* block forever when the semaphore is empty.
* @coverage xQueueSemaphoreTake
*/
void test_xSemaphoreTake_blocking_suspended_assert( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 2, 0 );
fakeAssertExpectFail();
vTaskSuspendAll_Stub( td_task_vTaskSuspendAllStubNoCheck );
td_task_setSchedulerState( taskSCHEDULER_SUSPENDED );
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
TEST_ASSERT_EQUAL( pdTRUE, fakeAssertGetFlagAndClear() );
td_task_setSchedulerState( taskSCHEDULER_RUNNING );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake with taskSCHEDULER_SUSPENDED and timeout=0
* @details This should not cause xSemaphoreTake to configASSERT becuase
* xSemaphoreTake is non-blocking when timeout=0.
* @coverage xQueueSemaphoreTake
*/
void test_xSemaphoreTake_nonblocking_suspended_noassert( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 2, 0 );
td_task_setSchedulerState( taskSCHEDULER_SUSPENDED );
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, 0 ) );
td_task_setSchedulerState( taskSCHEDULER_RUNNING );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Callback which calls xSemaphoreGive on xSemaphoreHandleStatic when
* cmock_num_calls == NUM_CALLS_TO_INTERCEPT
*/
static BaseType_t blocking_xTaskCheckForTimeOut_cb( TimeOut_t * const pxTimeOut,
TickType_t * const pxTicksToWait,
int cmock_num_calls )
{
BaseType_t xReturnValue = td_task_xTaskCheckForTimeOutStub( pxTimeOut, pxTicksToWait, cmock_num_calls );
if( cmock_num_calls == NUM_CALLS_TO_INTERCEPT )
{
( void ) xSemaphoreGiveFromISR( xSemaphoreHandleStatic, NULL );
TEST_ASSERT_EQUAL( 1, uxSemaphoreGetCount( xSemaphoreHandleStatic ) );
}
return xReturnValue;
}
/**
* @brief Test xSemaphoreTake in blocking mode with a fully taken Counting Semaphore
* which becomes available while a call to xSemaphoreTake is blocking.
* @coverage xQueueSemaphoreTake
*/
void test_xSemaphoreTake_blocking_sucess( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 2, 0 );
/* Export for blocking_success_xTaskCheckForTimeOut_cb callback */
xSemaphoreHandleStatic = xSemaphore;
vFakePortAssertIfInterruptPriorityInvalid_Expect();
xTaskCheckForTimeOut_Stub( &blocking_xTaskCheckForTimeOut_cb );
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Callback which calls xSemaphoreGive on xSemaphoreHandleStatic when
* cmock_num_calls == TICKS_TO_WAIT
*/
static BaseType_t blocking_last_chance_xTaskCheckForTimeOut_cb( TimeOut_t * const pxTimeOut,
TickType_t * const pxTicksToWait,
int cmock_num_calls )
{
BaseType_t xReturnValue = td_task_xTaskCheckForTimeOutStub( pxTimeOut, pxTicksToWait, cmock_num_calls );
if( cmock_num_calls == TICKS_TO_WAIT )
{
( void ) xSemaphoreGiveFromISR( xSemaphoreHandleStatic, NULL );
TEST_ASSERT_EQUAL( 1, uxSemaphoreGetCount( xSemaphoreHandleStatic ) );
return pdTRUE;
}
return xReturnValue;
}
/**
* @brief Test xSemaphoreTake in blocking mode with a Counting Semaphore that is
* initially fully taken, but becomes available at the end of the blocking time.
* @coverage xQueueSemaphoreTake
*/
void test_xSemaphoreTake_blocking_success_last_chance( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 2, 0 );
/* Export for blocking_success_xTaskCheckForTimeOut_cb callback */
xSemaphoreHandleStatic = xSemaphore;
vFakePortAssertIfInterruptPriorityInvalid_Expect();
xTaskCheckForTimeOut_Stub( &blocking_last_chance_xTaskCheckForTimeOut_cb );
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/*
* @brief Test xSemaphoreTake in blocking mode with a taken binary semaphore
* @coverage xQueueSemaphoreTake
*/
void test_xSemaphoreTake_blocking_timeout( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 2, 0 );
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake in blocking mode with a taken locked semaphore
* @details This test case verifies a situation that should never occur
* ( xSemaphoreTake called on a locked semaphore ).
* @coverage xQueueSemaphoreTake
*/
void test_xSemaphoreTake_blocking_locked( void )
{
/* Create a new binary semaphore */
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 2, 0 );
/* Set private lock counters */
vSetQueueRxLock( xSemaphore, queueLOCKED_UNMODIFIED );
vSetQueueTxLock( xSemaphore, queueLOCKED_UNMODIFIED );
/* Run xSemaphoreTake in blocking mode with the semaphore locked */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
/* Verify that the semaphore is now unlocked */
TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueRxLock( xSemaphore ) );
TEST_ASSERT_EQUAL( queueUNLOCKED, cGetQueueTxLock( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Callback for test_xSemaphoreTake_blocking_success_locked_no_pending
* which adds an item to it's test queue.
*/
static BaseType_t xSemaphoreTake_xTaskCheckForTimeOutCB( TimeOut_t * const pxTimeOut,
TickType_t * const pxTicksToWait,
int cmock_num_calls )
{
BaseType_t xReturnValue = td_task_xTaskCheckForTimeOutStub( pxTimeOut, pxTicksToWait, cmock_num_calls );
if( cmock_num_calls == NUM_CALLS_TO_INTERCEPT )
{
TEST_ASSERT_TRUE( xSemaphoreGiveFromISR( xSemaphoreHandleStatic, NULL ) );
TEST_ASSERT_EQUAL( 1, uxSemaphoreGetCount( xSemaphoreHandleStatic ) );
}
return xReturnValue;
}
/**
* @brief Test a blocking call to xSemaphoreTake with a locked counting semaphore.
* @details Test a blocking call to xSemaphoreTake with a locked counting semaphore with no
* tasks in the counting semaphore WaitingToReceiveFrom event list.
* @coverage xQueueSemaphoreTake prvUnlockQueue
*/
void test_xSemaphoreTake_blocking_success_locked_no_pending( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 2, 0 );
vFakePortAssertIfInterruptPriorityInvalid_Ignore();
/* Export for callbacks */
xSemaphoreHandleStatic = xSemaphore;
xTaskCheckForTimeOut_Stub( &xSemaphoreTake_xTaskCheckForTimeOutCB );
xTaskResumeAll_Stub( &td_task_xTaskResumeAllStub );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
vQueueDelete( xSemaphore );
}
/**
* @brief Callback for xTaskResumeAll used by tests for blocking calls to
* xSemaphoreTake
*/
static BaseType_t xSemaphoreTake_xTaskResumeAllCallback( int cmock_num_calls )
{
BaseType_t xReturnValue = td_task_xTaskResumeAllStub( cmock_num_calls );
/* If td_task_xTaskResumeAllStub returns pdTRUE, a higher priority task is pending
* Receive from an ISR to block */
if( pdTRUE == xReturnValue )
{
if( cmock_num_calls == NUM_CALLS_TO_INTERCEPT )
{
TEST_ASSERT_EQUAL( 1, uxSemaphoreGetCount( xSemaphoreHandleStatic ) );
TEST_ASSERT_TRUE( xSemaphoreTakeFromISR( xSemaphoreHandleStatic, NULL ) );
}
}
return xReturnValue;
}
/**
* @brief Test a blocking call to xSemaphoreTake with a locked counting semaphore.
* @details Test a blocking call to xSemaphoreTake with a locked counting semaphore with a
* higher priority task in the counting semaphore WaitingToReceiveFrom event list.
* @coverage xQueueSemaphoreTake prvUnlockQueue
*/
void test_xSemaphoreTake_blocking_timeout_locked_high_prio_pending( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 2, 0 );
vFakePortAssertIfInterruptPriorityInvalid_Ignore();
/* Export for callbacks */
xSemaphoreHandleStatic = xSemaphore;
xTaskCheckForTimeOut_Stub( &xSemaphoreTake_xTaskCheckForTimeOutCB );
xTaskResumeAll_Stub( &xSemaphoreTake_xTaskResumeAllCallback );
td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 );
td_task_addFakeTaskWaitingToReceiveFromQueue( xSemaphore );
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT + 1, td_task_getCount_YieldFromTaskResumeAll() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT - 1, td_task_getCount_vPortYieldWithinAPI() );
TEST_ASSERT_EQUAL( 1, td_task_getCount_vTaskMissedYield() );
vQueueDelete( xSemaphore );
}
/**
* @brief Test a blocking call to xSemaphoreTake with a locked counting semaphore.
* @details Test a blocking call to xSemaphoreTake with a locked counting semaphore with a
* lower priority task in the semaphore WaitingToReceiveFrom event list.
* @coverage xQueueSemaphoreTake prvUnlockQueue
*/
void test_xSemaphoreTake_blocking_success_locked_low_prio_pending( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 2, 0 );
vFakePortAssertIfInterruptPriorityInvalid_Ignore();
/* Export for callbacks */
xSemaphoreHandleStatic = xSemaphore;
xTaskCheckForTimeOut_Stub( &xSemaphoreTake_xTaskCheckForTimeOutCB );
xTaskResumeAll_Stub( &xSemaphoreTake_xTaskResumeAllCallback );
td_task_setFakeTaskPriority( DEFAULT_PRIORITY - 1 );
td_task_addFakeTaskWaitingToReceiveFromQueue( xSemaphore );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT, td_task_getCount_vPortYieldWithinAPI() );
vQueueDelete( xSemaphore );
}

View file

@ -0,0 +1,588 @@
/*
* FreeRTOS V202012.00
* 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 mutex_utest.c */
#include "../queue_utest_common.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "semphr.h"
#include "mock_fake_port.h"
/* ============================ GLOBAL VARIABLES =========================== */
static SemaphoreHandle_t xSemaphoreHandleStatic = NULL;
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* ========================== Helper functions =========================== */
/* ========================== Test Cases =========================== */
/**
* @brief Test xSemaphoreCreateMutex where the call to malloc fails
* @coverage xQueueCreateMutex
*/
void test_macro_xSemaphoreCreateMutex_malloc_fail( void )
{
UnityMalloc_MakeMallocFailAfterCount( 0 );
SemaphoreHandle_t xSemaphore = INVALID_PTR;
xSemaphore = xSemaphoreCreateMutex();
/* validate returned semaphore handle */
TEST_ASSERT_EQUAL( NULL, xSemaphore );
}
/**
* @brief Test xSemaphoreCreateMutex
* @details Create a mutex using xSemaphoreCreateMutex
* @coverage xQueueCreateMutex
*/
void test_macro_xSemaphoreCreateMutex_success( void )
{
xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
SemaphoreHandle_t xSemaphore = xSemaphoreCreateMutex();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreCreateMutexStatic with a null buffer
* @coverage xQueueCreateMutexStatic
*/
void test_macro_xSemaphoreCreateMutexStatic_nullptr( void )
{
SemaphoreHandle_t xSemaphore = INVALID_PTR;
/* Expect that xQueueCreate will assert due to the NULL buffer */
fakeAssertExpectFail();
xSemaphore = xSemaphoreCreateMutexStatic( NULL );
/* verify that configASSERT was called */
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
TEST_ASSERT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
}
/**
* @brief Test xSemaphoreCreateMutexStatic with a valid buffer.
* @details Create a semaphore using xSemaphoreCreateMutexStatic
* @coverage xQueueCreateMutexStatic
*/
void test_macro_xSemaphoreCreateMutexStatic_success( void )
{
SemaphoreHandle_t xSemaphore = NULL;
StaticSemaphore_t xSemaphoreBuffer;
xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
xSemaphore = xSemaphoreCreateMutexStatic( &xSemaphoreBuffer );
/* Check that no call to malloc occurred */
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake with a Mutex
* @details Create a mutex using xSemaphoreCreateMutex
* and verify that an immediate call to xSemaphoreTake succeeds.
* @coverage xQueueSemaphoreTake
*/
void test_macro_xSemaphoreTake_success( void )
{
xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
SemaphoreHandle_t xSemaphore = xSemaphoreCreateMutex();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
pvTaskIncrementMutexHeldCount_IgnoreAndReturn( NULL );
/* Verify that an immediate xSemaphoreTake operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGive with xSemaphoreCreateMutex
* @details Create a mutex using xSemaphoreCreateMutex
* and verify that an immediate call to xSemaphoreGive fails.
* @coverage xQueueGenericSend
*/
void test_macro_xSemaphoreGive_fail( void )
{
xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
SemaphoreHandle_t xSemaphore = xSemaphoreCreateMutex();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Verify that an immediate xSemaphoreGive operation fails */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGive( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGive and xSemaphoreTake with xSemaphoreCreateMutex
* @details Create a mutex using xSemaphoreCreateMutex
* and verify that an immediate call to xSemaphoreGive succeeds and a subsequent
* call to xSemaphoreTake succeeds.
* @coverage xQueueGenericSend xQueueSemaphoreTake
*/
void test_macro_xSemaphoreGive_xSemaphoreTake_success( void )
{
xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
SemaphoreHandle_t xSemaphore = xSemaphoreCreateMutex();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
pvTaskIncrementMutexHeldCount_ExpectAndReturn( 0 );
/* Verify that an immediate xSemaphoreTake operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
/* Verify that a subsequent xSemaphoreGive operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGive( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGive multiple times on a Mutex.
* @details Create a mutex using xSemaphoreCreateMutex
* and verify that an immediate call to xSemaphoreGive succeeds and a subsequent
* call to xSemaphoreGive fails.
* @coverage xQueueGenericSend
*/
void test_macro_xSemaphoreGive_multiple_Mutex_fail( void )
{
xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
SemaphoreHandle_t xSemaphore = xSemaphoreCreateMutex();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
pvTaskIncrementMutexHeldCount_ExpectAndReturn( 0 );
xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
xSemaphoreTake( xSemaphore, 0 );
/* Verify that the first xSemaphoreGive call succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGive( xSemaphore ) );
/* Verify that a second xSemaphoreGive call fails */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGive( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake multiple times on a Mutex.
* @details Create a Mutex using xSemaphoreCreateMutex,
* verify that an immediate call to xSemaphoreTake succeeds, a subsequent
* call to xSemaphoreGive succeds, but a second call to xSemaphoreGive fails.
* @coverage xQueueSemaphoreTake
*/
void test_macro_xSemaphoreTake_multiple_Mutex_fail( void )
{
xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
SemaphoreHandle_t xSemaphore = xSemaphoreCreateMutex();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
pvTaskIncrementMutexHeldCount_ExpectAndReturn( 0 );
/* Verify that an immediate xSemaphoreTake operation succeeds */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
/* Verify that the second xSemaphoreTake operation fails */
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, 0 ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test uxSemaphoreGetCount with a Mutex
* @details Create a Mutex using xSemaphoreCreateMutex.
* validate the return value of uxSemaphoreGetCount(),
* call xSemaphoreTake() and validate the return value of uxSemaphoreGetCount()
* @coverage uxQueueMessagesWaiting
*/
void test_macro_uxSemaphoreGetCount_Mutex( void )
{
SemaphoreHandle_t xSemaphore = NULL;
xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
pvTaskIncrementMutexHeldCount_ExpectAndReturn( 0 );
xSemaphore = xSemaphoreCreateMutex();
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
xSemaphoreTake( xSemaphore, 0 );
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGetMutexHolder with an invalid (null) SemaphoreHandle_t
* @coverage xQueueGetMutexHolder
*/
void test_macro_xSemaphoreGetMutexHolder_NULL( void )
{
/* This previously caused a segfault, but I patched queue.c */
EXPECT_ASSERT_BREAK( xSemaphoreGetMutexHolder( NULL ) );
}
/**
* @brief Test xSemaphoreGetMutexHolder with a handle of a binary semaphore
* @details Verify that xSemaphoreGetMutexHolder returns NULL when given a handle to a binary semaphore rather than a mutex.
* @coverage xQueueGetMutexHolder
*/
void test_macro_xSemaphoreGetMutexHolder_binary_semaphore( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
TEST_ASSERT_EQUAL( NULL, xSemaphoreGetMutexHolder( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGetMutexHolder with a valid SemaphoreHandle_t
* @coverage xQueueGetMutexHolder
*/
void test_macro_xSemaphoreGetMutexHolder_Mutex( void )
{
TaskHandle_t xMutexHolder = ( void * ) ( BaseType_t ) getNextMonotonicTestValue();
xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
SemaphoreHandle_t xSemaphore = xSemaphoreCreateMutex();
pvTaskIncrementMutexHeldCount_ExpectAndReturn( xMutexHolder );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
TEST_ASSERT_EQUAL( xMutexHolder, xSemaphoreGetMutexHolder( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGetMutexHolderFromISR with an invalid (null) SemaphoreHandle_t
* @coverage xQueueGetMutexHolderFromISR
*/
void test_macro_xSemaphoreGetMutexHolderFromISR_Mutex_NULL( void )
{
EXPECT_ASSERT_BREAK( xSemaphoreGetMutexHolderFromISR( NULL ) );
}
/**
* @brief Test xSemaphoreGetMutexHolderFromISR with a handle of a binary semaphore
* @details Verify that xSemaphoreGetMutexHolderFromISR returns NULL when given a handle to a binary semaphore rather than a mutex.
* @coverage xQueueGetMutexHolderFromISR
*/
void test_macro_xSemaphoreGetMutexHolderFromISR_binary_semaphore( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
TEST_ASSERT_EQUAL( NULL, xSemaphoreGetMutexHolderFromISR( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGetMutexHolderFromISR with a valid SemaphoreHandle_t
* @coverage xQueueGetMutexHolderFromISR
*/
void test_macro_xSemaphoreGetMutexHolderFromISR_Mutex( void )
{
TaskHandle_t xMutexHolder = ( void * ) ( BaseType_t ) getNextMonotonicTestValue();
xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
SemaphoreHandle_t xSemaphore = xSemaphoreCreateMutex();
pvTaskIncrementMutexHeldCount_ExpectAndReturn( xMutexHolder );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
TEST_ASSERT_EQUAL( xMutexHolder, xSemaphoreGetMutexHolderFromISR( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGiveFromISR with a Mutex that has an owner.
* @details Verify that xSemaphoreGiveFromISR configASSERTs when an owned mutex is given as the xSemaphore argument.
* @coverage xQueueGiveFromISR
*/
void test_macro_xSemaphoreGiveFromISR_mutex_owned( void )
{
TaskHandle_t xMutexHolder = ( void * ) ( BaseType_t ) getNextMonotonicTestValue();
xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
SemaphoreHandle_t xSemaphore = xSemaphoreCreateMutex();
/* Setup mocks for xSemaphoretake */
pvTaskIncrementMutexHeldCount_ExpectAndReturn( xMutexHolder );
vFakePortAssertIfInterruptPriorityInvalid_Expect();
xSemaphoreTake( xSemaphore, 0 );
/* Expect that xSemaphoreGiveFromISR will assert due to the mutex usage */
fakeAssertExpectFail();
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveFromISR( xSemaphore, NULL ) );
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGiveFromISR with a Mutex that has a NULL owner.
* @details Verify that xSemaphoreGiveFromISR does not configASSERT when a mutex with a NULL owner is given in the xSemaphore argument.
* @coverage xQueueGiveFromISR
*/
void test_macro_xSemaphoreGiveFromISR_mutex_not_owned( void )
{
xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
SemaphoreHandle_t xSemaphore = xSemaphoreCreateMutex();
/* Setup mocks for xSemaphoretake */
pvTaskIncrementMutexHeldCount_ExpectAndReturn( NULL );
vFakePortAssertIfInterruptPriorityInvalid_Expect();
xSemaphoreTake( xSemaphore, 0 );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveFromISR( xSemaphore, NULL ) );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake in blocking mode on an already owned mutex.
* @details Test xSemaphoreTake on a mutex owned by another task where the owning task has lower priority.
* @coverage xQueueSemaphoreTake prvGetDisinheritPriorityAfterTimeout
*/
void test_macro_xSemaphoreTake_blocking_mutex_inherit_timeout( void )
{
xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
SemaphoreHandle_t xSemaphore = xSemaphoreCreateMutex();
BaseType_t xFakeMutexHolder = getNextMonotonicTestValue();
/* Return a test value from the call to pvTaskIncrementMutexHeldCount */
pvTaskIncrementMutexHeldCount_ExpectAndReturn( ( void * ) xFakeMutexHolder );
/* Take the mutex */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
for( int i = 0; i < TICKS_TO_WAIT; i++ )
{
/* Return pdTRUE to signify that priority inheritence occurred */
xTaskPriorityInherit_ExpectAndReturn( ( void * ) xFakeMutexHolder, pdTRUE );
}
vTaskPriorityDisinheritAfterTimeout_Expect( ( void * ) ( BaseType_t ) getLastMonotonicTestValue(), tskIDLE_PRIORITY );
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT, td_task_getCount_vPortYieldWithinAPI() );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTake in blocking mode on an already owned mutex.
* @details Test xSemaphoreTake on a mutex owned by another task with another high priority task waiting and the current task timing out.
* @coverage xQueueSemaphoreTake prvGetDisinheritPriorityAfterTimeout
*/
void test_macro_xSemaphoreTake_blocking_mutex_inherit_timeout_high_prio_waiting( void )
{
xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
SemaphoreHandle_t xSemaphore = xSemaphoreCreateMutex();
TaskHandle_t xFakeMutexHolder = ( TaskHandle_t ) ( ( uint64_t ) 0 + getNextMonotonicTestValue() );
/* Return a test value from the call to pvTaskIncrementMutexHeldCount */
pvTaskIncrementMutexHeldCount_ExpectAndReturn( xFakeMutexHolder );
/* Take the mutex */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
/* Insert an item into the event list */
td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 );
td_task_addFakeTaskWaitingToReceiveFromQueue( xSemaphore );
for( int i = 0; i < TICKS_TO_WAIT; i++ )
{
/* Return pdTRUE to signify that priority inheritence occurred */
xTaskPriorityInherit_ExpectAndReturn( xFakeMutexHolder, pdTRUE );
}
vTaskPriorityDisinheritAfterTimeout_Expect( xFakeMutexHolder, DEFAULT_PRIORITY + 1 );
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTake( xSemaphore, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT + 1, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( TICKS_TO_WAIT + 1, td_task_getCount_YieldFromTaskResumeAll() );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Callback for test_macro_xSemaphoreTake_blocking_mutex_inherit_disinherit
*/
static BaseType_t xSemaphoreTake_blocking_xTaskResumeAllStub( int cmock_num_calls )
{
BaseType_t xReturnValue = td_task_xTaskResumeAllStub( cmock_num_calls );
if( cmock_num_calls == NUM_CALLS_TO_INTERCEPT )
{
TEST_ASSERT_TRUE( xSemaphoreGive( xSemaphoreHandleStatic ) );
}
return xReturnValue;
}
/**
* @brief Test priority inheritance during a successful blocking call to xSemaphoreTake
* @coverage xQueueSemaphoreTake
*/
void test_macro_xSemaphoreTake_blocking_mutex_inherit_disinherit( void )
{
xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
SemaphoreHandle_t xSemaphore = xSemaphoreCreateMutex();
xSemaphoreHandleStatic = xSemaphore;
TaskHandle_t xFakeMutexHolder = ( TaskHandle_t ) ( ( uint64_t ) 0 + getNextMonotonicTestValue() );
xTaskResumeAll_Stub( &xSemaphoreTake_blocking_xTaskResumeAllStub );
/* Return a test value from the call to pvTaskIncrementMutexHeldCount */
pvTaskIncrementMutexHeldCount_ExpectAndReturn( xFakeMutexHolder );
/* Take the mutex */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, 0 ) );
for( int i = 0; i < NUM_CALLS_TO_INTERCEPT + 1; i++ )
{
/* Return pdTRUE to signify that priority inheritence occurred */
xTaskPriorityInherit_ExpectAndReturn( xFakeMutexHolder, pdTRUE );
}
xTaskPriorityDisinherit_ExpectAndReturn( xFakeMutexHolder, pdTRUE );
/* Return a test value from the call to pvTaskIncrementMutexHeldCount */
pvTaskIncrementMutexHeldCount_ExpectAndReturn( xFakeMutexHolder );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xSemaphore, TICKS_TO_WAIT ) );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT + 2, td_task_getYieldCount() );
TEST_ASSERT_EQUAL( NUM_CALLS_TO_INTERCEPT + 2, td_task_getCount_vPortYieldWithinAPI() );
vSemaphoreDelete( xSemaphore );
}

View file

@ -0,0 +1,355 @@
/*
* FreeRTOS V202012.00
* 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 recursive_mutex_utest.c */
#include "../queue_utest_common.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "semphr.h"
#include "mock_fake_port.h"
/* ============================ GLOBAL VARIABLES =========================== */
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
xTaskPriorityDisinherit_IgnoreAndReturn( pdFALSE );
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* ========================== Helper functions =========================== */
/* ============================= Test Cases ============================== */
/**
* @brief Test xSemaphoreCreateRecursiveMutex where the call to malloc fails
* @coverage xQueueCreateMutex
*/
void test_macro_xSemaphoreCreateRecursiveMutex_malloc_fail( void )
{
UnityMalloc_MakeMallocFailAfterCount( 0 );
SemaphoreHandle_t xSemaphore = INVALID_PTR;
xSemaphore = xSemaphoreCreateRecursiveMutex();
/* validate returned semaphore handle */
TEST_ASSERT_EQUAL( NULL, xSemaphore );
}
/**
* @brief Test xSemaphoreCreateRecursiveMutex
* @details Create a mutex using xSemaphoreCreateRecursiveMutex
* @coverage xQueueCreateMutex
*/
void test_macro_xSemaphoreCreateRecursiveMutex_success( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateRecursiveMutex();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreCreateRecursiveMutexStatic with a null buffer
* @coverage xQueueCreateMutexStatic
*/
void test_macro_xSemaphoreCreateRecursiveMutexStatic_nullptr( void )
{
SemaphoreHandle_t xSemaphore = INVALID_PTR;
/* Expect that xQueueCreate will assert due to the NULL buffer */
fakeAssertExpectFail();
xSemaphore = xSemaphoreCreateRecursiveMutexStatic( NULL );
/* verify that configASSERT was called */
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
TEST_ASSERT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
}
/**
* @brief Verify that calling xSemaphoreTakeRecursive with a NULL mutex handle causes a configASSERT failure.
* @coverage xQueueTakeMutexRecursive
*/
void test_macro_xSemaphoreTakeRecursive_null_handle( void )
{
EXPECT_ASSERT_BREAK( xSemaphoreTakeRecursive( NULL, 0 ) );
}
/**
* @brief Test xSemaphoreTakeRecursive with a mutex that is not owned by any task.
* @coverage xQueueTakeMutexRecursive
*/
void test_macro_xSemaphoreTakeRecursive_not_owned_once( void )
{
TaskHandle_t xMutexHolder = ( void * ) ( BaseType_t ) getNextMonotonicTestValue();
SemaphoreHandle_t xSemaphore = xSemaphoreCreateRecursiveMutex();
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
xTaskGetCurrentTaskHandle_ExpectAndReturn( xMutexHolder );
pvTaskIncrementMutexHeldCount_ExpectAndReturn( xMutexHolder );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTakeRecursive( xSemaphore, 0 ) );
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTakeRecursive with a mutex that is already owned by the current task
* @coverage xQueueTakeMutexRecursive
*/
void test_macro_xSemaphoreTakeRecursive_self_owned_twice( void )
{
TaskHandle_t xMutexHolder = ( void * ) ( BaseType_t ) getNextMonotonicTestValue();
SemaphoreHandle_t xSemaphore = xSemaphoreCreateRecursiveMutex();
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
xTaskGetCurrentTaskHandle_ExpectAndReturn( xMutexHolder );
pvTaskIncrementMutexHeldCount_ExpectAndReturn( xMutexHolder );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTakeRecursive( xSemaphore, 0 ) );
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
xTaskGetCurrentTaskHandle_ExpectAndReturn( xMutexHolder );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTakeRecursive( xSemaphore, 0 ) );
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreTakeRecursive on a mutex that is already owned by a different task
* @coverage xQueueTakeMutexRecursive
*/
void test_macro_xSemaphoreTakeRecursive_owned_other_task( void )
{
TaskHandle_t xMutexHolder1 = ( void * ) ( BaseType_t ) getNextMonotonicTestValue();
TaskHandle_t xMutexHolder2 = ( void * ) ( BaseType_t ) getNextMonotonicTestValue();
SemaphoreHandle_t xSemaphore = xSemaphoreCreateRecursiveMutex();
/* Take the recursive mutex with task handle == xMutexHolder1 */
xTaskGetCurrentTaskHandle_ExpectAndReturn( xMutexHolder1 );
pvTaskIncrementMutexHeldCount_ExpectAndReturn( xMutexHolder1 );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTakeRecursive( xSemaphore, 0 ) );
/* Attempt to take the recursive mutex with task handle == xMutexHolder2 */
xTaskGetCurrentTaskHandle_ExpectAndReturn( xMutexHolder2 );
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreTakeRecursive( xSemaphore, 0 ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Verify that calling xSemaphoreGiveRecursive with a NULL mutex handle causes a configASSERT failure.
* @coverage xQueueGiveMutexRecursive
*/
void test_macro_xSemaphoreGiveRecursive_null_handle( void )
{
EXPECT_ASSERT_BREAK( xSemaphoreGiveRecursive( NULL ) );
}
/**
* @brief Test xSemaphoreGiveRecursive with a mutex that is not already owned by any task.
* @coverage xQueueGiveMutexRecursive
*/
void test_macro_xSemaphoreGiveRecursive_unowned( void )
{
TaskHandle_t xMutexHolder = ( void * ) ( BaseType_t ) getNextMonotonicTestValue();
SemaphoreHandle_t xSemaphore = xSemaphoreCreateRecursiveMutex();
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
xTaskGetCurrentTaskHandle_ExpectAndReturn( xMutexHolder );
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGiveRecursive( xSemaphore ) );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGiveRecursive with a mutex that is not owned by any task with a NULL TaskHandle returned by calls to xTaskGetCurrentTaskHandle.
* @coverage xQueueGiveMutexRecursive
*/
void test_macro_xSemaphoreGiveRecursive_unowned_null_taskhandle( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateRecursiveMutex();
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
xTaskGetCurrentTaskHandle_ExpectAndReturn( NULL );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveRecursive( xSemaphore ) );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGiveRecursive with a mutex that is already owned by the current task
* @coverage xQueueGiveMutexRecursive
*/
void test_macro_xSemaphoreGiveRecursive_self_owned( void )
{
TaskHandle_t xMutexHolder = ( void * ) ( BaseType_t ) getNextMonotonicTestValue();
SemaphoreHandle_t xSemaphore = xSemaphoreCreateRecursiveMutex();
/* Take the Recursive Mutex from taskHandle == xMutexHolder */
xTaskGetCurrentTaskHandle_ExpectAndReturn( xMutexHolder );
pvTaskIncrementMutexHeldCount_ExpectAndReturn( xMutexHolder );
xSemaphoreTakeRecursive( xSemaphore, 0 );
/* Verify that the Recursive Mutex is in the taken state */
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
/* call xSemaphoreGiveRecursive to release the Recursive Mutex */
xTaskGetCurrentTaskHandle_ExpectAndReturn( xMutexHolder );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveRecursive( xSemaphore ) );
/* Verify that the Recursive Mutex is now in the available state */
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGiveRecursive on a mutex that is already owned by a different task
* @coverage xQueueGiveMutexRecursive
*/
void test_macro_xSemaphoreGiveRecursive_owned_other_task( void )
{
TaskHandle_t xMutexHolder1 = ( void * ) ( BaseType_t ) getNextMonotonicTestValue();
TaskHandle_t xMutexHolder2 = ( void * ) ( BaseType_t ) getNextMonotonicTestValue();
SemaphoreHandle_t xSemaphore = xSemaphoreCreateRecursiveMutex();
/* Take the Recursive Mutex from taskHandle == xMutexHolder */
xTaskGetCurrentTaskHandle_ExpectAndReturn( xMutexHolder1 );
pvTaskIncrementMutexHeldCount_ExpectAndReturn( xMutexHolder1 );
xSemaphoreTakeRecursive( xSemaphore, 0 );
/* Verify that the Recursive Mutex is in the taken state */
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
/* call xSemaphoreGiveRecursive to release the Recursive Mutex */
xTaskGetCurrentTaskHandle_ExpectAndReturn( xMutexHolder2 );
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGiveRecursive( xSemaphore ) );
/* Verify that the Recursive Mutex remains in the taken state */
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Call xSemaphoreTakeRecursive and xSemaphoreGiveRecursive each multiple times
* @coverage xQueueTakeMutexRecursive xQueueGiveMutexRecursive
*/
void test_macro_xSemaphoreTakeRecursive_xSemaphoreGiveRecursive_recursive( void )
{
TaskHandle_t xMutexHolder = ( void * ) ( BaseType_t ) getNextMonotonicTestValue();
SemaphoreHandle_t xSemaphore = xSemaphoreCreateRecursiveMutex();
/* Take the Recursive Mutex */
xTaskGetCurrentTaskHandle_ExpectAndReturn( xMutexHolder );
pvTaskIncrementMutexHeldCount_ExpectAndReturn( xMutexHolder );
xSemaphoreTakeRecursive( xSemaphore, 0 );
/* Verify that the Recursive Mutex is in the taken state */
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
/* Take the Recursive Mutex a second time */
xTaskGetCurrentTaskHandle_ExpectAndReturn( xMutexHolder );
xSemaphoreTakeRecursive( xSemaphore, 0 );
/* Verify that the Recursive Mutex remains in the taken state */
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
/* call xSemaphoreGiveRecursive to release the Recursive Mutex (first time) */
xTaskGetCurrentTaskHandle_ExpectAndReturn( xMutexHolder );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveRecursive( xSemaphore ) );
/* Verify that the Recursive Mutex remains in the taken state */
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
/* call xSemaphoreGiveRecursive to release the Recursive Mutex (second time) */
xTaskGetCurrentTaskHandle_ExpectAndReturn( xMutexHolder );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveRecursive( xSemaphore ) );
/* Verify that the Recursive Mutex is now in the available state */
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}

View file

@ -0,0 +1,169 @@
/*
* FreeRTOS V202012.00
* 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 semaphore_common_utest.c */
#include "../queue_utest_common.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "semphr.h"
/* ============================ GLOBAL VARIABLES =========================== */
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* =========================== Helper functions ============================ */
/* ============================== Test Cases =============================== */
/**
* @brief Test xSemaphoreTake with an invalid (NULL) handle
* @coverage xQueueSemaphoreTake
*/
void test_macro_xSemaphoreTake_invalid_handle( void )
{
EXPECT_ASSERT_BREAK( xSemaphoreTake( NULL, 0 ) );
}
/**
* @brief Test xSemaphoreTake with a QueueHandle rather than a SemaphoreHandle
* @coverage xQueueSemaphoreTake
*/
void test_macro_xSemaphoreTake_queue_handle( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
uint32_t testVal = getNextMonotonicTestValue();
xQueueSend( xQueue, &testVal, 0 );
/* Expect that xSemaphoreTake will assert because xQueue is not a semaphore */
fakeAssertExpectFail();
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreTake( xQueue, 0 ) );
/* verify that configASSERT was called */
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
vQueueDelete( xQueue );
}
/**
* @brief Test xSemaphoreGive with an invalid (NULL) handle
* @coverage xQueueGenericSend
*/
void test_macro_xSemaphoreGive_invalid_handle( void )
{
EXPECT_ASSERT_BREAK( xSemaphoreGive( NULL ) );
}
/**
* @brief Test xSemaphoreGive with a QueueHandle rather than a SemaphoreHandle
* @coverage xQueueGenericSend
*/
void test_macro_xSemaphoreGive_queue_handle( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
EXPECT_ASSERT_BREAK( xSemaphoreGive( xQueue ) );
vQueueDelete( xQueue );
}
/**
* @brief Test xSemaphoreTakeFromISR with an invalid (NULL) handle
* @coverage xQueueReceiveFromISR
*/
void test_macro_xSemaphoreTakeFromISR_invalid_handle( void )
{
EXPECT_ASSERT_BREAK( xSemaphoreTakeFromISR( NULL, NULL ) );
}
/**
* @brief Test xSemaphoreTakeFromISR with a QueueHandle rather than a SemaphoreHandle
* @coverage xQueueReceiveFromISR
*/
void test_macro_xSemaphoreTakeFromISR_queue_handle( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
/* Expect that xSemaphoreTake will assert because xQueue is not a semaphore */
fakeAssertExpectFail();
uint32_t testVal = getNextMonotonicTestValue();
xQueueSend( xQueue, &testVal, 0 );
EXPECT_ASSERT_BREAK( xSemaphoreTakeFromISR( xQueue, NULL ) );
vQueueDelete( xQueue );
}
/**
* @brief Test xSemaphoreGiveFromISR with an invalid (NULL) handle
* @coverage xQueueGiveFromISR
*/
void test_macro_xSemaphoreGiveFromISR_invalid_handle( void )
{
EXPECT_ASSERT_BREAK( xSemaphoreGiveFromISR( NULL, NULL ) );
}
/**
* @brief Test xSemaphoreGiveFromISR with a QueueHandle rather than a SemaphoreHandle
* @coverage xQueueGiveFromISR
*/
void test_macro_xSemaphoreGiveFromISR_queue_handle( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
EXPECT_ASSERT_BREAK( xSemaphoreGiveFromISR( xQueue, NULL ) );
vQueueDelete( xQueue );
}

View file

@ -0,0 +1,434 @@
/*
* FreeRTOS V202012.00
* 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 semaphore_create_utest.c */
#include "../queue_utest_common.h"
#include "mock_fake_port.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "semphr.h"
/* ================================ CONSTANTS ============================== */
/* ============================ GLOBAL VARIABLES =========================== */
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* ========================== Helper functions =========================== */
/* ============================= Test Cases ============================== */
/**
* @brief Test xSemaphoreCreateBinary where the call to malloc fails
* @coverage xQueueGenericCreate
*/
void test_macro_xSemaphoreCreateBinary_malloc_fail( void )
{
UnityMalloc_MakeMallocFailAfterCount( 0 );
SemaphoreHandle_t xSemaphore = INVALID_PTR;
xSemaphore = xSemaphoreCreateBinary();
/* validate returned semaphore handle */
TEST_ASSERT_EQUAL( NULL, xSemaphore );
}
/**
* @brief Test xSemaphoreCreateBinary
* @details Create a semaphore using xSemaphoreCreateBinary and verify that it
* is in the "taken" state upon creation.
* @coverage xQueueGenericCreateStatic
*/
void test_macro_xSemaphoreCreateBinary_success( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreCreateBinaryStatic with a null buffer
* @coverage xQueueGenericCreateStatic
*/
void test_macro_xSemaphoreCreateBinaryStatic_fail( void )
{
SemaphoreHandle_t xSemaphore = INVALID_PTR;
/* Expect that xSemaphoreCreate will assert due to the NULL buffer */
fakeAssertExpectFail();
xSemaphore = xSemaphoreCreateBinaryStatic( NULL );
/* verify that configASSERT was called */
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
TEST_ASSERT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
}
/**
* @brief Test xSemaphoreCreateBinaryStatic with a valid buffer.
* @details Create a semaphore using xSemaphoreCreateBinaryStatic and verify
* that it is in the "taken" state upon creation.
* @coverage xQueueGenericCreateStatic
*/
void test_macro_xSemaphoreCreateBinaryStatic_success( void )
{
SemaphoreHandle_t xSemaphore = NULL;
StaticSemaphore_t xSemaphoreBuffer;
xSemaphore = xSemaphoreCreateBinaryStatic( &xSemaphoreBuffer );
/* Check that no call to malloc occurred */
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
TEST_ASSERT_EQUAL( B_SEMPHR_TAKEN, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @deprecated
* @brief Test vSemaphoreCreateBinary where the call to malloc fails
* @coverage xQueueGenericCreate
*/
void test_macro_vSemaphoreCreateBinary_malloc_fail( void )
{
SemaphoreHandle_t xSemaphore = INVALID_PTR;
UnityMalloc_MakeMallocFailAfterCount( 0 );
vSemaphoreCreateBinary( xSemaphore );
/* validate returned semaphore handle */
TEST_ASSERT_EQUAL( NULL, xSemaphore );
}
/**
* @deprecated
* @brief Test vSemaphoreCreateBinary
* @details Create a semaphore using vSemaphoreCreateBinary and verify that it
* is in the "given" state upon creation
* @coverage xQueueGenericCreate xQueueGenericSend
*/
void test_macro_vSemaphoreCreateBinary_success( void )
{
SemaphoreHandle_t xSemaphore = NULL;
vSemaphoreCreateBinary( xSemaphore );
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreCreateCounting where the call to malloc fails
* @coverage
* @coverage xQueueCreateCountingSemaphore
*/
void test_macro_xSemaphoreCreateCounting_malloc_fail( void )
{
UnityMalloc_MakeMallocFailAfterCount( 0 );
SemaphoreHandle_t xSemaphore = INVALID_PTR;
xSemaphore = xSemaphoreCreateCounting( 10, 0 );
/* validate returned semaphore handle */
TEST_ASSERT_EQUAL( NULL, xSemaphore );
}
/**
* @brief Test xSemaphoreCreateCounting with uxMaxCount=1 and uxInitialCount=2
* @details This is an invalid initial condition for a counting semaphore since
* uxMaxCount >= uxInitialCount.
* @coverage xQueueCreateCountingSemaphore
*/
void test_macro_xSemaphoreCreateCounting_one_two( void )
{
/* Expect that xSemaphoreCreateCounting will assert because
* uxInitialCount > xMaxCount is invalid */
fakeAssertExpectFail();
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 1, 2 );
fakeAssertGetFlagAndClear();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Check that the count was initialized correctly */
TEST_ASSERT_EQUAL( 2, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreCreateCounting with uxMaxCount=1 and uxInitialCount=0
* @details Create a binary semaphore using xSemaphoreCreateCounting.
* @coverage xQueueCreateCountingSemaphore
*/
void test_macro_xSemaphoreCreateCounting_one_zero( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 1, 0 );
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Check the initial count */
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreCreateCounting with uxMaxCount=0 and uxInitialCount=0
* @details This is an invalid counting semaphore since the following condition
* is always true for a counting semaphore: uxMaxCount > 0
* @coverage xQueueCreateCountingSemaphore
*/
void test_macro_xSemaphoreCreateCounting_zero_zero( void )
{
/* Expect that xSemaphoreCreateCounting will assert because uxMaxCount=0 is invalid */
fakeAssertExpectFail();
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 0, 0 );
fakeAssertVerifyNumAssertsAndClear( 2 );
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreCreateCounting( 100, 50 )
* @details Test xSemaphoreCreateCounting with uxMaxCount=100 and uxInitialCount=50
* @coverage xQueueCreateCountingSemaphore
*/
void test_macro_xSemaphoreCreateCounting_100_50_success( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 100, 50 );
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Check the initial count */
TEST_ASSERT_EQUAL( 50, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreCreateCounting( UINT64_MAX, UINT64_MAX-1 )
* @coverage xQueueCreateCountingSemaphore
*/
void test_macro_xSemaphoreCreateCounting_upper_bound_1( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( UINT64_MAX, UINT64_MAX - 1 );
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
TEST_ASSERT_EQUAL( UINT64_MAX - 1, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreCreateCounting( UINT64_MAX, UINT64_MAX )
* @coverage xQueueCreateCountingSemaphore
*/
void test_macro_xSemaphoreCreateCounting_upper_bound_2( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( UINT64_MAX, UINT64_MAX );
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
TEST_ASSERT_EQUAL( UINT64_MAX, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreCreateCountingStatic with a null buffer
* @details Calls xSemaphoreCreateCountingStatic with a null buffer and
* uxMaxCount=2 and uxInitialCount=1
* @coverage xQueueCreateCountingSemaphoreStatic
*/
void test_macro_xSemaphoreCreateCountingStatic_null_fail( void )
{
SemaphoreHandle_t xSemaphore = INVALID_PTR;
/* Expect that xQueueCreate will assert due to the NULL buffer */
fakeAssertExpectFail();
xSemaphore = xSemaphoreCreateCountingStatic( 2, 1, NULL );
/* Verify that configASSERT was called due to the null buffer */
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
/* Verify that the returned handle is NULL */
TEST_ASSERT_EQUAL( NULL, xSemaphore );
/* check that no call to malloc ocurred */
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
}
/**
* @brief Test xSemaphoreCreateCountingStatic with uxMaxCount=0 and uxInitialCount=0
* @details This is an invalid counting semaphore since uxMaxCount > 0
* @coverage xQueueCreateCountingSemaphoreStatic
*/
void test_macro_xSemaphoreCreateCountingStatic_zero_zero_fail( void )
{
SemaphoreHandle_t xSemaphore = NULL;
StaticSemaphore_t xSemaphoreBuffer;
/* Expect that xQueueCreate will assert due to the NULL buffer */
fakeAssertExpectFail();
xSemaphore = xSemaphoreCreateCountingStatic( 0, 0, &xSemaphoreBuffer );
fakeAssertVerifyNumAssertsAndClear( 2 );
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
/* Check that no malloc occured */
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
/* Check that the returned count is zero */
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreCreateCountingStatic with uxMaxCount=1 and uxInitialCount=2
* @details This is an invalid initial condition for a counting semaphore since
* uxMaxCount >= uxInitialCount.
* @coverage xQueueCreateCountingSemaphoreStatic
*/
void test_macro_xSemaphoreCreateCountingStatic_one_two( void )
{
SemaphoreHandle_t xSemaphore = NULL;
StaticSemaphore_t xSemaphoreBuffer;
/* Expect that xSemaphoreCreateCountingStatic will assert because
* uxInitialCount > xMaxCount is invalid */
fakeAssertExpectFail();
xSemaphore = xSemaphoreCreateCountingStatic( 1, 2, &xSemaphoreBuffer );
fakeAssertGetFlagAndClear();
/* validate returned semaphore handle */
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
/* verify that no heap memory allocation occurred */
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
/* Check that the count was initialized correctly */
TEST_ASSERT_EQUAL( 2, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreCreateCountingStatic with uxMaxCount=1 and uxInitialCount=0
* @details Create a binary semaphore using xSemaphoreCreateCountingStatic
* @coverage xQueueCreateCountingSemaphoreStatic
*/
void test_macro_xSemaphoreCreateCountingStatic_one_zero_success( void )
{
SemaphoreHandle_t xSemaphore = INVALID_PTR;
StaticSemaphore_t xSemaphoreBuffer;
xSemaphore = xSemaphoreCreateCountingStatic( 1, 0, &xSemaphoreBuffer );
TEST_ASSERT_NOT_EQUAL( NULL, xSemaphore );
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
/* Check the initial count */
TEST_ASSERT_EQUAL( 0, uxSemaphoreGetCount( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}

View file

@ -0,0 +1,140 @@
/*
* FreeRTOS V202012.00
* 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
#include "fake_assert.h"
/*-----------------------------------------------------------
* 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_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 0
#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 ( 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 1
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats()
#define portGET_RUN_TIME_COUNTER_VALUE() ulGetRunTimeCounterValue()
/* Co-routine related configuration options. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* 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 1
/* 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 1
#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 ) \
do \
{ \
if( x ) \
{ \
vFakeAssert( true, __FILE__, __LINE__ ); \
} \
else \
{ \
vFakeAssert( false, __FILE__, __LINE__ ); \
} \
} while ( 0 )
#define mtCOVERAGE_TEST_MARKER() __asm volatile ( "NOP" )
#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0
#if ( configINCLUDE_MESSAGE_BUFFER_AMP_DEMO == 1 )
extern void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer );
#define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )
#endif /* configINCLUDE_MESSAGE_BUFFER_AMP_DEMO */
#endif /* FREERTOS_CONFIG_H */

View file

@ -0,0 +1,54 @@
# Indent with spaces
.RECIPEPREFIX := $(.RECIPEPREFIX) $(.RECIPEPREFIX)
# Do not move this line below the include
MAKEFILE_ABSPATH := $(abspath $(lastword $(MAKEFILE_LIST)))
include ../../makefile.in
# PROJECT_SRC lists the .c files under test
PROJECT_SRC += queue.c
# PROJECT_DEPS_SRC list the .c file that are dependencies of PROJECT_SRC files
# Files in PROJECT_DEPS_SRC are excluded from coverage measurements
PROJECT_DEPS_SRC += list.c
# PROJECT_HEADER_DEPS: headers that should be excluded from coverage measurements.
PROJECT_HEADER_DEPS += FreeRTOS.h
# SUITE_UT_SRC: .c files that contain test cases (must end in _utest.c)
SUITE_UT_SRC += queue_set_utest.c
SUITE_UT_SRC += queue_in_set_utest.c
SUITE_UT_SRC += queue_send_nonblocking_utest.c
SUITE_UT_SRC += queue_send_blocking_utest.c
SUITE_UT_SRC += semaphore_in_set_utest.c
SUITE_UT_SRC += binary_semaphore_utest.c
SUITE_UT_SRC += mutex_utest.c
# SUITE_SUPPORT_SRC: .c files used for testing that do not contain test cases.
# Paths are relative to PROJECT_DIR
SUITE_SUPPORT_SRC += queue_utest_common.c
SUITE_SUPPORT_SRC += td_task.c
SUITE_SUPPORT_SRC += td_port.c
# List the headers used by PROJECT_SRC that you would like to mock
MOCK_FILES_FP += $(KERNEL_DIR)/include/task.h
MOCK_FILES_FP += $(UT_ROOT_DIR)/config/fake_assert.h
MOCK_FILES_FP += $(UT_ROOT_DIR)/config/fake_port.h
# List any addiitonal flags needed by the preprocessor
CPPFLAGS += -DportUSING_MPU_WRAPPERS=0
# List any addiitonal flags needed by the compiler
CFLAGS +=
# Try not to edit beyond this line unless necessary.
# Project / Suite are determined based on path: $(UT_ROOT_DIR)/$(PROJECT)/$(SUITE)
PROJECT := $(lastword $(subst /, ,$(dir $(abspath $(MAKEFILE_ABSPATH)/../))))
SUITE := $(lastword $(subst /, ,$(dir $(MAKEFILE_ABSPATH))))
# Make variables available to included makefile
export
include ../../testdir.mk

View file

@ -0,0 +1 @@
../semaphore/binary_semaphore_utest.c

View file

@ -0,0 +1 @@
../semaphore/mutex_utest.c

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1 @@
../generic/queue_receive_blocking_utest.c

View file

@ -0,0 +1 @@
../generic/queue_receive_nonblocking_utest.c

View file

@ -0,0 +1 @@
../generic/queue_send_blocking_utest.c

View file

@ -0,0 +1 @@
../generic/queue_send_nonblocking_utest.c

View file

@ -0,0 +1,449 @@
/*
* FreeRTOS V202012.00
* 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 queue_set_utest.c */
/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "../queue_utest_common.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "queue.h"
#include "mock_fake_port.h"
/* ============================ GLOBAL VARIABLES =========================== */
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* ========================== Helper functions =========================== */
/* ========================== Test Cases =========================== */
/**
* @brief Test xQueueCreateSet when calls to malloc fail.
* @coverage xQueueCreateSet
*/
void test_xQueueCreateSet_malloc_fail( void )
{
UnityMalloc_MakeMallocFailAfterCount( 0 );
QueueSetHandle_t xQueueSet = INVALID_PTR;
xQueueSet = xQueueCreateSet( 1 );
TEST_ASSERT_EQUAL( NULL, xQueueSet );
}
/**
* @brief Test xQueueCreateSet with uxEventQueueLength=0
* @coverage xQueueCreateSet
*/
void test_xQueueCreateSet_zeroLength( void )
{
/* Expect that xQueueCreateSet will assert because a length of 0 is invalid */
fakeAssertExpectFail();
QueueSetHandle_t xQueueSet = xQueueCreateSet( 0 );
/* validate returned QueueSet handle */
TEST_ASSERT_NOT_EQUAL( NULL, xQueueSet );
/* verify that configASSERT was called */
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE, getLastMallocSize() );
/* Veify that QueueSet is full */
TEST_ASSERT_EQUAL( 0, uxQueueSpacesAvailable( xQueueSet ) );
/* Veify that QueueSet is also empty */
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueueSet ) );
vQueueDelete( xQueueSet );
}
/**
* @brief Test xQueueCreateSet with uxEventQueueLength=1
* @coverage xQueueCreateSet
*/
void test_xQueueCreateSet_oneLength( void )
{
QueueSetHandle_t xQueueSet = xQueueCreateSet( 1 );
/* validate returned QueueSet handle */
TEST_ASSERT_NOT_EQUAL( NULL, xQueueSet );
TEST_ASSERT_EQUAL( QUEUE_T_SIZE + sizeof( void * ), getLastMallocSize() );
/* Veify that QueueSet is not full */
TEST_ASSERT_EQUAL( 1, uxQueueSpacesAvailable( xQueueSet ) );
/* Veify that QueueSet is empty */
TEST_ASSERT_EQUAL( 0, uxQueueMessagesWaiting( xQueueSet ) );
vQueueDelete( xQueueSet );
}
/**
* @brief Test xQueueAddToSet with a QueueSet of uxEventQueueLength=0
* @details: Adds two queues of size 1,0 to a QueueSet of size 0.
* @coverage xQueueAddToSet
*/
void test_xQueueAddToSet_ZeroLength( void )
{
/* Expect that xQueueCreateSet will assert because a length of 0 is invalid */
fakeAssertExpectFail();
QueueSetHandle_t xQueueSet = xQueueCreateSet( 0 );
fakeAssertGetFlagAndClear();
QueueHandle_t xQueue1 = xQueueCreate( 1, 0 );
TEST_ASSERT_EQUAL( pdTRUE, xQueueAddToSet( xQueue1, xQueueSet ) );
QueueHandle_t xQueue2 = xQueueCreate( 1, 0 );
TEST_ASSERT_EQUAL( pdTRUE, xQueueAddToSet( xQueue2, xQueueSet ) );
( void ) xQueueRemoveFromSet( xQueue1, xQueueSet );
( void ) xQueueRemoveFromSet( xQueue2, xQueueSet );
vQueueDelete( xQueueSet );
vQueueDelete( xQueue1 );
vQueueDelete( xQueue2 );
}
/**
* @brief Test xQueueAddToSet with the same queue twice
* @coverage xQueueAddToSet
*/
void test_xQueueAddToSet_AlreadyInSameSet( void )
{
QueueSetHandle_t xQueueSet = xQueueCreateSet( 2 );
QueueHandle_t xQueue = xQueueCreate( 1, 0 );
TEST_ASSERT_EQUAL( pdTRUE, xQueueAddToSet( xQueue, xQueueSet ) );
TEST_ASSERT_EQUAL( pdFALSE, xQueueAddToSet( xQueue, xQueueSet ) );
( void ) xQueueRemoveFromSet( xQueue, xQueueSet );
vQueueDelete( xQueueSet );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueAddToSet with a queue that is already a member of a different QueueSet.
* @coverage xQueueAddToSet
*/
void test_xQueueAddToSet_AlreadyInDifferentSet( void )
{
QueueSetHandle_t xQueueSet1 = xQueueCreateSet( 1 );
QueueSetHandle_t xQueueSet2 = xQueueCreateSet( 1 );
QueueHandle_t xQueue = xQueueCreate( 1, 0 );
TEST_ASSERT_EQUAL( pdTRUE, xQueueAddToSet( xQueue, xQueueSet1 ) );
TEST_ASSERT_EQUAL( pdFALSE, xQueueAddToSet( xQueue, xQueueSet2 ) );
( void ) xQueueRemoveFromSet( xQueue, xQueueSet1 );
vQueueDelete( xQueueSet1 );
vQueueDelete( xQueueSet2 );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueAddToSet with a queue that was previously a member of a different QueueSet, which was deleted.
* @coverage xQueueAddToSet
*/
void test_xQueueAddToSet_PreviouslyInDifferentSet( void )
{
QueueSetHandle_t xQueueSet1 = xQueueCreateSet( 1 );
QueueSetHandle_t xQueueSet2 = xQueueCreateSet( 1 );
QueueHandle_t xQueue = xQueueCreate( 1, 0 );
TEST_ASSERT_EQUAL( pdTRUE, xQueueAddToSet( xQueue, xQueueSet1 ) );
( void ) xQueueRemoveFromSet( xQueue, xQueueSet1 );
vQueueDelete( xQueueSet1 );
TEST_ASSERT_EQUAL( pdTRUE, xQueueAddToSet( xQueue, xQueueSet2 ) );
( void ) xQueueRemoveFromSet( xQueue, xQueueSet2 );
vQueueDelete( xQueue );
vQueueDelete( xQueueSet2 );
}
/**
* @brief Test xQueueAddToSet with a queue that is not empty.
* @coverage xQueueAddToSet
*/
void test_xQueueAddToSet_QueueNotEmpty( void )
{
QueueSetHandle_t xQueueSet = xQueueCreateSet( 1 );
QueueHandle_t xQueue = xQueueCreate( 1, 0 );
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, NULL, 0 ) );
TEST_ASSERT_EQUAL( pdFALSE, xQueueAddToSet( xQueue, xQueueSet ) );
( void ) xQueueRemoveFromSet( xQueue, xQueueSet );
vQueueDelete( xQueueSet );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueSelectFromSet with multiple queues in a set.
* @coverage xQueueSelectFromSet
*/
void test_xQueueSelectFromSet( void )
{
QueueSetHandle_t xQueueSet = xQueueCreateSet( 3 );
QueueHandle_t xQueue1 = xQueueCreate( 1, sizeof( uint32_t ) );
QueueHandle_t xQueue2 = xQueueCreate( 1, sizeof( uint32_t ) );
QueueHandle_t xQueue3 = xQueueCreate( 1, sizeof( uint32_t ) );
TEST_ASSERT_EQUAL( pdTRUE, xQueueAddToSet( xQueue1, xQueueSet ) );
TEST_ASSERT_EQUAL( pdTRUE, xQueueAddToSet( xQueue2, xQueueSet ) );
TEST_ASSERT_EQUAL( pdTRUE, xQueueAddToSet( xQueue3, xQueueSet ) );
uint32_t testVal1 = 1;
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue1, &testVal1, 0 ) );
uint32_t testVal2 = 2;
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue2, &testVal2, 0 ) );
uint32_t testVal3 = 3;
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue3, &testVal3, 0 ) );
QueueHandle_t xQueueTemp = xQueueSelectFromSet( xQueueSet, 0 );
TEST_ASSERT_EQUAL( xQueueTemp, xQueue1 );
uint32_t checkVal1 = 0;
TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueueTemp, &checkVal1, 0 ) );
TEST_ASSERT_EQUAL( testVal1, checkVal1 );
xQueueTemp = xQueueSelectFromSet( xQueueSet, 0 );
TEST_ASSERT_EQUAL( xQueueTemp, xQueue2 );
uint32_t checkVal2 = 0;
TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueueTemp, &checkVal2, 0 ) );
TEST_ASSERT_EQUAL( testVal2, checkVal2 );
xQueueTemp = xQueueSelectFromSet( xQueueSet, 0 );
TEST_ASSERT_EQUAL( xQueueTemp, xQueue3 );
uint32_t checkVal3 = 0;
TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueueTemp, &checkVal3, 0 ) );
TEST_ASSERT_EQUAL( testVal3, checkVal3 );
( void ) xQueueRemoveFromSet( xQueue1, xQueueSet );
( void ) xQueueRemoveFromSet( xQueue2, xQueueSet );
( void ) xQueueRemoveFromSet( xQueue3, xQueueSet );
vQueueDelete( xQueueSet );
vQueueDelete( xQueue1 );
vQueueDelete( xQueue2 );
vQueueDelete( xQueue3 );
}
/**
* @brief Test xQueueSelectFromSetFromISR with multiple queues in a set.
* @coverage xQueueSelectFromSetFromISR
*/
void test_xQueueSelectFromSetFromISR( void )
{
QueueSetHandle_t xQueueSet = xQueueCreateSet( 3 );
QueueHandle_t xQueue1 = xQueueCreate( 1, sizeof( uint32_t ) );
QueueHandle_t xQueue2 = xQueueCreate( 1, sizeof( uint32_t ) );
QueueHandle_t xQueue3 = xQueueCreate( 1, sizeof( uint32_t ) );
TEST_ASSERT_EQUAL( pdTRUE, xQueueAddToSet( xQueue1, xQueueSet ) );
TEST_ASSERT_EQUAL( pdTRUE, xQueueAddToSet( xQueue2, xQueueSet ) );
TEST_ASSERT_EQUAL( pdTRUE, xQueueAddToSet( xQueue3, xQueueSet ) );
uint32_t testVal1 = 1;
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue1, &testVal1, 0 ) );
uint32_t testVal2 = 2;
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue2, &testVal2, 0 ) );
uint32_t testVal3 = 3;
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue3, &testVal3, 0 ) );
vFakePortAssertIfInterruptPriorityInvalid_Expect();
QueueHandle_t xQueueTemp = xQueueSelectFromSetFromISR( xQueueSet );
TEST_ASSERT_EQUAL( xQueueTemp, xQueue1 );
vFakePortAssertIfInterruptPriorityInvalid_Expect();
uint32_t checkVal1 = 0;
TEST_ASSERT_EQUAL( pdTRUE, xQueueReceiveFromISR( xQueueTemp, &checkVal1, 0 ) );
TEST_ASSERT_EQUAL( testVal1, checkVal1 );
vFakePortAssertIfInterruptPriorityInvalid_Expect();
xQueueTemp = xQueueSelectFromSetFromISR( xQueueSet );
TEST_ASSERT_EQUAL( xQueueTemp, xQueue2 );
vFakePortAssertIfInterruptPriorityInvalid_Expect();
uint32_t checkVal2 = 0;
TEST_ASSERT_EQUAL( pdTRUE, xQueueReceiveFromISR( xQueueTemp, &checkVal2, 0 ) );
TEST_ASSERT_EQUAL( testVal2, checkVal2 );
vFakePortAssertIfInterruptPriorityInvalid_Expect();
xQueueTemp = xQueueSelectFromSetFromISR( xQueueSet );
TEST_ASSERT_EQUAL( xQueueTemp, xQueue3 );
vFakePortAssertIfInterruptPriorityInvalid_Expect();
uint32_t checkVal3 = 0;
TEST_ASSERT_EQUAL( pdTRUE, xQueueReceiveFromISR( xQueueTemp, &checkVal3, 0 ) );
TEST_ASSERT_EQUAL( testVal3, checkVal3 );
( void ) xQueueRemoveFromSet( xQueue1, xQueueSet );
( void ) xQueueRemoveFromSet( xQueue2, xQueueSet );
( void ) xQueueRemoveFromSet( xQueue3, xQueueSet );
vQueueDelete( xQueueSet );
vQueueDelete( xQueue1 );
vQueueDelete( xQueue2 );
vQueueDelete( xQueue3 );
}
/**
* @brief Test xQueueRemoveFromSet where the queue to be removed
* is not empty.
* @coverage xQueueRemoveFromSet
*/
void test_xQueueRemoveFromSet_QueueNotEmpty( void )
{
QueueSetHandle_t xQueueSet = xQueueCreateSet( 1 );
QueueHandle_t xQueue = xQueueCreate( 1, 0 );
TEST_ASSERT_EQUAL( pdTRUE, xQueueAddToSet( xQueue, xQueueSet ) );
TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, NULL, 0 ) );
TEST_ASSERT_EQUAL( pdFALSE, xQueueRemoveFromSet( xQueue, xQueueSet ) );
vQueueDelete( xQueueSet );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueRemoveFromSet where the queue to be removed
* is already in a different set.
* @coverage xQueueRemoveFromSet
*/
void test_xQueueRemoveFromSet_QueueNotInSet( void )
{
QueueSetHandle_t xQueueSet1 = xQueueCreateSet( 1 );
QueueSetHandle_t xQueueSet2 = xQueueCreateSet( 1 );
QueueHandle_t xQueue = xQueueCreate( 1, 0 );
TEST_ASSERT_EQUAL( pdTRUE, xQueueAddToSet( xQueue, xQueueSet1 ) );
TEST_ASSERT_EQUAL( pdFALSE, xQueueRemoveFromSet( xQueue, xQueueSet2 ) );
TEST_ASSERT_EQUAL( pdTRUE, xQueueRemoveFromSet( xQueue, xQueueSet1 ) );
TEST_ASSERT_EQUAL( pdTRUE, xQueueAddToSet( xQueue, xQueueSet2 ) );
vQueueDelete( xQueueSet1 );
vQueueDelete( xQueueSet2 );
vQueueDelete( xQueue );
}
/**
* @brief Test xQueueRemoveFromSet where the queue to be removed
* is in the given set.
* @coverage xQueueRemoveFromSet
*/
void test_xQueueRemoveFromSet_QueueInSet( void )
{
QueueSetHandle_t xQueueSet1 = xQueueCreateSet( 1 );
QueueSetHandle_t xQueueSet2 = xQueueCreateSet( 1 );
QueueHandle_t xQueue = xQueueCreate( 1, 0 );
TEST_ASSERT_EQUAL( pdTRUE, xQueueAddToSet( xQueue, xQueueSet1 ) );
TEST_ASSERT_EQUAL( pdTRUE, xQueueRemoveFromSet( xQueue, xQueueSet1 ) );
TEST_ASSERT_EQUAL( pdTRUE, xQueueAddToSet( xQueue, xQueueSet2 ) );
vQueueDelete( xQueueSet1 );
vQueueDelete( xQueueSet2 );
vQueueDelete( xQueue );
}

View file

@ -0,0 +1,359 @@
/*
* FreeRTOS V202012.00
* 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 queue_unlock_utest.c */
/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "../queue_utest_common.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "queue.h"
#include "mock_fake_port.h"
/* ============================ GLOBAL VARIABLES =========================== */
#define TICKS_TO_WAIT 10
#define NUM_CALLS_TO_INTERCEPT_TX TICKS_TO_WAIT / 2
#define NUM_CALLS_TO_INTERCEPT_RX TICKS_TO_WAIT / 2
/* Share QueueHandle_t / QueueSetHandle_t between a test case and it's callbacks */
static QueueHandle_t xQueueHandleStatic;
static QueueSetHandle_t xQueueSetHandleStatic;
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
vFakePortAssertIfInterruptPriorityInvalid_Ignore();
xQueueHandleStatic = NULL;
xQueueSetHandleStatic = NULL;
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* ========================== Helper functions =========================== */
/* ========================== Test Cases =========================== */
/* / ** */
/* * @brief Callback for test_macro_xQueueSend_blocking_success which empties it's test queue. */
/* * / */
/* static BaseType_t xQueueSend_locked_xTaskCheckForTimeOutCB( TimeOut_t* const pxTimeOut, */
/* TickType_t* const pxTicksToWait, */
/* int cmock_num_calls ) */
/* { */
/* BaseType_t xReturnValue = td_task_xTaskCheckForTimeOutStub( pxTimeOut, pxTicksToWait, cmock_num_calls ); */
/* if(cmock_num_calls == NUM_CALLS_TO_INTERCEPT_TX) */
/* { */
/* uint32_t checkVal = INVALID_UINT32; */
/* QueueHandle_t xQueue = xQueueSelectFromSetFromISR( xQueueSetHandleStatic ); */
/* TEST_ASSERT_NOT_NULL( xQueue ); */
/* xQueueReceiveFromISR( xQueue, &checkVal, NULL ); */
/* TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal ); */
/* } */
/* return xReturnValue; */
/* } */
/* void test_macro_xQueueSend_in_set_blocking_success_locked_no_pending( void ) */
/* { */
/* QueueSetHandle_t xQueueSet = xQueueCreateSet( 1 ); */
/* QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) ); */
/* xQueueAddToSet( xQueue, xQueueSet ); */
/* / * Export for callbacks * / */
/* xQueueSetHandleStatic = xQueueSet; */
/* uint32_t testVal = getNextMonotonicTestValue(); */
/* TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, &testVal, 0 ) ); */
/* xTaskCheckForTimeOut_Stub( &xQueueSend_locked_xTaskCheckForTimeOutCB ); */
/* xTaskResumeAll_Stub( &td_task_xTaskResumeAllStub ); */
/* uint32_t testVal2 = getLastMonotonicTestValue() + 12345; */
/* TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, &testVal2, TICKS_TO_WAIT ) ); */
/* (void) xQueueRemoveFromSet( xQueue, xQueueSet ); */
/* vQueueDelete( xQueueSet ); */
/* vQueueDelete( xQueue ); */
/* } */
/* static BaseType_t xQueueSend_xTaskResumeAllCallback( int cmock_num_calls ) */
/* { */
/* BaseType_t xReturnValue = td_task_xTaskResumeAllStub( cmock_num_calls ); */
/* / * If td_task_xTaskResumeAllStub returns pdTRUE, a higher priority task is pending */
/* Send from an ISR to block * / */
/* if( pdTRUE == xReturnValue ) */
/* { */
/* if(cmock_num_calls == NUM_CALLS_TO_INTERCEPT_TX) */
/* { */
/* uint32_t testVal = getNextMonotonicTestValue(); */
/* (void) xQueueSendFromISR( xQueueHandleStatic, &testVal, NULL ); */
/* } */
/* } */
/* return xReturnValue; */
/* } */
/* / * @coverage prvUnlockQueue * / */
/* void test_macro_xQueueSend_in_set_blocking_fail_locked_high_prio_pending( void ) */
/* { */
/* QueueSetHandle_t xQueueSet = xQueueCreateSet( 1 ); */
/* QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) ); */
/* xQueueAddToSet( xQueue, xQueueSet ); */
/* / * Export for callbacks * / */
/* xQueueHandleStatic = xQueue; */
/* xQueueSetHandleStatic = xQueueSet; */
/* uint32_t testVal = getNextMonotonicTestValue(); */
/* TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, &testVal, 0 ) ); */
/* xTaskCheckForTimeOut_Stub( &xQueueSend_locked_xTaskCheckForTimeOutCB ); */
/* xTaskResumeAll_Stub( &xQueueSend_xTaskResumeAllCallback ); */
/* / * this task is lower priority than the pending task * / */
/* td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 ); */
/* td_task_addFakeTaskWaitingToSendToQueue( xQueue ); */
/* uint32_t testVal2 = getLastMonotonicTestValue() + 12345; */
/* TEST_ASSERT_EQUAL( pdFALSE, xQueueSend( xQueue, &testVal2, TICKS_TO_WAIT ) ); */
/* (void) xQueueRemoveFromSet( xQueue, xQueueSet ); */
/* vQueueDelete( xQueueSet ); */
/* vQueueDelete( xQueue ); */
/* } */
/* void test_macro_xQueueSend_in_set_blocking_success_locked_low_prio_pending( void ) */
/* { */
/* QueueSetHandle_t xQueueSet = xQueueCreateSet( 1 ); */
/* QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) ); */
/* xQueueAddToSet( xQueue, xQueueSet ); */
/* / * Export for callbacks * / */
/* xQueueHandleStatic = xQueue; */
/* xQueueSetHandleStatic = xQueueSet; */
/* uint32_t testVal = getNextMonotonicTestValue(); */
/* TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, &testVal, 0 ) ); */
/* xTaskCheckForTimeOut_Stub( &xQueueSend_locked_xTaskCheckForTimeOutCB ); */
/* xTaskResumeAll_Stub( &xQueueSend_xTaskResumeAllCallback ); */
/* / * this task is higher priority than the pending task * / */
/* td_task_setFakeTaskPriority( DEFAULT_PRIORITY - 1 ); */
/* td_task_addFakeTaskWaitingToSendToQueue( xQueue ); */
/* uint32_t testVal2 = getLastMonotonicTestValue() + 12345; */
/* TEST_ASSERT_EQUAL( pdTRUE, xQueueSend( xQueue, &testVal2, TICKS_TO_WAIT ) ); */
/* (void) xQueueRemoveFromSet( xQueue, xQueueSet ); */
/* vQueueDelete( xQueueSet ); */
/* vQueueDelete( xQueue ); */
/* } */
/**
* @brief Callback for test_macro_xQueueReceive_blocking_success_locked_no_pending which adds an item to it's test queue.
*/
static BaseType_t xQueueReceive_xTaskCheckForTimeOutCB( TimeOut_t * const pxTimeOut,
TickType_t * const pxTicksToWait,
int cmock_num_calls )
{
BaseType_t xReturnValue = td_task_xTaskCheckForTimeOutStub( pxTimeOut, pxTicksToWait, cmock_num_calls );
printf( "In xQueueReceive_xTaskCheckForTimeOutCB %d\n", cmock_num_calls );
if( cmock_num_calls == NUM_CALLS_TO_INTERCEPT_TX )
{
uint32_t testVal = getNextMonotonicTestValue();
printf( "Calling xQueueSendFromISR\n" );
TEST_ASSERT_TRUE( xQueueSendFromISR( xQueueHandleStatic, &testVal, NULL ) );
}
return xReturnValue;
}
void test_macro_xQueueReceive_in_set_blocking_success_locked_no_pending( void )
{
QueueSetHandle_t xQueueSetOuter = xQueueCreateSet( 1 );
QueueSetHandle_t xQueueSetInner = xQueueCreateSet( 1 );
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
printf( "xQueueSetOuter: %lu, xQueueSetInner: %lu, xQueue: %lu\n", ( unsigned long ) xQueueSetOuter, ( unsigned long ) xQueueSetInner, ( unsigned long ) xQueue );
TEST_ASSERT_TRUE( xQueueAddToSet( xQueueSetInner, xQueueSetOuter ) );
TEST_ASSERT_TRUE( xQueueAddToSet( xQueue, xQueueSetInner ) );
/* Export for callbacks */
xQueueHandleStatic = xQueue;
xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB );
xTaskResumeAll_Stub( &td_task_xTaskResumeAllStub );
uint32_t checkVal = INVALID_UINT32;
/* printf("Calling xQueueSelectFromSet from OuterSet\n"); */
/* QueueSetHandle_t xQueueSetFromSet = xQueueSelectFromSet( xQueueSetOuter, TICKS_TO_WAIT ); */
/* TEST_ASSERT_EQUAL( xQueueSetInner, xQueueSetFromSet ); */
QueueHandle_t xQueueFromSet = xQueueSelectFromSet( xQueueSetOuter, TICKS_TO_WAIT );
TEST_ASSERT_EQUAL( xQueue, xQueueFromSet ); /* TODO: assert equality */
printf( "Calling xQueueReceive\n" );
TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueueFromSet, &checkVal, 0 ) );
TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal );
( void ) xQueueRemoveFromSet( xQueueSetInner, xQueueSetOuter );
vQueueDelete( xQueueSetOuter );
( void ) xQueueRemoveFromSet( xQueue, xQueueSetInner );
vQueueDelete( xQueueSetInner );
vQueueDelete( xQueue );
}
/* static BaseType_t xQueueReceive_xTaskResumeAllCallback( int cmock_num_calls ) */
/* { */
/* BaseType_t xReturnValue = td_task_xTaskResumeAllStub( cmock_num_calls ); */
/* / * If td_task_xTaskResumeAllStub returns pdTRUE, a higher priority task is pending */
/* Receive from an ISR to block * / */
/* printf("In xQueueReceive_xTaskResumeAllCallback %d\n", cmock_num_calls); */
/* if( pdTRUE == xReturnValue ) */
/* { */
/* if(cmock_num_calls == NUM_CALLS_TO_INTERCEPT_TX) */
/* { */
/* uint32_t checkValue = INVALID_UINT32; */
/* QueueHandle_t xQueue = xQueueSelectFromSetFromISR( xQueueSetHandleStatic ); */
/* TEST_ASSERT_TRUE( xQueueReceiveFromISR( xQueue, &checkValue, NULL ) ); */
/* TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkValue ); */
/* } */
/* } */
/* return xReturnValue; */
/* } */
/* void test_macro_xQueueReceive_in_set_blocking_success_locked_high_prio_pending( void ) */
/* { */
/* QueueSetHandle_t xQueueSet = xQueueCreateSet( 1 ); */
/* QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) ); */
/* xQueueAddToSet( xQueue, xQueueSet ); */
/* / * Export for callbacks * / */
/* xQueueHandleStatic = xQueue; */
/* xQueueSetHandleStatic = xQueueSet; */
/* xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB ); */
/* xTaskResumeAll_Stub( &xQueueReceive_xTaskResumeAllCallback ); */
/* td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 ); */
/* td_task_addFakeTaskWaitingToReceiveFromQueue( xQueueSet ); */
/* QueueHandle_t xQueueFromSet = xQueueSelectFromSet( xQueueSet, TICKS_TO_WAIT ); */
/* TEST_ASSERT_EQUAL( NULL, xQueueFromSet ); */
/* (void) xQueueRemoveFromSet( xQueue, xQueueSet ); */
/* vQueueDelete( xQueueSet ); */
/* vQueueDelete( xQueue ); */
/* } */
/* void test_macro_xQueueReceive_in_set_blocking_success_locked_low_prio_pending( void ) */
/* { */
/* QueueSetHandle_t xQueueSet = xQueueCreateSet( 1 ); */
/* QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) ); */
/* xQueueAddToSet( xQueue, xQueueSet ); */
/* / * Export for callbacks * / */
/* xQueueHandleStatic = xQueue; */
/* xQueueSetHandleStatic = xQueueSet; */
/* xTaskCheckForTimeOut_Stub( &xQueueReceive_xTaskCheckForTimeOutCB ); */
/* xTaskResumeAll_Stub( &xQueueReceive_xTaskResumeAllCallback ); */
/* td_task_setFakeTaskPriority( DEFAULT_PRIORITY - 1 ); */
/* td_task_addFakeTaskWaitingToReceiveFromQueue( xQueueSet ); */
/* uint32_t checkVal = INVALID_UINT32; */
/* QueueHandle_t xQueueFromSet = xQueueSelectFromSet( xQueueSet, TICKS_TO_WAIT ); */
/* TEST_ASSERT_NOT_NULL( xQueueFromSet ); */
/* TEST_ASSERT_EQUAL( pdTRUE, xQueueReceive( xQueueFromSet, &checkVal, TICKS_TO_WAIT ) ); */
/* TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), checkVal ); */
/* (void) xQueueRemoveFromSet( xQueue, xQueueSet ); */
/* vQueueDelete( xQueueSet ); */
/* vQueueDelete( xQueue ); */
/* } */

View file

@ -0,0 +1,206 @@
/*
* FreeRTOS V202012.00
* 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 semaphore_in_set_utest.c */
/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "../queue_utest_common.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "semphr.h"
#include "mock_fake_port.h"
/* ============================ GLOBAL VARIABLES =========================== */
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* ========================== Helper functions =========================== */
/* ========================== Test Cases =========================== */
/**
* @brief Test xSemaphoreGiveFromISR with a higher priority task waiting and a null pointer for pxHigherPriorityTaskWoken
* @details Test xSemaphoreGiveFromISR on a queue that is in a Queue Set with a higher priority task waiting.
* Verify that a null pxHigherPriorityTaskWoken is handled correctly.
* @coverage xQueueGiveFromISR
*/
void test_macro_xSemaphoreGiveFromISR_in_set_high_priority_pending_null_ptr( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
QueueSetHandle_t xQueueSet = xQueueCreateSet( 1 );
xQueueAddToSet( xSemaphore, xQueueSet );
vFakePortAssertIfInterruptPriorityInvalid_Expect();
/* Insert an item into the event list */
td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 );
td_task_addFakeTaskWaitingToReceiveFromQueue( xQueueSet );
/* Give the semaphore */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveFromISR( xSemaphore, NULL ) );
TEST_ASSERT_EQUAL( pdTRUE, td_task_getYieldPending() );
SemaphoreHandle_t xSemaphoreTemp = xQueueSelectFromSet( xQueueSet, 0 );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphoreTemp ) );
vSemaphoreDelete( xSemaphore );
vQueueDelete( xQueueSet );
}
/**
* @brief Test xSemaphoreGiveFromISR with a higher priority task waiting on a queue in and Queue Set
* @details Test xSemaphoreGiveFromISR with a higher priority task waiting and
* verifies that xHigherPriorityTaskWoken is set accoridngly.
* @coverage xQueueGiveFromISR
*/
void test_macro_xSemaphoreGiveFromISR_in_set_high_priority_pending( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
QueueSetHandle_t xQueueSet = xQueueCreateSet( 1 );
xQueueAddToSet( xSemaphore, xQueueSet );
vFakePortAssertIfInterruptPriorityInvalid_Expect();
/* Insert an item into the event list */
td_task_setFakeTaskPriority( DEFAULT_PRIORITY + 1 );
td_task_addFakeTaskWaitingToReceiveFromQueue( xQueueSet );
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
/* Give the semaphore */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken ) );
TEST_ASSERT_EQUAL( pdTRUE, xHigherPriorityTaskWoken );
TEST_ASSERT_EQUAL( pdTRUE, td_task_getYieldPending() );
SemaphoreHandle_t xSemaphoreTemp = xQueueSelectFromSet( xQueueSet, 0 );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphoreTemp ) );
vSemaphoreDelete( xSemaphore );
vQueueDelete( xQueueSet );
}
/**
* @brief Test xSemaphoreGiveFromISR with a lower priority task waiting on a queue in a Queue Set
* @details Test xSemaphoreGiveFromISR on a Queeu in a Queue Set with a lower priority task waiting and
* verify that xHigherPriorityTaskWoken is not modified.
* @coverage xQueueGiveFromISR
*/
void test_macro_xSemaphoreGiveFromISR_in_set_low_priority_pending( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
QueueSetHandle_t xQueueSet = xQueueCreateSet( 1 );
xQueueAddToSet( xSemaphore, xQueueSet );
vFakePortAssertIfInterruptPriorityInvalid_Expect();
/* Insert an item into the event list */
td_task_setFakeTaskPriority( DEFAULT_PRIORITY - 1 );
td_task_addFakeTaskWaitingToReceiveFromQueue( xQueueSet );
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
/* Give the semaphore */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken ) );
TEST_ASSERT_EQUAL( pdFALSE, xHigherPriorityTaskWoken );
TEST_ASSERT_EQUAL( pdFALSE, td_task_getYieldPending() );
SemaphoreHandle_t xSemaphoreTemp = xQueueSelectFromSet( xQueueSet, 0 );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphoreTemp ) );
vSemaphoreDelete( xSemaphore );
vQueueDelete( xQueueSet );
}
/**
* @brief Test xSemaphoreGiveFromISR on a queue in a Queue Set with no tasks waiting
* @details Test xSemaphoreGiveFromISR on a Queue in a Queue Set no tasks waiting and verify that xHigherPriorityTaskWoken is not modified.
* @coverage xQueueGiveFromISR
*/
void test_macro_xSemaphoreGiveFromISR_in_set_no_pending( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
QueueSetHandle_t xQueueSet = xQueueCreateSet( 1 );
xQueueAddToSet( xSemaphore, xQueueSet );
vFakePortAssertIfInterruptPriorityInvalid_Expect();
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
/* Give the semaphore */
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken ) );
TEST_ASSERT_EQUAL( pdFALSE, xHigherPriorityTaskWoken );
SemaphoreHandle_t xSemaphoreTemp = xQueueSelectFromSet( xQueueSet, 0 );
TEST_ASSERT_EQUAL( B_SEMPHR_AVAILABLE, uxSemaphoreGetCount( xSemaphoreTemp ) );
vSemaphoreDelete( xSemaphore );
vQueueDelete( xQueueSet );
}

View file

@ -0,0 +1,141 @@
/*
* FreeRTOS V202012.00
* 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
#include "fake_assert.h"
/*-----------------------------------------------------------
* 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_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 0
#define configUSE_RECURSIVE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 0
#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 0
#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 ( 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 1
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats()
#define portGET_RUN_TIME_COUNTER_VALUE() ulGetRunTimeCounterValue()
/* Co-routine related configuration options. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* 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 1
/* 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 1
#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 ) \
do \
{ \
if( x ) \
{ \
vFakeAssert( true, __FILE__, __LINE__ ); \
} \
else \
{ \
vFakeAssert( false, __FILE__, __LINE__ ); \
} \
} while ( 0 )
#define mtCOVERAGE_TEST_MARKER() __asm volatile ( "NOP" )
#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0
#if ( configINCLUDE_MESSAGE_BUFFER_AMP_DEMO == 1 )
extern void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer );
#define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )
#endif /* configINCLUDE_MESSAGE_BUFFER_AMP_DEMO */
#endif /* FREERTOS_CONFIG_H */

View file

@ -10,22 +10,23 @@ PROJECT_SRC += queue.c
# PROJECT_DEPS_SRC list the .c file that are dependencies of PROJECT_SRC files
# Files in PROJECT_DEPS_SRC are excluded from coverage measurements
PROJECT_DEPS_SRC +=
PROJECT_DEPS_SRC += list.c
# PROJECT_HEADER_DEPS: headers that should be excluded from coverage measurements.
PROJECT_HEADER_DEPS += FreeRTOS.h
# SUITE_UT_SRC: .c files that contain test cases (must end in _utest.c)
SUITE_UT_SRC += queue_2_utest.c
SUITE_UT_SRC += queue_1_utest.c
SUITE_UT_SRC += queue_create_static_utest.c
SUITE_UT_SRC += queue_delete_static_utest.c
# SUITE_SUPPORT_SRC: .c files used for testing that do not contain test cases.
# Paths are relative to PROJECT_DIR
SUITE_SUPPORT_SRC +=
SUITE_SUPPORT_SRC += queue_utest_common.c
SUITE_SUPPORT_SRC += td_task.c
SUITE_SUPPORT_SRC += td_port.c
# List the headers used by PROJECT_SRC that you would like to mock
MOCK_FILES_FP += $(KERNEL_DIR)/include/task.h
MOCK_FILES_FP += $(KERNEL_DIR)/include/list.h
MOCK_FILES_FP += $(UT_ROOT_DIR)/config/fake_assert.h
MOCK_FILES_FP += $(UT_ROOT_DIR)/config/fake_port.h

View file

@ -0,0 +1 @@
../generic/queue_create_static_utest.c

View file

@ -0,0 +1 @@
../generic/queue_delete_static_utest.c

View file

@ -0,0 +1,122 @@
/*
* FreeRTOS V202012.00
* 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 td_port.c */
#include "queue_utest_common.h"
/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
/* Test includes. */
#include "unity.h"
#include "unity_memory.h"
/* Mock includes. */
#include "mock_task.h"
#include "mock_fake_port.h"
/* ============================ GLOBAL VARIABLES =========================== */
bool xInCriticalSection = false;
uint32_t ulNumEnterCriticalSection = 0;
uint32_t ulNumExitCriticalSection = 0;
UBaseType_t uxSavedInterruptStatusGlobal = 0;
uint32_t ulNumCallsSetInterruptMaskFromISR = 0;
uint32_t ulNumCallsClearInterruptMaskFromISR = 0;
/* ========================== CALLBACK FUNCTIONS =========================== */
static void enterCriticalSectionStub( int cmock_num_calls )
{
/* check that enterCriticalSectionStub was not called twice in a row */
TEST_ASSERT_FALSE_MESSAGE( xInCriticalSection, "vFakePortEnterCriticalSection was called twice in a row." );
xInCriticalSection = true;
ulNumEnterCriticalSection++;
}
static void exitCriticalSectionStub( int cmock_num_calls )
{
/* check that exitCriticalSectionStub was not called twice in a row */
TEST_ASSERT_TRUE_MESSAGE( xInCriticalSection, "vFakePortExitCriticalSection was called twice in a row." );
xInCriticalSection = false;
ulNumExitCriticalSection++;
}
static UBaseType_t portSetInterruptMaskFromISRStub( int cmock_num_calls )
{
ulNumCallsSetInterruptMaskFromISR++;
uxSavedInterruptStatusGlobal = getLastMonotonicTestValue() + 241235;
xInCriticalSection = true;
return uxSavedInterruptStatusGlobal;
}
static void portClearInterruptMaskFromISRStub( UBaseType_t uxSavedInterruptStatus,
int cmock_num_calls )
{
ulNumCallsClearInterruptMaskFromISR++;
TEST_ASSERT_EQUAL_MESSAGE( uxSavedInterruptStatusGlobal, uxSavedInterruptStatus,
"Saved interrupt state from call to portClearInterruptMaskFromISR does not match last call to portSetInterruptMaskFromISR." );
xInCriticalSection = false;
uxSavedInterruptStatusGlobal = 0;
}
/* ============================= Unity Fixtures ============================= */
/* ========================== Helper functions =========================== */
void td_port_register_stubs( void )
{
/* Track critical section state */
xInCriticalSection = false;
ulNumEnterCriticalSection = 0;
ulNumExitCriticalSection = 0;
vFakePortEnterCriticalSection_Stub( &enterCriticalSectionStub );
vFakePortExitCriticalSection_Stub( &exitCriticalSectionStub );
uxSavedInterruptStatusGlobal = 0;
vFakePortClearInterruptMaskFromISR_Stub( &portClearInterruptMaskFromISRStub );
ulFakePortSetInterruptMaskFromISR_Stub( &portSetInterruptMaskFromISRStub );
}
BaseType_t td_port_isInCriticalSection( void )
{
return xInCriticalSection;
}
void td_port_teardown_check( void )
{
TEST_ASSERT_EQUAL_MESSAGE( ulNumEnterCriticalSection,
ulNumExitCriticalSection,
"Number of calls to vFakePortEnterCriticalSection does not match the number of calls to vFakePortExitCriticalSection." );
TEST_ASSERT_EQUAL_MESSAGE( 0,
uxSavedInterruptStatusGlobal,
"uxSavedInterruptStatus was non-zero at the end of the preceeding test case." );
}

View file

@ -0,0 +1,352 @@
/*
* FreeRTOS V202012.00
* 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 td_task.c */
#include "queue_utest_common.h"
/* Test includes. */
#include "unity.h"
/* Mock includes. */
#include "mock_task.h"
#include "mock_fake_port.h"
/* ============================ GLOBAL VARIABLES =========================== */
static BaseType_t xSchedulerState = taskSCHEDULER_RUNNING;
static ListItem_t taskListItem;
static ListItem_t fakeTaskListItem;
static TickType_t xTickCount = 0;
static BaseType_t xYieldPending = pdFALSE;
static BaseType_t xYieldCount = 0;
static BaseType_t xPortYieldCount = 0;
static BaseType_t xPortYieldFromISRCount = 0;
static BaseType_t xPortYieldWithinAPICount = 0;
static BaseType_t xTaskMissedYieldCount = 0;
static BaseType_t xYieldFromTaskResumeAllCount = 0;
/* ========================== CALLBACK FUNCTIONS =========================== */
static BaseType_t xTaskGetSchedulerStateStub( int num_calls )
{
return xSchedulerState;
}
static void vTaskSuspendAllStub( int cmock_num_calls )
{
TEST_ASSERT_EQUAL_MESSAGE( taskSCHEDULER_RUNNING, xSchedulerState, "vTaskSuspendAll called with scheduler suspended." );
xSchedulerState = taskSCHEDULER_SUSPENDED;
}
void td_task_vTaskSuspendAllStubNoCheck( int cmock_num_calls )
{
xSchedulerState = taskSCHEDULER_SUSPENDED;
}
static void vTaskMissedYieldStub( int cmock_num_calls )
{
TEST_ASSERT_TRUE_MESSAGE( ( td_task_getFakeTaskPriority() >= DEFAULT_PRIORITY ), "A Missed Yield should only occur when a higher priority task is pending." );
xTaskMissedYieldCount++;
xYieldPending = pdTRUE;
}
BaseType_t td_task_xTaskResumeAllStub( int cmock_num_calls )
{
BaseType_t xDidYield = pdFALSE;
TEST_ASSERT_EQUAL_MESSAGE( taskSCHEDULER_SUSPENDED, xSchedulerState, "xTaskResumeAll called with scheduler running." );
xSchedulerState = taskSCHEDULER_RUNNING;
if( ( td_task_getFakeTaskPriority() >= DEFAULT_PRIORITY ) &&
( listLIST_ITEM_CONTAINER( &fakeTaskListItem ) != NULL ) )
{
xYieldPending = pdTRUE;
}
if( xYieldPending )
{
#if ( configUSE_PREEMPTION == 1 )
xDidYield = pdTRUE;
xYieldCount++;
xYieldFromTaskResumeAllCount++;
xYieldPending = pdFALSE;
#endif
}
/* Remove task from blocked list */
if( listLIST_ITEM_CONTAINER( &taskListItem ) )
{
uxListRemove( &taskListItem );
}
return xDidYield;
}
static void vPortYieldStub( int cmock_num_calls )
{
xYieldCount++;
xPortYieldCount++;
xYieldPending = pdFALSE;
}
static void vPortYieldFromISRStub( int cmock_num_calls )
{
xYieldCount++;
xPortYieldFromISRCount++;
xYieldPending = pdFALSE;
}
void td_task_vPortYieldWithinAPIStub( int cmock_num_calls )
{
xYieldCount++;
xPortYieldWithinAPICount++;
xYieldPending = pdFALSE;
}
/* Timeout handling callbacks */
static void vTaskInternalSetTimeOutStateStub( TimeOut_t * const pxTimeOut,
int cmock_num_calls )
{
pxTimeOut->xOverflowCount = 0;
pxTimeOut->xTimeOnEntering = xTickCount;
}
BaseType_t td_task_xTaskCheckForTimeOutStub( TimeOut_t * const pxTimeOut,
TickType_t * const pxTicksToWait,
int cmock_num_calls )
{
BaseType_t xReturnValue = pdFALSE;
xTickCount++;
if( ( xTickCount - pxTimeOut->xTimeOnEntering ) > *pxTicksToWait )
{
xReturnValue = pdTRUE;
}
return xReturnValue;
}
/* Sorted Event list related */
static BaseType_t xTaskRemoveFromEventListStub( const List_t * const pxEventList,
int cmock_num_calls )
{
BaseType_t xReturnValue = pdFALSE;
/* check that xTaskRemoveFromEventList was called from within a critical section */
TEST_ASSERT_TRUE_MESSAGE( td_port_isInCriticalSection(), "xTaskRemoveFromEventList was called outside of a critical section." );
ListItem_t * pxItem = listGET_HEAD_ENTRY( pxEventList );
TickType_t xItemPriority = ( configMAX_PRIORITIES - listGET_LIST_ITEM_VALUE( pxItem ) );
( void ) uxListRemove( pxItem );
xReturnValue = ( xItemPriority > DEFAULT_PRIORITY );
xYieldPending |= xReturnValue;
return( xReturnValue );
}
static void vTaskPlaceOnEventListStub( List_t * const pxEventList,
const TickType_t xTicksToWait,
int cmock_num_calls )
{
if( listLIST_ITEM_CONTAINER( &taskListItem ) )
{
uxListRemove( &taskListItem );
}
listSET_LIST_ITEM_VALUE( &taskListItem, ( configMAX_PRIORITIES - DEFAULT_PRIORITY ) );
vListInsert( pxEventList, &taskListItem );
}
/* ============================= Unity Fixtures ============================= */
/* ========================== Helper functions ============================= */
void td_task_register_stubs( void )
{
/* Initialize local static variables */
xSchedulerState = taskSCHEDULER_RUNNING;
xTickCount = 0;
vListInitialiseItem( &taskListItem );
listSET_LIST_ITEM_VALUE( &taskListItem, configMAX_PRIORITIES - DEFAULT_PRIORITY );
vListInitialiseItem( &fakeTaskListItem );
listSET_LIST_ITEM_VALUE( &fakeTaskListItem, configMAX_PRIORITIES - DEFAULT_PRIORITY );
xYieldPending = pdFALSE;
xYieldCount = 0;
xPortYieldCount = 0;
xPortYieldFromISRCount = 0;
xPortYieldWithinAPICount = 0;
xTaskMissedYieldCount = 0;
xYieldFromTaskResumeAllCount = 0;
/* Setup stubs */
vFakePortYield_Stub( &vPortYieldStub );
vFakePortYieldFromISR_Stub( &vPortYieldFromISRStub );
vFakePortYieldWithinAPI_Stub( &td_task_vPortYieldWithinAPIStub );
xTaskGetSchedulerState_Stub( &xTaskGetSchedulerStateStub );
vTaskSuspendAll_Stub( &vTaskSuspendAllStub );
vTaskMissedYield_Stub( &vTaskMissedYieldStub );
xTaskResumeAll_Stub( &td_task_xTaskResumeAllStub );
vTaskInternalSetTimeOutState_Stub( &vTaskInternalSetTimeOutStateStub );
xTaskCheckForTimeOut_Stub( &td_task_xTaskCheckForTimeOutStub );
xTaskRemoveFromEventList_Stub( &xTaskRemoveFromEventListStub );
vTaskPlaceOnEventList_Stub( &vTaskPlaceOnEventListStub );
}
void td_task_setSchedulerState( BaseType_t state )
{
xSchedulerState = state;
}
void td_task_teardown_check( void )
{
/* Assertions to run at the end of the test case */
TEST_ASSERT_EQUAL_MESSAGE( taskSCHEDULER_RUNNING, xSchedulerState, "Test case ended with the scheduler suspended." );
TEST_ASSERT_EQUAL_MESSAGE( 0, xYieldCount, "Test case ended with xYieldCount > 0" );
TEST_ASSERT_EQUAL_MESSAGE( 0, xPortYieldCount, "Test case ended with xPortYieldCount > 0" );
TEST_ASSERT_EQUAL_MESSAGE( 0, xPortYieldFromISRCount, "Test case ended with xPortYieldFromISRCount > 0" );
TEST_ASSERT_EQUAL_MESSAGE( 0, xPortYieldWithinAPICount, "Test case ended with xPortYieldWithinAPICount > 0" );
TEST_ASSERT_EQUAL_MESSAGE( 0, xYieldFromTaskResumeAllCount, "Test case ended with xYieldFromTaskResumeAllCount > 0" );
TEST_ASSERT_EQUAL_MESSAGE( 0, xTaskMissedYieldCount, "Test case ended with xTaskMissedYieldCount > 0" );
TEST_ASSERT_EQUAL_MESSAGE( pdFALSE, xYieldPending, "Test case ended with xYieldPending != pdFALSE" );
}
void td_task_setFakeTaskPriority( TickType_t priority )
{
fakeTaskListItem.xItemValue = ( configMAX_PRIORITIES - priority );
List_t * pxContainer = listLIST_ITEM_CONTAINER( &fakeTaskListItem );
if( pxContainer != NULL )
{
uxListRemove( &fakeTaskListItem );
vListInsert( pxContainer, &fakeTaskListItem );
}
}
void td_task_addFakeTaskWaitingToSendToQueue( QueueHandle_t xQueue )
{
StaticQueue_t * pxQueue = ( StaticQueue_t * ) xQueue;
List_t * pxTasksWaitingToSend = ( List_t * ) &( pxQueue->xDummy3[ 0 ] );
if( listLIST_ITEM_CONTAINER( &fakeTaskListItem ) )
{
uxListRemove( &fakeTaskListItem );
}
fakeTaskListItem.pvOwner = NULL;
vListInsert( pxTasksWaitingToSend, &fakeTaskListItem );
}
void td_task_addFakeTaskWaitingToReceiveFromQueue( QueueHandle_t xQueue )
{
StaticQueue_t * pxQueue = ( StaticQueue_t * ) xQueue;
List_t * pxTasksWaitingToReceive = ( List_t * ) &( pxQueue->xDummy3[ 1 ] );
if( listLIST_ITEM_CONTAINER( &fakeTaskListItem ) )
{
uxListRemove( &fakeTaskListItem );
}
fakeTaskListItem.pvOwner = NULL;
vListInsert( pxTasksWaitingToReceive, &fakeTaskListItem );
}
TickType_t td_task_getFakeTaskPriority( void )
{
return( configMAX_PRIORITIES - fakeTaskListItem.xItemValue );
}
BaseType_t td_task_getYieldCount( void )
{
BaseType_t xReturnValue = xYieldCount;
xYieldCount = 0;
return xReturnValue;
}
BaseType_t td_task_getCount_vPortYield( void )
{
BaseType_t xReturnValue = xPortYieldCount;
xPortYieldCount = 0;
return xReturnValue;
}
BaseType_t td_task_getCount_vPortYieldFromISR( void )
{
BaseType_t xReturnValue = xPortYieldFromISRCount;
xPortYieldFromISRCount = 0;
return xReturnValue;
}
BaseType_t td_task_getCount_vPortYieldWithinAPI( void )
{
BaseType_t xReturnValue = xPortYieldWithinAPICount;
xPortYieldWithinAPICount = 0;
return xReturnValue;
}
BaseType_t td_task_getCount_vTaskMissedYield( void )
{
BaseType_t xReturnValue = xTaskMissedYieldCount;
xTaskMissedYieldCount = 0;
return xReturnValue;
}
BaseType_t td_task_getCount_YieldFromTaskResumeAll( void )
{
BaseType_t xReturnValue = xYieldFromTaskResumeAllCount;
xYieldFromTaskResumeAllCount = 0;
return xReturnValue;
}
BaseType_t td_task_getYieldPending( void )
{
BaseType_t xReturnValue = xYieldPending;
xYieldPending = pdFALSE;
return xReturnValue;
}

View file

@ -0,0 +1,139 @@
/*
* FreeRTOS V202012.00
* 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
#include "fake_assert.h"
/*-----------------------------------------------------------
* 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_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 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configCHECK_FOR_STACK_OVERFLOW 0
#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 ( 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 1
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats()
#define portGET_RUN_TIME_COUNTER_VALUE() ulGetRunTimeCounterValue()
/* Co-routine related configuration options. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* 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 1
/* 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 1
#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 ) \
do \
{ \
if( x ) \
{ \
vFakeAssert( true, __FILE__, __LINE__ ); \
} \
else \
{ \
vFakeAssert( false, __FILE__, __LINE__ ); \
} \
} while ( 0 )
#define mtCOVERAGE_TEST_MARKER() __asm volatile ( "NOP" )
#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0
#if ( configINCLUDE_MESSAGE_BUFFER_AMP_DEMO == 1 )
extern void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer );
#define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )
#endif /* configINCLUDE_MESSAGE_BUFFER_AMP_DEMO */
#endif /* FREERTOS_CONFIG_H */

View file

@ -0,0 +1,50 @@
# Indent with spaces
.RECIPEPREFIX := $(.RECIPEPREFIX) $(.RECIPEPREFIX)
# Do not move this line below the include
MAKEFILE_ABSPATH := $(abspath $(lastword $(MAKEFILE_LIST)))
include ../../makefile.in
# PROJECT_SRC lists the .c files under test
PROJECT_SRC += queue.c
# PROJECT_DEPS_SRC list the .c file that are dependencies of PROJECT_SRC files
# Files in PROJECT_DEPS_SRC are excluded from coverage measurements
PROJECT_DEPS_SRC += list.c
# PROJECT_HEADER_DEPS: headers that should be excluded from coverage measurements.
PROJECT_HEADER_DEPS += FreeRTOS.h
# SUITE_UT_SRC: .c files that contain test cases (must end in _utest.c)
SUITE_UT_SRC += queue_registry_utest.c
SUITE_UT_SRC += queue_trace_utest.c
SUITE_UT_SRC += queue_delete_dynamic_utest.c
SUITE_UT_SRC += queue_delete_static_utest.c
# SUITE_SUPPORT_SRC: .c files used for testing that do not contain test cases.
# Paths are relative to PROJECT_DIR
SUITE_SUPPORT_SRC += queue_utest_common.c
SUITE_SUPPORT_SRC += td_task.c
SUITE_SUPPORT_SRC += td_port.c
# List the headers used by PROJECT_SRC that you would like to mock
MOCK_FILES_FP += $(KERNEL_DIR)/include/task.h
MOCK_FILES_FP += $(UT_ROOT_DIR)/config/fake_assert.h
MOCK_FILES_FP += $(UT_ROOT_DIR)/config/fake_port.h
# List any addiitonal flags needed by the preprocessor
CPPFLAGS += -DportUSING_MPU_WRAPPERS=0
# List any addiitonal flags needed by the compiler
CFLAGS +=
# Try not to edit beyond this line unless necessary.
# Project / Suite are determined based on path: $(UT_ROOT_DIR)/$(PROJECT)/$(SUITE)
PROJECT := $(lastword $(subst /, ,$(dir $(abspath $(MAKEFILE_ABSPATH)/../))))
SUITE := $(lastword $(subst /, ,$(dir $(MAKEFILE_ABSPATH))))
# Make variables available to included makefile
export
include ../../testdir.mk

View file

@ -0,0 +1 @@
../generic/queue_delete_dynamic_utest.c

View file

@ -0,0 +1 @@
../generic/queue_delete_static_utest.c

View file

@ -0,0 +1,395 @@
/*
* FreeRTOS V202012.00
* 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 queue_registry_utest.c */
/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include "../queue_utest_common.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "queue.h"
/* ============================ GLOBAL VARIABLES =========================== */
/**
* @brief Copy of QueueRegistryItem_t from queue.c to allow clearing items between test cases.
*/
typedef struct QUEUE_REGISTRY_ITEM
{
const char * pcQueueName;
QueueHandle_t xHandle;
} xQueueRegistryItem;
typedef xQueueRegistryItem QueueRegistryItem_t;
/* Access the xQueueRegistry to clear between test cases */
extern PRIVILEGED_DATA QueueRegistryItem_t xQueueRegistry[ configQUEUE_REGISTRY_SIZE ];
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
/* Clear the queue registry between test cases */
memset( &xQueueRegistry, 0, ( configQUEUE_REGISTRY_SIZE * sizeof( QueueRegistryItem_t ) ) );
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* =========================== Helper functions ============================ */
static bool helper_find_in_queue_registry( QueueHandle_t xQueue,
const char * pcQueueName )
{
for( int i = 0; i < configQUEUE_REGISTRY_SIZE; i++ )
{
if( ( xQueueRegistry[ i ].pcQueueName == pcQueueName ) &&
( xQueueRegistry[ i ].xHandle == xQueue ) )
{
return true;
}
}
return false;
}
static bool helper_find_handle_in_queue_registry( QueueHandle_t xQueue )
{
for( int i = 0; i < configQUEUE_REGISTRY_SIZE; i++ )
{
if( xQueueRegistry[ i ].xHandle == xQueue )
{
return true;
}
}
return false;
}
/* ============================== Test Cases =============================== */
/**
* @brief Test vQueueAddToRegistry with a NULL QueueHandle_t
* @details Verify that a NULL QueueHandle_t results in the string being stored
* to the QueueRegistry and a configASSERT failure.
* @coverage vQueueAddToRegistry
**/
void test_vQueueAddToRegistry_null_xQueue( void )
{
const char * pcFakeStringPtr = ( char * ) ( BaseType_t ) getNextMonotonicTestValue();
/* Expect a failed configASSERT when adding a NULL xQueue to the QueueRegistry */
fakeAssertExpectFail();
vQueueAddToRegistry( NULL, pcFakeStringPtr );
TEST_ASSERT_TRUE( fakeAssertGetFlagAndClear() );
TEST_ASSERT_TRUE( helper_find_in_queue_registry( NULL, pcFakeStringPtr ) );
}
/**
* @brief Test vQueueAddToRegistry with a NULL pcQueueName
* @details Verify that a NULL pcQueueName results in the NULL string being stored
* in the QueueRegistry and a configASSERT failure.
* @coverage vQueueAddToRegistry
**/
void test_vQueueAddToRegistry_null_pcQueueName( void )
{
QueueHandle_t xFakeHandle = ( QueueHandle_t ) ( BaseType_t ) getNextMonotonicTestValue();
vQueueAddToRegistry( xFakeHandle, NULL );
TEST_ASSERT_FALSE( helper_find_in_queue_registry( xFakeHandle, NULL ) );
}
/**
* @brief Test vQueueAddToRegistry with a valid xQueue and pcQueueName
* @details Verify that calling vQueueAddToRegistry with a valid xQueue and
* pcQueueName stores the tuple.
* @coverage vQueueAddToRegistry
**/
void test_vQueueAddToRegistry_success( void )
{
QueueHandle_t xFakeHandle = ( QueueHandle_t ) ( BaseType_t ) getNextMonotonicTestValue();
const char * pcFakeString = ( char * ) ( BaseType_t ) getNextMonotonicTestValue();
/* Add an item to the registry */
vQueueAddToRegistry( xFakeHandle, pcFakeString );
/* Verify that the value was added to the registry */
TEST_ASSERT_TRUE( helper_find_in_queue_registry( xFakeHandle, pcFakeString ) );
}
/**
* @brief Test vQueueAddToRegistry with the same QueueHandle_t twice
* @details Verify that a given QueueHandle_t can be added to the queue registry
* multiple times and that the l
* @coverage vQueueAddToRegistry
**/
void test_vQueueAddToRegistry_twice( void )
{
QueueHandle_t xFakeHandle = ( QueueHandle_t ) ( BaseType_t ) getNextMonotonicTestValue();
const char * pcFakeString1 = ( char * ) ( BaseType_t ) getNextMonotonicTestValue();
const char * pcFakeString2 = ( char * ) ( BaseType_t ) getNextMonotonicTestValue();
/* Add an item to the registry **/
vQueueAddToRegistry( xFakeHandle, pcFakeString1 );
TEST_ASSERT_TRUE( helper_find_in_queue_registry( xFakeHandle, pcFakeString1 ) );
vQueueAddToRegistry( xFakeHandle, pcFakeString2 );
/* Verify that pcFakeString2 is now in the queue registry */
TEST_ASSERT_TRUE( helper_find_in_queue_registry( xFakeHandle, pcFakeString2 ) );
/* Verify that pcFakeString1 is no longer in the queue registry */
TEST_ASSERT_FALSE( helper_find_in_queue_registry( xFakeHandle, pcFakeString1 ) );
vQueueUnregisterQueue( xFakeHandle );
/* Verify that pcFakeString2 has been removed from the registry */
TEST_ASSERT_FALSE( helper_find_in_queue_registry( xFakeHandle, pcFakeString2 ) );
}
/**
* @brief Test vQueueAddToRegistry with a queue registry that is already full.
* @details Verify that a call to vQueueAddToRegistry with a full queue registry
* fails silently.
* @coverage vQueueAddToRegistry
**/
void test_vQueueAddToRegistry_full( void )
{
TEST_ASSERT_TRUE( configQUEUE_REGISTRY_SIZE < UINT32_MAX );
/* Fill the queue registry and verify that the max items were successfully stored.
* Start at i=1 since a NULL / 0 pcQueueName denotes an empty queue registry location */
for( BaseType_t i = 1; i <= configQUEUE_REGISTRY_SIZE; i++ )
{
QueueHandle_t fakeHandle = ( QueueHandle_t ) i;
const char * fakeString = ( char * ) i;
/* Add our fake QueueHandle_t and const char* to the registry */
vQueueAddToRegistry( fakeHandle, fakeString );
/* Verify that the fake queue handle was added to the registry */
TEST_ASSERT_EQUAL( pcQueueGetName( fakeHandle ), fakeString );
}
/* Prepare one more fake item to add to the registry */
QueueHandle_t fakeHandle = ( QueueHandle_t ) ( configQUEUE_REGISTRY_SIZE + 1 );
const char * fakeString = ( char * ) ( configQUEUE_REGISTRY_SIZE + 1 );
/* Add one more item */
vQueueAddToRegistry( fakeHandle, fakeString );
TEST_ASSERT_FALSE( helper_find_in_queue_registry( fakeHandle, fakeString ) );
}
/**
* @brief Test pcQueueGetName with a NULL QueueHandle_t
* @details Verify that a NULL QueueHandle_t can be used as a lookup value with
* pcQueueGetName, but causes a failed configASSERT.
* @coverage pcQueueGetName
**/
void test_pcQueueGetName_null_xQueue( void )
{
const char * pcFakeString = ( char * ) ( BaseType_t ) getNextMonotonicTestValue();
/* Expect a failed configASSERT when adding a NULL xQueue to the QueueRegistry */
fakeAssertExpectFail();
vQueueAddToRegistry( NULL, pcFakeString );
fakeAssertGetFlagAndClear();
TEST_ASSERT_TRUE( helper_find_in_queue_registry( NULL, pcFakeString ) );
/* Expect a failed configASSERT when pcQueueGetName with a NULL xQueue */
fakeAssertExpectFail();
/* Validate the value returned by pcQueueGetName */
TEST_ASSERT_EQUAL( pcQueueGetName( NULL ), pcFakeString );
TEST_ASSERT_TRUE( fakeAssertGetFlagAndClear() );
}
/**
* @brief Test pcQueueGetName with an xQueue handle that was not registered.
* @details Verify that a call to pcQueueGetName with an unregisteredd xQueue
* returns a NULL pointer.
* @coverage pcQueueGetName
**/
void test_pcQueueGetName_not_registered( void )
{
QueueHandle_t xFakeHandle = ( QueueHandle_t ) ( BaseType_t ) getNextMonotonicTestValue();
const char * pcFakeString = ( char * ) ( BaseType_t ) getNextMonotonicTestValue();
/* Add an item to the registry */
vQueueAddToRegistry( xFakeHandle, pcFakeString );
/* Verify the value returned by pcQueueGetName matches the value added to the registry */
TEST_ASSERT_EQUAL( pcQueueGetName( xFakeHandle ), pcFakeString );
vQueueUnregisterQueue( xFakeHandle );
/* Verify the value returned by pcQueueGetName matches the value added to the registry */
TEST_ASSERT_EQUAL( NULL, pcQueueGetName( xFakeHandle ) );
}
/**
* @brief Test pcQueueGetName with an xQueue handle that was previously registered.
* @details Verify that a call to pcQueueGetName with a registered xQueue handle
* returns the correct pointer
* @coverage pcQueueGetName
**/
void test_pcQueueGetName_registered( void )
{
QueueHandle_t xFakeHandle = ( QueueHandle_t ) ( BaseType_t ) getNextMonotonicTestValue();
const char * pcFakeString = ( char * ) ( BaseType_t ) getNextMonotonicTestValue();
/* Add an item to the registry */
vQueueAddToRegistry( xFakeHandle, pcFakeString );
/* Verify the value returned by pcQueueGetName matches the value added to the registry */
TEST_ASSERT_EQUAL( pcQueueGetName( xFakeHandle ), pcFakeString );
}
/**
* @brief Test vQueueUnregisterQueue with a NULL xQueue handle
* @details Verify that calling vQueueUnregisterQueue with a NULL xQueue results
* in a configASSERT failure.
* @coverage vQueueUnregisterQueue
**/
void test_vQueueUnregisterQueue_null_handle( void )
{
fakeAssertExpectFail();
vQueueUnregisterQueue( NULL );
TEST_ASSERT_TRUE( fakeAssertGetFlagAndClear() );
}
/**
* @brief Test vQueueUnregisterQueue with an unregisterd xQueue handle
* @details Verify that calling vQueueUnregisterQueue does not result in an assertion.
* @coverage vQueueUnregisterQueue
**/
void test_vQueueUnregisterQueue_queue_not_registered( void )
{
QueueHandle_t xFakeHandle = ( QueueHandle_t ) ( BaseType_t ) getNextMonotonicTestValue();
vQueueUnregisterQueue( xFakeHandle );
}
/**
* @brief Test vQueueUnregisterQueue on a registered xQueue
* @details Verify that calling vQueueUnregisterQueue with a registered xQueue
* removes the xQueue from the Queue Registry and does not result in a
* configASSERT failure.
* @coverage vQueueUnregisterQueue
**/
void test_vQueueUnregisterQueue( void )
{
QueueHandle_t xFakeHandle = ( QueueHandle_t ) ( BaseType_t ) getNextMonotonicTestValue();
const char * pcFakeString = ( char * ) ( BaseType_t ) getNextMonotonicTestValue();
/* Add an item to the registry */
vQueueAddToRegistry( xFakeHandle, pcFakeString );
TEST_ASSERT_TRUE( helper_find_handle_in_queue_registry( xFakeHandle ) );
TEST_ASSERT_EQUAL( pcFakeString, pcQueueGetName( xFakeHandle ) );
vQueueUnregisterQueue( xFakeHandle );
TEST_ASSERT_FALSE( helper_find_handle_in_queue_registry( xFakeHandle ) );
}
/**
* @brief Test two subsequent calls to vQueueUnregisterQueue on a registered xQueue
* @details Verify that calling vQueueUnregisterQueue twice on a registered xQueue
* succeeds the first time and results in no change on the second call.
* @coverage vQueueUnregisterQueue
**/
void test_vQueueUnregisterQueue_twice( void )
{
QueueHandle_t xFakeHandle = ( QueueHandle_t ) ( BaseType_t ) getNextMonotonicTestValue();
const char * pcFakeString = ( char * ) ( BaseType_t ) getNextMonotonicTestValue();
/* Add an item to the registry */
vQueueAddToRegistry( xFakeHandle, pcFakeString );
/* Verify that the value was added to the registry */
TEST_ASSERT_TRUE( helper_find_handle_in_queue_registry( xFakeHandle ) );
vQueueUnregisterQueue( xFakeHandle );
TEST_ASSERT_FALSE( helper_find_handle_in_queue_registry( xFakeHandle ) );
vQueueUnregisterQueue( xFakeHandle );
TEST_ASSERT_FALSE( helper_find_handle_in_queue_registry( xFakeHandle ) );
}
/**
* @brief Test that vQueueDelete removes the xQueue from the Queue Registry
* @details Verify that vQueueDelete removes a queue from the Queue Registry
* by calling vQueueUnregisterQueue.
* @coverage vQueueDelete vQueueUnregisterQueue
**/
void test_vQueueDelete_vQueueUnregisterQueue( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
const char * xQueueName = "Testing 123";
/* Add the queue to the registry */
vQueueAddToRegistry( xQueue, xQueueName );
/* Verify the value returned by pcQueueGetName matches the value added to the registry */
TEST_ASSERT_EQUAL( xQueueName, pcQueueGetName( xQueue ) );
vQueueDelete( xQueue );
/* Verify the value returned by pcQueueGetName is now NULL */
TEST_ASSERT_EQUAL( NULL, pcQueueGetName( xQueue ) );
}

View file

@ -0,0 +1,195 @@
/*
* FreeRTOS V202012.00
* 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 queue_trace_utest.c */
/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "../queue_utest_common.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "queue.h"
#include "semphr.h"
/* ============================ GLOBAL VARIABLES =========================== */
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* ========================== Helper functions =========================== */
/**
* @brief Test vQueueSetQueueNumber and uxQueueGetQueueNumber
* @details Verify that the queue number set with vQueueSetQueueNumber is returned
* by a subsequent call to uxQueueGetQueueNumber.
* @coverage vQueueSetQueueNumber uxQueueGetQueueNumber
*/
void test_vQueueSetQueueNumber_uxQueueGetQueueNumber( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
vQueueSetQueueNumber( xQueue, getNextMonotonicTestValue() );
TEST_ASSERT_EQUAL( getLastMonotonicTestValue(), uxQueueGetQueueNumber( xQueue ) );
vQueueDelete( xQueue );
}
/**
* @brief Test vQueueSetQueueNumber and uxQueueGetQueueNumber with UINT64_MAX
* @details Verify that the queue number of UINT64_MAX set with
* vQueueSetQueueNumber is returned by a subsequent call to uxQueueGetQueueNumber.
* @coverage vQueueSetQueueNumber uxQueueGetQueueNumber
*/
void test_vQueueSetQueueNumber_uxQueueGetQueueNumber_max( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
vQueueSetQueueNumber( xQueue, UINT64_MAX );
TEST_ASSERT_EQUAL( UINT64_MAX, uxQueueGetQueueNumber( xQueue ) );
vQueueDelete( xQueue );
}
/**
* @brief Test vQueueSetQueueNumber and uxQueueGetQueueNumber with 0
* @details Verify that the queue number of 0 set with vQueueSetQueueNumber
* is returned by a subsequent call to uxQueueGetQueueNumber.
* @coverage vQueueSetQueueNumber uxQueueGetQueueNumber
*/
void test_vQueueSetQueueNumber_uxQueueGetQueueNumber_zero( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
vQueueSetQueueNumber( xQueue, 0 );
TEST_ASSERT_EQUAL( 0, uxQueueGetQueueNumber( xQueue ) );
vQueueDelete( xQueue );
}
/**
* @brief Test ucQueueGetQueueType with a Queue
* @details Verify that ucQueueGetQueueType returns queueQUEUE_TYPE_BASE for a normal queue.
* @coverage ucQueueGetQueueType prvInitialiseNewQueue
*/
void test_ucQueueGetQueueType_queue( void )
{
QueueHandle_t xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
TEST_ASSERT_EQUAL( queueQUEUE_TYPE_BASE, ucQueueGetQueueType( xQueue ) );
vQueueDelete( xQueue );
}
/**
* @brief Test ucQueueGetQueueType with a QueueSet
* @details Verify that ucQueueGetQueueType returns queueQUEUE_TYPE_SET for a QueueSet.
* @coverage ucQueueGetQueueType prvInitialiseNewQueue
*/
void test_ucQueueGetQueueType_queue_set( void )
{
QueueSetHandle_t xQueueSet = xQueueCreateSet( 1 );
TEST_ASSERT_EQUAL( queueQUEUE_TYPE_SET, ucQueueGetQueueType( xQueueSet ) );
vQueueDelete( xQueueSet );
}
/**
* @brief Test ucQueueGetQueueType with a Mutex
* @details Verify that ucQueueGetQueueType returns queueQUEUE_TYPE_MUTEX for a Mutex.
* @coverage ucQueueGetQueueType prvInitialiseNewQueue
*/
void test_ucQueueGetQueueType_mutex( void )
{
xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
SemaphoreHandle_t xSemaphore = xSemaphoreCreateMutex();
TEST_ASSERT_EQUAL( queueQUEUE_TYPE_MUTEX, ucQueueGetQueueType( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test ucQueueGetQueueType with a Counting Semaphore
* @details Verify that ucQueueGetQueueType returns queueQUEUE_TYPE_COUNTING_SEMAPHORE for a Counting Semaphore.
* @coverage ucQueueGetQueueType prvInitialiseNewQueue
*/
void test_ucQueueGetQueueType_counting_semaphore( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateCounting( 1, 0 );
TEST_ASSERT_EQUAL( queueQUEUE_TYPE_COUNTING_SEMAPHORE, ucQueueGetQueueType( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test ucQueueGetQueueType with a Binary Semaphore
* @details Verify that ucQueueGetQueueType returns queueQUEUE_TYPE_BINARY_SEMAPHORE for a Binary Semaphore.
* @coverage ucQueueGetQueueType prvInitialiseNewQueue
*/
void test_ucQueueGetQueueType_binary_semaphore( void )
{
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
TEST_ASSERT_EQUAL( queueQUEUE_TYPE_BINARY_SEMAPHORE, ucQueueGetQueueType( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test ucQueueGetQueueType with a Recursive Mutex
* @details Verify that ucQueueGetQueueType returns queueQUEUE_TYPE_RECURSIVE_MUTEX for a Recursive Mutex.
* @coverage ucQueueGetQueueType prvInitialiseNewQueue
*/
void test_ucQueueGetQueueType_recursive_mutex( void )
{
xTaskPriorityDisinherit_ExpectAndReturn( NULL, pdFALSE );
SemaphoreHandle_t xSemaphore = xSemaphoreCreateRecursiveMutex();
TEST_ASSERT_EQUAL( queueQUEUE_TYPE_RECURSIVE_MUTEX, ucQueueGetQueueType( xSemaphore ) );
vSemaphoreDelete( xSemaphore );
}

View file

@ -1 +0,0 @@
../queue_utest.c

View file

@ -1 +0,0 @@
../queue_utest.c

View file

@ -199,7 +199,7 @@ def filter_coverage_file(covfile_handle, cov_functions):
cur_file["functions"] = cur_functions
cur_lines = list()
for line in targetfile["lines"]:
if line["function_name"] in cov_functions:
if "function_name" in line and line["function_name"] in cov_functions:
cur_lines.append(line)
cur_file["lines"] = cur_lines
covdata_out["files"].append(cur_file)