Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:36

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2009.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #define CONFIGURE_INIT
0034 #include "system.h"
0035 #include <signal.h>
0036 
0037 const char rtems_test_name[] = "PSX 2";
0038 
0039 volatile int Signal_occurred;
0040 volatile int Signal_count;
0041 void Signal_handler( int signo );
0042 
0043 void Signal_handler(
0044   int signo
0045 )
0046 {
0047   Signal_count++;
0048   printf(
0049     "Signal: %d caught by 0x%x (%d)\n",
0050     (int) signo,
0051     (unsigned int) pthread_self(),
0052     Signal_count
0053   );
0054   Signal_occurred = 1;
0055 }
0056 
0057 void *POSIX_Init(
0058   void *argument
0059 )
0060 {
0061   int               status;
0062   struct timespec   tv;
0063   struct timespec   tr;
0064   struct sigaction  act;
0065   sigset_t          mask;
0066   sigset_t          pending_set;
0067 
0068   TEST_BEGIN();
0069 
0070   /* set the time of day, and print our buffer in multiple ways */
0071 
0072   set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
0073 
0074   /* get id of this thread */
0075 
0076   Init_id = pthread_self();
0077   printf( "Init's ID is 0x%08" PRIxpthread_t "\n", Init_id );
0078 
0079   /* install a signal handler */
0080 
0081   status = sigemptyset( &act.sa_mask );
0082   rtems_test_assert( !status );
0083 
0084   act.sa_handler = Signal_handler;
0085   act.sa_flags   = 0;
0086 
0087   sigaction( SIGUSR1, &act, NULL );
0088 
0089   /* simple signal to self */
0090 
0091   Signal_count = 0;
0092   Signal_occurred = 0;
0093 
0094   status = pthread_kill( Init_id, SIGUSR1 );
0095   rtems_test_assert( !status );
0096 
0097   Signal_occurred = 0;
0098 
0099   /* now block the signal, send it, see if it is pending, and unblock it */
0100 
0101   status = sigemptyset( &mask );
0102   rtems_test_assert( !status );
0103 
0104   status = sigaddset( &mask, SIGUSR1 );
0105   rtems_test_assert( !status );
0106 
0107   printf( "Init: Block SIGUSR1\n" );
0108   status = sigprocmask( SIG_BLOCK, &mask, NULL );
0109   rtems_test_assert( !status );
0110 
0111   status = sigpending( &pending_set );
0112   rtems_test_assert( !status );
0113   printf( "Init: Signals pending 0x%08x\n", (unsigned int) pending_set );
0114 
0115 
0116   printf( "Init: send SIGUSR1 to self\n" );
0117   status = pthread_kill( Init_id, SIGUSR1 );
0118   rtems_test_assert( !status );
0119 
0120   status = sigpending( &pending_set );
0121   rtems_test_assert( !status );
0122   printf( "Init: Signals pending 0x%08x\n", (unsigned int) pending_set );
0123 
0124   printf( "Init: Unblock SIGUSR1\n" );
0125   status = sigprocmask( SIG_UNBLOCK, &mask, NULL );
0126   rtems_test_assert( !status );
0127 
0128   /* create a thread */
0129 
0130   status = pthread_create( &Task_id, NULL, Task_1_through_3, NULL );
0131   rtems_test_assert( !status );
0132 
0133   /*
0134    *  Loop for 5 seconds seeing how many signals we catch
0135    */
0136 
0137   tr.tv_sec = 5;
0138   tr.tv_nsec = 0;
0139 
0140   do {
0141     tv = tr;
0142 
0143     Signal_occurred = 0;
0144 
0145     status = nanosleep ( &tv, &tr );
0146 
0147     if ( status == -1 ) {
0148       rtems_test_assert( errno == EINTR );
0149       rtems_test_assert( tr.tv_nsec || tr.tv_sec );
0150     } else if ( !status ) {
0151       rtems_test_assert( !tr.tv_nsec && !tr.tv_sec );
0152     }
0153 
0154     printf(
0155       "Init: signal was %sprocessed with %d:%d time remaining\n",
0156       (Signal_occurred) ? "" : "not ",
0157       (int) tr.tv_sec,
0158       (int) tr.tv_nsec
0159    );
0160 
0161   } while ( tr.tv_sec || tr.tv_nsec );
0162 
0163   /* exit this thread */
0164 
0165   TEST_END();
0166   rtems_test_exit( 0 );
0167 
0168   return NULL; /* just so the compiler thinks we returned something */
0169 }