summaryrefslogtreecommitdiffstats
path: root/testsuites/psxtests/psxsignal02
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2009-07-24 19:18:20 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2009-07-24 19:18:20 +0000
commita3e4a589d5675db67668371a512b8412364b0f5a (patch)
tree60891ff5eadcdead6d5a84a60a76bb7d037a799f /testsuites/psxtests/psxsignal02
parent2009-07-24 Joel Sherrill <joel.sherrill@OARcorp.com> (diff)
downloadrtems-a3e4a589d5675db67668371a512b8412364b0f5a.tar.bz2
2009-07-24 Joel Sherrill <joel.sherrill@OARcorp.com>
* Makefile.am, configure.ac: Add new test to exercise algorithm to dispatch process wide signals to individual threads. * psxsignal02/.cvsignore, psxsignal02/Makefile.am, psxsignal02/init.c, psxsignal02/psxsignal02.doc, psxsignal02/psxsignal02.scn: New files.
Diffstat (limited to 'testsuites/psxtests/psxsignal02')
-rw-r--r--testsuites/psxtests/psxsignal02/.cvsignore2
-rw-r--r--testsuites/psxtests/psxsignal02/Makefile.am29
-rw-r--r--testsuites/psxtests/psxsignal02/init.c193
-rw-r--r--testsuites/psxtests/psxsignal02/psxsignal02.doc38
-rw-r--r--testsuites/psxtests/psxsignal02/psxsignal02.scn19
5 files changed, 281 insertions, 0 deletions
diff --git a/testsuites/psxtests/psxsignal02/.cvsignore b/testsuites/psxtests/psxsignal02/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/testsuites/psxtests/psxsignal02/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/testsuites/psxtests/psxsignal02/Makefile.am b/testsuites/psxtests/psxsignal02/Makefile.am
new file mode 100644
index 0000000000..ab16c24b49
--- /dev/null
+++ b/testsuites/psxtests/psxsignal02/Makefile.am
@@ -0,0 +1,29 @@
+##
+## $Id$
+##
+
+MANAGERS = all
+
+rtems_tests_PROGRAMS = psxsignal02
+psxsignal02_SOURCES = init.c ../include/pmacros.h
+
+dist_rtems_tests_DATA = psxsignal02.scn
+dist_rtems_tests_DATA += psxsignal02.doc
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+psxsignal02_LDADD = $(MANAGERS_NOT_WANTED:%=$(PROJECT_LIB)/no-%.rel)
+
+AM_CPPFLAGS += -I$(top_srcdir)/include
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(psxsignal02_OBJECTS) $(psxsignal02_LDADD)
+LINK_LIBS = $(psxsignal02_LDLIBS)
+
+psxsignal02$(EXEEXT): $(psxsignal02_OBJECTS) $(psxsignal02_DEPENDENCIES)
+ @rm -f psxsignal02$(EXEEXT)
+ $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/psxtests/psxsignal02/init.c b/testsuites/psxtests/psxsignal02/init.c
new file mode 100644
index 0000000000..801a9e278a
--- /dev/null
+++ b/testsuites/psxtests/psxsignal02/init.c
@@ -0,0 +1,193 @@
+/*
+ * 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.
+ *
+ * $Id$
+ */
+
+
+#include <pmacros.h>
+#include <signal.h>
+#include <errno.h>
+#include <pthread.h>
+#include <sched.h>
+
+volatile bool Signal_occurred;
+volatile pthread_t Signal_thread;
+
+void Signal_handler(
+ int signo
+)
+{
+ Signal_occurred = true;
+ Signal_thread = pthread_self();
+}
+
+void Install_Signal_Handler(
+ const char *task_name
+)
+{
+ int sc;
+ sigset_t mask;
+ sigset_t pending_set;
+ sigset_t oset;
+
+ sc = sigemptyset( &mask );
+ assert( !sc );
+
+ sc = sigaddset( &mask, SIGUSR1 );
+ assert( !sc );
+
+ printf( "%s - Unblock SIGUSR1\n", task_name );
+ sc = pthread_sigmask( SIG_UNBLOCK, &mask, NULL );
+ assert( !sc );
+}
+
+/*
+
+Tasks and actions, created in this order, all interested in SIGUSR1
+ - 20 - interested, suspend?
+ - 18 - interested, suspend?
+ - 16 - interested, spins
+ - 14 - interested, spins
+ - 12 - interested, sleeps
+ - 10 - interested, suspends
+ - 8 - interested, sleeps
+
+Order is critical because the algorithm works by thread index
+*/
+
+typedef enum {
+ SUSPEND,
+ SPIN,
+ SLEEP
+} Action_t;
+
+const char *Actions[] = {
+ "Suspends self",
+ "Spins",
+ "Sleeps"
+};
+
+
+typedef struct {
+ int priority;
+ Action_t action;
+ const char *name;
+} Test_t;
+
+Test_t Threads[] = {
+ { 8, SUSPEND, "P8" }, /* base priority */
+ { 7, SUSPEND, "P7" }, /* lower priority -- no change */
+ { 12, SUSPEND, "P12" }, /* higher priority, blocked */
+ { 12, SUSPEND, "P12" }, /* equal priority, blocked */
+ { 12, SLEEP, "P12" }, /* equal priority, interruptible */
+ { 12, SLEEP, "P12" }, /* equal priority, interruptible */
+ { 12, SPIN, "P12" }, /* equal priority, ready */
+ { 12, SPIN, "P12" }, /* equal priority, ready -- no change */
+ { -1, 0, "" },
+};
+
+void *Test_Thread(void *arg)
+{
+ Test_t *test = (Test_t *)arg;
+
+ Install_Signal_Handler( test->name );
+
+ printf( "%s - %s\n", test->name, Actions[test->action] );
+ switch ( test->action ) {
+ case SUSPEND:
+ (void) rtems_task_suspend( RTEMS_SELF );
+ break;
+ case SPIN:
+ while (1) ;
+ break;
+ case SLEEP:
+ sleep( 30 );
+ break;
+ }
+
+ printf( "%s - exiting\n", test->name );
+ return NULL;
+
+}
+
+void *POSIX_Init(
+ void *argument
+)
+{
+ int i;
+ int sc;
+ pthread_t id;
+ pthread_attr_t attr;
+ struct sched_param param;
+ Test_t *test;
+
+ puts( "\n\n*** POSIX TEST SIGNAL 02 ***" );
+
+ Signal_occurred = false;
+
+ struct sigaction act;
+ act.sa_handler = Signal_handler;
+ act.sa_flags = 0;
+ sigaction( SIGUSR1, &act, NULL );
+
+ puts( "Init - Raise my priority" );
+ sc = pthread_attr_init( &attr );
+ assert( !sc );
+
+ param.sched_priority = 30;
+ sc = pthread_setschedparam( pthread_self(), SCHED_RR, &param );
+ assert( !sc );
+
+ for ( i=0, test=Threads ; test->priority != -1 ; i++, test++ ) {
+ printf( "Init - Create thread %d, priority=%d\n", i, test->priority );
+ sc = pthread_attr_init( &attr );
+ assert( !sc );
+
+ sc = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
+ assert( !sc );
+
+ sc = pthread_attr_setschedpolicy( &attr, SCHED_RR );
+ assert( !sc );
+
+ param.sched_priority = test->priority;
+ sc = pthread_attr_setschedparam( &attr, &param );
+ assert( !sc );
+
+ sc = pthread_create( &id, &attr, Test_Thread, test );
+ assert( !sc );
+
+ puts( "Init - sleep - let thread settle - OK" );
+ usleep(500000);
+ }
+
+ puts( "Init - sending SIGUSR1" );
+ sc = kill( getpid(), SIGUSR1 );
+ assert( !sc );
+
+ /* we are just scheduling the signal, not delivering it */
+ assert( Signal_occurred == false );
+
+ puts( "*** END OF POSIX TEST SIGNAL 02 ***" );
+ rtems_test_exit(0);
+
+ return NULL; /* just so the compiler thinks we returned something */
+}
+
+/* configuration information */
+
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_MICROSECONDS_PER_TICK 1000
+#define CONFIGURE_MAXIMUM_POSIX_THREADS 9
+
+#define CONFIGURE_POSIX_INIT_THREAD_TABLE
+
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
diff --git a/testsuites/psxtests/psxsignal02/psxsignal02.doc b/testsuites/psxtests/psxsignal02/psxsignal02.doc
new file mode 100644
index 0000000000..fdefaaa428
--- /dev/null
+++ b/testsuites/psxtests/psxsignal02/psxsignal02.doc
@@ -0,0 +1,38 @@
+#
+# $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: psxsignal02
+
+directives:
+
+ sigemptyset
+ sigaddset
+ pthread_sigmask
+ sigaction
+ pthread_attr_init
+ pthread_setschedparam
+ pthread_attr_setinheritsched
+ pthread_attr_setschedpolicy
+ pthread_attr_setschedparam
+ pthread_create
+ kill
+
+concepts:
+
++ Ensure the the algorithm in killinfo.c which decides which
+ thread to deliver a POSIX process signal to is fully exercised.
+
+NOTE:
+
++ The order of thread creation, priority and their action is
+ very carefully chosen to force every path through killinfo.c.
diff --git a/testsuites/psxtests/psxsignal02/psxsignal02.scn b/testsuites/psxtests/psxsignal02/psxsignal02.scn
new file mode 100644
index 0000000000..0e5c11ba2f
--- /dev/null
+++ b/testsuites/psxtests/psxsignal02/psxsignal02.scn
@@ -0,0 +1,19 @@
+*** POSIX TEST SIGNAL ***
+Init's ID is 0x0b020002
+Validate signal with SIG_DFL
+Validate signal with SIG_IGN
+Init: Unblock SIGUSR1 SIGFPE SIGILL SIGSEGV
+Init: signal return value verified
+Init: send SIGUSR1 to process
+Signal: 25 caught by 0xb020002 (1)
+Init: send SIGFPE to process
+Handler_1: Signal: 8 caught by 0xb020002 (2)
+Init: send SIGILL to process
+Handler_1: Signal: 4 caught by 0xb020002 (3)
+Init: send SIGSEGV to process
+Handler_1: Signal: 11 caught by 0xb020002 (4)
+Init: send SIGUSR1 to process from a TSR (interruptible sleep)
+Signal: 25 caught by 0xb020002 (1)
+Init: send SIGUSR1 to process from a TSR (spin)
+Signal: 25 caught by 0xb020002 (1)
+*** Validate unexpected program termination ***