1 | /* |
---|
2 | * Copyright (c) 2012 Zhongwei Yao. |
---|
3 | * COPYRIGHT (c) 1989-2014. |
---|
4 | * On-Line Applications Research Corporation (OAR). |
---|
5 | * |
---|
6 | * The license and distribution terms for this file may be |
---|
7 | * found in the file LICENSE in this distribution or at |
---|
8 | * http://www.rtems.org/license/LICENSE. |
---|
9 | */ |
---|
10 | |
---|
11 | #ifdef HAVE_CONFIG_H |
---|
12 | #include "config.h" |
---|
13 | #endif |
---|
14 | |
---|
15 | #include <pthread.h> |
---|
16 | #include <errno.h> |
---|
17 | #include "tmacros.h" |
---|
18 | #include "pmacros.h" |
---|
19 | |
---|
20 | const char rtems_test_name[] = "PSXKEY 6"; |
---|
21 | |
---|
22 | /* forward declarations to avoid warnings */ |
---|
23 | rtems_task Init(rtems_task_argument argument); |
---|
24 | rtems_task Test_Thread1(rtems_task_argument argument); |
---|
25 | rtems_task Test_Thread2(rtems_task_argument argument); |
---|
26 | |
---|
27 | int Data_array[4] = {1, 2, 3, 4}; |
---|
28 | |
---|
29 | pthread_key_t key1, key2; |
---|
30 | |
---|
31 | rtems_task Test_Thread1( rtems_task_argument argument ) |
---|
32 | { |
---|
33 | int sc; |
---|
34 | int *value; |
---|
35 | struct timespec delay_request; |
---|
36 | |
---|
37 | puts( "Test_Thread 1 - key1 pthread_setspecific - OK" ); |
---|
38 | sc = pthread_setspecific( key1, &Data_array[0] ); |
---|
39 | rtems_test_assert( !sc ); |
---|
40 | |
---|
41 | puts( "Test_Thread 1 - key2 pthread_setspecific - OK" ); |
---|
42 | sc = pthread_setspecific( key2, &Data_array[1] ); |
---|
43 | rtems_test_assert( !sc ); |
---|
44 | |
---|
45 | puts( "Test_Thread 1 - sleep - let thread2 run - OK" ); |
---|
46 | delay_request.tv_sec = 0; |
---|
47 | delay_request.tv_nsec = 4 * 100000000; |
---|
48 | sc = nanosleep( &delay_request, NULL ); |
---|
49 | rtems_test_assert( !sc ); |
---|
50 | |
---|
51 | puts( "Test_Thread 1 - key1 pthread_getspecific - OK" ); |
---|
52 | value = pthread_getspecific( key1 ); |
---|
53 | rtems_test_assert( *value == Data_array[0] ); |
---|
54 | |
---|
55 | puts( "Test_Thread 1 - key2 pthread_getspecific - OK" ); |
---|
56 | value = pthread_getspecific( key2 ); |
---|
57 | rtems_test_assert( *value == Data_array[1] ); |
---|
58 | |
---|
59 | rtems_task_delete( RTEMS_SELF ); |
---|
60 | } |
---|
61 | |
---|
62 | rtems_task Test_Thread2( rtems_task_argument argument ) |
---|
63 | { |
---|
64 | int sc; |
---|
65 | int *value; |
---|
66 | |
---|
67 | puts( "Test_Thread 2 - key1 pthread_setspecific - OK" ); |
---|
68 | sc = pthread_setspecific( key1, &Data_array[2] ); |
---|
69 | rtems_test_assert( !sc ); |
---|
70 | |
---|
71 | puts( "Test_Thread 2 - key2 pthread_setspecific - OK" ); |
---|
72 | sc = pthread_setspecific( key2, &Data_array[3] ); |
---|
73 | rtems_test_assert( !sc ); |
---|
74 | |
---|
75 | puts( "Test_Thread 2 - key1 pthread_getspecific - OK" ); |
---|
76 | value = pthread_getspecific( key1 ); |
---|
77 | rtems_test_assert( *value == Data_array[2] ); |
---|
78 | |
---|
79 | puts( "Test_Thread 2 - key2 pthread_getspecific - OK" ); |
---|
80 | value = pthread_getspecific( key2 ); |
---|
81 | rtems_test_assert( *value == Data_array[3] ); |
---|
82 | |
---|
83 | rtems_task_delete( RTEMS_SELF ); |
---|
84 | } |
---|
85 | |
---|
86 | rtems_task Init( rtems_task_argument ignored ) |
---|
87 | { |
---|
88 | rtems_id thread1; |
---|
89 | rtems_id thread2; |
---|
90 | rtems_status_code rc; |
---|
91 | int sc; |
---|
92 | struct timespec delay_request; |
---|
93 | |
---|
94 | TEST_BEGIN(); |
---|
95 | |
---|
96 | puts( "Init - pthread key1 create - OK" ); |
---|
97 | sc = pthread_key_create( &key1, NULL ); |
---|
98 | rtems_test_assert( !sc ); |
---|
99 | |
---|
100 | puts( "Init - pthread key2 create - OK" ); |
---|
101 | sc = pthread_key_create( &key2, NULL ); |
---|
102 | rtems_test_assert( !sc ); |
---|
103 | |
---|
104 | puts( "Init - thread1 create - OK" ); |
---|
105 | rc = rtems_task_create( |
---|
106 | rtems_build_name( 'T', 'E', 'S', 'T' ), |
---|
107 | 1, |
---|
108 | RTEMS_MINIMUM_STACK_SIZE, |
---|
109 | RTEMS_DEFAULT_MODES, |
---|
110 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
111 | &thread1 |
---|
112 | ); |
---|
113 | rtems_test_assert( rc == RTEMS_SUCCESSFUL ); |
---|
114 | |
---|
115 | rc = rtems_task_start( thread1, Test_Thread1, 0 ); |
---|
116 | rtems_test_assert( rc == RTEMS_SUCCESSFUL ); |
---|
117 | |
---|
118 | puts( "Init - thread2 create - OK" ); |
---|
119 | rc = rtems_task_create( |
---|
120 | rtems_build_name( 'T', 'E', 'S', 'T' ), |
---|
121 | 1, |
---|
122 | RTEMS_MINIMUM_STACK_SIZE, |
---|
123 | RTEMS_DEFAULT_MODES, |
---|
124 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
125 | &thread2 |
---|
126 | ); |
---|
127 | rtems_test_assert( rc == RTEMS_SUCCESSFUL ); |
---|
128 | |
---|
129 | rc = rtems_task_start( thread2, Test_Thread2, 0 ); |
---|
130 | rtems_test_assert( rc == RTEMS_SUCCESSFUL ); |
---|
131 | |
---|
132 | puts( "Init - sleep - let thread run - OK" ); |
---|
133 | delay_request.tv_sec = 0; |
---|
134 | delay_request.tv_nsec = 8 * 100000000; |
---|
135 | sc = nanosleep( &delay_request, NULL ); |
---|
136 | rtems_test_assert( !sc ); |
---|
137 | |
---|
138 | puts( "Init - pthread key1 delete - OK" ); |
---|
139 | sc = pthread_key_delete( key1 ); |
---|
140 | rtems_test_assert( sc == 0 ); |
---|
141 | |
---|
142 | puts( "Init - pthread key2 delete - OK" ); |
---|
143 | sc = pthread_key_delete( key2 ); |
---|
144 | rtems_test_assert( sc == 0 ); |
---|
145 | |
---|
146 | TEST_END(); |
---|
147 | rtems_test_exit(0); |
---|
148 | } |
---|
149 | |
---|
150 | /* configuration information */ |
---|
151 | |
---|
152 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
153 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
154 | |
---|
155 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
156 | |
---|
157 | #define CONFIGURE_MAXIMUM_TASKS 3 |
---|
158 | #define CONFIGURE_MAXIMUM_POSIX_KEYS 2 |
---|
159 | |
---|
160 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
161 | |
---|
162 | #define CONFIGURE_INIT |
---|
163 | #include <rtems/confdefs.h> |
---|
164 | |
---|
165 | /* global variables */ |
---|