2006-11-15 Joel Sherrill <joel.sherrill@oarcorp.com>

* psxrwlock01/.cvsignore, psxrwlock01/Makefile.am, psxrwlock01/main.c,
	psxrwlock01/psxrwlock01.scn, psxrwlock01/test.c,
	psxspin01/.cvsignore, psxspin01/Makefile.am, psxspin01/main.c,
	psxspin01/psxspin01.scn, psxspin01/test.c: New files.
This commit is contained in:
Joel Sherrill
2006-11-15 14:10:06 +00:00
parent b4e79bc271
commit 7c6dac1e24
11 changed files with 656 additions and 0 deletions

View File

@@ -1,3 +1,10 @@
2006-11-15 Joel Sherrill <joel.sherrill@oarcorp.com>
* psxrwlock01/.cvsignore, psxrwlock01/Makefile.am, psxrwlock01/main.c,
psxrwlock01/psxrwlock01.scn, psxrwlock01/test.c,
psxspin01/.cvsignore, psxspin01/Makefile.am, psxspin01/main.c,
psxspin01/psxspin01.scn, psxspin01/test.c: New files.
2006-11-15 Joel Sherrill <joel.sherrill@oarcorp.com>
* Makefile.am, configure.ac: Adding POSIX barriers, POSIX spinlocks,

View File

@@ -0,0 +1,2 @@
Makefile
Makefile.in

View File

@@ -0,0 +1,30 @@
##
## $Id$
##
MANAGERS = all
rtems_tests_PROGRAMS = psxrwlock01.exe
psxrwlock01_exe_SOURCES = main.c test.c ../include/pmacros.h
scndir = $(rtems_testsdir)
dist_scn_DATA = psxrwlock01.scn
include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
include $(top_srcdir)/../automake/compile.am
include $(top_srcdir)/../automake/leaf.am
psxrwlock01_exe_LDADD = $(MANAGERS_NOT_WANTED:%=$(PROJECT_LIB)/no-%.rel)
AM_CPPFLAGS += -I$(top_srcdir)/include
AM_CPPFLAGS += -I$(top_srcdir)/../support/include
LINK_OBJS = $(psxrwlock01_exe_OBJECTS) $(psxrwlock01_exe_LDADD)
LINK_LIBS = $(psxrwlock01_exe_LDLIBS)
psxrwlock01.exe$(EXEEXT): $(psxrwlock01_exe_OBJECTS) \
$(psxrwlock01_exe_DEPENDENCIES)
@rm -f psxrwlock01.exe$(EXEEXT)
$(make-exe)
include $(top_srcdir)/../automake/local.am

View File

@@ -0,0 +1,47 @@
/*
* Simple test program -- simplified version of sample test hello.
*
* COPYRIGHT (c) 1989-1999.
* 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$
*/
#define TEST_INIT
#include <bsp.h>
#include <pmacros.h>
void test_main( void );
rtems_task Init(
rtems_task_argument ignored
)
{
test_main();
rtems_test_exit( 0 );
}
/* configuration information */
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_MAXIMUM_TASKS 2
#define CONFIGURE_MAXIMUM_POSIX_RWLOCKS 1
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_INIT_TASK_STACK_SIZE (RTEMS_MINIMUM_STACK_SIZE * 2)
#define CONFIGURE_INIT_TASK_PRIORITY 2
#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_PREEMPT
#define CONFIGURE_INIT
#include <rtems/confdefs.h>
/* end of file */

View File

@@ -0,0 +1,268 @@
/*
* This test exercises the POSIX RWLock manager.
*
* COPYRIGHT (c) 1989-2006.
* 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$
*/
#include <assert.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
/* #define __USE_XOPEN2K XXX already defined on GNU/Linux */
#include <pthread.h>
#define NUMBER_THREADS 2
pthread_t ThreadIds[NUMBER_THREADS];
pthread_rwlock_t RWLock;
void *RWLockThread(void *arg)
{
return NULL;
}
/*
* main entry point to the test
*/
#if defined(__rtems__)
int test_main(void)
#else
int main(
int argc,
char **argv
)
#endif
{
pthread_rwlock_t rwlock;
pthread_rwlockattr_t attr;
int status;
int p;
pthread_t thread_id;
int i;
struct timespec abstime;
puts( "\n\n*** POSIX RWLOCK TEST 01 ***" );
/*************** NULL POINTER CHECKS *****************/
puts( "pthread_rwlockattr_init( NULL ) -- EINVAL" );
status = pthread_rwlockattr_init( NULL );
assert( status == EINVAL );
puts( "pthread_rwlockattr_setpshared( NULL, private ) -- EINVAL" );
status = pthread_rwlockattr_setpshared( NULL, PTHREAD_PROCESS_PRIVATE );
assert( status == EINVAL );
puts( "pthread_rwlockattr_setpshared( NULL, shared ) -- EINVAL" );
status = pthread_rwlockattr_setpshared( NULL, PTHREAD_PROCESS_SHARED );
assert( status == EINVAL );
puts( "pthread_rwlockattr_getpshared( NULL, &p ) -- EINVAL" );
status = pthread_rwlockattr_getpshared( NULL, &p );
assert( status == EINVAL );
puts( "pthread_rwlockattr_destroy( NULL ) -- EINVAL" );
status = pthread_rwlockattr_destroy( NULL );
assert( status == EINVAL );
/*************** NOT INITIALIZED CHECKS *****************/
/* cheat visibility */
attr.is_initialized = 0;
puts( "pthread_rwlockattr_setpshared( &attr, shared ) -- EINVAL" );
status = pthread_rwlockattr_setpshared( &attr, PTHREAD_PROCESS_SHARED );
assert( status == EINVAL );
puts( "pthread_rwlockattr_getpshared( &attr, NULL ) -- EINVAL" );
status = pthread_rwlockattr_getpshared( &attr, NULL );
assert( status == EINVAL );
puts( "pthread_rwlockattr_destroy( &attr ) -- EINVAL" );
status = pthread_rwlockattr_destroy( &attr );
assert( status == EINVAL );
/*************** ACTUALLY WORK THIS TIME *****************/
puts( "pthread_rwlockattr_init( &attr ) -- OK" );
status = pthread_rwlockattr_init( &attr );
assert( status == 0 );
puts( "pthread_rwlockattr_setpshared( &attr, private ) -- OK" );
status = pthread_rwlockattr_setpshared( &attr, PTHREAD_PROCESS_PRIVATE );
assert( status == 0 );
puts( "pthread_rwlockattr_getpshared( &attr, &p ) -- OK" );
status = pthread_rwlockattr_getpshared( &attr, &p );
assert( status == 0 );
assert( p == PTHREAD_PROCESS_PRIVATE );
puts( "pthread_rwlockattr_setpshared( &attr, shared ) -- OK" );
status = pthread_rwlockattr_setpshared( &attr, PTHREAD_PROCESS_SHARED );
assert( status == 0 );
puts( "pthread_rwlockattr_getpshared( &attr, &p ) -- OK" );
status = pthread_rwlockattr_getpshared( &attr, &p );
assert( status == 0 );
assert( p == PTHREAD_PROCESS_SHARED );
/*************** BAD PSHARED CHECK *****************/
puts( "pthread_rwlockattr_setpshared( &attr, private ) -- EINVAL" );
status = pthread_rwlockattr_setpshared( &attr, ~PTHREAD_PROCESS_PRIVATE );
assert( status == EINVAL );
/*************** DESTROY/REUSE CHECK *****************/
puts( "pthread_rwlockattr_destroy( &attr ) -- OK" );
status = pthread_rwlockattr_destroy( &attr );
assert( status == 0 );
puts( "pthread_rwlockattr_getpshared( &attr, &p ) destroyed -- EINVAL" );
status = pthread_rwlockattr_getpshared( &attr, &p );
assert( status == EINVAL );
/* XXX _init error checks */
/*************** NULL ID ARGUMENT CHECKS *****************/
puts( "pthread_rwlock_init(NULL, &attr) -- EINVAL" );
status = pthread_rwlock_init(NULL, &attr);
assert( status == EINVAL );
puts( "pthread_rwlock_init(&rwlock, NULL) -- EINVAL" );
status = pthread_rwlock_init(&rwlock, NULL);
assert( status == EINVAL );
puts( "pthread_rwlock_destroy(NULL) -- EINVAL" );
status = pthread_rwlock_destroy(NULL);
assert( status == EINVAL );
puts( "pthread_rwlock_rdlock(NULL) -- EINVAL" );
status = pthread_rwlock_rdlock(NULL);
assert( status == EINVAL );
puts( "pthread_rwlock_tryrdlock(NULL) -- EINVAL" );
status = pthread_rwlock_tryrdlock(NULL);
assert( status == EINVAL );
puts( "pthread_rwlock_timedrdlock( NULL, &abstime) -- EINVAL" );
status = pthread_rwlock_timedrdlock( NULL, &abstime);
assert( status == EINVAL );
puts( "pthread_rwlock_timedrdlock( &rwlock, NULL) -- EINVAL" );
status = pthread_rwlock_timedrdlock( &rwlock, NULL);
assert( status == EINVAL );
puts( "pthread_rwlock_timedrdlock( &rwlock, NULL) -- EINVAL" );
status = pthread_rwlock_timedrdlock( &rwlock, NULL);
assert( status == EINVAL );
puts( "pthread_rwlock_wrlock(NULL) -- EINVAL" );
status = pthread_rwlock_wrlock(NULL);
assert( status == EINVAL );
puts( "pthread_rwlock_trywrlock(NULL) -- EINVAL" );
status = pthread_rwlock_trywrlock(NULL);
assert( status == EINVAL );
puts( "pthread_rwlock_timedwrlock( NULL, &abstime) -- EINVAL" );
status = pthread_rwlock_timedwrlock( NULL, &abstime );
assert( status == EINVAL );
puts( "pthread_rwlock_timedwrlock( &rwlock, NULL) -- EINVAL" );
status = pthread_rwlock_timedwrlock( &rwlock, NULL);
assert( status == EINVAL );
/*************** BAD ID CHECK *****************/
rwlock = 1;
/* XXX make a valid abstime */
puts( "pthread_rwlock_destroy(BadId) -- EINVAL" );
status = pthread_rwlock_destroy(&rwlock);
assert( status == EINVAL );
puts( "pthread_rwlock_rdlock(BadId) -- EINVAL" );
status = pthread_rwlock_rdlock(NULL);
assert( status == EINVAL );
puts( "pthread_rwlock_tryrdlock(BadId) -- EINVAL" );
status = pthread_rwlock_tryrdlock(NULL);
assert( status == EINVAL );
puts( "pthread_rwlock_timedrdlock( BadId, &abstime) -- EINVAL" );
status = pthread_rwlock_timedrdlock( NULL, &abstime);
assert( status == EINVAL );
puts( "pthread_rwlock_timedrdlock( &rwlock, BadId) -- EINVAL" );
status = pthread_rwlock_timedrdlock( &rwlock, NULL);
assert( status == EINVAL );
puts( "pthread_rwlock_timedrdlock( &rwlock, BadId) -- EINVAL" );
status = pthread_rwlock_timedrdlock( &rwlock, NULL);
assert( status == EINVAL );
puts( "pthread_rwlock_wrlock(BadId) -- EINVAL" );
status = pthread_rwlock_wrlock(NULL);
assert( status == EINVAL );
puts( "pthread_rwlock_trywrlock(BadId) -- EINVAL" );
status = pthread_rwlock_trywrlock(NULL);
assert( status == EINVAL );
puts( "pthread_rwlock_timedwrlock( BadId, &abstime) -- EINVAL" );
status = pthread_rwlock_timedwrlock( &rwlock, &abstime );
assert( status == EINVAL );
/*************** BAD ABSTIME CHECK *****************/
/* in the past */
abstime.tv_sec = 0;
abstime.tv_nsec = 0;
/* invalid tv_nsec */
abstime.tv_sec = 0;
abstime.tv_nsec = 0x7fffffffL;
/*************** ACTUALLY CREATE ONE CHECK *****************/
puts( "pthread_rwlockattr_init( &attr ) -- OK" );
status = pthread_rwlockattr_init( &attr );
assert( status == 0 );
puts( "pthread_rwlock_init( &rwlock, &attr ) -- OK" );
status = pthread_rwlock_init( &rwlock, &attr );
assert( status == 0 );
assert( rwlock != 0 );
puts( "pthread_rwlock_destroy( &rwlock ) -- OK" );
status = pthread_rwlock_destroy( &rwlock );
assert( status == 0 );
#if 0
/*************** CREATE TESTS AND LET THEM RELEASE *****************/
puts( "pthread_rwlock_init( &RWLock, &attr, 2 ) -- OK" );
status = pthread_rwlock_init( &RWLock, &attr, 2 );
assert( status == 0 );
assert( rwlock != 0 );
for (i=0 ; i<NUMBER_THREADS ; i++ ) {
printf( "Init: pthread_create - thread %d OK\n", i+1 );
status = pthread_create(&ThreadIds[i], NULL, RWLockThread, &ThreadIds[i]);
assert( !status );
sleep(1);
}
#endif
/*************** END OF TEST *****************/
puts( "*** END OF POSIX RWLOCK TEST 01 ***" );
exit(0);
}

View File

@@ -0,0 +1,2 @@
Makefile
Makefile.in

View File

@@ -0,0 +1,30 @@
##
## $Id$
##
MANAGERS = all
rtems_tests_PROGRAMS = psxspin01.exe
psxspin01_exe_SOURCES = main.c test.c ../include/pmacros.h
scndir = $(rtems_testsdir)
dist_scn_DATA = psxspin01.scn
include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
include $(top_srcdir)/../automake/compile.am
include $(top_srcdir)/../automake/leaf.am
psxspin01_exe_LDADD = $(MANAGERS_NOT_WANTED:%=$(PROJECT_LIB)/no-%.rel)
AM_CPPFLAGS += -I$(top_srcdir)/include
AM_CPPFLAGS += -I$(top_srcdir)/../support/include
LINK_OBJS = $(psxspin01_exe_OBJECTS) $(psxspin01_exe_LDADD)
LINK_LIBS = $(psxspin01_exe_LDLIBS)
psxspin01.exe$(EXEEXT): $(psxspin01_exe_OBJECTS) \
$(psxspin01_exe_DEPENDENCIES)
@rm -f psxspin01.exe$(EXEEXT)
$(make-exe)
include $(top_srcdir)/../automake/local.am

View File

@@ -0,0 +1,47 @@
/*
* Simple test program wrapper for Spinlocks
*
* COPYRIGHT (c) 1989-2006.
* 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$
*/
#define TEST_INIT
#include <bsp.h>
#include <pmacros.h>
void test_main( void );
rtems_task Init(
rtems_task_argument ignored
)
{
test_main();
rtems_test_exit( 0 );
}
/* configuration information */
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_MAXIMUM_TASKS 2
#define CONFIGURE_MAXIMUM_POSIX_SPINLOCKS 1
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_INIT_TASK_STACK_SIZE (RTEMS_MINIMUM_STACK_SIZE * 2)
#define CONFIGURE_INIT_TASK_PRIORITY 2
#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_PREEMPT
#define CONFIGURE_INIT
#include <rtems/confdefs.h>
/* end of file */

View File

@@ -0,0 +1,223 @@
/*
* This test exercises the POSIX Spinlock manager.
*
* COPYRIGHT (c) 1989-2006.
* 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$
*/
#include <assert.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <pthread.h>
#include <rtems.h> /* for task creation */
#define NUMBER_THREADS 2
pthread_t ThreadIds[NUMBER_THREADS];
pthread_spinlock_t Spinlock;
volatile int mainThreadSpinning;
rtems_task SpinlockThread(rtems_task_argument arg)
{
int status;
if ( mainThreadSpinning ) {
puts( "main thread is not supposed to be spinning yet" );
exit(0);
}
puts( "pthread_spin_lock( &Spinlock ) from Thread -- OK" );
status = pthread_spin_lock( &Spinlock );
assert( status == 0 );
puts( "sleep to allow main thread to run" );
sleep( 1 );
if ( !mainThreadSpinning ) {
puts( "main thread is not spinning on lock" );
exit(0);
}
puts( "pthread_spin_unlock( &Spinlock ) from Thread -- OK" );
status = pthread_spin_unlock( &Spinlock );
assert( status == 0 );
rtems_task_delete( RTEMS_SELF );
}
/*
* main entry point to the test
*/
#if defined(__rtems__)
int test_main(void)
#else
int main(
int argc,
char **argv
)
#endif
{
pthread_spinlock_t spinlock;
pthread_spinlock_t spinlockExtra;
int status;
int p;
pthread_t thread_id;
int i;
rtems_status_code rstatus;
rtems_id taskid;
puts( "\n\n*** POSIX SPINLOCK TEST 01 ***" );
puts( "pthread_spin_init( NULL, PTHREAD_PROCESS_PRIVATE ) -- EINVAL" );
status = pthread_spin_init( NULL, PTHREAD_PROCESS_PRIVATE );
assert( status == EINVAL );
puts( "pthread_spin_init( NULL, PTHREAD_PROCESS_SHARED ) -- EINVAL" );
status = pthread_spin_init( NULL, PTHREAD_PROCESS_PRIVATE );
assert( status == EINVAL );
puts( "pthread_spin_init( &spinlock, 0x1234 ) -- EINVAL" );
status = pthread_spin_init( &spinlock, 0x1234 );
assert( status == EINVAL );
puts( "pthread_spin_init( &spinlock, PTHREAD_PROCESS_SHARED ) -- EINVAL" );
status = pthread_spin_init( &spinlock, PTHREAD_PROCESS_SHARED );
assert( status == EINVAL );
/* This successfully creates one */
puts( "pthread_spin_init( &Spinlock, PTHREAD_PROCESS_PRIVATE ) -- OK" );
status = pthread_spin_init( &Spinlock, PTHREAD_PROCESS_PRIVATE );
assert( status == 0 );
puts( "pthread_spin_init( &spinlock, PTHREAD_PROCESS_PRIVATE ) -- EAGAIN" );
status = pthread_spin_init( &spinlock, PTHREAD_PROCESS_PRIVATE );
assert( status == EAGAIN );
puts( "pthread_spin_init( &spinlock, PTHREAD_PROCESS_PRIVATE ) -- EAGAIN" );
status = pthread_spin_init( &spinlock, PTHREAD_PROCESS_PRIVATE );
assert( status == EAGAIN );
puts( "pthread_spin_lock( NULL ) -- EINVAL" );
status = pthread_spin_lock( NULL );
assert( status == EINVAL );
puts( "pthread_spin_trylock( NULL ) -- EINVAL" );
status = pthread_spin_trylock( NULL );
assert( status == EINVAL );
puts( "pthread_spin_unlock( NULL ) -- EINVAL" );
status = pthread_spin_unlock( NULL );
assert( status == EINVAL );
puts( "pthread_spin_destroy( NULL ) -- EINVAL" );
status = pthread_spin_destroy( NULL );
assert( status == EINVAL );
spinlock = 0;
puts( "pthread_spin_lock( &spinlock ) -- EINVAL" );
status = pthread_spin_lock( &spinlock );
assert( status == EINVAL );
puts( "pthread_spin_trylock( &spinlock ) -- EINVAL" );
status = pthread_spin_trylock( &spinlock );
assert( status == EINVAL );
puts( "pthread_spin_unlock( &spinlock ) -- EINVAL" );
status = pthread_spin_unlock( &spinlock );
assert( status == EINVAL );
puts( "pthread_spin_destroy( &spinlock ) -- EINVAL" );
status = pthread_spin_destroy( &spinlock );
assert( status == EINVAL );
puts( "pthread_spin_unlock( &Spinlock ) -- already unlocked OK" );
status = pthread_spin_unlock( &Spinlock );
assert( status == 0 );
/* Now some basic locking and unlocking with a deadlock verification */
puts( "pthread_spin_lock( &Spinlock ) -- OK" );
status = pthread_spin_lock( &Spinlock );
assert( status == 0 );
puts( "pthread_spin_lock( &Spinlock ) -- EDEADLK" );
status = pthread_spin_lock( &Spinlock );
assert( status == EDEADLK );
puts( "pthread_spin_trylock( &Spinlock ) -- EDEADLK" );
status = pthread_spin_trylock( &Spinlock );
assert( status == EDEADLK );
puts( "pthread_spin_unlock( &Spinlock ) -- OK" );
status = pthread_spin_unlock( &Spinlock );
assert( status == 0 );
/* Try lock/unlock pair */
puts( "pthread_spin_trylock( &Spinlock ) -- OK" );
status = pthread_spin_trylock( &Spinlock );
assert( status == 0 );
puts( "pthread_spin_unlock( &Spinlock ) -- OK" );
status = pthread_spin_unlock( &Spinlock );
assert( status == 0 );
/* Let another thread lock a spinlock and we contend with it */
mainThreadSpinning = 0;
/* Create a helper task */
rstatus = rtems_task_create(
rtems_build_name( 'S', 'P', 'I', 'N' ),
1,
RTEMS_MINIMUM_STACK_SIZE,
RTEMS_DEFAULT_MODES,
RTEMS_DEFAULT_ATTRIBUTES,
&taskid
);
assert( rstatus == RTEMS_SUCCESSFUL );
rstatus = rtems_task_start( taskid, SpinlockThread, 0 );
assert( rstatus == RTEMS_SUCCESSFUL );
/* We should be preempted immediately. The thread is expected to:
* + verify we haven't set the main thread spinning flag
* + lock the spinlock
* + delay
*/
mainThreadSpinning = 1;
puts( "pthread_spin_lock( &Spinlock ) -- OK" );
status = pthread_spin_lock( &Spinlock );
assert( status == 0 );
/* The thread wakes up, unlocks spin lock, and deletes itself.
* So when we get back here, about a second has passed and we now
* have the spinlock locked.
*/
/* spin lock should be locked when we return so destroying it gives busy */
puts( "pthread_spin_destroy( &Spinlock ) -- EBUSY" );
status = pthread_spin_destroy( &Spinlock );
assert( status == EBUSY );
/* Unlock it for a normal destroy */
puts( "pthread_spin_unlock( &Spinlock ) -- OK" );
status = pthread_spin_unlock( &Spinlock );
assert( status == 0 );
puts( "pthread_spin_destroy( &Spinlock ) -- OK" );
status = pthread_spin_destroy( &Spinlock );
assert( status == 0 );
/*************** END OF TEST *****************/
puts( "*** END OF POSIX SPINLOCK TEST 01 ***" );
exit(0);
}