All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] ipc/msgget03: Make sure we get ENOSPC error after creating MSGMNI message queues
@ 2021-06-24  6:16 Yang Xu
  2021-06-25  9:03 ` Li Wang
  0 siblings, 1 reply; 5+ messages in thread
From: Yang Xu @ 2021-06-24  6:16 UTC (permalink / raw)
  To: ltp

Even msgget() failed, this for loop still continues. So we can't know whether
system creates actual MSGMNI message queues and then fail with ENOSPC. Fix this by
reporting fail if msgget failed in setup.

Also make use of TST_EXP_FAIL2 macro.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 .../kernel/syscalls/ipc/msgget/msgget03.c     | 21 +++++++------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget03.c b/testcases/kernel/syscalls/ipc/msgget/msgget03.c
index 8fa620855..da3753a19 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget03.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget03.c
@@ -20,22 +20,14 @@
 #include "tst_safe_sysv_ipc.h"
 #include "libnewipc.h"
 
-static int maxmsgs;
+static int maxmsgs, queue_cnt;
 static int *queues;
 static key_t msgkey;
 
 static void verify_msgget(void)
 {
-	TEST(msgget(msgkey + maxmsgs, IPC_CREAT | IPC_EXCL));
-	if (TST_RET != -1)
-		tst_res(TFAIL, "msgget() succeeded unexpectedly");
-
-	if (TST_ERR == ENOSPC) {
-		tst_res(TPASS | TTERRNO, "msgget() failed as expected");
-	} else {
-		tst_res(TFAIL | TTERRNO, "msgget() failed unexpectedly,"
-			" expected ENOSPC");
-	}
+	TST_EXP_FAIL2(msgget(msgkey + maxmsgs, IPC_CREAT | IPC_EXCL), ENOSPC,
+		"msgget(%i, %i)", msgkey + maxmsgs, IPC_CREAT | IPC_EXCL);
 }
 
 static void setup(void)
@@ -52,8 +44,9 @@ static void setup(void)
 		queues[num] = -1;
 
 		res = msgget(msgkey + num, IPC_CREAT | IPC_EXCL);
-		if (res != -1)
-			queues[num] = res;
+		if (res == -1)
+			tst_brk(TBROK | TERRNO, "msgget failed unexpectedly");
+		queues[queue_cnt++] = res;
 	}
 
 	tst_res(TINFO, "The maximum number of message queues (%d) reached",
@@ -67,7 +60,7 @@ static void cleanup(void)
 	if (!queues)
 		return;
 
-	for (num = 0; num < maxmsgs; num++) {
+	for (num = 0; num < queue_cnt; num++) {
 		if (queues[num] != -1)
 			SAFE_MSGCTL(queues[num], IPC_RMID, NULL);
 	}
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH] ipc/msgget03: Make sure we get ENOSPC error after creating MSGMNI message queues
  2021-06-24  6:16 [LTP] [PATCH] ipc/msgget03: Make sure we get ENOSPC error after creating MSGMNI message queues Yang Xu
@ 2021-06-25  9:03 ` Li Wang
  2021-06-25  9:23   ` xuyang2018.jy
  2021-06-29  1:40   ` [LTP] [PATCH v2] " Yang Xu
  0 siblings, 2 replies; 5+ messages in thread
From: Li Wang @ 2021-06-25  9:03 UTC (permalink / raw)
  To: ltp

On Thu, Jun 24, 2021 at 2:16 PM Yang Xu <xuyang2018.jy@fujitsu.com> wrote:

> Even msgget() failed, this for loop still continues. So we can't know
> whether
> system creates actual MSGMNI message queues and then fail with ENOSPC. Fix
> this by
> reporting fail if msgget failed in setup.
>
> Also make use of TST_EXP_FAIL2 macro.
>

Do we have TST_EXP_FAIL2 macro? or do you mean TST_EXP_FAIL?
And the remaining part looks good.


> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
>  .../kernel/syscalls/ipc/msgget/msgget03.c     | 21 +++++++------------
>  1 file changed, 7 insertions(+), 14 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget03.c
> b/testcases/kernel/syscalls/ipc/msgget/msgget03.c
> index 8fa620855..da3753a19 100644
> --- a/testcases/kernel/syscalls/ipc/msgget/msgget03.c
> +++ b/testcases/kernel/syscalls/ipc/msgget/msgget03.c
> @@ -20,22 +20,14 @@
>  #include "tst_safe_sysv_ipc.h"
>  #include "libnewipc.h"
>
> -static int maxmsgs;
> +static int maxmsgs, queue_cnt;
>  static int *queues;
>  static key_t msgkey;
>
>  static void verify_msgget(void)
>  {
> -       TEST(msgget(msgkey + maxmsgs, IPC_CREAT | IPC_EXCL));
> -       if (TST_RET != -1)
> -               tst_res(TFAIL, "msgget() succeeded unexpectedly");
> -
> -       if (TST_ERR == ENOSPC) {
> -               tst_res(TPASS | TTERRNO, "msgget() failed as expected");
> -       } else {
> -               tst_res(TFAIL | TTERRNO, "msgget() failed unexpectedly,"
> -                       " expected ENOSPC");
> -       }
> +       TST_EXP_FAIL2(msgget(msgkey + maxmsgs, IPC_CREAT | IPC_EXCL),
> ENOSPC,
> +               "msgget(%i, %i)", msgkey + maxmsgs, IPC_CREAT | IPC_EXCL);
>  }
>
>  static void setup(void)
> @@ -52,8 +44,9 @@ static void setup(void)
>                 queues[num] = -1;
>
>                 res = msgget(msgkey + num, IPC_CREAT | IPC_EXCL);
> -               if (res != -1)
> -                       queues[num] = res;
> +               if (res == -1)
> +                       tst_brk(TBROK | TERRNO, "msgget failed
> unexpectedly");
> +               queues[queue_cnt++] = res;
>         }
>
>         tst_res(TINFO, "The maximum number of message queues (%d) reached",
> @@ -67,7 +60,7 @@ static void cleanup(void)
>         if (!queues)
>                 return;
>
> -       for (num = 0; num < maxmsgs; num++) {
> +       for (num = 0; num < queue_cnt; num++) {
>                 if (queues[num] != -1)
>                         SAFE_MSGCTL(queues[num], IPC_RMID, NULL);
>         }
> --
> 2.23.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210625/9f3cb97a/attachment.htm>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] [PATCH] ipc/msgget03: Make sure we get ENOSPC error after creating MSGMNI message queues
  2021-06-25  9:03 ` Li Wang
@ 2021-06-25  9:23   ` xuyang2018.jy
  2021-06-29  1:40   ` [LTP] [PATCH v2] " Yang Xu
  1 sibling, 0 replies; 5+ messages in thread
From: xuyang2018.jy @ 2021-06-25  9:23 UTC (permalink / raw)
  To: ltp

Hi Li
>
>
> On Thu, Jun 24, 2021 at 2:16 PM Yang Xu <xuyang2018.jy@fujitsu.com
> <mailto:xuyang2018.jy@fujitsu.com>> wrote:
>
>     Even msgget() failed, this for loop still continues. So we can't
>     know whether
>     system creates actual MSGMNI message queues and then fail with
>     ENOSPC. Fix this by
>     reporting fail if msgget failed in setup.
>
>     Also make use of TST_EXP_FAIL2 macro.
>
>
> Do we have TST_EXP_FAIL2 macro? or do you mean TST_EXP_FAIL?
> And the remaining part looks good.
Sorry. I should have added this macro implementation url(In review).
https://patchwork.ozlabs.org/project/ltp/patch/1624512827-3256-2-git-send-email-xuyang2018.jy@fujitsu.com/

Best Regards
Yang Xu

>
>
>     Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com
>     <mailto:xuyang2018.jy@fujitsu.com>>
>     ---
>     .../kernel/syscalls/ipc/msgget/msgget03.c | 21 +++++++------------
>     1 file changed, 7 insertions(+), 14 deletions(-)
>
>     diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget03.c
>     b/testcases/kernel/syscalls/ipc/msgget/msgget03.c
>     index 8fa620855..da3753a19 100644
>     --- a/testcases/kernel/syscalls/ipc/msgget/msgget03.c
>     +++ b/testcases/kernel/syscalls/ipc/msgget/msgget03.c
>     @@ -20,22 +20,14 @@
>     #include "tst_safe_sysv_ipc.h"
>     #include "libnewipc.h"
>
>     -static int maxmsgs;
>     +static int maxmsgs, queue_cnt;
>     static int *queues;
>     static key_t msgkey;
>
>     static void verify_msgget(void)
>     {
>     - TEST(msgget(msgkey + maxmsgs, IPC_CREAT | IPC_EXCL));
>     - if (TST_RET != -1)
>     - tst_res(TFAIL, "msgget() succeeded unexpectedly");
>     -
>     - if (TST_ERR == ENOSPC) {
>     - tst_res(TPASS | TTERRNO, "msgget() failed as expected");
>     - } else {
>     - tst_res(TFAIL | TTERRNO, "msgget() failed unexpectedly,"
>     - " expected ENOSPC");
>     - }
>     + TST_EXP_FAIL2(msgget(msgkey + maxmsgs, IPC_CREAT | IPC_EXCL), ENOSPC,
>     + "msgget(%i, %i)", msgkey + maxmsgs, IPC_CREAT | IPC_EXCL);
>     }
>
>     static void setup(void)
>     @@ -52,8 +44,9 @@ static void setup(void)
>     queues[num] = -1;
>
>     res = msgget(msgkey + num, IPC_CREAT | IPC_EXCL);
>     - if (res != -1)
>     - queues[num] = res;
>     + if (res == -1)
>     + tst_brk(TBROK | TERRNO, "msgget failed unexpectedly");
>     + queues[queue_cnt++] = res;
>     }
>
>     tst_res(TINFO, "The maximum number of message queues (%d) reached",
>     @@ -67,7 +60,7 @@ static void cleanup(void)
>     if (!queues)
>     return;
>
>     - for (num = 0; num < maxmsgs; num++) {
>     + for (num = 0; num < queue_cnt; num++) {
>     if (queues[num] != -1)
>     SAFE_MSGCTL(queues[num], IPC_RMID, NULL);
>     }
>     --
>     2.23.0
>
>
>     --
>     Mailing list info: https://lists.linux.it/listinfo/ltp
>
>
>
> --
> Regards,
> Li Wang

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v2] ipc/msgget03: Make sure we get ENOSPC error after creating MSGMNI message queues
  2021-06-25  9:03 ` Li Wang
  2021-06-25  9:23   ` xuyang2018.jy
@ 2021-06-29  1:40   ` Yang Xu
  2021-06-29 10:10     ` Li Wang
  1 sibling, 1 reply; 5+ messages in thread
From: Yang Xu @ 2021-06-29  1:40 UTC (permalink / raw)
  To: ltp

Even msgget() failed, this for loop in setup phase still continues. So we can't know
whether system creates actual MSGMNI message queues and then fail with ENOSPC. Fix this by
reporting fail if msgget failed in setup.

Also make use of TST_EXP_FAIL2 macro. It has been introduced in the previous commit
95f518efe ("include/tst_test_macro.h: Add TST_EXP_FAIL2 macros").

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
v1->v2: Remove check for -1 and pre-initialize the array
 .../kernel/syscalls/ipc/msgget/msgget03.c     | 27 ++++++-------------
 1 file changed, 8 insertions(+), 19 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget03.c b/testcases/kernel/syscalls/ipc/msgget/msgget03.c
index 8fa620855..76cf82cd3 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget03.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget03.c
@@ -20,22 +20,14 @@
 #include "tst_safe_sysv_ipc.h"
 #include "libnewipc.h"
 
-static int maxmsgs;
+static int maxmsgs, queue_cnt;
 static int *queues;
 static key_t msgkey;
 
 static void verify_msgget(void)
 {
-	TEST(msgget(msgkey + maxmsgs, IPC_CREAT | IPC_EXCL));
-	if (TST_RET != -1)
-		tst_res(TFAIL, "msgget() succeeded unexpectedly");
-
-	if (TST_ERR == ENOSPC) {
-		tst_res(TPASS | TTERRNO, "msgget() failed as expected");
-	} else {
-		tst_res(TFAIL | TTERRNO, "msgget() failed unexpectedly,"
-			" expected ENOSPC");
-	}
+	TST_EXP_FAIL2(msgget(msgkey + maxmsgs, IPC_CREAT | IPC_EXCL), ENOSPC,
+		"msgget(%i, %i)", msgkey + maxmsgs, IPC_CREAT | IPC_EXCL);
 }
 
 static void setup(void)
@@ -49,11 +41,10 @@ static void setup(void)
 	queues = SAFE_MALLOC(maxmsgs * sizeof(int));
 
 	for (num = 0; num < maxmsgs; num++) {
-		queues[num] = -1;
-
 		res = msgget(msgkey + num, IPC_CREAT | IPC_EXCL);
-		if (res != -1)
-			queues[num] = res;
+		if (res == -1)
+			tst_brk(TBROK | TERRNO, "msgget failed unexpectedly");
+		queues[queue_cnt++] = res;
 	}
 
 	tst_res(TINFO, "The maximum number of message queues (%d) reached",
@@ -67,10 +58,8 @@ static void cleanup(void)
 	if (!queues)
 		return;
 
-	for (num = 0; num < maxmsgs; num++) {
-		if (queues[num] != -1)
-			SAFE_MSGCTL(queues[num], IPC_RMID, NULL);
-	}
+	for (num = 0; num < queue_cnt; num++)
+		SAFE_MSGCTL(queues[num], IPC_RMID, NULL);
 
 	free(queues);
 }
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v2] ipc/msgget03: Make sure we get ENOSPC error after creating MSGMNI message queues
  2021-06-29  1:40   ` [LTP] [PATCH v2] " Yang Xu
@ 2021-06-29 10:10     ` Li Wang
  0 siblings, 0 replies; 5+ messages in thread
From: Li Wang @ 2021-06-29 10:10 UTC (permalink / raw)
  To: ltp

Hi Xu,

Patch applied, thanks.

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210629/af3ce3d3/attachment.htm>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-29 10:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-24  6:16 [LTP] [PATCH] ipc/msgget03: Make sure we get ENOSPC error after creating MSGMNI message queues Yang Xu
2021-06-25  9:03 ` Li Wang
2021-06-25  9:23   ` xuyang2018.jy
2021-06-29  1:40   ` [LTP] [PATCH v2] " Yang Xu
2021-06-29 10:10     ` Li Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.