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-2012.
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 #include <pmacros.h>
0034 
0035 #include <sys/time.h>
0036 #include <signal.h>
0037 #include <errno.h>
0038 
0039 const char rtems_test_name[] = "PSXALARM 1";
0040 
0041 /* forward declarations to avoid warnings */
0042 void *POSIX_Init(void *argument);
0043 
0044 volatile int Signal_count;
0045 
0046 static void Signal_handler(
0047   int signo
0048 )
0049 {
0050   Signal_count++;
0051   printf(
0052     "Signal: %d caught by 0x%" PRIxpthread_t " (%d)\n",
0053     signo,
0054     pthread_self(),
0055     Signal_count
0056   );
0057 }
0058 
0059 void *POSIX_Init(
0060   void *argument
0061 )
0062 {
0063   unsigned int      remaining;
0064   int               sc;
0065   struct sigaction  act;
0066   sigset_t          mask;
0067   struct timeval    delta;
0068 
0069   TEST_BEGIN();
0070 
0071   /* install a signal handler for SIGALRM and unblock it */
0072 
0073   sc = sigemptyset( &act.sa_mask );
0074   rtems_test_assert( !sc );
0075 
0076   act.sa_handler = Signal_handler;
0077   act.sa_flags   = 0;
0078 
0079   sigaction( SIGALRM, &act, NULL );
0080 
0081   sc = sigemptyset( &mask );
0082   rtems_test_assert( !sc );
0083 
0084   sc = sigaddset( &mask, SIGALRM );
0085   rtems_test_assert( !sc );
0086 
0087   puts( "Init: Unblock SIGALRM" );
0088   sc = sigprocmask( SIG_UNBLOCK, &mask, NULL );
0089   rtems_test_assert( !sc );
0090 
0091   /* schedule the alarm */
0092 
0093   puts( "Init: Firing alarm in 1 second" );
0094   remaining = alarm( 1 );
0095   printf( "Init: %d seconds left on previous alarm\n", sc );
0096   rtems_test_assert( !sc );
0097 
0098   puts( "Init: Wait for alarm" );
0099   sleep( 2 );
0100 
0101   rtems_test_assert( Signal_count == 1 );
0102 
0103   puts( "Init: Cancel alarm" );
0104   remaining = alarm( 0 );
0105   printf( "Init: %d seconds left on previous alarm\n", remaining );
0106   rtems_test_assert( remaining == 0 );
0107 
0108   remaining = alarm( 1 );
0109   rtems_test_assert( remaining == 0 );
0110 
0111   delta.tv_sec = 2;
0112   delta.tv_usec = 0;
0113   sc = adjtime( &delta, NULL );
0114   rtems_test_assert( sc == 0 );
0115 
0116   rtems_test_assert( Signal_count == 1 );
0117 
0118   remaining = alarm( 0 );
0119   rtems_test_assert( remaining == 1 );
0120 
0121   TEST_END();
0122   rtems_test_exit( 0 );
0123 
0124   return NULL; /* just so the compiler thinks we returned something */
0125 }
0126 
0127 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0128 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0129 
0130 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0131 
0132 #define CONFIGURE_MAXIMUM_POSIX_THREADS        1
0133 
0134 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
0135 #define CONFIGURE_POSIX_INIT_THREAD_STACK_SIZE \
0136         (RTEMS_MINIMUM_STACK_SIZE * 4)
0137 
0138 #define CONFIGURE_INIT
0139 #include <rtems/confdefs.h>
0140