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  *  COPYRIGHT (c) 1989-2013.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  *  Copyright (c) 2016. Gedare Bloom.
0008  *
0009  * Redistribution and use in source and binary forms, with or without
0010  * modification, are permitted provided that the following conditions
0011  * are met:
0012  * 1. Redistributions of source code must retain the above copyright
0013  *    notice, this list of conditions and the following disclaimer.
0014  * 2. Redistributions in binary form must reproduce the above copyright
0015  *    notice, this list of conditions and the following disclaimer in the
0016  *    documentation and/or other materials provided with the distribution.
0017  *
0018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0019  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0021  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0022  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0023  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0024  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0026  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0027  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0028  * POSSIBILITY OF SUCH DAMAGE.
0029  */
0030 
0031 #ifdef HAVE_CONFIG_H
0032 #include "config.h"
0033 #endif
0034 
0035 #include <timesys.h>
0036 #include <rtems/btimer.h>
0037 #include "test_support.h"
0038 
0039 #include <pthread.h>
0040 
0041 const char rtems_test_name[] = "PSXTMCLOCKNANOSLEEP 03";
0042 
0043 /* forward declarations to avoid warnings */
0044 void *POSIX_Init(void *argument);
0045 void *Middle(void *argument);
0046 void *Low(void *argument);
0047 
0048 void *Low(
0049   void *argument
0050 )
0051 {
0052   benchmark_timer_t end_time;
0053 
0054   end_time = benchmark_timer_read();
0055 
0056   put_time(
0057     "clock_nanosleep: blocking",
0058     end_time,
0059     OPERATION_COUNT,
0060     0,
0061     0
0062   );
0063 
0064   TEST_END();
0065 
0066   rtems_test_exit( 0 );
0067   return NULL;
0068 }
0069 
0070 void *Middle(
0071   void *argument
0072 )
0073 {
0074   /* calling nanosleep */
0075   struct timespec sleepTime;
0076   sleepTime.tv_sec = 0;
0077   sleepTime.tv_nsec = 1;
0078 
0079   clock_nanosleep(
0080     CLOCK_REALTIME,
0081     TIMER_ABSTIME,
0082     &sleepTime,
0083     (struct timespec *) NULL
0084   );
0085 
0086   return NULL;
0087 }
0088 
0089 void *POSIX_Init(
0090   void *argument
0091 )
0092 {
0093   int        i;
0094   int        status;
0095   pthread_t  threadId;
0096   struct timespec sleepTime;
0097   struct timespec remainder;
0098 
0099   sleepTime.tv_sec = 0;
0100   sleepTime.tv_nsec = 1;
0101   remainder.tv_sec = 0;
0102   remainder.tv_nsec = 0;
0103 
0104   TEST_BEGIN();
0105 
0106   for ( i=0 ; i < OPERATION_COUNT - 1 ; i++ ) {
0107     status = pthread_create( &threadId, NULL, Middle, NULL );
0108     rtems_test_assert( !status );
0109   }
0110 
0111   status = pthread_create( &threadId, NULL, Low, NULL );
0112   rtems_test_assert( !status );
0113 
0114   /* start the timer and switch through all the other tasks */
0115   benchmark_timer_initialize();
0116   /* calling clock_nanosleep*/
0117   clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &sleepTime, &remainder);
0118 
0119   return NULL;
0120 }
0121 
0122 /* configuration information */
0123 
0124 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0125 #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
0126 
0127 #define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 2
0128 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
0129 
0130 #define CONFIGURE_INIT
0131 
0132 #include <rtems/confdefs.h>
0133   /* end of file */