source: rtems/testsuites/psxtests/psx01/init.c @ 39615f4

4.104.11
Last change on this file since 39615f4 was 39615f4, checked in by Ralf Corsepius <ralf.corsepius@…>, on Oct 27, 2009 at 2:10:54 PM

Use PRIxpthread_t to print pthread_t's.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#define CONFIGURE_INIT
13#include "system.h"
14#include <sched.h>
15#include <sys/utsname.h>
16
17void *POSIX_Init(
18  void *argument
19)
20{
21  struct timespec tr;
22  int             status;
23  int             priority;
24  pthread_t       thread_id;
25  struct utsname  uts;
26
27  puts( "\n\n*** POSIX TEST 1 ***" );
28
29  /* print some system information */
30
31  puts( "Init: uname - EFAULT (invalid uts pointer argument)" );
32  status = uname( NULL );
33  rtems_test_assert( status == -1 );
34  rtems_test_assert( errno == EFAULT );
35
36  status = uname( &uts );
37  rtems_test_assert( !status );
38  printf( "Init: uts.sysname: %s\n", uts.sysname );
39  printf( "Init: uts.nodename: %s\n", uts.nodename );
40  printf( "Init: uts.release: %s\n", uts.release );
41  printf( "Init: uts.version: %s\n", uts.version );
42  printf( "Init: uts.machine: %s\n", uts.machine );
43  puts("");
44
45  /* get id of this thread */
46
47  Init_id = pthread_self();
48  printf( "Init: ID is 0x%08" PRIxpthread_t "\n", Init_id );
49
50  /* exercise get minimum priority */
51
52  priority = sched_get_priority_min( SCHED_FIFO );
53  printf( "Init: sched_get_priority_min (SCHED_FIFO) -- %d\n", priority );
54  rtems_test_assert( priority != -1 );
55
56  puts( "Init: sched_get_priority_min -- EINVAL (invalid policy)" );
57  priority = sched_get_priority_min( -1 );
58  rtems_test_assert( priority == -1 );
59  rtems_test_assert( errno == EINVAL );
60
61  /* exercise get maximum priority */
62
63  priority = sched_get_priority_max( SCHED_FIFO );
64  printf( "Init: sched_get_priority_max (SCHED_FIFO) -- %d\n", priority );
65  rtems_test_assert( priority != -1 );
66
67  puts( "Init: sched_get_priority_max -- EINVAL (invalid policy)" );
68  priority = sched_get_priority_max( -1 );
69  rtems_test_assert( priority == -1 );
70  rtems_test_assert( errno == EINVAL );
71
72  puts( "Init: sched_rr_get_interval -- ESRCH (invalid PID)" );
73  status = sched_rr_get_interval( 4, &tr );
74  rtems_test_assert( status == -1 );
75  rtems_test_assert( errno == ESRCH );
76 
77  puts( "Init: sched_rr_get_interval -- EINVAL (invalid interval pointer)" );
78  status = sched_rr_get_interval( getpid(), NULL );
79  rtems_test_assert( status == -1 );
80  rtems_test_assert( errno == EINVAL );
81 
82  /* print the round robin time quantum */
83
84  status = sched_rr_get_interval( getpid(), &tr );
85  printf(
86    "Init: Round Robin quantum is %ld seconds, %ld nanoseconds\n",
87    tr.tv_sec,
88    tr.tv_nsec
89  );
90  rtems_test_assert( !status );
91
92  /* create a thread */
93
94  puts( "Init: pthread_create - SUCCESSFUL" );
95  status = pthread_create( &thread_id, NULL, Task_1_through_3, NULL );
96  rtems_test_assert( !status );
97
98  /* too may threads error */
99
100  puts( "Init: pthread_create - EAGAIN (too many threads)" );
101  status = pthread_create( &thread_id, NULL, Task_1_through_3, NULL );
102  rtems_test_assert( status == EAGAIN );
103
104  puts( "Init: sched_yield to Task_1" );
105  status = sched_yield();
106  rtems_test_assert( !status );
107
108    /* switch to Task_1 */
109
110  /* exit this thread */
111
112  puts( "Init: pthread_exit" );
113  pthread_exit( NULL );
114
115    /* switch to Task_1 */
116
117  return NULL; /* just so the compiler thinks we returned something */
118}
Note: See TracBrowser for help on using the repository browser.