1 | /* |
---|
2 | * SPDX-License-Identifier: BSD-2-Clause |
---|
3 | * |
---|
4 | * Copyright (C) 2018, Himanshu Sekhar Nayak |
---|
5 | * |
---|
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. |
---|
26 | */ |
---|
27 | |
---|
28 | #ifdef HAVE_CONFIG_H |
---|
29 | #include "config.h" |
---|
30 | #endif |
---|
31 | |
---|
32 | #include <fcntl.h> |
---|
33 | #include <timesys.h> |
---|
34 | #include <rtems/btimer.h> |
---|
35 | #include <tmacros.h> |
---|
36 | #include "test_support.h" |
---|
37 | #include <sched.h> |
---|
38 | #include <pthread.h> |
---|
39 | #include <mqueue.h> |
---|
40 | #include <signal.h> |
---|
41 | |
---|
42 | const char rtems_test_name[] = "PSXTMMQRCVBLOCK 02"; |
---|
43 | |
---|
44 | /* forward declarations to avoid warnings */ |
---|
45 | void *POSIX_Init(void *argument); |
---|
46 | void *Middle(void *argument); |
---|
47 | void *Low(void *argument); |
---|
48 | |
---|
49 | #define MQ_MAXMSG 1 |
---|
50 | #define MQ_MSGSIZE sizeof(int) |
---|
51 | |
---|
52 | static mqd_t queue; |
---|
53 | int message[MQ_MAXMSG]; |
---|
54 | const char *q_name; |
---|
55 | unsigned int priority; |
---|
56 | struct timespec timeout; |
---|
57 | |
---|
58 | void *POSIX_Init( |
---|
59 | void *argument |
---|
60 | ) |
---|
61 | { |
---|
62 | int i; |
---|
63 | int status; |
---|
64 | int oflag = O_CREAT |O_RDWR; |
---|
65 | pthread_t threadId; |
---|
66 | struct mq_attr attr; |
---|
67 | |
---|
68 | priority = 0; |
---|
69 | timeout.tv_sec = 0; |
---|
70 | timeout.tv_nsec = 0; |
---|
71 | attr.mq_maxmsg = MQ_MAXMSG; |
---|
72 | attr.mq_msgsize = MQ_MSGSIZE; |
---|
73 | |
---|
74 | TEST_BEGIN(); |
---|
75 | |
---|
76 | for ( i=0 ; i < OPERATION_COUNT - 1 ; i++ ) { |
---|
77 | status = pthread_create( &threadId, NULL, Middle, NULL ); |
---|
78 | rtems_test_assert( !status ); |
---|
79 | } |
---|
80 | |
---|
81 | status = pthread_create( &threadId, NULL, Low, NULL ); |
---|
82 | rtems_test_assert( !status ); |
---|
83 | |
---|
84 | queue = mq_open( "queue", oflag, 0x777, &attr ); |
---|
85 | |
---|
86 | /* let other threads run */ |
---|
87 | sched_yield(); |
---|
88 | |
---|
89 | /* now run the benchmark */ |
---|
90 | benchmark_timer_initialize(); |
---|
91 | status = mq_timedreceive( |
---|
92 | queue, (char *)message, MQ_MSGSIZE, &priority, &timeout); |
---|
93 | return NULL; |
---|
94 | } |
---|
95 | |
---|
96 | void *Middle( |
---|
97 | void *argument |
---|
98 | ) |
---|
99 | { |
---|
100 | sched_yield(); |
---|
101 | |
---|
102 | /* let other threads run */ |
---|
103 | |
---|
104 | (void) mq_timedreceive( |
---|
105 | queue, (char *)message, MQ_MSGSIZE, &priority, &timeout); |
---|
106 | |
---|
107 | return NULL; |
---|
108 | } |
---|
109 | |
---|
110 | void *Low( |
---|
111 | void *argument |
---|
112 | ) |
---|
113 | { |
---|
114 | benchmark_timer_t end_time; |
---|
115 | |
---|
116 | sched_yield(); |
---|
117 | |
---|
118 | end_time = benchmark_timer_read(); |
---|
119 | |
---|
120 | put_time( |
---|
121 | "mq_timedreceive: not available: block", |
---|
122 | end_time, |
---|
123 | OPERATION_COUNT, |
---|
124 | 0, |
---|
125 | 0 |
---|
126 | ); |
---|
127 | |
---|
128 | TEST_END(); |
---|
129 | |
---|
130 | rtems_test_exit( 0 ); |
---|
131 | return NULL; |
---|
132 | } |
---|
133 | |
---|
134 | /* configuration information */ |
---|
135 | |
---|
136 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
137 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
138 | |
---|
139 | #define CONFIGURE_MAXIMUM_POSIX_THREADS OPERATION_COUNT + 2 |
---|
140 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
141 | |
---|
142 | #define CONFIGURE_INIT |
---|
143 | |
---|
144 | #include <rtems/confdefs.h> |
---|
145 | /* end of file */ |
---|