mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-09-21 11:44:17 +08:00
2009-07-19 Joel Sherrill <joel.sherrill@oarcorp.com>
* Makefile.am, configure.ac: Add psxspin02 to exercise case where trylock is unable to obtain the spinlock and that attempting to unlock a spinlock from a thread which did not lock it works as expected. * psxspin02/.cvsignore, psxspin02/Makefile.am, psxspin02/main.c, psxspin02/psxspin02.doc, psxspin02/psxspin02.scn, psxspin02/test.c: New files.
This commit is contained in:
@@ -1,3 +1,13 @@
|
||||
2009-07-19 Joel Sherrill <joel.sherrill@oarcorp.com>
|
||||
|
||||
* Makefile.am, configure.ac: Add psxspin02 to exercise case where
|
||||
trylock is unable to obtain the spinlock and that attempting to
|
||||
unlock a spinlock from a thread which did not lock it works as
|
||||
expected.
|
||||
* psxspin02/.cvsignore, psxspin02/Makefile.am, psxspin02/main.c,
|
||||
psxspin02/psxspin02.doc, psxspin02/psxspin02.scn, psxspin02/test.c:
|
||||
New files.
|
||||
|
||||
2009-07-19 Joel Sherrill <joel.sherrill@oarcorp.com>
|
||||
|
||||
* psxspin01/test.c: Remove unnecessary defines.
|
||||
|
||||
@@ -8,8 +8,8 @@ SUBDIRS = psxhdrs psx01 psx02 psx03 psx04 psx05 psx06 psx07 psx08 psx09 \
|
||||
psx10 psx11 psx12 psx13 psx14 psxautoinit01 psxautoinit02 psxbarrier01 \
|
||||
psxcancel psxcleanup psxenosys psxfatal01 psxfatal02 psxkey01 psxitimer \
|
||||
psxmsgq01 psxmsgq02 psxmsgq03 psxmutexattr01 psxobj01 psxrwlock01 \
|
||||
psxsem01 psxsignal01 psxspin01 psxsysconf psxtime psxtimer01 psxtimer02 \
|
||||
psxualarm
|
||||
psxsem01 psxsignal01 psxspin01 psxspin02 psxsysconf psxtime psxtimer01 \
|
||||
psxtimer02 psxualarm
|
||||
|
||||
## File IO tests
|
||||
SUBDIRS += psxfile01 psxreaddir psxstat psxmount psx13 psxchroot01
|
||||
|
||||
@@ -65,6 +65,7 @@ psxrwlock01/Makefile
|
||||
psxsem01/Makefile
|
||||
psxsignal01/Makefile
|
||||
psxspin01/Makefile
|
||||
psxspin02/Makefile
|
||||
psxstat/Makefile
|
||||
psxsysconf/Makefile
|
||||
psxtime/Makefile
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
Makefile
|
||||
Makefile.in
|
||||
@@ -0,0 +1,30 @@
|
||||
##
|
||||
## $Id$
|
||||
##
|
||||
|
||||
MANAGERS = all
|
||||
|
||||
rtems_tests_PROGRAMS = psxspin02
|
||||
psxspin02_SOURCES = main.c test.c ../include/pmacros.h
|
||||
|
||||
scndir = $(rtems_testsdir)
|
||||
dist_scn_DATA = psxspin02.scn
|
||||
|
||||
include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
|
||||
include $(top_srcdir)/../automake/compile.am
|
||||
include $(top_srcdir)/../automake/leaf.am
|
||||
|
||||
psxspin02_LDADD = $(MANAGERS_NOT_WANTED:%=$(PROJECT_LIB)/no-%.rel)
|
||||
|
||||
AM_CPPFLAGS += -I$(top_srcdir)/include
|
||||
AM_CPPFLAGS += -I$(top_srcdir)/../support/include
|
||||
|
||||
LINK_OBJS = $(psxspin02_OBJECTS) $(psxspin02_LDADD)
|
||||
LINK_LIBS = $(psxspin02_LDLIBS)
|
||||
|
||||
psxspin02$(EXEEXT): $(psxspin02_OBJECTS) \
|
||||
$(psxspin02_DEPENDENCIES)
|
||||
@rm -f psxspin02$(EXEEXT)
|
||||
$(make-exe)
|
||||
|
||||
include $(top_srcdir)/../automake/local.am
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Simple test program wrapper for Spinlocks
|
||||
*
|
||||
* COPYRIGHT (c) 1989-2008.
|
||||
* 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 CONFIGURE_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_EXTRA_TASK_STACKS RTEMS_MINIMUM_STACK_SIZE
|
||||
|
||||
#define CONFIGURE_INIT
|
||||
|
||||
#include <rtems/confdefs.h>
|
||||
|
||||
/* end of file */
|
||||
@@ -0,0 +1,28 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# COPYRIGHT (c) 1989-2009.
|
||||
# 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.
|
||||
#
|
||||
|
||||
This file describes the directives and concepts tested by this test set.
|
||||
|
||||
test set name: psxspin02
|
||||
|
||||
directives:
|
||||
|
||||
pthread_spin_lock
|
||||
pthread_spin_trylock
|
||||
pthread_spin_unlock
|
||||
|
||||
concepts:
|
||||
|
||||
+ Ensure that attempting to obtain a locked spin lock with
|
||||
pthread_spin_trylock returns the correct error.
|
||||
|
||||
+ Ensure that attempting to release a locked spin lock from a thread which
|
||||
did not lock it returns the correct error.
|
||||
@@ -0,0 +1,8 @@
|
||||
*** POSIX SPINLOCK TEST 02 ***
|
||||
pthread_spin_init( &Spinlock, PTHREAD_PROCESS_PRIVATE ) -- OK
|
||||
pthread_spin_lock( &Spinlock ) -- OK
|
||||
pthread_spin_trylock( &Spinlock ) -- EBUSY
|
||||
pthread_spin_unlock( &Spinlock ) -- EPERM
|
||||
pthread_spin_unlock( &Spinlock ) -- OK
|
||||
pthread_spin_destroy( &Spinlock ) -- OK
|
||||
*** END OF POSIX SPINLOCK TEST 02 ***
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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 */
|
||||
|
||||
pthread_spinlock_t Spinlock;
|
||||
|
||||
rtems_task SpinlockThread(rtems_task_argument arg)
|
||||
{
|
||||
int status;
|
||||
|
||||
puts( "pthread_spin_trylock( &Spinlock ) -- EBUSY" );
|
||||
status = pthread_spin_trylock( &Spinlock );
|
||||
assert( status == EBUSY );
|
||||
|
||||
puts( "pthread_spin_unlock( &Spinlock ) -- EPERM" );
|
||||
status = pthread_spin_unlock( &Spinlock );
|
||||
assert( status == EPERM );
|
||||
|
||||
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 02 ***" );
|
||||
|
||||
/* This successfully creates one */
|
||||
puts( "pthread_spin_init( &Spinlock, PTHREAD_PROCESS_PRIVATE ) -- OK" );
|
||||
status = pthread_spin_init( &Spinlock, PTHREAD_PROCESS_PRIVATE );
|
||||
assert( status == 0 );
|
||||
|
||||
/* Lock it */
|
||||
puts( "pthread_spin_lock( &Spinlock ) -- OK" );
|
||||
status = pthread_spin_lock( &Spinlock );
|
||||
assert( status == 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 );
|
||||
|
||||
sleep(1);
|
||||
|
||||
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 02 ***" );
|
||||
exit(0);
|
||||
}
|
||||
Reference in New Issue
Block a user