summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@oarcorp.com>2015-04-14 10:01:05 -0500
committerJoel Sherrill <joel.sherrill@oarcorp.com>2015-04-14 11:17:10 -0500
commitfc0756e8d9caf1155e2df1ad4a1282619c6668f1 (patch)
treebf4aa3a51cac86cfb220a6d34ba7538d60fb780e
parent0a73de2fc802e183affed8b2f6835e29f5c89b4d (diff)
downloadrtems-fc0756e8d9caf1155e2df1ad4a1282619c6668f1.tar.bz2
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.
-rw-r--r--cpukit/score/Makefile.am2
-rw-r--r--cpukit/score/include/rtems/score/apimutex.h7
-rw-r--r--cpukit/score/src/apimutexislocked.c36
-rw-r--r--testsuites/psxtests/psxmsgq01/init.c9
-rw-r--r--testsuites/psxtests/psxsem01/init.c10
-rw-r--r--testsuites/support/include/tmacros.h55
6 files changed, 98 insertions, 21 deletions
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index dc51e9a691..f0cd67641c 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -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 \
diff --git a/cpukit/score/include/rtems/score/apimutex.h b/cpukit/score/include/rtems/score/apimutex.h
index 5f02e0a1cf..c960679d6b 100644
--- a/cpukit/score/include/rtems/score/apimutex.h
+++ b/cpukit/score/include/rtems/score/apimutex.h
@@ -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 )
diff --git a/cpukit/score/src/apimutexislocked.c b/cpukit/score/src/apimutexislocked.c
new file mode 100644
index 0000000000..804ce4a6ce
--- /dev/null
+++ b/cpukit/score/src/apimutexislocked.c
@@ -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;
+}
diff --git a/testsuites/psxtests/psxmsgq01/init.c b/testsuites/psxtests/psxmsgq01/init.c
index 5d544ddeeb..de2965a715 100644
--- a/testsuites/psxtests/psxmsgq01/init.c
+++ b/testsuites/psxtests/psxmsgq01/init.c
@@ -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;
diff --git a/testsuites/psxtests/psxsem01/init.c b/testsuites/psxtests/psxsem01/init.c
index ed741bda11..f377a4e68b 100644
--- a/testsuites/psxtests/psxsem01/init.c
+++ b/testsuites/psxtests/psxsem01/init.c
@@ -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(
diff --git a/testsuites/support/include/tmacros.h b/testsuites/support/include/tmacros.h
index 2b0df83eff..a67bb956e9 100644
--- a/testsuites/support/include/tmacros.h
+++ b/testsuites/support/include/tmacros.h
@@ -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.
*/
@@ -70,6 +70,32 @@ extern "C" {
#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
*/
#define directive_failed( _dirstat, _failmsg ) \
@@ -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) ); \
@@ -136,6 +165,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
*/