diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2011-07-12 13:22:24 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2011-07-12 13:22:24 +0000 |
commit | 91b38c632a097596bf0fb7c58b4a5a28bee84236 (patch) | |
tree | f6efd773dabeda7784abb2a6b3e17cb1b6538521 /testsuites/psxtmtests/psxtmmutex03/init.c | |
parent | 2011-07-11 Sebastian Huber <sebastian.huber@embedded-brains.de> (diff) | |
download | rtems-91b38c632a097596bf0fb7c58b4a5a28bee84236.tar.bz2 |
2011-07-12 Ricardo Aguirre <el.mastin@ymail.com>
* Makefile.am, configure.ac, psxtmtests_plan.csv: Add psxtmmutex03.
* psxtmmutex03/.cvsignore, psxtmmutex03/Makefile.am,
psxtmmutex03/init.c, psxtmmutex03/psxtmmutex03.doc: New files.
Diffstat (limited to '')
-rw-r--r-- | testsuites/psxtmtests/psxtmmutex03/init.c | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/testsuites/psxtmtests/psxtmmutex03/init.c b/testsuites/psxtmtests/psxtmmutex03/init.c new file mode 100644 index 0000000000..e65761b7d6 --- /dev/null +++ b/testsuites/psxtmtests/psxtmmutex03/init.c @@ -0,0 +1,175 @@ +/* + * COPYRIGHT (c) 1989-2011. + * 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.com/license/LICENSE. + * + * $Id$ + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <timesys.h> +#include <rtems/timerdrv.h> +#include <errno.h> +#include <pthread.h> +#include "test_support.h" + +pthread_mutex_t MutexId; + +void benchmark_mutex_lock_available(void) +{ + long end_time; + int status; + + benchmark_timer_initialize(); + status = pthread_mutex_lock( &MutexId ); + end_time = benchmark_timer_read(); + rtems_test_assert( !status ); + + put_time( + "pthread_mutex_lock - available", + end_time, + 1, + 0, + 0 + ); +} + +void benchmark_mutex_unlock_no_threads_waiting(void) +{ + long end_time; + int status; + + benchmark_timer_initialize(); + status = pthread_mutex_unlock( &MutexId ); + end_time = benchmark_timer_read(); + rtems_test_assert( !status ); + + put_time( + "pthread_mutex_unlock - no threads waiting", + end_time, + 1, + 0, + 0 + ); +} + +void benchmark_mutex_trylock_available(void) +{ + long end_time; + int status; + + benchmark_timer_initialize(); + status = pthread_mutex_trylock( &MutexId ); + end_time = benchmark_timer_read(); + rtems_test_assert( !status ); + + put_time( + "pthread_mutex_trylock - available", + end_time, + 1, + 0, + 0 + ); +} + + +void benchmark_mutex_trylock_not_available(void) +{ + long end_time; + int status; + + benchmark_timer_initialize(); + status = pthread_mutex_trylock( &MutexId ); + /* + * it has to return a negative value + * because it try to lock a not available mutex + * so the assert call is make with status instead !status + */ + end_time = benchmark_timer_read(); + rtems_test_assert( status ); + + put_time( + "pthread_mutex_trylock - not available", + end_time, + 1, + 0, + 0 + ); +} + +void benchmark_mutex_timedlock_available(void) +{ + long end_time; + int status; + + benchmark_timer_initialize(); + status = pthread_mutex_timedlock( &MutexId, 0 ); + end_time = benchmark_timer_read(); + rtems_test_assert( !status ); + + put_time( + "pthread_mutex_timedlock - available", + end_time, + 1, + 0, + 0 + ); +} + +void *POSIX_Init( + void *argument +) +{ + int status; + + puts( "\n\n*** POSIX TIME TEST PSXTMMUTEX03 ***" ); + + /* + * Create the single Mutex used in all the test case + */ + status = pthread_mutex_init( &MutexId, NULL ); + rtems_test_assert( !status ); + + /* + * Now invoke subroutines to time each test case + * get the goal depends of its order + */ + benchmark_mutex_lock_available(); + benchmark_mutex_unlock_no_threads_waiting(); + benchmark_mutex_trylock_available(); + benchmark_mutex_trylock_not_available(); + benchmark_mutex_unlock_no_threads_waiting(); + benchmark_mutex_timedlock_available(); + benchmark_mutex_unlock_no_threads_waiting(); + + + /* + * Destroy the mutex used in the tests + */ + status = pthread_mutex_destroy( &MutexId ); + rtems_test_assert( !status ); + + puts( "*** END OF POSIX TIME TEST PSXTMMUTEX03 ***" ); + + rtems_test_exit(0); +} + +/* configuration information */ + +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER + +#define CONFIGURE_MAXIMUM_POSIX_THREADS 1 +#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 1 +#define CONFIGURE_POSIX_INIT_THREAD_TABLE + +#define CONFIGURE_INIT + +#include <rtems/confdefs.h> +/* end of file */ |