Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file POSIX Timer Test of FACE Behavior
0005  */
0006 
0007 /*
0008  *  COPYRIGHT (c) 2022. On-Line Applications Research Corporation (OAR).
0009  *
0010  * Redistribution and use in source and binary forms, with or without
0011  * modification, are permitted provided that the following conditions
0012  * are met:
0013  * 1. Redistributions of source code must retain the above copyright
0014  *    notice, this list of conditions and the following disclaimer.
0015    * 2. Redistributions in binary form must reproduce the above copyright
0016  *    notice, this list of conditions and the following disclaimer in the
0017  *    documentation and/or other materials provided with the distribution.
0018  *
0019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0022  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0023  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0024  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0025  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0027  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0028  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0029  * POSSIBILITY OF SUCH DAMAGE.
0030  */
0031 
0032 #ifdef HAVE_CONFIG_H
0033 #include "config.h"
0034 #endif
0035 
0036 #include <pmacros.h>
0037 #include "tmacros.h"
0038 
0039 #include <unistd.h>
0040 #include <errno.h>
0041 #include <sched.h>
0042 #include <time.h>     /* time facilities */
0043 #include <stdio.h>    /* console facilities */
0044 
0045 const char rtems_test_name[] = "PSXTIMER FACE 1";
0046 
0047 static void *POSIX_Init (
0048   void *argument
0049 )
0050 
0051 {
0052   struct sigevent   event;
0053   int               status;
0054   timer_t           timer;
0055 
0056   /*
0057    *  If these are not filled in correctly, we do not execute pass the
0058    *  error checking for a NULL event pointer.
0059    */
0060   event.sigev_notify = SIGEV_SIGNAL;
0061   event.sigev_signo = SIGUSR1;
0062 
0063   TEST_BEGIN();
0064 
0065   /*
0066    * When FACE timer behavior is configured, creating a POSIX timer
0067    * using CLOCK_REALTIME is not allowed.
0068    */
0069   puts( "timer_create - CLOCK_REALTIME forbidden - EPERM" );
0070   status = timer_create( CLOCK_REALTIME, &event, &timer );
0071   fatal_posix_service_status_errno( status, EPERM, "not allowed" );
0072 
0073   /*
0074    * When FACE timer behavior is configured, creating a POSIX timer
0075    * on a value other than CLOCK_REALTIME or CLOCK_MONOTONIC is not allowed.
0076    */
0077   puts( "timer_create - CLOCK_PROCESS_CPUTIME_ID not allowed - EINVAL" );
0078   status = timer_create( CLOCK_PROCESS_CPUTIME_ID, &event, &timer );
0079   fatal_posix_service_status_errno( status, EINVAL, "invalid clock" );
0080 
0081   /*
0082    * When FACE timer behavior is configured, creating a POSIX timer
0083    * on CLOCK_MONOTONIC allowed.
0084    */
0085   puts( "timer_create - OK" );
0086   status = timer_create( CLOCK_MONOTONIC, &event, &timer );
0087   posix_service_failed( status, "timer_create OK" );
0088 
0089   /*
0090    * Delete the previously created timer.
0091    */
0092   puts( "timer_delete - OK" );
0093   status = timer_delete(  timer );
0094   posix_service_failed( status, "timer_delete ok" );
0095 
0096   /*
0097    */
0098   puts( "timer_create - CLOCK_MONOTONIC is allowed - OK" );
0099   status = timer_create( CLOCK_MONOTONIC, &event, &timer );
0100   posix_service_failed( status, "timer_create ok" );
0101 
0102   TEST_END();
0103   rtems_test_exit (0);
0104 }
0105 
0106 /* configuration information */
0107 
0108 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0109 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0110 
0111 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
0112 
0113 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0114 
0115 #define CONFIGURE_MAXIMUM_POSIX_THREADS             1
0116 #define CONFIGURE_MAXIMUM_POSIX_TIMERS              1
0117 
0118 #define CONFIGURE_POSIX_TIMERS_FACE_BEHAVIOR
0119 
0120 #define CONFIGURE_INIT
0121 #include <rtems/confdefs.h>
0122 
0123 /* end of include file */