source: rtems/testsuites/psxtests/psx01/init.c

Last change on this file was a3610bb, checked in by Joel Sherrill <joel@…>, on 04/07/22 at 15:03:59

testsuites/psxtests/psx[01]*: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 *  COPYRIGHT (c) 1989-2009.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include <sched.h>
34#include <sys/utsname.h>
35
36#define CONFIGURE_INIT
37#include "system.h"
38#include "pritime.h"
39
40#include <rtems/score/todimpl.h>
41
42const char rtems_test_name[] = "PSX 1";
43
44void *POSIX_Init(
45  void *argument
46)
47{
48  struct timespec tr;
49  int             status;
50  int             priority;
51  pthread_t       thread_id;
52  struct utsname  uts;
53
54  TEST_BEGIN();
55
56  /* print some system information */
57
58  puts( "Init: uname - EFAULT (invalid uts pointer argument)" );
59  status = uname( NULL );
60  rtems_test_assert( status == -1 );
61  rtems_test_assert( errno == EFAULT );
62
63  status = uname( &uts );
64  rtems_test_assert( !status );
65  printf( "Init: uts.sysname: %s\n", uts.sysname );
66  printf( "Init: uts.nodename: %s\n", uts.nodename );
67  printf( "Init: uts.release: %s\n", uts.release );
68  printf( "Init: uts.version: %s\n", uts.version );
69  printf( "Init: uts.machine: %s\n", uts.machine );
70  puts("");
71
72  /* get id of this thread */
73
74  Init_id = pthread_self();
75  printf( "Init: ID is 0x%08" PRIxpthread_t "\n", Init_id );
76
77  /* exercise get minimum priority */
78
79  priority = sched_get_priority_min( SCHED_FIFO );
80  printf( "Init: sched_get_priority_min (SCHED_FIFO) -- %d\n", priority );
81  rtems_test_assert( priority != -1 );
82
83  puts( "Init: sched_get_priority_min -- EINVAL (invalid policy)" );
84  priority = sched_get_priority_min( -1 );
85  rtems_test_assert( priority == -1 );
86  rtems_test_assert( errno == EINVAL );
87
88  /* exercise get maximum priority */
89
90  priority = sched_get_priority_max( SCHED_FIFO );
91  printf( "Init: sched_get_priority_max (SCHED_FIFO) -- %d\n", priority );
92  rtems_test_assert( priority != -1 );
93
94  puts( "Init: sched_get_priority_max -- EINVAL (invalid policy)" );
95  priority = sched_get_priority_max( -1 );
96  rtems_test_assert( priority == -1 );
97  rtems_test_assert( errno == EINVAL );
98
99  puts( "Init: sched_rr_get_interval -- ESRCH (invalid PID)" );
100  status = sched_rr_get_interval( 4, &tr );
101  rtems_test_assert( status == -1 );
102  rtems_test_assert( errno == ESRCH );
103
104  puts( "Init: sched_rr_get_interval -- EINVAL (invalid interval pointer)" );
105  status = sched_rr_get_interval( getpid(), NULL );
106  rtems_test_assert( status == -1 );
107  rtems_test_assert( errno == EINVAL );
108
109  /* print the round robin time quantum */
110
111  status = sched_rr_get_interval( getpid(), &tr );
112  printf(
113    "Init: Round Robin quantum is %" PRIdtime_t " seconds, %ld nanoseconds\n",
114    tr.tv_sec,
115    tr.tv_nsec
116  );
117  rtems_test_assert( !status );
118
119  /* create a thread */
120
121  puts( "Init: pthread_create - SUCCESSFUL" );
122  status = pthread_create( &thread_id, NULL, Task_1_through_3, NULL );
123  rtems_test_assert( !status );
124
125  /* too may threads error */
126
127  puts( "Init: pthread_create - EAGAIN (too many threads)" );
128  status = pthread_create( &thread_id, NULL, Task_1_through_3, NULL );
129  rtems_test_assert( status == EAGAIN );
130
131  puts( "Init: sched_yield to Task_1" );
132  status = sched_yield();
133  rtems_test_assert( !status );
134
135    /* switch to Task_1 */
136
137  /* exit this thread */
138
139  puts( "Init: pthread_exit" );
140  pthread_exit( NULL );
141
142    /* switch to Task_1 */
143
144  return NULL; /* just so the compiler thinks we returned something */
145}
Note: See TracBrowser for help on using the repository browser.