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 | #ifdef HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <sched.h> |
---|
17 | #include <sys/utsname.h> |
---|
18 | |
---|
19 | #define CONFIGURE_INIT |
---|
20 | #include "system.h" |
---|
21 | #include "pritime.h" |
---|
22 | |
---|
23 | void *POSIX_Init( |
---|
24 | void *argument |
---|
25 | ) |
---|
26 | { |
---|
27 | struct timespec tr; |
---|
28 | int status; |
---|
29 | int priority; |
---|
30 | pthread_t thread_id; |
---|
31 | struct utsname uts; |
---|
32 | |
---|
33 | puts( "\n\n*** POSIX TEST 1 ***" ); |
---|
34 | |
---|
35 | /* print some system information */ |
---|
36 | |
---|
37 | puts( "Init: uname - EFAULT (invalid uts pointer argument)" ); |
---|
38 | status = uname( NULL ); |
---|
39 | rtems_test_assert( status == -1 ); |
---|
40 | rtems_test_assert( errno == EFAULT ); |
---|
41 | |
---|
42 | status = uname( &uts ); |
---|
43 | rtems_test_assert( !status ); |
---|
44 | printf( "Init: uts.sysname: %s\n", uts.sysname ); |
---|
45 | printf( "Init: uts.nodename: %s\n", uts.nodename ); |
---|
46 | printf( "Init: uts.release: %s\n", uts.release ); |
---|
47 | printf( "Init: uts.version: %s\n", uts.version ); |
---|
48 | printf( "Init: uts.machine: %s\n", uts.machine ); |
---|
49 | puts(""); |
---|
50 | |
---|
51 | /* get id of this thread */ |
---|
52 | |
---|
53 | Init_id = pthread_self(); |
---|
54 | printf( "Init: ID is 0x%08" PRIxpthread_t "\n", Init_id ); |
---|
55 | |
---|
56 | /* exercise get minimum priority */ |
---|
57 | |
---|
58 | priority = sched_get_priority_min( SCHED_FIFO ); |
---|
59 | printf( "Init: sched_get_priority_min (SCHED_FIFO) -- %d\n", priority ); |
---|
60 | rtems_test_assert( priority != -1 ); |
---|
61 | |
---|
62 | puts( "Init: sched_get_priority_min -- EINVAL (invalid policy)" ); |
---|
63 | priority = sched_get_priority_min( -1 ); |
---|
64 | rtems_test_assert( priority == -1 ); |
---|
65 | rtems_test_assert( errno == EINVAL ); |
---|
66 | |
---|
67 | /* exercise get maximum priority */ |
---|
68 | |
---|
69 | priority = sched_get_priority_max( SCHED_FIFO ); |
---|
70 | printf( "Init: sched_get_priority_max (SCHED_FIFO) -- %d\n", priority ); |
---|
71 | rtems_test_assert( priority != -1 ); |
---|
72 | |
---|
73 | puts( "Init: sched_get_priority_max -- EINVAL (invalid policy)" ); |
---|
74 | priority = sched_get_priority_max( -1 ); |
---|
75 | rtems_test_assert( priority == -1 ); |
---|
76 | rtems_test_assert( errno == EINVAL ); |
---|
77 | |
---|
78 | puts( "Init: sched_rr_get_interval -- ESRCH (invalid PID)" ); |
---|
79 | status = sched_rr_get_interval( 4, &tr ); |
---|
80 | rtems_test_assert( status == -1 ); |
---|
81 | rtems_test_assert( errno == ESRCH ); |
---|
82 | |
---|
83 | puts( "Init: sched_rr_get_interval -- EINVAL (invalid interval pointer)" ); |
---|
84 | status = sched_rr_get_interval( getpid(), NULL ); |
---|
85 | rtems_test_assert( status == -1 ); |
---|
86 | rtems_test_assert( errno == EINVAL ); |
---|
87 | |
---|
88 | /* print the round robin time quantum */ |
---|
89 | |
---|
90 | status = sched_rr_get_interval( getpid(), &tr ); |
---|
91 | printf( |
---|
92 | "Init: Round Robin quantum is %" PRIdtime_t " seconds, %ld nanoseconds\n", |
---|
93 | tr.tv_sec, |
---|
94 | tr.tv_nsec |
---|
95 | ); |
---|
96 | rtems_test_assert( !status ); |
---|
97 | |
---|
98 | /* create a thread */ |
---|
99 | |
---|
100 | puts( "Init: pthread_create - SUCCESSFUL" ); |
---|
101 | status = pthread_create( &thread_id, NULL, Task_1_through_3, NULL ); |
---|
102 | rtems_test_assert( !status ); |
---|
103 | |
---|
104 | /* too may threads error */ |
---|
105 | |
---|
106 | puts( "Init: pthread_create - EAGAIN (too many threads)" ); |
---|
107 | status = pthread_create( &thread_id, NULL, Task_1_through_3, NULL ); |
---|
108 | rtems_test_assert( status == EAGAIN ); |
---|
109 | |
---|
110 | puts( "Init: sched_yield to Task_1" ); |
---|
111 | status = sched_yield(); |
---|
112 | rtems_test_assert( !status ); |
---|
113 | |
---|
114 | /* switch to Task_1 */ |
---|
115 | |
---|
116 | /* exit this thread */ |
---|
117 | |
---|
118 | puts( "Init: pthread_exit" ); |
---|
119 | pthread_exit( NULL ); |
---|
120 | |
---|
121 | /* switch to Task_1 */ |
---|
122 | |
---|
123 | return NULL; /* just so the compiler thinks we returned something */ |
---|
124 | } |
---|