1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2014. |
---|
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.org/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 "tmacros.h" |
---|
17 | #include "pmacros.h" |
---|
18 | |
---|
19 | const char rtems_test_name[] = "PSXKEY 3"; |
---|
20 | |
---|
21 | /* forward declarations to avoid warnings */ |
---|
22 | rtems_task Init(rtems_task_argument value ); |
---|
23 | rtems_task Test_Thread( rtems_task_argument value ); |
---|
24 | |
---|
25 | void destructor(void *value); |
---|
26 | |
---|
27 | pthread_key_t Key; |
---|
28 | volatile bool destructor_ran; |
---|
29 | |
---|
30 | void destructor(void *value) |
---|
31 | { |
---|
32 | destructor_ran = true; |
---|
33 | } |
---|
34 | |
---|
35 | rtems_task Test_Thread( rtems_task_argument value ) |
---|
36 | { |
---|
37 | int sc; |
---|
38 | void *key_value = (void *) value; |
---|
39 | |
---|
40 | puts( "Test_Thread - pthread_setspecific - OK" ); |
---|
41 | sc = pthread_setspecific( Key, key_value ); |
---|
42 | rtems_test_assert( !sc ); |
---|
43 | |
---|
44 | puts( "Test_Thread - pthread_exit to run key destructors - OK" ); |
---|
45 | rtems_task_delete( RTEMS_SELF ); |
---|
46 | } |
---|
47 | |
---|
48 | rtems_task Init(rtems_task_argument ignored) |
---|
49 | { |
---|
50 | rtems_id thread; |
---|
51 | rtems_status_code rc; |
---|
52 | int sc; |
---|
53 | struct timespec delay_request; |
---|
54 | |
---|
55 | TEST_BEGIN(); |
---|
56 | |
---|
57 | /* |
---|
58 | * Key with NULL destructor |
---|
59 | */ |
---|
60 | puts( "Init - pthread_key_create with NULL destructor - OK" ); |
---|
61 | sc = pthread_key_create( &Key, NULL ); |
---|
62 | rtems_test_assert( !sc ); |
---|
63 | |
---|
64 | puts( "Init - create/start - OK" ); |
---|
65 | rc = rtems_task_create( |
---|
66 | rtems_build_name( 'T', 'E', 'S', 'T' ), |
---|
67 | 1, |
---|
68 | RTEMS_MINIMUM_STACK_SIZE, |
---|
69 | RTEMS_DEFAULT_MODES, |
---|
70 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
71 | &thread |
---|
72 | ); |
---|
73 | rtems_test_assert( rc == RTEMS_SUCCESSFUL ); |
---|
74 | |
---|
75 | rc = rtems_task_start( thread, Test_Thread, 0 ); |
---|
76 | rtems_test_assert( rc == RTEMS_SUCCESSFUL ); |
---|
77 | |
---|
78 | puts( "Init - sleep - let thread run - OK" ); |
---|
79 | delay_request.tv_sec = 0; |
---|
80 | delay_request.tv_nsec = 5 * 100000000; |
---|
81 | sc = nanosleep( &delay_request, NULL ); |
---|
82 | rtems_test_assert( !sc ); |
---|
83 | |
---|
84 | puts( "Init - pthread_key_delete - OK" ); |
---|
85 | sc = pthread_key_delete( Key ); |
---|
86 | rtems_test_assert( sc == 0 ); |
---|
87 | |
---|
88 | /* |
---|
89 | * Key with non-NULL destructor |
---|
90 | */ |
---|
91 | destructor_ran = false; |
---|
92 | puts( "Init - pthread_key_create with non-NULL destructor - OK" ); |
---|
93 | sc = pthread_key_create( &Key, destructor ); |
---|
94 | rtems_test_assert( !sc ); |
---|
95 | |
---|
96 | puts( "Init - task create/start - OK" ); |
---|
97 | rc = rtems_task_create( |
---|
98 | rtems_build_name( 'T', 'E', 'S', 'T' ), |
---|
99 | 1, |
---|
100 | RTEMS_MINIMUM_STACK_SIZE, |
---|
101 | RTEMS_DEFAULT_MODES, |
---|
102 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
103 | &thread |
---|
104 | ); |
---|
105 | rtems_test_assert( rc == RTEMS_SUCCESSFUL ); |
---|
106 | |
---|
107 | rc = rtems_task_start( thread, Test_Thread, 0 ); |
---|
108 | rtems_test_assert( rc == RTEMS_SUCCESSFUL ); |
---|
109 | |
---|
110 | puts( "Init - sleep - let thread run - OK" ); |
---|
111 | sc = nanosleep( &delay_request, NULL ); |
---|
112 | rtems_test_assert( !sc ); |
---|
113 | |
---|
114 | puts( "Init - verify destructor did NOT ran" ); |
---|
115 | rtems_test_assert( destructor_ran == false ); |
---|
116 | |
---|
117 | puts( "Init - pthread_key_delete - OK" ); |
---|
118 | sc = pthread_key_delete( Key ); |
---|
119 | rtems_test_assert( sc == 0 ); |
---|
120 | |
---|
121 | TEST_END(); |
---|
122 | rtems_test_exit(0); |
---|
123 | } |
---|
124 | |
---|
125 | /* configuration information */ |
---|
126 | |
---|
127 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
128 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
129 | |
---|
130 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
131 | |
---|
132 | #define CONFIGURE_MAXIMUM_TASKS 2 |
---|
133 | #define CONFIGURE_MAXIMUM_POSIX_KEYS 1 |
---|
134 | |
---|
135 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
136 | |
---|
137 | #define CONFIGURE_INIT |
---|
138 | #include <rtems/confdefs.h> |
---|
139 | |
---|
140 | /* global variables */ |
---|