Skip to content

Commit f490d38

Browse files
xuyang0410metan-ucw
authored andcommitted
syscalls/msgrcv07: Add different msgtyp test
After lookging msgcrv(2) man-page, the different msgtyp has the following effect: 1) If msgtyp is 0, then the first message in the queue is read. 2) If msgtyp is greater than 0, then the first message in the queue of type msgtyp is read. 3) If msgtyp is less than 0, then the first message in the queue with the lowest type less than or equal to the absolute value of msgtyp will be read. Signed-off-by: Yang Xu <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]>
1 parent 63e2a09 commit f490d38

File tree

1 file changed

+85
-4
lines changed

1 file changed

+85
-4
lines changed

testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,22 @@
33
* Copyright (c) 2014-2020 Fujitsu Ltd.
44
* Author: Xiaoguang Wang <[email protected]>
55
*
6-
* Basic test for msgrcv(2) using MSG_EXCEPT, MSG_NOERROR
6+
* Basic test for msgrcv(2) using MSG_EXCEPT, MSG_NOERROR and different
7+
* msg_typ(zero,positive,negative).
8+
*
9+
* * With MSG_EXCEPT flag any message type but the one passed to the function
10+
* is received.
11+
*
12+
* * With MSG_NOERROR and buffer size less than message size only part of the
13+
* buffer is received.
14+
*
15+
* * With msgtyp is 0, then the first message in the queue is read.
16+
*
17+
* * With msgtyp is greater than 0, then the first message in the queue of type
18+
* msgtyp is read.
19+
*
20+
* * With msgtyp is less than 0, then the first message in the queue with the
21+
* lowest type less than or equal to absolute value of msgtyp is received.
722
*/
823

924
#define _GNU_SOURCE
@@ -33,13 +48,18 @@ static void cleanup(void)
3348
SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
3449
}
3550

36-
static void test_msg_except(void)
51+
static void prepare_queue(void)
3752
{
3853
queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
3954
SAFE_MSGSND(queue_id, &snd_buf[0], MSGSIZE, 0);
4055
SAFE_MSGSND(queue_id, &snd_buf[1], MSGSIZE, 0);
41-
4256
memset(&rcv_buf, 0, sizeof(rcv_buf));
57+
}
58+
59+
static void test_msg_except(void)
60+
{
61+
prepare_queue();
62+
4363
TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, MSGTYPE2, MSG_EXCEPT));
4464
if (TST_RET == -1) {
4565
tst_res(TFAIL | TTERRNO, "msgrcv(MSG_EXCEPT) failed");
@@ -77,12 +97,73 @@ static void test_msg_noerror(void)
7797
SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
7898
}
7999

100+
static void test_zero_msgtyp(void)
101+
{
102+
prepare_queue();
103+
104+
TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, 0, 0));
105+
if (TST_RET == -1) {
106+
tst_res(TFAIL | TTERRNO, "msgrcv(zero_msgtyp) failed");
107+
cleanup();
108+
return;
109+
}
110+
tst_res(TPASS, "msgrcv(zero_msgtyp) succeeded");
111+
if (strcmp(rcv_buf.mtext, MSG1) == 0 && rcv_buf.type == MSGTYPE1)
112+
tst_res(TPASS, "msgrcv(zero_msgtyp) got the first message");
113+
else
114+
tst_res(TFAIL, "msgrcv(zero_msgtyp) didn't get the first message");
115+
SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
116+
}
117+
118+
static void test_positive_msgtyp(void)
119+
{
120+
prepare_queue();
121+
122+
TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, MSGTYPE2, 0));
123+
if (TST_RET == -1) {
124+
tst_res(TFAIL | TTERRNO, "msgrcv(positive_msgtyp) failed");
125+
cleanup();
126+
return;
127+
}
128+
tst_res(TPASS, "msgrcv(positive_msgtyp) succeeded");
129+
if (strcmp(rcv_buf.mtext, MSG2) == 0 && rcv_buf.type == MSGTYPE2)
130+
tst_res(TPASS, "msgrcv(positive_msgtyp) got the first message"
131+
" in the queue of type msgtyp");
132+
else
133+
tst_res(TFAIL, "msgrcv(positive_msgtyp) didn't get the first "
134+
"message in the queue of type msgtyp");
135+
SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
136+
}
137+
138+
static void test_negative_msgtyp(void)
139+
{
140+
prepare_queue();
141+
142+
TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, -MSGTYPE2, 0));
143+
if (TST_RET == -1) {
144+
tst_res(TFAIL | TTERRNO, "msgrcv(negative_msgtyp) failed");
145+
cleanup();
146+
return;
147+
}
148+
tst_res(TPASS, "msgrcv(negative_msgtyp) succeeded");
149+
if (strcmp(rcv_buf.mtext, MSG1) == 0 && rcv_buf.type == MSGTYPE1)
150+
tst_res(TPASS, "msgrcv(negative_msgtyp) got the first message"
151+
" in the queue with the lowest type");
152+
else
153+
tst_res(TFAIL, "msgrcv(negative_msgtyp) didn't get the first "
154+
"message in the queue with the lowest type");
155+
SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
156+
}
157+
158+
80159
static void setup(void)
81160
{
82161
msgkey = GETIPCKEY();
83162
}
84163

85-
static void (*testfunc[])(void) = {test_msg_except, test_msg_noerror};
164+
static void (*testfunc[])(void) = {test_msg_except, test_msg_noerror,
165+
test_zero_msgtyp, test_positive_msgtyp,
166+
test_negative_msgtyp};
86167

87168
static void verify_msgcrv(unsigned int n)
88169
{

0 commit comments

Comments
 (0)