mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-05 15:15:44 +00:00
2006-11-15 Joel Sherrill <joel.sherrill@oarcorp.com>
* Makefile.am, configure.ac: Adding POSIX barriers, POSIX spinlocks, and partial implementation of POSIX rwlocks. * psxbarrier01/.cvsignore, psxbarrier01/Makefile.am, psxbarrier01/psxbarrier01.scn, psxbarrier01/test.c: New files.
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
2006-11-15 Joel Sherrill <joel.sherrill@oarcorp.com>
|
||||
|
||||
* Makefile.am, configure.ac: Adding POSIX barriers, POSIX spinlocks,
|
||||
and partial implementation of POSIX rwlocks.
|
||||
* psxbarrier01/.cvsignore, psxbarrier01/Makefile.am,
|
||||
psxbarrier01/psxbarrier01.scn, psxbarrier01/test.c: New files.
|
||||
|
||||
2006-10-30 Joel Sherrill <joel@OARcorp.com>
|
||||
|
||||
PR 841/rtems
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
ACLOCAL_AMFLAGS = -I ../aclocal
|
||||
|
||||
SUBDIRS = psxhdrs psx01 psx02 psx03 psx04 psx05 psx06 psx07 psx08 psx09 \
|
||||
psx10 psx11 psx12 psxtime psxtimer psxcancel psxmsgq01 psxsem01
|
||||
psx10 psx11 psx12 psxtime psxtimer psxcancel psxbarrier01 psxmsgq01 \
|
||||
psxrwlock01 psxsem01 psxspin01
|
||||
|
||||
SUBDIRS += psxfile01 psxreaddir psxstat psxmount psx13 psxchroot01
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ psx10/Makefile
|
||||
psx11/Makefile
|
||||
psx12/Makefile
|
||||
psx13/Makefile
|
||||
psxbarrier01/Makefile
|
||||
psxcancel/Makefile
|
||||
psxchroot01/Makefile
|
||||
psxfile01/Makefile
|
||||
@@ -46,7 +47,9 @@ psxhdrs/Makefile
|
||||
psxmount/Makefile
|
||||
psxmsgq01/Makefile
|
||||
psxreaddir/Makefile
|
||||
psxrwlock01/Makefile
|
||||
psxsem01/Makefile
|
||||
psxspin01/Makefile
|
||||
psxstat/Makefile
|
||||
psxtime/Makefile
|
||||
psxtimer/Makefile
|
||||
|
||||
2
testsuites/psxtests/psxbarrier01/.cvsignore
Normal file
2
testsuites/psxtests/psxbarrier01/.cvsignore
Normal file
@@ -0,0 +1,2 @@
|
||||
Makefile
|
||||
Makefile.in
|
||||
30
testsuites/psxtests/psxbarrier01/Makefile.am
Normal file
30
testsuites/psxtests/psxbarrier01/Makefile.am
Normal file
@@ -0,0 +1,30 @@
|
||||
##
|
||||
## $Id$
|
||||
##
|
||||
|
||||
MANAGERS = all
|
||||
|
||||
rtems_tests_PROGRAMS = psxbarrier01.exe
|
||||
psxbarrier01_exe_SOURCES = main.c test.c ../include/pmacros.h
|
||||
|
||||
scndir = $(rtems_testsdir)
|
||||
dist_scn_DATA = psxbarrier01.scn
|
||||
|
||||
include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
|
||||
include $(top_srcdir)/../automake/compile.am
|
||||
include $(top_srcdir)/../automake/leaf.am
|
||||
|
||||
psxbarrier01_exe_LDADD = $(MANAGERS_NOT_WANTED:%=$(PROJECT_LIB)/no-%.rel)
|
||||
|
||||
AM_CPPFLAGS += -I$(top_srcdir)/include
|
||||
AM_CPPFLAGS += -I$(top_srcdir)/../support/include
|
||||
|
||||
LINK_OBJS = $(psxbarrier01_exe_OBJECTS) $(psxbarrier01_exe_LDADD)
|
||||
LINK_LIBS = $(psxbarrier01_exe_LDLIBS)
|
||||
|
||||
psxbarrier01.exe$(EXEEXT): $(psxbarrier01_exe_OBJECTS) \
|
||||
$(psxbarrier01_exe_DEPENDENCIES)
|
||||
@rm -f psxbarrier01.exe$(EXEEXT)
|
||||
$(make-exe)
|
||||
|
||||
include $(top_srcdir)/../automake/local.am
|
||||
0
testsuites/psxtests/psxbarrier01/psxbarrier01.scn
Normal file
0
testsuites/psxtests/psxbarrier01/psxbarrier01.scn
Normal file
175
testsuites/psxtests/psxbarrier01/test.c
Normal file
175
testsuites/psxtests/psxbarrier01/test.c
Normal file
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* This test exercises the POSIX Barrier 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_barrier_t Barrier;
|
||||
|
||||
void *BarrierThread(void *arg)
|
||||
{
|
||||
pthread_t id = *(pthread_t *) arg;
|
||||
int status;
|
||||
|
||||
printf( "pthread_barrier_wait( &Barrier ) for thread 0x%08x\n", id );
|
||||
status = pthread_barrier_wait( &Barrier );
|
||||
if ( id == ThreadIds[NUMBER_THREADS - 1] ) {
|
||||
printf( "pthread_barrier_wait - 0x%08x auto released\n", id );
|
||||
assert( status == PTHREAD_BARRIER_SERIAL_THREAD );
|
||||
} else {
|
||||
printf( "pthread_barrier_wait - 0x%08x released\n", id );
|
||||
assert( status == 0 );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* main entry point to the test
|
||||
*/
|
||||
|
||||
#if defined(__rtems__)
|
||||
int test_main(void)
|
||||
#else
|
||||
int main(
|
||||
int argc,
|
||||
char **argv
|
||||
)
|
||||
#endif
|
||||
{
|
||||
pthread_barrier_t barrier;
|
||||
pthread_barrierattr_t attr;
|
||||
int status;
|
||||
int p;
|
||||
pthread_t thread_id;
|
||||
int i;
|
||||
|
||||
puts( "\n\n*** POSIX BARRIER TEST 01 ***" );
|
||||
|
||||
/*************** NULL POINTER CHECKS *****************/
|
||||
puts( "pthread_barrierattr_init( NULL ) -- EINVAL" );
|
||||
status = pthread_barrierattr_init( NULL );
|
||||
assert( status == EINVAL );
|
||||
|
||||
puts( "pthread_barrierattr_setpshared( NULL, private ) -- EINVAL" );
|
||||
status = pthread_barrierattr_setpshared( NULL, PTHREAD_PROCESS_PRIVATE );
|
||||
assert( status == EINVAL );
|
||||
|
||||
puts( "pthread_barrierattr_setpshared( NULL, shared ) -- EINVAL" );
|
||||
status = pthread_barrierattr_setpshared( NULL, PTHREAD_PROCESS_SHARED );
|
||||
assert( status == EINVAL );
|
||||
|
||||
puts( "pthread_barrierattr_getpshared( NULL, &p ) -- EINVAL" );
|
||||
status = pthread_barrierattr_getpshared( NULL, &p );
|
||||
assert( status == EINVAL );
|
||||
|
||||
puts( "pthread_barrierattr_destroy( NULL ) -- EINVAL" );
|
||||
status = pthread_barrierattr_destroy( NULL );
|
||||
assert( status == EINVAL );
|
||||
|
||||
/*************** NOT INITIALIZED CHECKS *****************/
|
||||
/* cheat visibility */
|
||||
attr.is_initialized = 0;
|
||||
puts( "pthread_barrierattr_setpshared( &attr, shared ) -- EINVAL" );
|
||||
status = pthread_barrierattr_setpshared( &attr, PTHREAD_PROCESS_SHARED );
|
||||
assert( status == EINVAL );
|
||||
|
||||
puts( "pthread_barrierattr_getpshared( &attr, NULL ) -- EINVAL" );
|
||||
status = pthread_barrierattr_getpshared( &attr, NULL );
|
||||
assert( status == EINVAL );
|
||||
|
||||
puts( "pthread_barrierattr_destroy( &attr ) -- EINVAL" );
|
||||
status = pthread_barrierattr_destroy( &attr );
|
||||
assert( status == EINVAL );
|
||||
|
||||
|
||||
/*************** ACTUALLY WORK THIS TIME *****************/
|
||||
|
||||
puts( "pthread_barrierattr_init( &attr ) -- OK" );
|
||||
status = pthread_barrierattr_init( &attr );
|
||||
assert( status == 0 );
|
||||
|
||||
puts( "pthread_barrierattr_setpshared( &attr, private ) -- OK" );
|
||||
status = pthread_barrierattr_setpshared( &attr, PTHREAD_PROCESS_PRIVATE );
|
||||
assert( status == 0 );
|
||||
|
||||
puts( "pthread_barrierattr_getpshared( &attr, &p ) -- OK" );
|
||||
status = pthread_barrierattr_getpshared( &attr, &p );
|
||||
assert( status == 0 );
|
||||
assert( p == PTHREAD_PROCESS_PRIVATE );
|
||||
|
||||
puts( "pthread_barrierattr_setpshared( &attr, shared ) -- OK" );
|
||||
status = pthread_barrierattr_setpshared( &attr, PTHREAD_PROCESS_SHARED );
|
||||
assert( status == 0 );
|
||||
|
||||
puts( "pthread_barrierattr_getpshared( &attr, &p ) -- OK" );
|
||||
status = pthread_barrierattr_getpshared( &attr, &p );
|
||||
assert( status == 0 );
|
||||
assert( p == PTHREAD_PROCESS_SHARED );
|
||||
|
||||
/*************** BAD PSHARED CHECK *****************/
|
||||
puts( "pthread_barrierattr_setpshared( &attr, private ) -- EINVAL" );
|
||||
status = pthread_barrierattr_setpshared( &attr, ~PTHREAD_PROCESS_PRIVATE );
|
||||
assert( status == EINVAL );
|
||||
|
||||
/*************** DESTROY/REUSE CHECK *****************/
|
||||
puts( "pthread_barrierattr_destroy( &attr ) -- OK" );
|
||||
status = pthread_barrierattr_destroy( &attr );
|
||||
assert( status == 0 );
|
||||
|
||||
puts( "pthread_barrierattr_getpshared( &attr, &p ) destroyed -- EINVAL" );
|
||||
status = pthread_barrierattr_getpshared( &attr, &p );
|
||||
assert( status == EINVAL );
|
||||
|
||||
|
||||
/* XXX _init error checks */
|
||||
|
||||
/*************** ACTUALLY CREATE ONE CHECK *****************/
|
||||
puts( "pthread_barrierattr_init( &attr ) -- OK" );
|
||||
status = pthread_barrierattr_init( &attr );
|
||||
assert( status == 0 );
|
||||
|
||||
puts( "pthread_barrier_init( &barrier, &attr, 2 ) -- OK" );
|
||||
status = pthread_barrier_init( &barrier, &attr, 2 );
|
||||
assert( status == 0 );
|
||||
assert( barrier != 0 );
|
||||
|
||||
puts( "pthread_barrier_destroy( &barrier ) -- OK" );
|
||||
status = pthread_barrier_destroy( &barrier );
|
||||
assert( status == 0 );
|
||||
|
||||
/*************** CREATE TESTS AND LET THEM RELEASE *****************/
|
||||
puts( "pthread_barrier_init( &Barrier, &attr, 2 ) -- OK" );
|
||||
status = pthread_barrier_init( &Barrier, &attr, 2 );
|
||||
assert( status == 0 );
|
||||
assert( barrier != 0 );
|
||||
|
||||
for (i=0 ; i<NUMBER_THREADS ; i++ ) {
|
||||
printf( "Init: pthread_create - thread %d OK\n", i+1 );
|
||||
status = pthread_create(&ThreadIds[i], NULL, BarrierThread, &ThreadIds[i]);
|
||||
assert( !status );
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
/*************** END OF TEST *****************/
|
||||
puts( "*** END OF POSIX BARRIER TEST 01 ***" );
|
||||
exit(0);
|
||||
}
|
||||
Reference in New Issue
Block a user