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 #include <sched.h>
0034 #include <sys/utsname.h>
0035 
0036 #define CONFIGURE_INIT
0037 #include "system.h"
0038 #include "pritime.h"
0039 
0040 #include <rtems/score/todimpl.h>
0041 
0042 const char rtems_test_name[] = "PSX 1";
0043 
0044 void *POSIX_Init(
0045   void *argument
0046 )
0047 {
0048   struct timespec tr;
0049   int             status;
0050   int             priority;
0051   pthread_t       thread_id;
0052   struct utsname  uts;
0053 
0054   TEST_BEGIN();
0055 
0056   /* print some system information */
0057 
0058   puts( "Init: uname - EFAULT (invalid uts pointer argument)" );
0059   status = uname( NULL );
0060   rtems_test_assert( status == -1 );
0061   rtems_test_assert( errno == EFAULT );
0062 
0063   status = uname( &uts );
0064   rtems_test_assert( !status );
0065   printf( "Init: uts.sysname: %s\n", uts.sysname );
0066   printf( "Init: uts.nodename: %s\n", uts.nodename );
0067   printf( "Init: uts.release: %s\n", uts.release );
0068   printf( "Init: uts.version: %s\n", uts.version );
0069   printf( "Init: uts.machine: %s\n", uts.machine );
0070   puts("");
0071 
0072   /* get id of this thread */
0073 
0074   Init_id = pthread_self();
0075   printf( "Init: ID is 0x%08" PRIxpthread_t "\n", Init_id );
0076 
0077   /* exercise get minimum priority */
0078 
0079   priority = sched_get_priority_min( SCHED_FIFO );
0080   printf( "Init: sched_get_priority_min (SCHED_FIFO) -- %d\n", priority );
0081   rtems_test_assert( priority != -1 );
0082 
0083   puts( "Init: sched_get_priority_min -- EINVAL (invalid policy)" );
0084   priority = sched_get_priority_min( -1 );
0085   rtems_test_assert( priority == -1 );
0086   rtems_test_assert( errno == EINVAL );
0087 
0088   /* exercise get maximum priority */
0089 
0090   priority = sched_get_priority_max( SCHED_FIFO );
0091   printf( "Init: sched_get_priority_max (SCHED_FIFO) -- %d\n", priority );
0092   rtems_test_assert( priority != -1 );
0093 
0094   puts( "Init: sched_get_priority_max -- EINVAL (invalid policy)" );
0095   priority = sched_get_priority_max( -1 );
0096   rtems_test_assert( priority == -1 );
0097   rtems_test_assert( errno == EINVAL );
0098 
0099   puts( "Init: sched_rr_get_interval -- ESRCH (invalid PID)" );
0100   status = sched_rr_get_interval( 4, &tr );
0101   rtems_test_assert( status == -1 );
0102   rtems_test_assert( errno == ESRCH );
0103 
0104   puts( "Init: sched_rr_get_interval -- EINVAL (invalid interval pointer)" );
0105   status = sched_rr_get_interval( getpid(), NULL );
0106   rtems_test_assert( status == -1 );
0107   rtems_test_assert( errno == EINVAL );
0108 
0109   /* print the round robin time quantum */
0110 
0111   status = sched_rr_get_interval( getpid(), &tr );
0112   printf(
0113     "Init: Round Robin quantum is %" PRIdtime_t " seconds, %ld nanoseconds\n",
0114     tr.tv_sec,
0115     tr.tv_nsec
0116   );
0117   rtems_test_assert( !status );
0118 
0119   /* create a thread */
0120 
0121   puts( "Init: pthread_create - SUCCESSFUL" );
0122   status = pthread_create( &thread_id, NULL, Task_1_through_3, NULL );
0123   rtems_test_assert( !status );
0124 
0125   /* too may threads error */
0126 
0127   puts( "Init: pthread_create - EAGAIN (too many threads)" );
0128   status = pthread_create( &thread_id, NULL, Task_1_through_3, NULL );
0129   rtems_test_assert( status == EAGAIN );
0130 
0131   puts( "Init: sched_yield to Task_1" );
0132   status = sched_yield();
0133   rtems_test_assert( !status );
0134 
0135     /* switch to Task_1 */
0136 
0137   /* exit this thread */
0138 
0139   puts( "Init: pthread_exit" );
0140   pthread_exit( NULL );
0141 
0142     /* switch to Task_1 */
0143 
0144   return NULL; /* just so the compiler thinks we returned something */
0145 }