|
12 | 12 | #include "libnewipc.h"
|
13 | 13 |
|
14 | 14 | static key_t msgkey;
|
15 |
| -static int queue_id = -1; |
| 15 | +static int queue_id = -1, pid; |
16 | 16 | static struct buf {
|
17 | 17 | long type;
|
18 | 18 | char mtext[MSGSIZE];
|
19 | 19 | } rcv_buf, snd_buf = {MSGTYPE, "hello"};
|
20 | 20 |
|
21 | 21 | static void verify_msgrcv(void)
|
22 | 22 | {
|
| 23 | + struct msqid_ds qs_buf; |
| 24 | + time_t before_rcv, after_rcv; |
| 25 | + |
23 | 26 | SAFE_MSGSND(queue_id, &snd_buf, MSGSIZE, 0);
|
24 | 27 |
|
| 28 | + time(&before_rcv); |
25 | 29 | TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, 1, 0));
|
26 | 30 | if (TST_RET == -1) {
|
27 | 31 | tst_res(TFAIL | TTERRNO, "msgrcv failed");
|
28 | 32 | return;
|
29 | 33 | }
|
| 34 | + time(&after_rcv); |
| 35 | + |
30 | 36 | if (strcmp(rcv_buf.mtext, snd_buf.mtext) == 0)
|
31 | 37 | tst_res(TPASS, "message received(%s) = message sent(%s)",
|
32 | 38 | rcv_buf.mtext, snd_buf.mtext);
|
33 | 39 | else
|
34 | 40 | tst_res(TFAIL, "message received(%s) != message sent(%s)",
|
35 | 41 | 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 | + } |
36 | 62 | }
|
37 | 63 |
|
38 | 64 | static void setup(void)
|
39 | 65 | {
|
40 | 66 | msgkey = GETIPCKEY();
|
41 | 67 | queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
|
| 68 | + pid = getpid(); |
42 | 69 | }
|
43 | 70 |
|
44 | 71 | static void cleanup(void)
|
|
0 commit comments