Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*  Task_3
0004  *
0005  *  This routine serves as a test task.
0006  *
0007  *  Input parameters:
0008  *    argument - task argument
0009  *
0010  *  Output parameters:  NONE
0011  *
0012  *  COPYRIGHT (c) 1989-2011.
0013  *  On-Line Applications Research Corporation (OAR).
0014  *
0015  * Redistribution and use in source and binary forms, with or without
0016  * modification, are permitted provided that the following conditions
0017  * are met:
0018  * 1. Redistributions of source code must retain the above copyright
0019  *    notice, this list of conditions and the following disclaimer.
0020  * 2. Redistributions in binary form must reproduce the above copyright
0021  *    notice, this list of conditions and the following disclaimer in the
0022  *    documentation and/or other materials provided with the distribution.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #ifdef HAVE_CONFIG_H
0038 #include "config.h"
0039 #endif
0040 
0041 #include "system.h"
0042 #include <signal.h>
0043 
0044 void *Task_3(
0045   void *argument
0046 )
0047 {
0048   unsigned int  remaining;
0049   int           status;
0050   int           sig;
0051   volatile union sigval  value;
0052   sigset_t      mask;
0053   siginfo_t     info;
0054 
0055   value.sival_int = SIGUSR1;
0056 
0057   printf( "Task_3: sigqueue SIGUSR1 with value= %d\n", value.sival_int );
0058   status = sigqueue( getpid(), SIGUSR1, value );
0059   rtems_test_assert( !status );
0060 
0061      /* catch signal with sigwaitinfo */
0062 
0063   empty_line();
0064 
0065   status = sigemptyset( &mask );
0066   rtems_test_assert( !status );
0067 
0068   status = sigaddset( &mask, SIGUSR1 );
0069   rtems_test_assert( !status );
0070 
0071   printf( "Task_3: sigwaitinfo SIGUSR1 with value= %d\n", value.sival_int );
0072   status = sigwaitinfo( &mask, &info );
0073 
0074      /* switch to Init */
0075 
0076   rtems_test_assert( !(status==-1) );
0077   printf(
0078     "Task_3: si_signo= %d si_code= %d value= %d\n",
0079     info.si_signo,
0080     info.si_code,
0081     info.si_value.sival_int
0082   );
0083 
0084      /* catch signal with sigwait */
0085 
0086   empty_line();
0087 
0088   status = sigemptyset( &mask );
0089   rtems_test_assert( !status );
0090 
0091   status = sigaddset( &mask, SIGUSR1 );
0092   rtems_test_assert( !status );
0093 
0094   printf( "Task_3: sigwait SIGUSR1\n" );
0095   status = sigwait( &mask, &sig );
0096 
0097      /* switch to Init */
0098 
0099   rtems_test_assert( !status );
0100   printf( "Task_3: signo= %d\n", sig );
0101 
0102      /* catch signal with pause */
0103 
0104   empty_line();
0105 
0106   status = sigemptyset( &mask );
0107   rtems_test_assert( !status );
0108 
0109   status = sigaddset( &mask, SIGUSR1 );
0110   rtems_test_assert( !status );
0111 
0112   printf( "Task_3: pause\n" );
0113   status = pause( );
0114 
0115      /* switch to Init */
0116 
0117   rtems_test_assert( !(status==-1) );
0118   printf( "Task_3: pause= %d\n", status );
0119 
0120 
0121      /* send signal to Init task before it has pended for a signal */
0122 
0123   empty_line();
0124 
0125   printf( "Task_3: sending SIGUSR2\n" );
0126   status = pthread_kill( Init_id, SIGUSR2 );
0127   rtems_test_assert( !status );
0128 
0129   printf( "Task_3: sleep so the Init task can reguest a signal\n" );
0130   remaining = sleep( 1 );
0131   rtems_test_assert( !status );
0132   rtems_test_assert( remaining == 0 );
0133 
0134      /* end of task 3 */
0135   printf( "Task_3: exit\n" );
0136   pthread_exit( NULL );
0137 
0138      /* switch to Init */
0139 
0140   return NULL; /* just so the compiler thinks we returned something */
0141 }