1 | /* |
---|
2 | * COPYRIGHT (c) 2018. |
---|
3 | * Himanshu Sekhar Nayak |
---|
4 | * |
---|
5 | * Permission to use, copy, modify, and/or distribute this software |
---|
6 | * for any purpose with or without fee is hereby granted. |
---|
7 | * |
---|
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
---|
9 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
---|
10 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR |
---|
11 | * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES |
---|
12 | * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
---|
13 | * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, |
---|
14 | * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
---|
15 | */ |
---|
16 | |
---|
17 | #ifdef HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <fcntl.h> |
---|
22 | #include <timesys.h> |
---|
23 | #include <rtems/btimer.h> |
---|
24 | #include <tmacros.h> |
---|
25 | #include "test_support.h" |
---|
26 | #include <sched.h> |
---|
27 | #include <pthread.h> |
---|
28 | #include <mqueue.h> |
---|
29 | #include <signal.h> |
---|
30 | |
---|
31 | const char rtems_test_name[] = "PSXTMMQRCVBLOCK 02"; |
---|
32 | |
---|
33 | /* forward declarations to avoid warnings */ |
---|
34 | void *POSIX_Init(void *argument); |
---|
35 | void *Middle(void *argument); |
---|
36 | void *Low(void *argument); |
---|
37 | |
---|
38 | #define MQ_MAXMSG 1 |
---|
39 | #define MQ_MSGSIZE sizeof(int) |
---|
40 | |
---|
41 | static mqd_t queue; |
---|
42 | int message[MQ_MAXMSG]; |
---|
43 | const char *q_name; |
---|
44 | unsigned int priority; |
---|
45 | struct timespec timeout; |
---|
46 | |
---|
47 | void *POSIX_Init( |
---|
48 | void *argument |
---|
49 | ) |
---|
50 | { |
---|
51 | int i; |
---|
52 | int status; |
---|
53 | int oflag = O_CREAT |O_RDWR; |
---|
54 | pthread_t threadId; |
---|
55 | struct mq_attr attr; |
---|
56 | |
---|
57 | priority = 0; |
---|
58 | timeout.tv_sec = 0; |
---|
59 | timeout.tv_nsec = 0; |
---|
60 | attr.mq_maxmsg = MQ_MAXMSG; |
---|
61 | attr.mq_msgsize = MQ_MSGSIZE; |
---|
62 | |
---|
63 | TEST_BEGIN(); |
---|
64 | |
---|
65 | for ( i=0 ; i < OPERATION_COUNT - 1 ; i++ ) { |
---|
66 | status = pthread_create( &threadId, NULL, Middle, NULL ); |
---|
67 | rtems_test_assert( !status ); |
---|
68 | } |
---|
69 | |
---|
70 | status = pthread_create( &threadId, NULL, Low, NULL ); |
---|
71 | rtems_test_assert( !status ); |
---|
72 | |
---|
73 | queue = mq_open( "queue", oflag, 0x777, &attr ); |
---|
74 | |
---|
75 | /* let other threads run */ |
---|
76 | sched_yield(); |
---|
77 | |
---|
78 | /* now run the benchmark */ |
---|
79 | benchmark_timer_initialize(); |
---|
80 | status = mq_timedreceive( |
---|
81 | queue, (char *)message, MQ_MSGSIZE, &priority, &timeout); |
---|
82 | return NULL; |
---|
83 | } |
---|
84 | |
---|
85 | void *Middle( |
---|
86 | void *argument |
---|
87 | ) |
---|
88 | { |
---|
89 | sched_yield(); |
---|
90 | |
---|
91 | /* let other threads run */ |
---|
92 | |
---|
93 | (void) mq_timedreceive( |
---|
94 | queue, (char *)message, MQ_MSGSIZE, &priority, &timeout); |
---|
95 | |
---|
96 | return NULL; |
---|
97 | } |
---|
98 | |
---|
99 | void *Low( |
---|
100 | void *argument |
---|
101 | ) |
---|
102 | { |
---|
103 | benchmark_timer_t end_time; |
---|
104 | |
---|
105 | sched_yield(); |
---|
106 | |
---|
107 | end_time = benchmark_timer_read(); |
---|
108 | |
---|
109 | put_time( |
---|
110 | "mq_timedreceive: not available: block", |
---|
111 | end_time, |
---|
112 | OPERATION_COUNT, |
---|
113 | 0, |
---|
114 | 0 |
---|
115 | ); |
---|
116 | |
---|
117 | TEST_END(); |
---|
118 | |
---|
119 | rtems_test_exit( 0 ); |
---|
120 | return NULL; |
---|
121 | } |
---|
122 | |
---|
123 | /* configuration information */ |
---|
124 | |
---|
125 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
126 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
127 | |
---|
128 | #define CONFIGURE_MAXIMUM_POSIX_THREADS OPERATION_COUNT + 2 |
---|
129 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
130 | |
---|
131 | #define CONFIGURE_INIT |
---|
132 | |
---|
133 | #include <rtems/confdefs.h> |
---|
134 | /* end of file */ |
---|