1 | /* |
---|
2 | * Copyright (c) 2012 Zhongwei Yao. |
---|
3 | * COPYRIGHT (c) 1989-2012. |
---|
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.com/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 | /* 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 key1, key2; |
---|
28 | int sc, *value; |
---|
29 | int Data_array[2] = {1, 2}; |
---|
30 | |
---|
31 | puts( "\n\n*** TEST KEY 05 ***" ); |
---|
32 | |
---|
33 | puts( "Init - pthread key1 create - OK" ); |
---|
34 | sc = pthread_key_create( &key1, NULL ); |
---|
35 | rtems_test_assert( !sc ); |
---|
36 | |
---|
37 | puts( "Init - pthread key2 create - OK" ); |
---|
38 | sc = pthread_key_create( &key2, NULL ); |
---|
39 | rtems_test_assert( !sc ); |
---|
40 | |
---|
41 | puts( "Init - key1 pthread_setspecific - OK" ); |
---|
42 | sc = pthread_setspecific( key1, &Data_array[0] ); |
---|
43 | rtems_test_assert( !sc ); |
---|
44 | |
---|
45 | puts( "Init - key2 pthread_setspecific - OK" ); |
---|
46 | sc = pthread_setspecific( key2, &Data_array[1] ); |
---|
47 | rtems_test_assert( !sc ); |
---|
48 | |
---|
49 | puts( "Init - key1 pthread_getspecific - OK" ); |
---|
50 | value = pthread_getspecific( key1 ); |
---|
51 | rtems_test_assert( *value == Data_array[0] ); |
---|
52 | |
---|
53 | puts( "Init - key2 pthread_getspecific - OK" ); |
---|
54 | value = pthread_getspecific( key2 ); |
---|
55 | rtems_test_assert( *value == Data_array[1] ); |
---|
56 | |
---|
57 | puts( "Init - pthread key1 delete - OK" ); |
---|
58 | sc = pthread_key_delete( key1 ); |
---|
59 | rtems_test_assert( sc == 0 ); |
---|
60 | |
---|
61 | puts( "Init - pthread key2 delete - OK" ); |
---|
62 | sc = pthread_key_delete( key2 ); |
---|
63 | rtems_test_assert( sc == 0 ); |
---|
64 | |
---|
65 | puts( "*** END OF TEST KEY 05 ***" ); |
---|
66 | rtems_test_exit(0); |
---|
67 | } |
---|
68 | |
---|
69 | /* configuration information */ |
---|
70 | |
---|
71 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
72 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
73 | |
---|
74 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 1 |
---|
75 | #define CONFIGURE_MAXIMUM_POSIX_KEYS 2 |
---|
76 | |
---|
77 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
78 | |
---|
79 | #define CONFIGURE_INIT |
---|
80 | #include <rtems/confdefs.h> |
---|
81 | |
---|
82 | /* global variables */ |
---|