1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /* |
---|
4 | * COPYRIGHT (c) 1989-2013. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
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. |
---|
27 | */ |
---|
28 | |
---|
29 | #ifdef HAVE_CONFIG_H |
---|
30 | #include "config.h" |
---|
31 | #endif |
---|
32 | |
---|
33 | #include <tmacros.h> |
---|
34 | #include <timesys.h> |
---|
35 | #include "test_support.h" |
---|
36 | #include <pthread.h> |
---|
37 | #include <sched.h> |
---|
38 | #include <rtems/btimer.h> |
---|
39 | |
---|
40 | const char rtems_test_name[] = "PSXTMMUTEX 05"; |
---|
41 | |
---|
42 | /* forward declarations to avoid warnings */ |
---|
43 | void *POSIX_Init(void *argument); |
---|
44 | void *Blocker(void *argument); |
---|
45 | |
---|
46 | pthread_mutex_t MutexId; |
---|
47 | |
---|
48 | void *Blocker( |
---|
49 | void *argument |
---|
50 | ) |
---|
51 | { |
---|
52 | (void) pthread_mutex_lock( &MutexId ); |
---|
53 | /* should never return */ |
---|
54 | rtems_test_assert( FALSE ); |
---|
55 | |
---|
56 | return NULL; |
---|
57 | } |
---|
58 | |
---|
59 | void *POSIX_Init( |
---|
60 | void *argument |
---|
61 | ) |
---|
62 | { |
---|
63 | int status; |
---|
64 | pthread_t threadId; |
---|
65 | benchmark_timer_t end_time; |
---|
66 | |
---|
67 | TEST_BEGIN(); |
---|
68 | |
---|
69 | status = pthread_create( &threadId, NULL, Blocker, NULL ); |
---|
70 | rtems_test_assert( status == 0 ); |
---|
71 | |
---|
72 | /* |
---|
73 | * Deliberately create the mutex after the threads. This way if the |
---|
74 | * threads do run before we intend, they will get an error. |
---|
75 | */ |
---|
76 | status = pthread_mutex_init( &MutexId, NULL ); |
---|
77 | rtems_test_assert( status == 0 ); |
---|
78 | |
---|
79 | /* |
---|
80 | * Ensure the mutex is unavailable so the other threads block. |
---|
81 | */ |
---|
82 | status = pthread_mutex_lock( &MutexId ); |
---|
83 | rtems_test_assert( status == 0 ); |
---|
84 | |
---|
85 | /* |
---|
86 | * Let the other thread start so the thread startup overhead, |
---|
87 | * is accounted for. When we return, we can start the benchmark. |
---|
88 | */ |
---|
89 | sched_yield(); |
---|
90 | /* let other thread run */ |
---|
91 | |
---|
92 | benchmark_timer_initialize(); |
---|
93 | status = pthread_mutex_unlock( &MutexId ); |
---|
94 | end_time = benchmark_timer_read(); |
---|
95 | rtems_test_assert( status == 0 ); |
---|
96 | |
---|
97 | put_time( |
---|
98 | "pthread_mutex_unlock: unblocking no preemption", |
---|
99 | end_time, |
---|
100 | 1, |
---|
101 | 0, |
---|
102 | 0 |
---|
103 | ); |
---|
104 | |
---|
105 | TEST_END(); |
---|
106 | rtems_test_exit( 0 ); |
---|
107 | |
---|
108 | return NULL; |
---|
109 | } |
---|
110 | |
---|
111 | /* configuration information */ |
---|
112 | |
---|
113 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
114 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
115 | |
---|
116 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 2 |
---|
117 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
118 | |
---|
119 | #define CONFIGURE_INIT |
---|
120 | |
---|
121 | #include <rtems/confdefs.h> |
---|
122 | /* end of file */ |
---|