Skip to content

Commit b2d61f7

Browse files
xuyang0410metan-ucw
authored andcommitted
syscalls/msgrcv: Add check for msg_lrpid and msg_rtime
Signed-off-by: Yang Xu <[email protected]> Signed-off-by: Cyril Hrubis <[email protected]>
1 parent 42d3631 commit b2d61f7

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,60 @@
1212
#include "libnewipc.h"
1313

1414
static key_t msgkey;
15-
static int queue_id = -1;
15+
static int queue_id = -1, pid;
1616
static struct buf {
1717
long type;
1818
char mtext[MSGSIZE];
1919
} rcv_buf, snd_buf = {MSGTYPE, "hello"};
2020

2121
static void verify_msgrcv(void)
2222
{
23+
struct msqid_ds qs_buf;
24+
time_t before_rcv, after_rcv;
25+
2326
SAFE_MSGSND(queue_id, &snd_buf, MSGSIZE, 0);
2427

28+
time(&before_rcv);
2529
TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, 1, 0));
2630
if (TST_RET == -1) {
2731
tst_res(TFAIL | TTERRNO, "msgrcv failed");
2832
return;
2933
}
34+
time(&after_rcv);
35+
3036
if (strcmp(rcv_buf.mtext, snd_buf.mtext) == 0)
3137
tst_res(TPASS, "message received(%s) = message sent(%s)",
3238
rcv_buf.mtext, snd_buf.mtext);
3339
else
3440
tst_res(TFAIL, "message received(%s) != message sent(%s)",
3541
rcv_buf.mtext, snd_buf.mtext);
42+
43+
SAFE_MSGCTL(queue_id, IPC_STAT, &qs_buf);
44+
if (qs_buf.msg_cbytes == 0 && qs_buf.msg_qnum == 0)
45+
tst_res(TPASS, "queue bytes and number of queues matched");
46+
else
47+
tst_res(TFAIL, "queue bytes or number of queues mismatched");
48+
if (qs_buf.msg_lrpid == pid)
49+
tst_res(TPASS, "PID of last msgrcv(2) matched");
50+
else
51+
tst_res(TFAIL, "PID of last msgrcv(2) mismatched");
52+
53+
if (qs_buf.msg_rtime >= before_rcv && qs_buf.msg_rtime <= after_rcv) {
54+
tst_res(TPASS, "msg_rtime = %lu in [%lu, %lu]",
55+
(unsigned long)qs_buf.msg_rtime,
56+
(unsigned long)before_rcv, (unsigned long)after_rcv);
57+
} else {
58+
tst_res(TFAIL, "msg_rtime = %lu out of [%lu, %lu]",
59+
(unsigned long)qs_buf.msg_rtime,
60+
(unsigned long)before_rcv, (unsigned long)after_rcv);
61+
}
3662
}
3763

3864
static void setup(void)
3965
{
4066
msgkey = GETIPCKEY();
4167
queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
68+
pid = getpid();
4269
}
4370

4471
static void cleanup(void)

0 commit comments

Comments
 (0)