forked from Imagelibrary/rtems
Add test assertion for allocator mutex being unlocked
The Allocator Mutex should not be locked outside a tested service call. In an SMP test or heavily multithreaded test, this is possible since another thread could have the lock for an extended period of time but this is not the norm for the tests. updates 2319.
This commit is contained in:
@@ -149,7 +149,7 @@ endif
|
||||
|
||||
## CORE_APIMUTEX_C_FILES
|
||||
libscore_a_SOURCES += src/apimutex.c \
|
||||
src/apimutexlock.c src/apimutexunlock.c
|
||||
src/apimutexlock.c src/apimutexislocked.c src/apimutexunlock.c
|
||||
|
||||
## CORE_BARRIER_C_FILES
|
||||
libscore_a_SOURCES += src/corebarrier.c src/corebarrierrelease.c \
|
||||
|
||||
@@ -85,6 +85,8 @@ void _API_Mutex_Lock( API_Mutex_Control *mutex );
|
||||
*/
|
||||
void _API_Mutex_Unlock( API_Mutex_Control *mutex );
|
||||
|
||||
bool _API_Mutex_Is_Locked( API_Mutex_Control *mutex );
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
@@ -118,6 +120,11 @@ static inline void _RTEMS_Unlock_allocator( void )
|
||||
_API_Mutex_Unlock( _RTEMS_Allocator_Mutex );
|
||||
}
|
||||
|
||||
static inline bool _RTEMS_Check_if_allocator_is_locked( void )
|
||||
{
|
||||
return _API_Mutex_Is_Locked( _RTEMS_Allocator_Mutex );
|
||||
}
|
||||
|
||||
SCORE_EXTERN API_Mutex_Control *_Once_Mutex;
|
||||
|
||||
static inline void _Once_Lock( void )
|
||||
|
||||
36
cpukit/score/src/apimutexislocked.c
Normal file
36
cpukit/score/src/apimutexislocked.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @brief Check if the specified API mutex is locked.
|
||||
*
|
||||
* @ingroup ScoreAPIMutex
|
||||
*/
|
||||
|
||||
/*
|
||||
* COPYRIGHT (c) 1989-2015.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <rtems/score/apimutex.h>
|
||||
#include <rtems/score/coremuteximpl.h>
|
||||
#include <rtems/score/threadimpl.h>
|
||||
|
||||
bool _API_Mutex_Is_Locked( API_Mutex_Control *the_mutex )
|
||||
{
|
||||
bool is_locked;
|
||||
ISR_Level level;
|
||||
|
||||
_ISR_Disable( level );
|
||||
is_locked = _CORE_mutex_Is_locked( &the_mutex->Mutex );
|
||||
_ISR_Enable( level );
|
||||
|
||||
return is_locked;
|
||||
}
|
||||
@@ -61,15 +61,6 @@ void verify_timedout_mq_timedsend(int que, int is_blocking);
|
||||
void verify_mq_send(void);
|
||||
void verify_timed_receive(void);
|
||||
|
||||
#define fatal_posix_mqd( _ptr, _msg ) \
|
||||
if ( (_ptr != (mqd_t) -1) ) { \
|
||||
check_dispatch_disable_level( 0 ); \
|
||||
printf( "\n%s FAILED -- expected (-1) got (%" PRId32 " - %d/%s)\n", \
|
||||
(_msg), _ptr, errno, strerror(errno) ); \
|
||||
FLUSH_OUTPUT(); \
|
||||
rtems_test_exit( -1 ); \
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
char msg[ 50 ];
|
||||
int size;
|
||||
|
||||
@@ -25,16 +25,6 @@ const char rtems_test_name[] = "PSXSEM 1";
|
||||
/* forward declarations to avoid warnings */
|
||||
void *POSIX_Init(void *argument);
|
||||
|
||||
#define fatal_posix_sem( _ptr, _msg ) \
|
||||
if ( (_ptr != SEM_FAILED) ) { \
|
||||
check_dispatch_disable_level( 0 ); \
|
||||
printf( "\n%s FAILED -- expected (-1) got (%p - %d/%s)\n", \
|
||||
(_msg), _ptr, errno, strerror(errno) ); \
|
||||
FLUSH_OUTPUT(); \
|
||||
rtems_test_exit( -1 ); \
|
||||
}
|
||||
|
||||
|
||||
#define MAX_SEMS 10
|
||||
|
||||
void *POSIX_Init(
|
||||
|
||||
@@ -46,7 +46,7 @@ extern "C" {
|
||||
* Check that that the dispatch disable level is proper for the
|
||||
* mode/state of the test. Normally it should be 0 when in task space.
|
||||
*
|
||||
* This test is only valid when in a non smp system. In an smp system
|
||||
* This test is only valid when in a non-SMP system. In an smp system
|
||||
* another cpu may be accessing the core at any point when this core
|
||||
* does not have it locked.
|
||||
*/
|
||||
@@ -69,6 +69,32 @@ extern "C" {
|
||||
} while ( 0 )
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Check that that the allocator mutex is not locked. It should never
|
||||
* be locked unless inside a service which is allocating a resource.
|
||||
*
|
||||
* This test is only valid when in a non-SMP system. In an SMP system
|
||||
* another cpu may be allocating a resource while we are computing.
|
||||
*/
|
||||
#if defined SMPTEST
|
||||
#define check_if_allocator_mutex_is_unlocked()
|
||||
#else
|
||||
#include <rtems/score/apimutex.h>
|
||||
#define check_if_allocator_mutex_is_unlocked() \
|
||||
do { \
|
||||
if ( _RTEMS_Check_if_allocator_is_locked() ) { \
|
||||
printk( \
|
||||
"\nRTEMS Allocator Mutex is locked and should not be.\n" \
|
||||
"Detected at %s:%d\n", \
|
||||
__FILE__, \
|
||||
__LINE__ \
|
||||
); \
|
||||
FLUSH_OUTPUT(); \
|
||||
rtems_test_exit( 1 ); \
|
||||
} \
|
||||
} while ( 0 )
|
||||
#endif
|
||||
|
||||
/*
|
||||
* These macros properly report errors within the Classic API
|
||||
*/
|
||||
@@ -95,6 +121,7 @@ extern "C" {
|
||||
#define fatal_directive_status_with_level( _stat, _desired, _msg, _level ) \
|
||||
do { \
|
||||
check_dispatch_disable_level( _level ); \
|
||||
check_if_allocator_mutex_is_unlocked(); \
|
||||
fatal_directive_check_status_only( _stat, _desired, _msg ); \
|
||||
} while ( 0 )
|
||||
|
||||
@@ -112,6 +139,7 @@ extern "C" {
|
||||
if ( (_stat != -1) && (errno) != (_desired) ) { \
|
||||
long statx = _stat; \
|
||||
check_dispatch_disable_level( 0 ); \
|
||||
check_if_allocator_mutex_is_unlocked(); \
|
||||
printf( "\n%s FAILED -- expected (%d - %s) got (%ld %d - %s)\n", \
|
||||
(_msg), _desired, strerror(_desired), \
|
||||
statx, errno, strerror(errno) ); \
|
||||
@@ -125,6 +153,7 @@ extern "C" {
|
||||
#define fatal_posix_service_status_with_level( _stat, _desired, _msg, _level ) \
|
||||
do { \
|
||||
check_dispatch_disable_level( _level ); \
|
||||
check_if_allocator_mutex_is_unlocked(); \
|
||||
if ( (_stat) != (_desired) ) { \
|
||||
printf( "\n%s FAILED -- expected (%d - %s) got (%d - %s)\n", \
|
||||
(_msg), _desired, strerror(_desired), _stat, strerror(_stat) ); \
|
||||
@@ -135,6 +164,30 @@ extern "C" {
|
||||
} \
|
||||
} while ( 0 )
|
||||
|
||||
/*
|
||||
* This macro evaluates the semaphore id returned.
|
||||
*/
|
||||
#define fatal_posix_sem( _ptr, _msg ) \
|
||||
if ( (_ptr != SEM_FAILED) ) { \
|
||||
check_dispatch_disable_level( 0 ); \
|
||||
printf( "\n%s FAILED -- expected (-1) got (%p - %d/%s)\n", \
|
||||
(_msg), _ptr, errno, strerror(errno) ); \
|
||||
FLUSH_OUTPUT(); \
|
||||
rtems_test_exit( -1 ); \
|
||||
}
|
||||
|
||||
/*
|
||||
* This macro evaluates the message queue id returned.
|
||||
*/
|
||||
#define fatal_posix_mqd( _ptr, _msg ) \
|
||||
if ( (_ptr != (mqd_t) -1) ) { \
|
||||
check_dispatch_disable_level( 0 ); \
|
||||
printf( "\n%s FAILED -- expected (-1) got (%" PRId32 " - %d/%s)\n", \
|
||||
(_msg), _ptr, errno, strerror(errno) ); \
|
||||
FLUSH_OUTPUT(); \
|
||||
rtems_test_exit( -1 ); \
|
||||
}
|
||||
|
||||
/*
|
||||
* Generic integer version of the error reporting
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user