[edae517] | 1 | /* |
---|
[8f5abea] | 2 | * SPDX-License-Identifier: BSD-2-Clause |
---|
[edae517] | 3 | * |
---|
[8f5abea] | 4 | * Copyright (C) 2018, Himanshu Sekhar Nayak |
---|
[edae517] | 5 | * |
---|
[8f5abea] | 6 | * Redistribution and use in source and binary forms, with or without |
---|
| 7 | * modification, are permitted provided that the following conditions |
---|
| 8 | * are met: |
---|
| 9 | * 1. Redistributions of source code must retain the above copyright |
---|
| 10 | * notice, this list of conditions and the following disclaimer. |
---|
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
| 12 | * notice, this list of conditions and the following disclaimer in the |
---|
| 13 | * documentation and/or other materials provided with the distribution. |
---|
| 14 | * |
---|
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
| 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
| 25 | * POSSIBILITY OF SUCH DAMAGE. |
---|
[edae517] | 26 | */ |
---|
| 27 | |
---|
| 28 | #ifdef HAVE_CONFIG_H |
---|
| 29 | #include "config.h" |
---|
| 30 | #endif |
---|
| 31 | |
---|
| 32 | #include <pthread.h> |
---|
| 33 | #include <timesys.h> |
---|
| 34 | #include <rtems/btimer.h> |
---|
| 35 | #include <tmacros.h> |
---|
| 36 | #include <sched.h> |
---|
| 37 | #include "test_support.h" |
---|
| 38 | |
---|
| 39 | const char rtems_test_name[] = "PSXTMMUTEXATTR01"; |
---|
| 40 | |
---|
| 41 | /* forward declarations to avoid warnings */ |
---|
| 42 | static void *POSIX_Init(void *argument); |
---|
| 43 | |
---|
| 44 | static pthread_mutexattr_t attr; |
---|
| 45 | |
---|
| 46 | static void benchmark_create_pthread_mutexattr(void) |
---|
| 47 | { |
---|
| 48 | long end_time; |
---|
| 49 | int status; |
---|
| 50 | |
---|
| 51 | benchmark_timer_initialize(); |
---|
| 52 | status = pthread_mutexattr_init( &attr ); |
---|
| 53 | end_time = benchmark_timer_read(); |
---|
| 54 | rtems_test_assert( status == 0 ); |
---|
| 55 | |
---|
| 56 | put_time( |
---|
| 57 | "pthread_mutexattr_init: only case", |
---|
| 58 | end_time, |
---|
| 59 | 1, /* Only executed once */ |
---|
| 60 | 0, |
---|
| 61 | 0 |
---|
| 62 | ); |
---|
| 63 | |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | static void benchmark_pthread_mutexattr_setprioceiling(void) |
---|
| 67 | { |
---|
| 68 | long end_time; |
---|
| 69 | int status; |
---|
| 70 | |
---|
| 71 | benchmark_timer_initialize(); |
---|
| 72 | status = pthread_mutexattr_setprioceiling( &attr, SCHED_FIFO); |
---|
| 73 | end_time = benchmark_timer_read(); |
---|
| 74 | rtems_test_assert( status == 0 ); |
---|
| 75 | |
---|
| 76 | put_time( |
---|
| 77 | "pthread_mutexattr_setprioceiling: only case", |
---|
| 78 | end_time, |
---|
| 79 | 1, /* Only executed once */ |
---|
| 80 | 0, |
---|
| 81 | 0 |
---|
| 82 | ); |
---|
| 83 | |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | static void benchmark_pthread_mutexattr_getprioceiling(void) |
---|
| 87 | { |
---|
| 88 | long end_time; |
---|
| 89 | int status; |
---|
| 90 | int prioceiling; |
---|
| 91 | |
---|
| 92 | benchmark_timer_initialize(); |
---|
| 93 | status = pthread_mutexattr_getprioceiling( &attr, &prioceiling); |
---|
| 94 | end_time = benchmark_timer_read(); |
---|
| 95 | rtems_test_assert( status == 0 ); |
---|
| 96 | rtems_test_assert( prioceiling == SCHED_FIFO); |
---|
| 97 | |
---|
| 98 | put_time( |
---|
| 99 | "pthread_mutexattr_getprioceiling: only case", |
---|
| 100 | end_time, |
---|
| 101 | 1, /* Only executed once */ |
---|
| 102 | 0, |
---|
| 103 | 0 |
---|
| 104 | ); |
---|
| 105 | |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | static void benchmark_pthread_mutexattr_setprotocol(void) |
---|
| 109 | { |
---|
| 110 | long end_time; |
---|
| 111 | int status; |
---|
| 112 | |
---|
| 113 | benchmark_timer_initialize(); |
---|
| 114 | status = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_INHERIT ); |
---|
| 115 | end_time = benchmark_timer_read(); |
---|
| 116 | rtems_test_assert( status == 0 ); |
---|
| 117 | |
---|
| 118 | put_time( |
---|
| 119 | "pthread_mutexattr_setprotocol: only case", |
---|
| 120 | end_time, |
---|
| 121 | 1, /* Only executed once */ |
---|
| 122 | 0, |
---|
| 123 | 0 |
---|
| 124 | ); |
---|
| 125 | |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | static void benchmark_pthread_mutexattr_getprotocol(void) |
---|
| 129 | { |
---|
| 130 | long end_time; |
---|
| 131 | int status; |
---|
| 132 | int protocol; |
---|
| 133 | |
---|
| 134 | benchmark_timer_initialize(); |
---|
| 135 | status = pthread_mutexattr_getprotocol( &attr, &protocol ); |
---|
| 136 | end_time = benchmark_timer_read(); |
---|
| 137 | rtems_test_assert( status == 0 ); |
---|
| 138 | rtems_test_assert( protocol == PTHREAD_PRIO_INHERIT ); |
---|
| 139 | |
---|
| 140 | put_time( |
---|
| 141 | "pthread_mutexattr_getprotocol: only case", |
---|
| 142 | end_time, |
---|
| 143 | 1, /* Only executed once */ |
---|
| 144 | 0, |
---|
| 145 | 0 |
---|
| 146 | ); |
---|
| 147 | |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | static void benchmark_pthread_mutexattr_setpshared(void) |
---|
| 151 | { |
---|
| 152 | long end_time; |
---|
| 153 | int status; |
---|
| 154 | |
---|
| 155 | benchmark_timer_initialize(); |
---|
| 156 | status = pthread_mutexattr_setpshared( &attr, PTHREAD_PROCESS_PRIVATE ); |
---|
| 157 | end_time = benchmark_timer_read(); |
---|
| 158 | rtems_test_assert( status == 0 ); |
---|
| 159 | |
---|
| 160 | put_time( |
---|
| 161 | "pthread_mutexattr_setpshared: only case", |
---|
| 162 | end_time, |
---|
| 163 | 1, /* Only executed once */ |
---|
| 164 | 0, |
---|
| 165 | 0 |
---|
| 166 | ); |
---|
| 167 | |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | static void benchmark_pthread_mutexattr_getpshared(void) |
---|
| 171 | { |
---|
| 172 | long end_time; |
---|
| 173 | int status; |
---|
| 174 | int pshared; |
---|
| 175 | |
---|
| 176 | benchmark_timer_initialize(); |
---|
| 177 | status = pthread_mutexattr_getpshared( &attr, &pshared ); |
---|
| 178 | end_time = benchmark_timer_read(); |
---|
| 179 | rtems_test_assert( status == 0 ); |
---|
| 180 | rtems_test_assert( pshared == PTHREAD_PROCESS_PRIVATE ); |
---|
| 181 | |
---|
| 182 | put_time( |
---|
| 183 | "pthread_mutexattr_getpshared: only case", |
---|
| 184 | end_time, |
---|
| 185 | 1, /* Only executed once */ |
---|
| 186 | 0, |
---|
| 187 | 0 |
---|
| 188 | ); |
---|
| 189 | |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | static void benchmark_pthread_mutexattr_settype(void) |
---|
| 193 | { |
---|
| 194 | long end_time; |
---|
| 195 | int status; |
---|
| 196 | |
---|
| 197 | benchmark_timer_initialize(); |
---|
| 198 | status = pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_DEFAULT ); |
---|
| 199 | end_time = benchmark_timer_read(); |
---|
| 200 | rtems_test_assert( status == 0 ); |
---|
| 201 | |
---|
| 202 | put_time( |
---|
| 203 | "pthread_mutexattr_settype: only case", |
---|
| 204 | end_time, |
---|
| 205 | 1, /* Only executed once */ |
---|
| 206 | 0, |
---|
| 207 | 0 |
---|
| 208 | ); |
---|
| 209 | |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | static void benchmark_pthread_mutexattr_gettype(void) |
---|
| 213 | { |
---|
| 214 | long end_time; |
---|
| 215 | int status; |
---|
| 216 | int type; |
---|
| 217 | |
---|
| 218 | benchmark_timer_initialize(); |
---|
| 219 | status = pthread_mutexattr_gettype( &attr, &type ); |
---|
| 220 | end_time = benchmark_timer_read(); |
---|
| 221 | rtems_test_assert( status == 0 ); |
---|
| 222 | rtems_test_assert( type == PTHREAD_MUTEX_DEFAULT ); |
---|
| 223 | |
---|
| 224 | put_time( |
---|
| 225 | "pthread_mutexattr_gettype: only case", |
---|
| 226 | end_time, |
---|
| 227 | 1, /* Only executed once */ |
---|
| 228 | 0, |
---|
| 229 | 0 |
---|
| 230 | ); |
---|
| 231 | |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | static void benchmark_destroy_pthread_mutexattr(void) |
---|
| 235 | { |
---|
| 236 | long end_time; |
---|
| 237 | int status; |
---|
| 238 | |
---|
| 239 | benchmark_timer_initialize(); |
---|
| 240 | status = pthread_mutexattr_destroy( &attr ); |
---|
| 241 | end_time = benchmark_timer_read(); |
---|
| 242 | rtems_test_assert( status == 0 ); |
---|
| 243 | |
---|
| 244 | put_time( |
---|
| 245 | "pthread_mutexattr_destroy: only case", |
---|
| 246 | end_time, |
---|
| 247 | 1, /* Only executed once */ |
---|
| 248 | 0, |
---|
| 249 | 0 |
---|
| 250 | ); |
---|
| 251 | |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | void *POSIX_Init( |
---|
| 255 | void *argument |
---|
| 256 | ) |
---|
| 257 | { |
---|
| 258 | |
---|
| 259 | TEST_BEGIN(); |
---|
| 260 | |
---|
| 261 | benchmark_create_pthread_mutexattr(); |
---|
| 262 | benchmark_pthread_mutexattr_setprioceiling(); |
---|
| 263 | benchmark_pthread_mutexattr_getprioceiling(); |
---|
| 264 | benchmark_pthread_mutexattr_setprotocol(); |
---|
| 265 | benchmark_pthread_mutexattr_getprotocol(); |
---|
| 266 | benchmark_pthread_mutexattr_setpshared(); |
---|
| 267 | benchmark_pthread_mutexattr_getpshared(); |
---|
| 268 | benchmark_pthread_mutexattr_settype(); |
---|
| 269 | benchmark_pthread_mutexattr_gettype(); |
---|
| 270 | benchmark_destroy_pthread_mutexattr(); |
---|
| 271 | |
---|
| 272 | TEST_END(); |
---|
| 273 | rtems_test_exit(0); |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | /* configuration information */ |
---|
| 277 | |
---|
| 278 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
| 279 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
| 280 | |
---|
| 281 | |
---|
| 282 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 1 |
---|
| 283 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
| 284 | |
---|
| 285 | #define CONFIGURE_INIT |
---|
| 286 | |
---|
| 287 | #include <rtems/confdefs.h> |
---|
| 288 | /* end of file */ |
---|