source:
rtems/testsuites/psxtests/psxkey02/init.c
@
2317457
Last change on this file since 2317457 was 2317457, checked in by Joel Sherrill <joel.sherrill@…>, on 12/08/09 at 17:52:53 | |
---|---|
|
|
File size: 3.5 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 | #include <pthread.h> |
13 | #include <errno.h> |
14 | #include "tmacros.h" |
15 | #include "pmacros.h" |
16 | |
17 | void *POSIX_Init( |
18 | void *ignored |
19 | ) |
20 | { |
21 | pthread_key_t key; |
22 | int sc; |
23 | bool sb; |
24 | Heap_Information_block start; |
25 | Heap_Information_block info; |
26 | size_t to_alloc; |
27 | void *alloced; |
28 | |
29 | puts( "\n\n*** TEST KEY 02 ***" ); |
30 | |
31 | puts( "Init - rtems_workspace_get_information - OK" ); |
32 | sb = rtems_workspace_get_information( &start ); |
33 | rtems_test_assert( sb ); |
34 | |
35 | #if 0 |
36 | printf( "Init - workspace free = %d\n", start.Free.largest ); |
37 | printf( "Init - workspace free blocks = %d\n", start.Free.number ); |
38 | #endif |
39 | rtems_test_assert( start.Free.number == 1 ); |
40 | to_alloc = start.Free.largest; |
41 | |
42 | /* find the largest we can actually allocate */ |
43 | while ( 1 ) { |
44 | sb = rtems_workspace_allocate( to_alloc, &alloced ); |
45 | if ( sb ) |
46 | break; |
47 | to_alloc -= 4; |
48 | } |
49 | |
50 | rtems_workspace_free( alloced ); |
51 | |
52 | #if 0 |
53 | printf( "Init - start with to_alloc of = %d\n", to_alloc ); |
54 | #endif |
55 | |
56 | /* |
57 | * Verify heap is still in same shape if we couldn't allocate a task |
58 | */ |
59 | sb = rtems_workspace_get_information( &info ); |
60 | rtems_test_assert( sb ); |
61 | rtems_test_assert( info.Free.largest == start.Free.largest ); |
62 | rtems_test_assert( info.Free.number == start.Free.number ); |
63 | |
64 | puts( "Init - pthread_key_create - ENOMEM" ); |
65 | while (1) { |
66 | |
67 | sb = rtems_workspace_allocate( to_alloc, &alloced ); |
68 | rtems_test_assert( sb ); |
69 | |
70 | sc = pthread_key_create( &key, NULL ); |
71 | |
72 | /* free the memory we snagged, then check the status */ |
73 | rtems_workspace_free( alloced ); |
74 | |
75 | if ( !sc ) |
76 | break; |
77 | |
78 | if ( sc != ENOMEM ) { |
79 | printf( "key create returned %s\n", strerror(sc) ); |
80 | rtems_test_exit(0); |
81 | } |
82 | |
83 | /* |
84 | * Verify heap is still in same shape if we couldn't allocate a task |
85 | */ |
86 | sb = rtems_workspace_get_information( &info ); |
87 | #if 0 |
88 | printf( "Init - workspace free/blocks = %d/%d\n", |
89 | info.Free.largest, info.Free.number ); |
90 | #endif |
91 | rtems_test_assert( sb ); |
92 | rtems_test_assert( info.Free.largest == start.Free.largest ); |
93 | rtems_test_assert( info.Free.number == start.Free.number ); |
94 | |
95 | to_alloc -= 8; |
96 | if ( to_alloc == 0 ) |
97 | break; |
98 | } |
99 | |
100 | if ( sc ) |
101 | rtems_test_exit(0); |
102 | |
103 | /* |
104 | * Verify heap is still in same shape after we free the task |
105 | */ |
106 | puts( "Init - pthread_key_delete - OK" ); |
107 | sc = pthread_key_delete( key ); |
108 | rtems_test_assert( sc == 0 ); |
109 | |
110 | puts( "Init - verify workspace has same memory" ); |
111 | sb = rtems_workspace_get_information( &info ); |
112 | #if 0 |
113 | printf( "Init - workspace free/blocks = %d/%d\n", |
114 | info.Free.largest, info.Free.number ); |
115 | #endif |
116 | rtems_test_assert( sb ); |
117 | rtems_test_assert( info.Free.largest == start.Free.largest ); |
118 | rtems_test_assert( info.Free.number == start.Free.number ); |
119 | |
120 | puts( "*** END OF TEST KEY 02 ***" ); |
121 | rtems_test_exit(0); |
122 | } |
123 | |
124 | /* configuration information */ |
125 | |
126 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
127 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
128 | |
129 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 1 |
130 | #define CONFIGURE_MAXIMUM_POSIX_KEYS 1 |
131 | |
132 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
133 | |
134 | #define CONFIGURE_INIT |
135 | #include <rtems/confdefs.h> |
136 | |
137 | /* global variables */ |
Note: See TracBrowser
for help on using the repository browser.