1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2012. |
---|
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 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <pthread.h> |
---|
15 | #include <errno.h> |
---|
16 | #include <rtems/libcsupport.h> |
---|
17 | #include "tmacros.h" |
---|
18 | #include "pmacros.h" |
---|
19 | |
---|
20 | /* forward declarations to avoid warnings */ |
---|
21 | void *POSIX_Init(void *argument); |
---|
22 | |
---|
23 | void *POSIX_Init( |
---|
24 | void *ignored |
---|
25 | ) |
---|
26 | { |
---|
27 | pthread_key_t key; |
---|
28 | int eno; |
---|
29 | bool ok; |
---|
30 | uintptr_t to_alloc; |
---|
31 | void *alloced; |
---|
32 | rtems_resource_snapshot snapshot; |
---|
33 | void *greedy; |
---|
34 | |
---|
35 | puts( "\n\n*** TEST KEY 02 ***" ); |
---|
36 | |
---|
37 | greedy = rtems_workspace_greedy_allocate_all_except_largest( &to_alloc ); |
---|
38 | rtems_resource_snapshot_take( &snapshot ); |
---|
39 | |
---|
40 | puts( "Init - pthread_key_create - ENOMEM" ); |
---|
41 | while ( to_alloc > 8 ) { |
---|
42 | ok = rtems_workspace_allocate( to_alloc, &alloced ); |
---|
43 | rtems_test_assert( ok ); |
---|
44 | |
---|
45 | eno = pthread_key_create( &key, NULL ); |
---|
46 | |
---|
47 | rtems_workspace_free( alloced ); |
---|
48 | |
---|
49 | if ( eno == 0 ) |
---|
50 | break; |
---|
51 | |
---|
52 | rtems_test_assert( eno == ENOMEM ); |
---|
53 | |
---|
54 | /* |
---|
55 | * Verify heap is still in same shape if we couldn't allocate a task |
---|
56 | */ |
---|
57 | ok = rtems_resource_snapshot_check( &snapshot ); |
---|
58 | rtems_test_assert( ok ); |
---|
59 | |
---|
60 | to_alloc -= 8; |
---|
61 | } |
---|
62 | |
---|
63 | rtems_test_assert( eno == 0 ); |
---|
64 | |
---|
65 | /* |
---|
66 | * Verify heap is still in same shape after we free the task |
---|
67 | */ |
---|
68 | puts( "Init - pthread_key_delete - OK" ); |
---|
69 | eno = pthread_key_delete( key ); |
---|
70 | rtems_test_assert( eno == 0 ); |
---|
71 | |
---|
72 | puts( "Init - verify workspace has same memory" ); |
---|
73 | ok = rtems_resource_snapshot_check( &snapshot ); |
---|
74 | rtems_test_assert( ok ); |
---|
75 | |
---|
76 | rtems_workspace_greedy_free( greedy ); |
---|
77 | |
---|
78 | puts( "*** END OF TEST KEY 02 ***" ); |
---|
79 | rtems_test_exit(0); |
---|
80 | } |
---|
81 | |
---|
82 | /* configuration information */ |
---|
83 | |
---|
84 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
85 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
86 | |
---|
87 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 1 |
---|
88 | #define CONFIGURE_MAXIMUM_POSIX_KEYS 1 |
---|
89 | |
---|
90 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
91 | |
---|
92 | #define CONFIGURE_INIT |
---|
93 | #include <rtems/confdefs.h> |
---|
94 | |
---|
95 | /* global variables */ |
---|