[修改] 增加freeRTOS
1. 版本FreeRTOSv202212.01,命名为kernel;
This commit is contained in:
136
kernel/FreeRTOS/Test/CMock/queue/sets/FreeRTOSConfig.h
Normal file
136
kernel/FreeRTOS/Test/CMock/queue/sets/FreeRTOSConfig.h
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* FreeRTOS V202212.01
|
||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FREERTOS_CONFIG_H
|
||||
#define FREERTOS_CONFIG_H
|
||||
|
||||
#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
|
||||
* https://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()
|
||||
|
||||
/* 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 */
|
||||
54
kernel/FreeRTOS/Test/CMock/queue/sets/Makefile
Normal file
54
kernel/FreeRTOS/Test/CMock/queue/sets/Makefile
Normal 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
|
||||
901
kernel/FreeRTOS/Test/CMock/queue/sets/binary_semaphore_utest.c
Normal file
901
kernel/FreeRTOS/Test/CMock/queue/sets/binary_semaphore_utest.c
Normal file
@ -0,0 +1,901 @@
|
||||
/*
|
||||
* FreeRTOS V202212.01
|
||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
/*! @file 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 accordingly.
|
||||
* @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();
|
||||
uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 );
|
||||
|
||||
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();
|
||||
|
||||
/* The number of tasks need to be more than 127 to trigger the
|
||||
* overflow assertion. */
|
||||
uxTaskGetNumberOfTasks_IgnoreAndReturn( 128 );
|
||||
|
||||
|
||||
/* 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 because 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 because
|
||||
* 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_success( void )
|
||||
{
|
||||
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
|
||||
|
||||
/* Export for blocking_success_xTaskCheckForTimeOut_cb callback */
|
||||
xSemaphoreHandleStatic = xSemaphore;
|
||||
|
||||
vFakePortAssertIfInterruptPriorityInvalid_Ignore();
|
||||
|
||||
xTaskCheckForTimeOut_Stub( &blocking_success_xTaskCheckForTimeOut_cb );
|
||||
uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 );
|
||||
|
||||
|
||||
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 );
|
||||
uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 );
|
||||
|
||||
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 )
|
||||
{
|
||||
uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 );
|
||||
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 );
|
||||
uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 );
|
||||
|
||||
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 );
|
||||
uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 );
|
||||
|
||||
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 );
|
||||
}
|
||||
588
kernel/FreeRTOS/Test/CMock/queue/sets/mutex_utest.c
Normal file
588
kernel/FreeRTOS/Test/CMock/queue/sets/mutex_utest.c
Normal file
@ -0,0 +1,588 @@
|
||||
/*
|
||||
* FreeRTOS V202212.01
|
||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
/*! @file 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 );
|
||||
|
||||
/* Check that configASSERT was called twice */
|
||||
fakeAssertVerifyNumAssertsAndClear( 2 );
|
||||
|
||||
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 inheritance 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 inheritance 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 inheritance 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 );
|
||||
}
|
||||
1101
kernel/FreeRTOS/Test/CMock/queue/sets/queue_in_set_utest.c
Normal file
1101
kernel/FreeRTOS/Test/CMock/queue/sets/queue_in_set_utest.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,662 @@
|
||||
/*
|
||||
* FreeRTOS V202212.01
|
||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
/*! @file 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 );
|
||||
uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 );
|
||||
|
||||
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 );
|
||||
uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 );
|
||||
|
||||
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 );
|
||||
uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 );
|
||||
|
||||
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 );
|
||||
uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 );
|
||||
|
||||
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 );
|
||||
uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 );
|
||||
|
||||
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 );
|
||||
uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 );
|
||||
|
||||
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 because 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_success.
|
||||
*/
|
||||
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 because 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
@ -0,0 +1,342 @@
|
||||
/*
|
||||
* FreeRTOS V202212.01
|
||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
/*! @file 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 );
|
||||
uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 );
|
||||
|
||||
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 );
|
||||
uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 );
|
||||
|
||||
/* 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 );
|
||||
uxTaskGetNumberOfTasks_IgnoreAndReturn( 1 );
|
||||
|
||||
/* 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 because 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 );
|
||||
}
|
||||
1161
kernel/FreeRTOS/Test/CMock/queue/sets/queue_send_nonblocking_utest.c
Normal file
1161
kernel/FreeRTOS/Test/CMock/queue/sets/queue_send_nonblocking_utest.c
Normal file
File diff suppressed because it is too large
Load Diff
411
kernel/FreeRTOS/Test/CMock/queue/sets/queue_set_utest.c
Normal file
411
kernel/FreeRTOS/Test/CMock/queue/sets/queue_set_utest.c
Normal file
@ -0,0 +1,411 @@
|
||||
/*
|
||||
* FreeRTOS V202212.01
|
||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
/*! @file 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_EQUAL( NULL, xQueueSet );
|
||||
|
||||
/* verify that configASSERT was called */
|
||||
TEST_ASSERT_EQUAL( true, fakeAssertGetFlagAndClear() );
|
||||
TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 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 );
|
||||
}
|
||||
@ -0,0 +1,359 @@
|
||||
/*
|
||||
* FreeRTOS V202212.01
|
||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
/*! @file 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 ); */
|
||||
/* } */
|
||||
206
kernel/FreeRTOS/Test/CMock/queue/sets/semaphore_in_set_utest.c
Normal file
206
kernel/FreeRTOS/Test/CMock/queue/sets/semaphore_in_set_utest.c
Normal file
@ -0,0 +1,206 @@
|
||||
/*
|
||||
* FreeRTOS V202212.01
|
||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
/*! @file 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 accordingly.
|
||||
* @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 );
|
||||
}
|
||||
Reference in New Issue
Block a user