|
3 | 3 | * Copyright (c) 2014-2020 Fujitsu Ltd.
|
4 | 4 | * Author: Xiaoguang Wang <[email protected]>
|
5 | 5 | *
|
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. |
7 | 22 | */
|
8 | 23 |
|
9 | 24 | #define _GNU_SOURCE
|
@@ -33,13 +48,18 @@ static void cleanup(void)
|
33 | 48 | SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
|
34 | 49 | }
|
35 | 50 |
|
36 |
| -static void test_msg_except(void) |
| 51 | +static void prepare_queue(void) |
37 | 52 | {
|
38 | 53 | queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
|
39 | 54 | SAFE_MSGSND(queue_id, &snd_buf[0], MSGSIZE, 0);
|
40 | 55 | SAFE_MSGSND(queue_id, &snd_buf[1], MSGSIZE, 0);
|
41 |
| - |
42 | 56 | memset(&rcv_buf, 0, sizeof(rcv_buf));
|
| 57 | +} |
| 58 | + |
| 59 | +static void test_msg_except(void) |
| 60 | +{ |
| 61 | + prepare_queue(); |
| 62 | + |
43 | 63 | TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, MSGTYPE2, MSG_EXCEPT));
|
44 | 64 | if (TST_RET == -1) {
|
45 | 65 | tst_res(TFAIL | TTERRNO, "msgrcv(MSG_EXCEPT) failed");
|
@@ -77,12 +97,73 @@ static void test_msg_noerror(void)
|
77 | 97 | SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
|
78 | 98 | }
|
79 | 99 |
|
| 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 | + |
80 | 159 | static void setup(void)
|
81 | 160 | {
|
82 | 161 | msgkey = GETIPCKEY();
|
83 | 162 | }
|
84 | 163 |
|
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}; |
86 | 167 |
|
87 | 168 | static void verify_msgcrv(unsigned int n)
|
88 | 169 | {
|
|
0 commit comments