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 9"; |
---|
21 | |
---|
22 | /* forward declarations to avoid warnings */ |
---|
23 | rtems_task Init(rtems_task_argument argument); |
---|
24 | rtems_task Test_Thread(rtems_task_argument argument); |
---|
25 | void destructor(void *value); |
---|
26 | |
---|
27 | int Data_array[1] = {1}; |
---|
28 | |
---|
29 | pthread_key_t key; |
---|
30 | volatile bool destructor_ran; |
---|
31 | |
---|
32 | void destructor(void *value) |
---|
33 | { |
---|
34 | destructor_ran = true; |
---|
35 | } |
---|
36 | |
---|
37 | rtems_task Test_Thread( rtems_task_argument arg ) |
---|
38 | { |
---|
39 | void *argument = (void *)arg; |
---|
40 | int sc; |
---|
41 | |
---|
42 | puts( "Test_Thread - key pthread_setspecific - OK" ); |
---|
43 | sc = pthread_setspecific( key, argument ); |
---|
44 | rtems_test_assert( !sc ); |
---|
45 | |
---|
46 | puts( "Test_Thread - pthread_exit to run key destructors - OK" ); |
---|
47 | rtems_task_delete( RTEMS_SELF ); |
---|
48 | } |
---|
49 | |
---|
50 | rtems_task Init( rtems_task_argument ignored ) |
---|
51 | { |
---|
52 | rtems_id thread; |
---|
53 | rtems_status_code rc; |
---|
54 | int sc; |
---|
55 | struct timespec delay_request; |
---|
56 | |
---|
57 | TEST_BEGIN(); |
---|
58 | |
---|
59 | puts( "Init - pthread key create with destructor - OK" ); |
---|
60 | sc = pthread_key_create( &key, destructor ); |
---|
61 | rtems_test_assert( !sc ); |
---|
62 | |
---|
63 | puts( "Init - thread create - OK" ); |
---|
64 | rc = rtems_task_create( |
---|
65 | rtems_build_name( 'T', 'E', 'S', 'T' ), |
---|
66 | 1, |
---|
67 | RTEMS_MINIMUM_STACK_SIZE, |
---|
68 | RTEMS_DEFAULT_MODES, |
---|
69 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
70 | &thread |
---|
71 | ); |
---|
72 | rtems_test_assert( rc == RTEMS_SUCCESSFUL ); |
---|
73 | |
---|
74 | rc = rtems_task_start( thread, Test_Thread, (rtems_task_argument)Data_array ); |
---|
75 | rtems_test_assert( rc == RTEMS_SUCCESSFUL ); |
---|
76 | |
---|
77 | puts( "Init - sleep - let thread run - OK" ); |
---|
78 | delay_request.tv_sec = 0; |
---|
79 | delay_request.tv_nsec = 8 * 100000000; |
---|
80 | sc = nanosleep( &delay_request, NULL ); |
---|
81 | rtems_test_assert( !sc ); |
---|
82 | |
---|
83 | puts( "Init - verify destructor run - OK" ); |
---|
84 | rtems_test_assert( destructor_ran == true ); |
---|
85 | |
---|
86 | puts( "Init - pthread key delete - OK" ); |
---|
87 | sc = pthread_key_delete( key ); |
---|
88 | rtems_test_assert( sc == 0 ); |
---|
89 | |
---|
90 | TEST_END(); |
---|
91 | rtems_test_exit(0); |
---|
92 | } |
---|
93 | |
---|
94 | /* configuration information */ |
---|
95 | |
---|
96 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
97 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
98 | |
---|
99 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
100 | |
---|
101 | #define CONFIGURE_MAXIMUM_TASKS 2 |
---|
102 | #define CONFIGURE_MAXIMUM_POSIX_KEYS 1 |
---|
103 | |
---|
104 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
105 | |
---|
106 | #define CONFIGURE_INIT |
---|
107 | #include <rtems/confdefs.h> |
---|
108 | |
---|
109 | /* global variables */ |
---|