[9e07bcc] | 1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
| 2 | |
---|
[64bad68b] | 3 | /* |
---|
[e6c87f7] | 4 | * COPYRIGHT (c) 1989-2014. |
---|
[64bad68b] | 5 | * On-Line Applications Research Corporation (OAR). |
---|
| 6 | * |
---|
[9e07bcc] | 7 | * Redistribution and use in source and binary forms, with or without |
---|
| 8 | * modification, are permitted provided that the following conditions |
---|
| 9 | * are met: |
---|
| 10 | * 1. Redistributions of source code must retain the above copyright |
---|
| 11 | * notice, this list of conditions and the following disclaimer. |
---|
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
| 13 | * notice, this list of conditions and the following disclaimer in the |
---|
| 14 | * documentation and/or other materials provided with the distribution. |
---|
| 15 | * |
---|
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
| 26 | * POSSIBILITY OF SUCH DAMAGE. |
---|
[64bad68b] | 27 | */ |
---|
| 28 | |
---|
[cafefbf] | 29 | #ifdef HAVE_CONFIG_H |
---|
| 30 | #include "config.h" |
---|
| 31 | #endif |
---|
| 32 | |
---|
[64bad68b] | 33 | #include <pthread.h> |
---|
| 34 | #include <errno.h> |
---|
| 35 | #include "tmacros.h" |
---|
| 36 | #include "pmacros.h" |
---|
| 37 | |
---|
[698c2e50] | 38 | const char rtems_test_name[] = "PSXKEY 3"; |
---|
| 39 | |
---|
[6c2de60] | 40 | /* forward declarations to avoid warnings */ |
---|
[e6c87f7] | 41 | rtems_task Init(rtems_task_argument value ); |
---|
| 42 | rtems_task Test_Thread( rtems_task_argument value ); |
---|
| 43 | |
---|
[6c2de60] | 44 | void destructor(void *value); |
---|
| 45 | |
---|
[64bad68b] | 46 | pthread_key_t Key; |
---|
| 47 | volatile bool destructor_ran; |
---|
| 48 | |
---|
| 49 | void destructor(void *value) |
---|
| 50 | { |
---|
| 51 | destructor_ran = true; |
---|
| 52 | } |
---|
| 53 | |
---|
[e6c87f7] | 54 | rtems_task Test_Thread( rtems_task_argument value ) |
---|
[64bad68b] | 55 | { |
---|
[e6c87f7] | 56 | int sc; |
---|
| 57 | void *key_value = (void *) value; |
---|
[76e9a52f] | 58 | |
---|
[64bad68b] | 59 | puts( "Test_Thread - pthread_setspecific - OK" ); |
---|
| 60 | sc = pthread_setspecific( Key, key_value ); |
---|
[33c46f1] | 61 | rtems_test_assert( !sc ); |
---|
[b1274bd9] | 62 | |
---|
[64bad68b] | 63 | puts( "Test_Thread - pthread_exit to run key destructors - OK" ); |
---|
[51b3cbca] | 64 | rtems_task_exit(); |
---|
[64bad68b] | 65 | } |
---|
| 66 | |
---|
[e6c87f7] | 67 | rtems_task Init(rtems_task_argument ignored) |
---|
[64bad68b] | 68 | { |
---|
[e6c87f7] | 69 | rtems_id thread; |
---|
| 70 | rtems_status_code rc; |
---|
| 71 | int sc; |
---|
| 72 | struct timespec delay_request; |
---|
[64bad68b] | 73 | |
---|
[698c2e50] | 74 | TEST_BEGIN(); |
---|
[b1274bd9] | 75 | |
---|
[64bad68b] | 76 | /* |
---|
| 77 | * Key with NULL destructor |
---|
| 78 | */ |
---|
| 79 | puts( "Init - pthread_key_create with NULL destructor - OK" ); |
---|
| 80 | sc = pthread_key_create( &Key, NULL ); |
---|
[33c46f1] | 81 | rtems_test_assert( !sc ); |
---|
[64bad68b] | 82 | |
---|
[e6c87f7] | 83 | puts( "Init - create/start - OK" ); |
---|
| 84 | rc = rtems_task_create( |
---|
| 85 | rtems_build_name( 'T', 'E', 'S', 'T' ), |
---|
| 86 | 1, |
---|
| 87 | RTEMS_MINIMUM_STACK_SIZE, |
---|
| 88 | RTEMS_DEFAULT_MODES, |
---|
| 89 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
| 90 | &thread |
---|
| 91 | ); |
---|
| 92 | rtems_test_assert( rc == RTEMS_SUCCESSFUL ); |
---|
| 93 | |
---|
| 94 | rc = rtems_task_start( thread, Test_Thread, 0 ); |
---|
| 95 | rtems_test_assert( rc == RTEMS_SUCCESSFUL ); |
---|
[64bad68b] | 96 | |
---|
| 97 | puts( "Init - sleep - let thread run - OK" ); |
---|
[ea7d86b] | 98 | delay_request.tv_sec = 0; |
---|
| 99 | delay_request.tv_nsec = 5 * 100000000; |
---|
| 100 | sc = nanosleep( &delay_request, NULL ); |
---|
[33c46f1] | 101 | rtems_test_assert( !sc ); |
---|
[64bad68b] | 102 | |
---|
| 103 | puts( "Init - pthread_key_delete - OK" ); |
---|
| 104 | sc = pthread_key_delete( Key ); |
---|
[33c46f1] | 105 | rtems_test_assert( sc == 0 ); |
---|
[64bad68b] | 106 | |
---|
| 107 | /* |
---|
| 108 | * Key with non-NULL destructor |
---|
| 109 | */ |
---|
| 110 | destructor_ran = false; |
---|
| 111 | puts( "Init - pthread_key_create with non-NULL destructor - OK" ); |
---|
| 112 | sc = pthread_key_create( &Key, destructor ); |
---|
[33c46f1] | 113 | rtems_test_assert( !sc ); |
---|
[64bad68b] | 114 | |
---|
[e6c87f7] | 115 | puts( "Init - task create/start - OK" ); |
---|
| 116 | rc = rtems_task_create( |
---|
| 117 | rtems_build_name( 'T', 'E', 'S', 'T' ), |
---|
| 118 | 1, |
---|
| 119 | RTEMS_MINIMUM_STACK_SIZE, |
---|
| 120 | RTEMS_DEFAULT_MODES, |
---|
| 121 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
| 122 | &thread |
---|
| 123 | ); |
---|
| 124 | rtems_test_assert( rc == RTEMS_SUCCESSFUL ); |
---|
| 125 | |
---|
| 126 | rc = rtems_task_start( thread, Test_Thread, 0 ); |
---|
| 127 | rtems_test_assert( rc == RTEMS_SUCCESSFUL ); |
---|
[64bad68b] | 128 | |
---|
| 129 | puts( "Init - sleep - let thread run - OK" ); |
---|
[ea7d86b] | 130 | sc = nanosleep( &delay_request, NULL ); |
---|
[33c46f1] | 131 | rtems_test_assert( !sc ); |
---|
[64bad68b] | 132 | |
---|
| 133 | puts( "Init - verify destructor did NOT ran" ); |
---|
[33c46f1] | 134 | rtems_test_assert( destructor_ran == false ); |
---|
[64bad68b] | 135 | |
---|
| 136 | puts( "Init - pthread_key_delete - OK" ); |
---|
| 137 | sc = pthread_key_delete( Key ); |
---|
[33c46f1] | 138 | rtems_test_assert( sc == 0 ); |
---|
[64bad68b] | 139 | |
---|
[698c2e50] | 140 | TEST_END(); |
---|
[64bad68b] | 141 | rtems_test_exit(0); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | /* configuration information */ |
---|
| 145 | |
---|
[c4b8b147] | 146 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
[64bad68b] | 147 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
| 148 | |
---|
[698c2e50] | 149 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
| 150 | |
---|
[e6c87f7] | 151 | #define CONFIGURE_MAXIMUM_TASKS 2 |
---|
[64bad68b] | 152 | #define CONFIGURE_MAXIMUM_POSIX_KEYS 1 |
---|
| 153 | |
---|
[e6c87f7] | 154 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
[64bad68b] | 155 | |
---|
| 156 | #define CONFIGURE_INIT |
---|
| 157 | #include <rtems/confdefs.h> |
---|
| 158 | |
---|
| 159 | /* global variables */ |
---|