All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v1 0/3] increase msgrcv coverage
@ 2020-07-20  7:30 Yang Xu
  2020-07-20  7:30 ` [LTP] [PATCH v1 1/3] syscalls/msgrcv: Add check for msg_lrpid and msg_rtime Yang Xu
                   ` (4 more replies)
  0 siblings, 5 replies; 19+ messages in thread
From: Yang Xu @ 2020-07-20  7:30 UTC (permalink / raw)
  To: ltp

1. The first patch add check for msg_lrpid and msg_rtime.
2. The second patch tests different msgtyp.
3. The third patch tests MSG_COPY flag(basic error test),not functional
test because kernel selftest[1] has tested this.

[1]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/ipc/msgque.c

Yang Xu (3):
  syscalls/msgrcv: Add check for msg_lrpid and msg_rtime
  syscalls/msgrcv07: Add different msgtyp test
  syscalls/msgrcv09: Add error test for MSG_COPY flag

 include/lapi/msg.h                            | 15 +++
 runtest/syscalls                              |  1 +
 runtest/syscalls-ipc                          |  1 +
 .../kernel/syscalls/ipc/msgrcv/.gitignore     |  1 +
 .../kernel/syscalls/ipc/msgrcv/msgrcv01.c     | 28 +++++-
 .../kernel/syscalls/ipc/msgrcv/msgrcv07.c     | 81 +++++++++++++++-
 .../kernel/syscalls/ipc/msgrcv/msgrcv09.c     | 93 +++++++++++++++++++
 7 files changed, 215 insertions(+), 5 deletions(-)
 create mode 100644 include/lapi/msg.h
 create mode 100644 testcases/kernel/syscalls/ipc/msgrcv/msgrcv09.c

-- 
2.23.0




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

* [LTP] [PATCH v1 1/3] syscalls/msgrcv: Add check for msg_lrpid and msg_rtime
  2020-07-20  7:30 [LTP] [PATCH v1 0/3] increase msgrcv coverage Yang Xu
@ 2020-07-20  7:30 ` Yang Xu
  2020-08-13 12:53   ` Cyril Hrubis
  2020-07-20  7:30 ` [LTP] [PATCH v1 2/3] syscalls/msgrcv07: Add different msgtyp test Yang Xu
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 19+ messages in thread
From: Yang Xu @ 2020-07-20  7:30 UTC (permalink / raw)
  To: ltp

Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
 .../kernel/syscalls/ipc/msgrcv/msgrcv01.c     | 28 ++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c
index 204bf0575..3bdfa5b37 100644
--- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c
+++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c
@@ -12,7 +12,8 @@
 #include "libnewipc.h"
 
 static key_t msgkey;
-static int queue_id = -1;
+static time_t creat_time, last_rcv_time;
+static int queue_id = -1, pid;
 static struct buf {
 	long type;
 	char mtext[MSGSIZE];
@@ -20,6 +21,8 @@ static struct buf {
 
 static void verify_msgrcv(void)
 {
+	struct msqid_ds qs_buf;
+
 	SAFE_MSGSND(queue_id, &snd_buf, MSGSIZE, 0);
 
 	TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, 1, 0));
@@ -33,12 +36,35 @@ static void verify_msgrcv(void)
 	else
 		tst_res(TFAIL, "message received(%s) != message sent(%s)",
 			rcv_buf.mtext, snd_buf.mtext);
+
+	SAFE_MSGCTL(queue_id, IPC_STAT, &qs_buf);
+	if (qs_buf.msg_cbytes == 0 && qs_buf.msg_qnum == 0)
+		tst_res(TPASS, "queue bytes and number of queues matched");
+	else
+		tst_res(TFAIL, "queue bytes or number of queues mismatched");
+	if (qs_buf.msg_lrpid == pid)
+		tst_res(TPASS, "PID of last msgrcv(2) matched");
+	else
+		tst_res(TFAIL, "PID of last msgrcv(2) mismatched");
+
+	if (qs_buf.msg_rtime >= creat_time && qs_buf.msg_rtime >= last_rcv_time)
+		tst_res(TPASS, "create time = %lu, last_snd_time = %lu, msg_stime = %lu",
+			(unsigned long)creat_time, (unsigned long)last_rcv_time,
+			(unsigned long)qs_buf.msg_rtime);
+	else
+		tst_res(TFAIL, "create time = %lu, last_rcv_time = %lu, msg_rtime = %lu",
+			(unsigned long)creat_time, (unsigned long)last_rcv_time,
+			(unsigned long)qs_buf.msg_rtime);
+
+	last_rcv_time = qs_buf.msg_rtime;
 }
 
 static void setup(void)
 {
 	msgkey = GETIPCKEY();
 	queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
+	pid = getpid();
+	time(&creat_time);
 }
 
 static void cleanup(void)
-- 
2.23.0




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

* [LTP] [PATCH v1 2/3] syscalls/msgrcv07: Add different msgtyp test
  2020-07-20  7:30 [LTP] [PATCH v1 0/3] increase msgrcv coverage Yang Xu
  2020-07-20  7:30 ` [LTP] [PATCH v1 1/3] syscalls/msgrcv: Add check for msg_lrpid and msg_rtime Yang Xu
@ 2020-07-20  7:30 ` Yang Xu
  2020-08-13 14:11   ` Cyril Hrubis
  2020-07-20  7:30 ` [LTP] [PATCH v1 3/3] syscalls/msgrcv09: Add error test for MSG_COPY flag Yang Xu
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 19+ messages in thread
From: Yang Xu @ 2020-07-20  7:30 UTC (permalink / raw)
  To: ltp

After lookging msgcrv(2) man-page, the different msgtyp has the following effect:
1) If msgtyp is 0, then the first message in the queue is read.
2) If msgtyp is greater than 0, then the first message in the queue of type msgtyp is read.
3) If msgtyp is less than 0, then the first message in the queue with the lowest type less
 than or equal to the absolute value of msgtyp will be read.

Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
 .../kernel/syscalls/ipc/msgrcv/msgrcv07.c     | 81 ++++++++++++++++++-
 1 file changed, 77 insertions(+), 4 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
index 39fbdb67a..9b04fd2ac 100644
--- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
+++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
@@ -3,7 +3,8 @@
  * Copyright (c) 2014-2020 Fujitsu Ltd.
  * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
  *
- * Basic test for msgrcv(2) using MSG_EXCEPT, MSG_NOERROR
+ * Basic test for msgrcv(2) using MSG_EXCEPT, MSG_NOERROR and different
+ * msg_typ(zero,positive,negative).
  */
 
 #define  _GNU_SOURCE
@@ -22,15 +23,20 @@ static int queue_id = -1;
 static struct buf {
 	long type;
 	char mtext[MSGSIZE];
-} rcv_buf, snd_buf[2] = {
+} rcv_buf, snd_buf[3] = {
 	{MSGTYPE1, MSG1},
-	{MSGTYPE2, MSG2}
+	{MSGTYPE2, MSG2},
 };
 
 static void test_msg_except(void);
 static void test_msg_noerror(void);
+static void test_zero_msgtyp(void);
+static void test_positive_msgtyp(void);
+static void test_negative_msgtyp(void);
 static void cleanup(void);
-static void (*testfunc[])(void) = {test_msg_except, test_msg_noerror};
+static void (*testfunc[])(void) = {test_msg_except, test_msg_noerror,
+				   test_zero_msgtyp, test_positive_msgtyp,
+				   test_negative_msgtyp};
 
 static void verify_msgcrv(unsigned int n)
 {
@@ -81,6 +87,73 @@ static void test_msg_noerror(void)
 	SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
 }
 
+static void test_zero_msgtyp(void)
+{
+	queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
+	SAFE_MSGSND(queue_id, &snd_buf[0], MSGSIZE, 0);
+	SAFE_MSGSND(queue_id, &snd_buf[1], MSGSIZE, 0);
+	memset(&rcv_buf, 0, sizeof(rcv_buf));
+
+	TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, 0, 0));
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO, "msgrcv(zero_msgtyp) failed");
+		cleanup();
+		return;
+	}
+	tst_res(TPASS, "msgrcv(zero_msgtyp) succeeded");
+	if (strcmp(rcv_buf.mtext, MSG1) == 0 && rcv_buf.type == MSGTYPE1)
+		tst_res(TPASS, "msgrcv(zero_msgtyp) got the first message");
+	else
+		tst_res(TFAIL, "msgrcv(zero_msgtyp) didn't get the first message");
+	SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
+}
+
+static void test_positive_msgtyp(void)
+{
+	queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
+	SAFE_MSGSND(queue_id, &snd_buf[0], MSGSIZE, 0);
+	SAFE_MSGSND(queue_id, &snd_buf[1], MSGSIZE, 0);
+	memset(&rcv_buf, 0, sizeof(rcv_buf));
+
+	TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, MSGTYPE2, 0));
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO, "msgrcv(positive_msgtyp) failed");
+		cleanup();
+		return;
+	}
+	tst_res(TPASS, "msgrcv(positive_msgtyp) succeeded");
+	if (strcmp(rcv_buf.mtext, MSG2) == 0 && rcv_buf.type == MSGTYPE2)
+		tst_res(TPASS, "msgrcv(positive_msgtyp) got the first message"
+			       " in the queue of type msgtyp");
+	else
+		tst_res(TFAIL, "msgrcv(positive_msgtyp) didn't get the first "
+			       "message in the queue of type msgtyp");
+	SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
+}
+
+static void test_negative_msgtyp(void)
+{
+	queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
+	SAFE_MSGSND(queue_id, &snd_buf[0], MSGSIZE, 0);
+	SAFE_MSGSND(queue_id, &snd_buf[1], MSGSIZE, 0);
+	memset(&rcv_buf, 0, sizeof(rcv_buf));
+
+	TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, -MSGTYPE2, 0));
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO, "msgrcv(negative_msgtyp) failed");
+		cleanup();
+		return;
+	}
+	tst_res(TPASS, "msgrcv(negative_msgtyp) succeeded");
+	if (strcmp(rcv_buf.mtext, MSG1) == 0 && rcv_buf.type == MSGTYPE1)
+		tst_res(TPASS, "msgrcv(negative_msgtyp) got the first message"
+				" in the queue with the lowest type");
+	else
+		tst_res(TFAIL, "msgrcv(negative_msgtyp) didn't get the first "
+				"message in the queue with the lowest type");
+	SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
+}
+
 static void setup(void)
 {
 	msgkey = GETIPCKEY();
-- 
2.23.0




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

* [LTP] [PATCH v1 3/3] syscalls/msgrcv09: Add error test for MSG_COPY flag
  2020-07-20  7:30 [LTP] [PATCH v1 0/3] increase msgrcv coverage Yang Xu
  2020-07-20  7:30 ` [LTP] [PATCH v1 1/3] syscalls/msgrcv: Add check for msg_lrpid and msg_rtime Yang Xu
  2020-07-20  7:30 ` [LTP] [PATCH v1 2/3] syscalls/msgrcv07: Add different msgtyp test Yang Xu
@ 2020-07-20  7:30 ` Yang Xu
  2020-08-13 14:19   ` Cyril Hrubis
  2020-07-20  7:38 ` [LTP] [PATCH v1 0/3] increase msgrcv coverage Yang Xu
  2020-08-13 14:16 ` Cyril Hrubis
  4 siblings, 1 reply; 19+ messages in thread
From: Yang Xu @ 2020-07-20  7:30 UTC (permalink / raw)
  To: ltp

The MSG_COPY flag was added in 3.8 for the implementation of the kernel
checkpoint-restore facility and is available only if the kernel was
built with the CONFIG_CHECKPOINT_RESTORE option.

On old kernel without this support, it only ignores this flag and doesn't
report ENOSYS/EINVAL error, so I add kconfig and min_kver check.

Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
 include/lapi/msg.h                            | 15 +++
 runtest/syscalls                              |  1 +
 runtest/syscalls-ipc                          |  1 +
 .../kernel/syscalls/ipc/msgrcv/.gitignore     |  1 +
 .../kernel/syscalls/ipc/msgrcv/msgrcv09.c     | 93 +++++++++++++++++++
 5 files changed, 111 insertions(+)
 create mode 100644 include/lapi/msg.h
 create mode 100644 testcases/kernel/syscalls/ipc/msgrcv/msgrcv09.c

diff --git a/include/lapi/msg.h b/include/lapi/msg.h
new file mode 100644
index 000000000..d649f3318
--- /dev/null
+++ b/include/lapi/msg.h
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ */
+#ifndef LAPI_MSG_H
+#define LAPI_MSG_H
+
+#include <sys/msg.h>
+
+#ifndef MSG_COPY
+# define MSG_COPY  040000  /* copy (not remove) all queue messages */
+#endif
+
+#endif
diff --git a/runtest/syscalls b/runtest/syscalls
index 9d3808d66..9d927935b 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -815,6 +815,7 @@ msgrcv05 msgrcv05
 msgrcv06 msgrcv06
 msgrcv07 msgrcv07
 msgrcv08 msgrcv08
+msgrcv09 msgrcv09
 
 msgsnd01 msgsnd01
 msgsnd02 msgsnd02
diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc
index 61743be01..153e827cf 100644
--- a/runtest/syscalls-ipc
+++ b/runtest/syscalls-ipc
@@ -19,6 +19,7 @@ msgrcv05 msgrcv05
 msgrcv06 msgrcv06
 msgrcv07 msgrcv07
 msgrcv08 msgrcv08
+msgrcv09 msgrcv09
 
 msgsnd01 msgsnd01
 msgsnd02 msgsnd02
diff --git a/testcases/kernel/syscalls/ipc/msgrcv/.gitignore b/testcases/kernel/syscalls/ipc/msgrcv/.gitignore
index 0596ee00f..359f8adfa 100644
--- a/testcases/kernel/syscalls/ipc/msgrcv/.gitignore
+++ b/testcases/kernel/syscalls/ipc/msgrcv/.gitignore
@@ -4,3 +4,4 @@
 /msgrcv06
 /msgrcv07
 /msgrcv08
+/msgrcv09
diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv09.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv09.c
new file mode 100644
index 000000000..99f9a851b
--- /dev/null
+++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv09.c
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ *
+ * This is a basic test about MSG_COPY flag.
+ *
+ * 1)msgrcv(2) fails and sets errno to EINVAL if IPC_NOWAIT was not specified
+ *   in msgflag.
+ * 2)msgrcv(2) fails and sets errno to EINVAL if IPC_EXCEPT was specified
+ *   in msgflag.
+ * 3)msgrcv(2) fails and set errno to ENOMSG if IPC_NOWAIT and MSG_COPY were
+ *  specified in msgflg and the queue contains less than msgtyp messages.
+ */
+#define  _GNU_SOURCE
+#include <string.h>
+#include <sys/wait.h>
+#include <sys/msg.h>
+#include <pwd.h>
+#include "tst_test.h"
+#include "tst_safe_sysv_ipc.h"
+#include "libnewipc.h"
+#include "lapi/msg.h"
+
+static key_t msgkey;
+static int queue_id = -1;
+static struct buf {
+	long type;
+	char mtext[MSGSIZE];
+} rcv_buf, snd_buf = {MSGTYPE, "hello"};
+
+static struct tcase {
+	int exp_err;
+	int msg_flag;
+	int msg_type;
+	char *message;
+} tcases[] = {
+	{EINVAL, 0, MSGTYPE,
+	"Test EINVAL error when msgflg specified MSG_COPY, but not IPC_NOWAIT"},
+
+	{EINVAL, MSG_EXCEPT, MSGTYPE,
+	"Test EINVAL error when msgflg specified both MSG_COPY and MSG_EXCEPT"},
+
+	{ENOMSG, IPC_NOWAIT, 2,
+	"Test ENOMSG error when using IPC_NOWAIT and MSG_COPY but not have"
+	" corresponding msgtype msg"},
+};
+
+static void verify_msgrcv(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	tst_res(TINFO, "%s", tc->message);
+	TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, tc->msg_type, MSG_COPY | tc->msg_flag));
+	if (TST_RET != -1) {
+		tst_res(TFAIL, "smgrcv() succeeded unexpectedly");
+		SAFE_MSGSND(queue_id, &snd_buf, MSGSIZE, 0);
+		return;
+	}
+
+	if (TST_ERR == tc->exp_err)
+		tst_res(TPASS | TTERRNO, "msgrcv() failed as expected");
+	else
+		tst_res(TFAIL | TTERRNO, "msgrcv() failed unexpectedly,"
+			" expected %s but got", tst_strerrno(tc->exp_err));
+}
+
+static void setup(void)
+{
+	msgkey = GETIPCKEY();
+	queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
+	SAFE_MSGSND(queue_id, &snd_buf, MSGSIZE, 0);
+}
+
+static void cleanup(void)
+{
+	if (queue_id != -1)
+		SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
+}
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_CHECKPOINT_RESTORE",
+		NULL
+	},
+	.min_kver = "3.8.0",
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_msgrcv,
+	.setup = setup,
+	.cleanup = cleanup,
+};
-- 
2.23.0




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

* [LTP] [PATCH v1 0/3] increase msgrcv coverage
  2020-07-20  7:30 [LTP] [PATCH v1 0/3] increase msgrcv coverage Yang Xu
                   ` (2 preceding siblings ...)
  2020-07-20  7:30 ` [LTP] [PATCH v1 3/3] syscalls/msgrcv09: Add error test for MSG_COPY flag Yang Xu
@ 2020-07-20  7:38 ` Yang Xu
  2020-08-13 14:16 ` Cyril Hrubis
  4 siblings, 0 replies; 19+ messages in thread
From: Yang Xu @ 2020-07-20  7:38 UTC (permalink / raw)
  To: ltp

HI!

This patchset is based on my previous msgrcv cleanup patch.
https://patchwork.ozlabs.org/project/ltp/patch/1594962618-26004-1-git-send-email-xuyang2018.jy@cn.fujitsu.com/

> 1. The first patch add check for msg_lrpid and msg_rtime.
> 2. The second patch tests different msgtyp.
> 3. The third patch tests MSG_COPY flag(basic error test),not functional
> test because kernel selftest[1] has tested this.
> 
> [1]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/ipc/msgque.c
> 
> Yang Xu (3):
>    syscalls/msgrcv: Add check for msg_lrpid and msg_rtime
>    syscalls/msgrcv07: Add different msgtyp test
>    syscalls/msgrcv09: Add error test for MSG_COPY flag
> 
>   include/lapi/msg.h                            | 15 +++
>   runtest/syscalls                              |  1 +
>   runtest/syscalls-ipc                          |  1 +
>   .../kernel/syscalls/ipc/msgrcv/.gitignore     |  1 +
>   .../kernel/syscalls/ipc/msgrcv/msgrcv01.c     | 28 +++++-
>   .../kernel/syscalls/ipc/msgrcv/msgrcv07.c     | 81 +++++++++++++++-
>   .../kernel/syscalls/ipc/msgrcv/msgrcv09.c     | 93 +++++++++++++++++++
>   7 files changed, 215 insertions(+), 5 deletions(-)
>   create mode 100644 include/lapi/msg.h
>   create mode 100644 testcases/kernel/syscalls/ipc/msgrcv/msgrcv09.c
> 



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

* [LTP] [PATCH v1 1/3] syscalls/msgrcv: Add check for msg_lrpid and msg_rtime
  2020-07-20  7:30 ` [LTP] [PATCH v1 1/3] syscalls/msgrcv: Add check for msg_lrpid and msg_rtime Yang Xu
@ 2020-08-13 12:53   ` Cyril Hrubis
  0 siblings, 0 replies; 19+ messages in thread
From: Cyril Hrubis @ 2020-08-13 12:53 UTC (permalink / raw)
  To: ltp

Hi!
Pushed with the same changes as in msgsnd01, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v1 2/3] syscalls/msgrcv07: Add different msgtyp test
  2020-07-20  7:30 ` [LTP] [PATCH v1 2/3] syscalls/msgrcv07: Add different msgtyp test Yang Xu
@ 2020-08-13 14:11   ` Cyril Hrubis
  2020-08-13 15:21     ` [LTP] [PATCH v2] " Yang Xu
  0 siblings, 1 reply; 19+ messages in thread
From: Cyril Hrubis @ 2020-08-13 14:11 UTC (permalink / raw)
  To: ltp

Hi!
> diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
> index 39fbdb67a..9b04fd2ac 100644
> --- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
> +++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
> @@ -3,7 +3,8 @@
>   * Copyright (c) 2014-2020 Fujitsu Ltd.
>   * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
>   *
> - * Basic test for msgrcv(2) using MSG_EXCEPT, MSG_NOERROR
> + * Basic test for msgrcv(2) using MSG_EXCEPT, MSG_NOERROR and different
> + * msg_typ(zero,positive,negative).
>   */
>  
>  #define  _GNU_SOURCE
> @@ -22,15 +23,20 @@ static int queue_id = -1;
>  static struct buf {
>  	long type;
>  	char mtext[MSGSIZE];
> -} rcv_buf, snd_buf[2] = {
> +} rcv_buf, snd_buf[3] = {
>  	{MSGTYPE1, MSG1},
> -	{MSGTYPE2, MSG2}
> +	{MSGTYPE2, MSG2},
>  };

This is a bit useless change.

>  static void test_msg_except(void);
>  static void test_msg_noerror(void);
> +static void test_zero_msgtyp(void);
> +static void test_positive_msgtyp(void);
> +static void test_negative_msgtyp(void);
>  static void cleanup(void);
> -static void (*testfunc[])(void) = {test_msg_except, test_msg_noerror};
> +static void (*testfunc[])(void) = {test_msg_except, test_msg_noerror,
> +				   test_zero_msgtyp, test_positive_msgtyp,
> +				   test_negative_msgtyp};
>  
>  static void verify_msgcrv(unsigned int n)
>  {
> @@ -81,6 +87,73 @@ static void test_msg_noerror(void)
>  	SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
>  }
>  
> +static void test_zero_msgtyp(void)
> +{
> +	queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
> +	SAFE_MSGSND(queue_id, &snd_buf[0], MSGSIZE, 0);
> +	SAFE_MSGSND(queue_id, &snd_buf[1], MSGSIZE, 0);
> +	memset(&rcv_buf, 0, sizeof(rcv_buf));

This init is common for all of these tests, I guess that it would be
easier to put this piece of code into a function called prepare_queue()
so that we do not have to repeat it all over.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v1 0/3] increase msgrcv coverage
  2020-07-20  7:30 [LTP] [PATCH v1 0/3] increase msgrcv coverage Yang Xu
                   ` (3 preceding siblings ...)
  2020-07-20  7:38 ` [LTP] [PATCH v1 0/3] increase msgrcv coverage Yang Xu
@ 2020-08-13 14:16 ` Cyril Hrubis
  2020-08-13 15:22   ` Yang Xu
  4 siblings, 1 reply; 19+ messages in thread
From: Cyril Hrubis @ 2020-08-13 14:16 UTC (permalink / raw)
  To: ltp

Hi!
> 1. The first patch add check for msg_lrpid and msg_rtime.
> 2. The second patch tests different msgtyp.
> 3. The third patch tests MSG_COPY flag(basic error test),not functional
> test because kernel selftest[1] has tested this.
> 
> [1]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/ipc/msgque.c

Looking at the code there it actually does not seem to be automated
test, so I think that we should include a test for MSG_COPY in LTP.

We can put a simple one into msgrcv07 we would call msgrcv() with
MSG_COPY if we got an EINVAL we will skip the test since MSG_COPY is not
supported.

Otherwise msgrcv with id 0 and 1 should retrieve our two messages, so we
would check that the data are correct, then we would check that there
are still two messages queue in the queue, we can do that with msgctl()
and/or read them with regular msgrcv.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v1 3/3] syscalls/msgrcv09: Add error test for MSG_COPY flag
  2020-07-20  7:30 ` [LTP] [PATCH v1 3/3] syscalls/msgrcv09: Add error test for MSG_COPY flag Yang Xu
@ 2020-08-13 14:19   ` Cyril Hrubis
  2020-08-13 14:43     ` Yang Xu
  0 siblings, 1 reply; 19+ messages in thread
From: Cyril Hrubis @ 2020-08-13 14:19 UTC (permalink / raw)
  To: ltp

Hi!
> +static struct tst_test test = {
> +	.needs_tmpdir = 1,
> +	.needs_root = 1,
> +	.needs_kconfigs = (const char *[]) {
> +		"CONFIG_CHECKPOINT_RESTORE",
> +		NULL
> +	},
> +	.min_kver = "3.8.0",
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.test = verify_msgrcv,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +};

Do we need both min_kver and CONFIG_CHECKPOINT_RESTORE? Wouldn't be
CONFIG_CHECKPOINT_RESTORE enough?

Also msgrcv03 is free so we may as well name this test msgrcv03...

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v1 3/3] syscalls/msgrcv09: Add error test for MSG_COPY flag
  2020-08-13 14:19   ` Cyril Hrubis
@ 2020-08-13 14:43     ` Yang Xu
  2020-08-13 15:25       ` Cyril Hrubis
  0 siblings, 1 reply; 19+ messages in thread
From: Yang Xu @ 2020-08-13 14:43 UTC (permalink / raw)
  To: ltp

Hi Cyril


> Hi!
>> +static struct tst_test test = {
>> +	.needs_tmpdir = 1,
>> +	.needs_root = 1,
>> +	.needs_kconfigs = (const char *[]) {
>> +		"CONFIG_CHECKPOINT_RESTORE",
>> +		NULL
>> +	},
>> +	.min_kver = "3.8.0",
>> +	.tcnt = ARRAY_SIZE(tcases),
>> +	.test = verify_msgrcv,
>> +	.setup = setup,
>> +	.cleanup = cleanup,
>> +};
> 
> Do we need both min_kver and CONFIG_CHECKPOINT_RESTORE? Wouldn't be
> CONFIG_CHECKPOINT_RESTORE enough?
I think we need both because the CONFIG_CHECKPOINT_RESTORE macro was not 
introduced since 3.8. Before 3.8, we can enable this config but the 
kernel does not support this MSG_COPY FLAG.
also using "CONFIG_CHECKPOINT_RESTORE=y" is better.
> 
> Also msgrcv03 is free so we may as well name this test msgrcv03...
Agree. xfstests often does this(removing the useless case and new case 
uses this test name).
> 



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

* [LTP] [PATCH v2] syscalls/msgrcv07: Add different msgtyp test
  2020-08-13 14:11   ` Cyril Hrubis
@ 2020-08-13 15:21     ` Yang Xu
  2020-08-14 12:27       ` Cyril Hrubis
  0 siblings, 1 reply; 19+ messages in thread
From: Yang Xu @ 2020-08-13 15:21 UTC (permalink / raw)
  To: ltp

After lookging msgcrv(2) man-page, the different msgtyp has the following effect:
1) If msgtyp is 0, then the first message in the queue is read.
2) If msgtyp is greater than 0, then the first message in the queue of type msgtyp is read.
3) If msgtyp is less than 0, then the first message in the queue with the lowest type less
 than or equal to the absolute value of msgtyp will be read.

Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
v1-v2:
1.remove useless change
2.add prepare_queque() function to make code more simple
 .../kernel/syscalls/ipc/msgrcv/msgrcv07.c     | 75 ++++++++++++++++++-
 1 file changed, 71 insertions(+), 4 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
index bb321c645..f6139ba57 100644
--- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
+++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
@@ -3,7 +3,8 @@
  * Copyright (c) 2014-2020 Fujitsu Ltd.
  * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
  *
- * Basic test for msgrcv(2) using MSG_EXCEPT, MSG_NOERROR
+ * Basic test for msgrcv(2) using MSG_EXCEPT, MSG_NOERROR and different
+ * msg_typ(zero,positive,negative).
  */
 
 #define  _GNU_SOURCE
@@ -33,13 +34,18 @@ static void cleanup(void)
 		SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
 }
 
-static void test_msg_except(void)
+static void prepare_queue(void)
 {
 	queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
 	SAFE_MSGSND(queue_id, &snd_buf[0], MSGSIZE, 0);
 	SAFE_MSGSND(queue_id, &snd_buf[1], MSGSIZE, 0);
-
 	memset(&rcv_buf, 0, sizeof(rcv_buf));
+}
+
+static void test_msg_except(void)
+{
+	prepare_queue();
+
 	TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, MSGTYPE2, MSG_EXCEPT));
 	if (TST_RET == -1) {
 		tst_res(TFAIL | TTERRNO, "msgrcv(MSG_EXCEPT) failed");
@@ -77,12 +83,73 @@ static void test_msg_noerror(void)
 	SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
 }
 
+static void test_zero_msgtyp(void)
+{
+	prepare_queue();
+
+	TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, 0, 0));
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO, "msgrcv(zero_msgtyp) failed");
+		cleanup();
+		return;
+	}
+	tst_res(TPASS, "msgrcv(zero_msgtyp) succeeded");
+	if (strcmp(rcv_buf.mtext, MSG1) == 0 && rcv_buf.type == MSGTYPE1)
+		tst_res(TPASS, "msgrcv(zero_msgtyp) got the first message");
+	else
+		tst_res(TFAIL, "msgrcv(zero_msgtyp) didn't get the first message");
+	SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
+}
+
+static void test_positive_msgtyp(void)
+{
+	prepare_queue();
+
+	TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, MSGTYPE2, 0));
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO, "msgrcv(positive_msgtyp) failed");
+		cleanup();
+		return;
+	}
+	tst_res(TPASS, "msgrcv(positive_msgtyp) succeeded");
+	if (strcmp(rcv_buf.mtext, MSG2) == 0 && rcv_buf.type == MSGTYPE2)
+		tst_res(TPASS, "msgrcv(positive_msgtyp) got the first message"
+			       " in the queue of type msgtyp");
+	else
+		tst_res(TFAIL, "msgrcv(positive_msgtyp) didn't get the first "
+			       "message in the queue of type msgtyp");
+	SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
+}
+
+static void test_negative_msgtyp(void)
+{
+	prepare_queue();
+
+	TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, -MSGTYPE2, 0));
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO, "msgrcv(negative_msgtyp) failed");
+		cleanup();
+		return;
+	}
+	tst_res(TPASS, "msgrcv(negative_msgtyp) succeeded");
+	if (strcmp(rcv_buf.mtext, MSG1) == 0 && rcv_buf.type == MSGTYPE1)
+		tst_res(TPASS, "msgrcv(negative_msgtyp) got the first message"
+				" in the queue with the lowest type");
+	else
+		tst_res(TFAIL, "msgrcv(negative_msgtyp) didn't get the first "
+				"message in the queue with the lowest type");
+	SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
+}
+
+
 static void setup(void)
 {
 	msgkey = GETIPCKEY();
 }
 
-static void (*testfunc[])(void) = {test_msg_except, test_msg_noerror};
+static void (*testfunc[])(void) = {test_msg_except, test_msg_noerror,
+				   test_zero_msgtyp, test_positive_msgtyp,
+				   test_negative_msgtyp};
 
 static void verify_msgcrv(unsigned int n)
 {
-- 
2.23.0




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

* [LTP] [PATCH v1 0/3] increase msgrcv coverage
  2020-08-13 14:16 ` Cyril Hrubis
@ 2020-08-13 15:22   ` Yang Xu
  0 siblings, 0 replies; 19+ messages in thread
From: Yang Xu @ 2020-08-13 15:22 UTC (permalink / raw)
  To: ltp

HI Cyril


> Hi!
>> 1. The first patch add check for msg_lrpid and msg_rtime.
>> 2. The second patch tests different msgtyp.
>> 3. The third patch tests MSG_COPY flag(basic error test),not functional
>> test because kernel selftest[1] has tested this.
>>
>> [1]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/ipc/msgque.c
> 
> Looking at the code there it actually does not seem to be automated
> test, so I think that we should include a test for MSG_COPY in LTP.
> 
> We can put a simple one into msgrcv07 we would call msgrcv() with
> MSG_COPY if we got an EINVAL we will skip the test since MSG_COPY is not
> supported.
> 
> Otherwise msgrcv with id 0 and 1 should retrieve our two messages, so we
> would check that the data are correct, then we would check that there
> are still two messages queue in the queue, we can do that with msgctl()
> and/or read them with regular msgrcv.
I see. I will do it on new msgrcv07.c tomorrow(It is a little late today).
> 



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

* [LTP] [PATCH v1 3/3] syscalls/msgrcv09: Add error test for MSG_COPY flag
  2020-08-13 14:43     ` Yang Xu
@ 2020-08-13 15:25       ` Cyril Hrubis
  2020-08-14  5:37         ` Yang Xu
  2020-08-18  3:43         ` [LTP] [PATCH v2] syscalls/msgrcv03: " Yang Xu
  0 siblings, 2 replies; 19+ messages in thread
From: Cyril Hrubis @ 2020-08-13 15:25 UTC (permalink / raw)
  To: ltp

Hi!
> >> +static struct tst_test test = {
> >> +	.needs_tmpdir = 1,
> >> +	.needs_root = 1,
> >> +	.needs_kconfigs = (const char *[]) {
> >> +		"CONFIG_CHECKPOINT_RESTORE",
> >> +		NULL
> >> +	},
> >> +	.min_kver = "3.8.0",
> >> +	.tcnt = ARRAY_SIZE(tcases),
> >> +	.test = verify_msgrcv,
> >> +	.setup = setup,
> >> +	.cleanup = cleanup,
> >> +};
> > 
> > Do we need both min_kver and CONFIG_CHECKPOINT_RESTORE? Wouldn't be
> > CONFIG_CHECKPOINT_RESTORE enough?
> I think we need both because the CONFIG_CHECKPOINT_RESTORE macro was not 
> introduced since 3.8. Before 3.8, we can enable this config but the 
> kernel does not support this MSG_COPY FLAG.
> also using "CONFIG_CHECKPOINT_RESTORE=y" is better.

Ah, makes sense. I wonder if this worth a comment in the top level
test description.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v1 3/3] syscalls/msgrcv09: Add error test for MSG_COPY flag
  2020-08-13 15:25       ` Cyril Hrubis
@ 2020-08-14  5:37         ` Yang Xu
  2020-08-18  3:43         ` [LTP] [PATCH v2] syscalls/msgrcv03: " Yang Xu
  1 sibling, 0 replies; 19+ messages in thread
From: Yang Xu @ 2020-08-14  5:37 UTC (permalink / raw)
  To: ltp

Hi Cyril


> Hi!
>>>> +static struct tst_test test = {
>>>> +	.needs_tmpdir = 1,
>>>> +	.needs_root = 1,
>>>> +	.needs_kconfigs = (const char *[]) {
>>>> +		"CONFIG_CHECKPOINT_RESTORE",
>>>> +		NULL
>>>> +	},
>>>> +	.min_kver = "3.8.0",
>>>> +	.tcnt = ARRAY_SIZE(tcases),
>>>> +	.test = verify_msgrcv,
>>>> +	.setup = setup,
>>>> +	.cleanup = cleanup,
>>>> +};
>>>
>>> Do we need both min_kver and CONFIG_CHECKPOINT_RESTORE? Wouldn't be
>>> CONFIG_CHECKPOINT_RESTORE enough?
>> I think we need both because the CONFIG_CHECKPOINT_RESTORE macro was not
>> introduced since 3.8. Before 3.8, we can enable this config but the
>> kernel does not support this MSG_COPY FLAG.
>> also using "CONFIG_CHECKPOINT_RESTORE=y" is better.
> 
> Ah, makes sense. I wonder if this worth a comment in the top level
> test description.
In my personal habit, I think a comment is better becuase this is more 
friendly for user.
> 



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

* [LTP] [PATCH v2] syscalls/msgrcv07: Add different msgtyp test
  2020-08-13 15:21     ` [LTP] [PATCH v2] " Yang Xu
@ 2020-08-14 12:27       ` Cyril Hrubis
  0 siblings, 0 replies; 19+ messages in thread
From: Cyril Hrubis @ 2020-08-14 12:27 UTC (permalink / raw)
  To: ltp

Hi!
I've added a more verbose description to the test top level commend and
pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v2] syscalls/msgrcv03: Add error test for MSG_COPY flag
  2020-08-13 15:25       ` Cyril Hrubis
  2020-08-14  5:37         ` Yang Xu
@ 2020-08-18  3:43         ` Yang Xu
  2020-08-24  6:40           ` Yang Xu
  2020-09-08 13:03           ` Cyril Hrubis
  1 sibling, 2 replies; 19+ messages in thread
From: Yang Xu @ 2020-08-18  3:43 UTC (permalink / raw)
  To: ltp

The MSG_COPY flag was added in 3.8 for the implementation of the kernel
checkpoint-restore facility and is available only if the kernel was
built with the CONFIG_CHECKPOINT_RESTORE option.

On old kernel without this support, it only ignores this flag and doesn't
report ENOSYS/EINVAL error, so I add kconfig and min_kver check.

Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
v1->v2:
1.Rename msgrcv09->msgrcv03
2.add comment on top level for why we both need min_kernel and kconfig check
 include/lapi/msg.h                            |  15 +++
 runtest/syscalls                              |   1 +
 runtest/syscalls-ipc                          |   1 +
 .../kernel/syscalls/ipc/msgrcv/.gitignore     |   1 +
 .../kernel/syscalls/ipc/msgrcv/msgrcv03.c     | 102 ++++++++++++++++++
 5 files changed, 120 insertions(+)
 create mode 100644 include/lapi/msg.h
 create mode 100644 testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c

diff --git a/include/lapi/msg.h b/include/lapi/msg.h
new file mode 100644
index 000000000..d649f3318
--- /dev/null
+++ b/include/lapi/msg.h
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ */
+#ifndef LAPI_MSG_H
+#define LAPI_MSG_H
+
+#include <sys/msg.h>
+
+#ifndef MSG_COPY
+# define MSG_COPY  040000  /* copy (not remove) all queue messages */
+#endif
+
+#endif
diff --git a/runtest/syscalls b/runtest/syscalls
index 860c5c36d..20bbc022b 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -815,6 +815,7 @@ msgget05 msgget05
 
 msgrcv01 msgrcv01
 msgrcv02 msgrcv02
+msgrcv03 msgrcv03
 msgrcv05 msgrcv05
 msgrcv06 msgrcv06
 msgrcv07 msgrcv07
diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc
index e6837414c..94d1e4001 100644
--- a/runtest/syscalls-ipc
+++ b/runtest/syscalls-ipc
@@ -17,6 +17,7 @@ msgget05 msgget05
 
 msgrcv01 msgrcv01
 msgrcv02 msgrcv02
+msgrcv03 msgrcv03
 msgrcv05 msgrcv05
 msgrcv06 msgrcv06
 msgrcv07 msgrcv07
diff --git a/testcases/kernel/syscalls/ipc/msgrcv/.gitignore b/testcases/kernel/syscalls/ipc/msgrcv/.gitignore
index 0596ee00f..8ab91e763 100644
--- a/testcases/kernel/syscalls/ipc/msgrcv/.gitignore
+++ b/testcases/kernel/syscalls/ipc/msgrcv/.gitignore
@@ -1,5 +1,6 @@
 /msgrcv01
 /msgrcv02
+/msgrcv03
 /msgrcv05
 /msgrcv06
 /msgrcv07
diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c
new file mode 100644
index 000000000..84456c1cf
--- /dev/null
+++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ *
+ * This is a basic test about MSG_COPY flag.
+ * This flag was added in 3.8 for the implementation of the kernel checkpoint
+ * restore facility and is available only if the kernel was built with the
+ * CONFIG_CHECKPOINT_RESTORE option.
+ * On old kernel without this support, it only ignores this flag and doesn't
+ * report ENOSYS/EINVAL error. The CONFIG_CHECKPOINT_RESTORE has existed
+ * before kernel 3.8.
+ * So for using this flag, kernel should greater than 3.8 and enable
+ * CONFIG_CHECKPOINT_RESTORE together.
+ *
+ * 1)msgrcv(2) fails and sets errno to EINVAL if IPC_NOWAIT was not specified
+ *   in msgflag.
+ * 2)msgrcv(2) fails and sets errno to EINVAL if IPC_EXCEPT was specified
+ *   in msgflag.
+ * 3)msgrcv(2) fails and set errno to ENOMSG if IPC_NOWAIT and MSG_COPY were
+ *  specified in msgflg and the queue contains less than msgtyp messages.
+ */
+
+#define  _GNU_SOURCE
+#include <string.h>
+#include <sys/wait.h>
+#include <sys/msg.h>
+#include <pwd.h>
+#include "tst_test.h"
+#include "tst_safe_sysv_ipc.h"
+#include "libnewipc.h"
+#include "lapi/msg.h"
+
+static key_t msgkey;
+static int queue_id = -1;
+static struct buf {
+	long type;
+	char mtext[MSGSIZE];
+} rcv_buf, snd_buf = {MSGTYPE, "hello"};
+
+static struct tcase {
+	int exp_err;
+	int msg_flag;
+	int msg_type;
+	char *message;
+} tcases[] = {
+	{EINVAL, 0, MSGTYPE,
+	"Test EINVAL error when msgflg specified MSG_COPY, but not IPC_NOWAIT"},
+
+	{EINVAL, MSG_EXCEPT, MSGTYPE,
+	"Test EINVAL error when msgflg specified both MSG_COPY and MSG_EXCEPT"},
+
+	{ENOMSG, IPC_NOWAIT, 2,
+	"Test ENOMSG error when using IPC_NOWAIT and MSG_COPY but not have"
+	" corresponding msgtype msg"},
+};
+
+static void verify_msgrcv(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	tst_res(TINFO, "%s", tc->message);
+	TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, tc->msg_type, MSG_COPY | tc->msg_flag));
+	if (TST_RET != -1) {
+		tst_res(TFAIL, "msgrcv() succeeded unexpectedly");
+		SAFE_MSGSND(queue_id, &snd_buf, MSGSIZE, 0);
+		return;
+	}
+
+	if (TST_ERR == tc->exp_err)
+		tst_res(TPASS | TTERRNO, "msgrcv() failed as expected");
+	else
+		tst_res(TFAIL | TTERRNO, "msgrcv() failed unexpectedly,"
+			" expected %s but got", tst_strerrno(tc->exp_err));
+}
+
+static void setup(void)
+{
+	msgkey = GETIPCKEY();
+	queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
+	SAFE_MSGSND(queue_id, &snd_buf, MSGSIZE, 0);
+}
+
+static void cleanup(void)
+{
+	if (queue_id != -1)
+		SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
+}
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_CHECKPOINT_RESTORE",
+		NULL
+	},
+	.min_kver = "3.8.0",
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_msgrcv,
+	.setup = setup,
+	.cleanup = cleanup,
+};
-- 
2.23.0




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

* [LTP] [PATCH v2] syscalls/msgrcv03: Add error test for MSG_COPY flag
  2020-08-18  3:43         ` [LTP] [PATCH v2] syscalls/msgrcv03: " Yang Xu
@ 2020-08-24  6:40           ` Yang Xu
  2020-09-04  3:47             ` Yang Xu
  2020-09-08 13:03           ` Cyril Hrubis
  1 sibling, 1 reply; 19+ messages in thread
From: Yang Xu @ 2020-08-24  6:40 UTC (permalink / raw)
  To: ltp

Hi Cyril

Do you have some comments for this v2 patch?

Best Regards
Yang Xu
> The MSG_COPY flag was added in 3.8 for the implementation of the kernel
> checkpoint-restore facility and is available only if the kernel was
> built with the CONFIG_CHECKPOINT_RESTORE option.
> 
> On old kernel without this support, it only ignores this flag and doesn't
> report ENOSYS/EINVAL error, so I add kconfig and min_kver check.
> 
> Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
> ---
> v1->v2:
> 1.Rename msgrcv09->msgrcv03
> 2.add comment on top level for why we both need min_kernel and kconfig check
>   include/lapi/msg.h                            |  15 +++
>   runtest/syscalls                              |   1 +
>   runtest/syscalls-ipc                          |   1 +
>   .../kernel/syscalls/ipc/msgrcv/.gitignore     |   1 +
>   .../kernel/syscalls/ipc/msgrcv/msgrcv03.c     | 102 ++++++++++++++++++
>   5 files changed, 120 insertions(+)
>   create mode 100644 include/lapi/msg.h
>   create mode 100644 testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c
> 
> diff --git a/include/lapi/msg.h b/include/lapi/msg.h
> new file mode 100644
> index 000000000..d649f3318
> --- /dev/null
> +++ b/include/lapi/msg.h
> @@ -0,0 +1,15 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
> + * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
> + */
> +#ifndef LAPI_MSG_H
> +#define LAPI_MSG_H
> +
> +#include <sys/msg.h>
> +
> +#ifndef MSG_COPY
> +# define MSG_COPY  040000  /* copy (not remove) all queue messages */
> +#endif
> +
> +#endif
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 860c5c36d..20bbc022b 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -815,6 +815,7 @@ msgget05 msgget05
>   
>   msgrcv01 msgrcv01
>   msgrcv02 msgrcv02
> +msgrcv03 msgrcv03
>   msgrcv05 msgrcv05
>   msgrcv06 msgrcv06
>   msgrcv07 msgrcv07
> diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc
> index e6837414c..94d1e4001 100644
> --- a/runtest/syscalls-ipc
> +++ b/runtest/syscalls-ipc
> @@ -17,6 +17,7 @@ msgget05 msgget05
>   
>   msgrcv01 msgrcv01
>   msgrcv02 msgrcv02
> +msgrcv03 msgrcv03
>   msgrcv05 msgrcv05
>   msgrcv06 msgrcv06
>   msgrcv07 msgrcv07
> diff --git a/testcases/kernel/syscalls/ipc/msgrcv/.gitignore b/testcases/kernel/syscalls/ipc/msgrcv/.gitignore
> index 0596ee00f..8ab91e763 100644
> --- a/testcases/kernel/syscalls/ipc/msgrcv/.gitignore
> +++ b/testcases/kernel/syscalls/ipc/msgrcv/.gitignore
> @@ -1,5 +1,6 @@
>   /msgrcv01
>   /msgrcv02
> +/msgrcv03
>   /msgrcv05
>   /msgrcv06
>   /msgrcv07
> diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c
> new file mode 100644
> index 000000000..84456c1cf
> --- /dev/null
> +++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c
> @@ -0,0 +1,102 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
> + * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
> + *
> + * This is a basic test about MSG_COPY flag.
> + * This flag was added in 3.8 for the implementation of the kernel checkpoint
> + * restore facility and is available only if the kernel was built with the
> + * CONFIG_CHECKPOINT_RESTORE option.
> + * On old kernel without this support, it only ignores this flag and doesn't
> + * report ENOSYS/EINVAL error. The CONFIG_CHECKPOINT_RESTORE has existed
> + * before kernel 3.8.
> + * So for using this flag, kernel should greater than 3.8 and enable
> + * CONFIG_CHECKPOINT_RESTORE together.
> + *
> + * 1)msgrcv(2) fails and sets errno to EINVAL if IPC_NOWAIT was not specified
> + *   in msgflag.
> + * 2)msgrcv(2) fails and sets errno to EINVAL if IPC_EXCEPT was specified
> + *   in msgflag.
> + * 3)msgrcv(2) fails and set errno to ENOMSG if IPC_NOWAIT and MSG_COPY were
> + *  specified in msgflg and the queue contains less than msgtyp messages.
> + */
> +
> +#define  _GNU_SOURCE
> +#include <string.h>
> +#include <sys/wait.h>
> +#include <sys/msg.h>
> +#include <pwd.h>
> +#include "tst_test.h"
> +#include "tst_safe_sysv_ipc.h"
> +#include "libnewipc.h"
> +#include "lapi/msg.h"
> +
> +static key_t msgkey;
> +static int queue_id = -1;
> +static struct buf {
> +	long type;
> +	char mtext[MSGSIZE];
> +} rcv_buf, snd_buf = {MSGTYPE, "hello"};
> +
> +static struct tcase {
> +	int exp_err;
> +	int msg_flag;
> +	int msg_type;
> +	char *message;
> +} tcases[] = {
> +	{EINVAL, 0, MSGTYPE,
> +	"Test EINVAL error when msgflg specified MSG_COPY, but not IPC_NOWAIT"},
> +
> +	{EINVAL, MSG_EXCEPT, MSGTYPE,
> +	"Test EINVAL error when msgflg specified both MSG_COPY and MSG_EXCEPT"},
> +
> +	{ENOMSG, IPC_NOWAIT, 2,
> +	"Test ENOMSG error when using IPC_NOWAIT and MSG_COPY but not have"
> +	" corresponding msgtype msg"},
> +};
> +
> +static void verify_msgrcv(unsigned int n)
> +{
> +	struct tcase *tc = &tcases[n];
> +
> +	tst_res(TINFO, "%s", tc->message);
> +	TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, tc->msg_type, MSG_COPY | tc->msg_flag));
> +	if (TST_RET != -1) {
> +		tst_res(TFAIL, "msgrcv() succeeded unexpectedly");
> +		SAFE_MSGSND(queue_id, &snd_buf, MSGSIZE, 0);
> +		return;
> +	}
> +
> +	if (TST_ERR == tc->exp_err)
> +		tst_res(TPASS | TTERRNO, "msgrcv() failed as expected");
> +	else
> +		tst_res(TFAIL | TTERRNO, "msgrcv() failed unexpectedly,"
> +			" expected %s but got", tst_strerrno(tc->exp_err));
> +}
> +
> +static void setup(void)
> +{
> +	msgkey = GETIPCKEY();
> +	queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
> +	SAFE_MSGSND(queue_id, &snd_buf, MSGSIZE, 0);
> +}
> +
> +static void cleanup(void)
> +{
> +	if (queue_id != -1)
> +		SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
> +}
> +
> +static struct tst_test test = {
> +	.needs_tmpdir = 1,
> +	.needs_root = 1,
> +	.needs_kconfigs = (const char *[]) {
> +		"CONFIG_CHECKPOINT_RESTORE",
> +		NULL
> +	},
> +	.min_kver = "3.8.0",
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.test = verify_msgrcv,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +};
> 



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

* [LTP] [PATCH v2] syscalls/msgrcv03: Add error test for MSG_COPY flag
  2020-08-24  6:40           ` Yang Xu
@ 2020-09-04  3:47             ` Yang Xu
  0 siblings, 0 replies; 19+ messages in thread
From: Yang Xu @ 2020-09-04  3:47 UTC (permalink / raw)
  To: ltp

Hi
Ping.

> Hi Cyril
> 
> Do you have some comments for this v2 patch?
> 
> Best Regards
> Yang Xu
>> The MSG_COPY flag was added in 3.8 for the implementation of the kernel
>> checkpoint-restore facility and is available only if the kernel was
>> built with the CONFIG_CHECKPOINT_RESTORE option.
>>
>> On old kernel without this support, it only ignores this flag and doesn't
>> report ENOSYS/EINVAL error, so I add kconfig and min_kver check.
>>
>> Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
>> ---
>> v1->v2:
>> 1.Rename msgrcv09->msgrcv03
>> 2.add comment on top level for why we both need min_kernel and kconfig 
>> check
>> ? include/lapi/msg.h??????????????????????????? |? 15 +++
>> ? runtest/syscalls????????????????????????????? |?? 1 +
>> ? runtest/syscalls-ipc????????????????????????? |?? 1 +
>> ? .../kernel/syscalls/ipc/msgrcv/.gitignore???? |?? 1 +
>> ? .../kernel/syscalls/ipc/msgrcv/msgrcv03.c???? | 102 ++++++++++++++++++
>> ? 5 files changed, 120 insertions(+)
>> ? create mode 100644 include/lapi/msg.h
>> ? create mode 100644 testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c
>>
>> diff --git a/include/lapi/msg.h b/include/lapi/msg.h
>> new file mode 100644
>> index 000000000..d649f3318
>> --- /dev/null
>> +++ b/include/lapi/msg.h
>> @@ -0,0 +1,15 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/*
>> + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
>> + * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
>> + */
>> +#ifndef LAPI_MSG_H
>> +#define LAPI_MSG_H
>> +
>> +#include <sys/msg.h>
>> +
>> +#ifndef MSG_COPY
>> +# define MSG_COPY? 040000? /* copy (not remove) all queue messages */
>> +#endif
>> +
>> +#endif
>> diff --git a/runtest/syscalls b/runtest/syscalls
>> index 860c5c36d..20bbc022b 100644
>> --- a/runtest/syscalls
>> +++ b/runtest/syscalls
>> @@ -815,6 +815,7 @@ msgget05 msgget05
>> ? msgrcv01 msgrcv01
>> ? msgrcv02 msgrcv02
>> +msgrcv03 msgrcv03
>> ? msgrcv05 msgrcv05
>> ? msgrcv06 msgrcv06
>> ? msgrcv07 msgrcv07
>> diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc
>> index e6837414c..94d1e4001 100644
>> --- a/runtest/syscalls-ipc
>> +++ b/runtest/syscalls-ipc
>> @@ -17,6 +17,7 @@ msgget05 msgget05
>> ? msgrcv01 msgrcv01
>> ? msgrcv02 msgrcv02
>> +msgrcv03 msgrcv03
>> ? msgrcv05 msgrcv05
>> ? msgrcv06 msgrcv06
>> ? msgrcv07 msgrcv07
>> diff --git a/testcases/kernel/syscalls/ipc/msgrcv/.gitignore 
>> b/testcases/kernel/syscalls/ipc/msgrcv/.gitignore
>> index 0596ee00f..8ab91e763 100644
>> --- a/testcases/kernel/syscalls/ipc/msgrcv/.gitignore
>> +++ b/testcases/kernel/syscalls/ipc/msgrcv/.gitignore
>> @@ -1,5 +1,6 @@
>> ? /msgrcv01
>> ? /msgrcv02
>> +/msgrcv03
>> ? /msgrcv05
>> ? /msgrcv06
>> ? /msgrcv07
>> diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c 
>> b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c
>> new file mode 100644
>> index 000000000..84456c1cf
>> --- /dev/null
>> +++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c
>> @@ -0,0 +1,102 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/*
>> + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
>> + * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
>> + *
>> + * This is a basic test about MSG_COPY flag.
>> + * This flag was added in 3.8 for the implementation of the kernel 
>> checkpoint
>> + * restore facility and is available only if the kernel was built 
>> with the
>> + * CONFIG_CHECKPOINT_RESTORE option.
>> + * On old kernel without this support, it only ignores this flag and 
>> doesn't
>> + * report ENOSYS/EINVAL error. The CONFIG_CHECKPOINT_RESTORE has existed
>> + * before kernel 3.8.
>> + * So for using this flag, kernel should greater than 3.8 and enable
>> + * CONFIG_CHECKPOINT_RESTORE together.
>> + *
>> + * 1)msgrcv(2) fails and sets errno to EINVAL if IPC_NOWAIT was not 
>> specified
>> + *?? in msgflag.
>> + * 2)msgrcv(2) fails and sets errno to EINVAL if IPC_EXCEPT was 
>> specified
>> + *?? in msgflag.
>> + * 3)msgrcv(2) fails and set errno to ENOMSG if IPC_NOWAIT and 
>> MSG_COPY were
>> + *? specified in msgflg and the queue contains less than msgtyp 
>> messages.
>> + */
>> +
>> +#define? _GNU_SOURCE
>> +#include <string.h>
>> +#include <sys/wait.h>
>> +#include <sys/msg.h>
>> +#include <pwd.h>
>> +#include "tst_test.h"
>> +#include "tst_safe_sysv_ipc.h"
>> +#include "libnewipc.h"
>> +#include "lapi/msg.h"
>> +
>> +static key_t msgkey;
>> +static int queue_id = -1;
>> +static struct buf {
>> +??? long type;
>> +??? char mtext[MSGSIZE];
>> +} rcv_buf, snd_buf = {MSGTYPE, "hello"};
>> +
>> +static struct tcase {
>> +??? int exp_err;
>> +??? int msg_flag;
>> +??? int msg_type;
>> +??? char *message;
>> +} tcases[] = {
>> +??? {EINVAL, 0, MSGTYPE,
>> +??? "Test EINVAL error when msgflg specified MSG_COPY, but not 
>> IPC_NOWAIT"},
>> +
>> +??? {EINVAL, MSG_EXCEPT, MSGTYPE,
>> +??? "Test EINVAL error when msgflg specified both MSG_COPY and 
>> MSG_EXCEPT"},
>> +
>> +??? {ENOMSG, IPC_NOWAIT, 2,
>> +??? "Test ENOMSG error when using IPC_NOWAIT and MSG_COPY but not have"
>> +??? " corresponding msgtype msg"},
>> +};
>> +
>> +static void verify_msgrcv(unsigned int n)
>> +{
>> +??? struct tcase *tc = &tcases[n];
>> +
>> +??? tst_res(TINFO, "%s", tc->message);
>> +??? TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, tc->msg_type, MSG_COPY | 
>> tc->msg_flag));
>> +??? if (TST_RET != -1) {
>> +??????? tst_res(TFAIL, "msgrcv() succeeded unexpectedly");
>> +??????? SAFE_MSGSND(queue_id, &snd_buf, MSGSIZE, 0);
>> +??????? return;
>> +??? }
>> +
>> +??? if (TST_ERR == tc->exp_err)
>> +??????? tst_res(TPASS | TTERRNO, "msgrcv() failed as expected");
>> +??? else
>> +??????? tst_res(TFAIL | TTERRNO, "msgrcv() failed unexpectedly,"
>> +??????????? " expected %s but got", tst_strerrno(tc->exp_err));
>> +}
>> +
>> +static void setup(void)
>> +{
>> +??? msgkey = GETIPCKEY();
>> +??? queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
>> +??? SAFE_MSGSND(queue_id, &snd_buf, MSGSIZE, 0);
>> +}
>> +
>> +static void cleanup(void)
>> +{
>> +??? if (queue_id != -1)
>> +??????? SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
>> +}
>> +
>> +static struct tst_test test = {
>> +??? .needs_tmpdir = 1,
>> +??? .needs_root = 1,
>> +??? .needs_kconfigs = (const char *[]) {
>> +??????? "CONFIG_CHECKPOINT_RESTORE",
>> +??????? NULL
>> +??? },
>> +??? .min_kver = "3.8.0",
>> +??? .tcnt = ARRAY_SIZE(tcases),
>> +??? .test = verify_msgrcv,
>> +??? .setup = setup,
>> +??? .cleanup = cleanup,
>> +};
>>
> 
> 
> 



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

* [LTP] [PATCH v2] syscalls/msgrcv03: Add error test for MSG_COPY flag
  2020-08-18  3:43         ` [LTP] [PATCH v2] syscalls/msgrcv03: " Yang Xu
  2020-08-24  6:40           ` Yang Xu
@ 2020-09-08 13:03           ` Cyril Hrubis
  1 sibling, 0 replies; 19+ messages in thread
From: Cyril Hrubis @ 2020-09-08 13:03 UTC (permalink / raw)
  To: ltp

Hi!
Pushed with minor changes, thanks.

I've edited the strings so that they do not break over several lines and
also shortened some.

In LKML coding style strings that are printed as messages shouldn't be
broken into several parts in order to be able to grep for them in the
sources.

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2020-09-08 13:03 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-20  7:30 [LTP] [PATCH v1 0/3] increase msgrcv coverage Yang Xu
2020-07-20  7:30 ` [LTP] [PATCH v1 1/3] syscalls/msgrcv: Add check for msg_lrpid and msg_rtime Yang Xu
2020-08-13 12:53   ` Cyril Hrubis
2020-07-20  7:30 ` [LTP] [PATCH v1 2/3] syscalls/msgrcv07: Add different msgtyp test Yang Xu
2020-08-13 14:11   ` Cyril Hrubis
2020-08-13 15:21     ` [LTP] [PATCH v2] " Yang Xu
2020-08-14 12:27       ` Cyril Hrubis
2020-07-20  7:30 ` [LTP] [PATCH v1 3/3] syscalls/msgrcv09: Add error test for MSG_COPY flag Yang Xu
2020-08-13 14:19   ` Cyril Hrubis
2020-08-13 14:43     ` Yang Xu
2020-08-13 15:25       ` Cyril Hrubis
2020-08-14  5:37         ` Yang Xu
2020-08-18  3:43         ` [LTP] [PATCH v2] syscalls/msgrcv03: " Yang Xu
2020-08-24  6:40           ` Yang Xu
2020-09-04  3:47             ` Yang Xu
2020-09-08 13:03           ` Cyril Hrubis
2020-07-20  7:38 ` [LTP] [PATCH v1 0/3] increase msgrcv coverage Yang Xu
2020-08-13 14:16 ` Cyril Hrubis
2020-08-13 15:22   ` Yang Xu

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.