<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jun 24, 2021 at 2:16 PM Yang Xu <<a href="mailto:xuyang2018.jy@fujitsu.com">xuyang2018.jy@fujitsu.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Even msgget() failed, this for loop still continues. So we can't know whether<br>
system creates actual MSGMNI message queues and then fail with ENOSPC. Fix this by<br>
reporting fail if msgget failed in setup.<br>
<br>
Also make use of TST_EXP_FAIL2 macro.<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">Do we have TST_EXP_FAIL2 macro? or do you mean TST_EXP_FAIL?</div><div class="gmail_default" style="font-size:small"></div><div class="gmail_default" style="font-size:small">And the remaining part looks good.</div><div class="gmail_default" style="font-size:small"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Signed-off-by: Yang Xu <<a href="mailto:xuyang2018.jy@fujitsu.com" target="_blank">xuyang2018.jy@fujitsu.com</a>><br>
---<br>
 .../kernel/syscalls/ipc/msgget/msgget03.c     | 21 +++++++------------<br>
 1 file changed, 7 insertions(+), 14 deletions(-)<br>
<br>
diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget03.c b/testcases/kernel/syscalls/ipc/msgget/msgget03.c<br>
index 8fa620855..da3753a19 100644<br>
--- a/testcases/kernel/syscalls/ipc/msgget/msgget03.c<br>
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget03.c<br>
@@ -20,22 +20,14 @@<br>
 #include "tst_safe_sysv_ipc.h"<br>
 #include "libnewipc.h"<br>
<br>
-static int maxmsgs;<br>
+static int maxmsgs, queue_cnt;<br>
 static int *queues;<br>
 static key_t msgkey;<br>
<br>
 static void verify_msgget(void)<br>
 {<br>
-       TEST(msgget(msgkey + maxmsgs, IPC_CREAT | IPC_EXCL));<br>
-       if (TST_RET != -1)<br>
-               tst_res(TFAIL, "msgget() succeeded unexpectedly");<br>
-<br>
-       if (TST_ERR == ENOSPC) {<br>
-               tst_res(TPASS | TTERRNO, "msgget() failed as expected");<br>
-       } else {<br>
-               tst_res(TFAIL | TTERRNO, "msgget() failed unexpectedly,"<br>
-                       " expected ENOSPC");<br>
-       }<br>
+       TST_EXP_FAIL2(msgget(msgkey + maxmsgs, IPC_CREAT | IPC_EXCL), ENOSPC,<br>
+               "msgget(%i, %i)", msgkey + maxmsgs, IPC_CREAT | IPC_EXCL);<br>
 }<br>
<br>
 static void setup(void)<br>
@@ -52,8 +44,9 @@ static void setup(void)<br>
                queues[num] = -1;<br>
<br>
                res = msgget(msgkey + num, IPC_CREAT | IPC_EXCL);<br>
-               if (res != -1)<br>
-                       queues[num] = res;<br>
+               if (res == -1)<br>
+                       tst_brk(TBROK | TERRNO, "msgget failed unexpectedly");<br>
+               queues[queue_cnt++] = res;<br>
        }<br>
<br>
        tst_res(TINFO, "The maximum number of message queues (%d) reached",<br>
@@ -67,7 +60,7 @@ static void cleanup(void)<br>
        if (!queues)<br>
                return;<br>
<br>
-       for (num = 0; num < maxmsgs; num++) {<br>
+       for (num = 0; num < queue_cnt; num++) {<br>
                if (queues[num] != -1)<br>
                        SAFE_MSGCTL(queues[num], IPC_RMID, NULL);<br>
        }<br>
-- <br>
2.23.0<br>
<br>
<br>
-- <br>
Mailing list info: <a href="https://lists.linux.it/listinfo/ltp" rel="noreferrer" target="_blank">https://lists.linux.it/listinfo/ltp</a><br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>