increase msgrcv coverage
cover increase msgrcv coverage
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.
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
Signature · 1 line
2.23.0
PATCH 1/3 syscalls/msgrcv: Add check for msg_lrpid and msg_rtime
--- .../kernel/syscalls/ipc/msgrcv/msgrcv01.c | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c +27 -1
@@ -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 )
Signature · 1 line
2.23.0
PATCH 1/3 syscalls/msgrcv: Add check for msg_lrpid and msg_rtime
Hi!
Pushed with the same changes as in msgsnd01, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 2/3 syscalls/msgrcv07: Add different msgtyp test
In reply to Yang XuAfter 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.
--- .../kernel/syscalls/ipc/msgrcv/msgrcv07.c | 81 ++++++++++++++++++- 1 file changed, 77 insertions(+), 4 deletions(-)
testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c +77 -4
@@ -3,7 +3,8 @@* Copyright (c) 2014-2020 Fujitsu Ltd. * Author: Xiaoguang Wang <[email protected]> * -* 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 ();
Signature · 1 line
2.23.0
PATCH 2/3 syscalls/msgrcv07: Add different msgtyp test
Hi!
Quoted 15 lines
testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c +2
-1@@ -3,7 +3,8 @@* Copyright (c) 2014-2020 Fujitsu Ltd. * Author: Xiaoguang Wang <[email protected]> * -* 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
testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c static int queue_id = -1; · line 29
Quoted 9 lines
testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c +2
-2@@ -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.
Quoted 14 lines
testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c +6
-1static 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) {
testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c static void test_msg_noerror(void) · line 95
Quoted 9 lines
testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c +6
-0@@ -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.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/1 syscalls/msgrcv07: Add different msgtyp test
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.
---
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(-)
testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c +71 -4
@@ -3,7 +3,8 @@* Copyright (c) 2014-2020 Fujitsu Ltd. * Author: Xiaoguang Wang <[email protected]> * -* 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) {
Signature · 1 line
2.23.0
PATCH v2 1/1 syscalls/msgrcv07: Add different msgtyp test
Hi!
I've added a more verbose description to the test top level commend and pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 3/3 syscalls/msgrcv09: Add error test for MSG_COPY flag
In reply to Yang XuThe 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.
--- 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
include/lapi/msg.h new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. +* Author: Yang Xu <[email protected]> +*/ +#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
runtest/syscalls +1 -0
@@ -815,6 +815,7 @@ msgrcv05 msgrcv05 msgrcv06 msgrcv06 msgrcv07 msgrcv07 msgrcv08 msgrcv08 +msgrcv09 msgrcv09 msgsnd01 msgsnd01 msgsnd02 msgsnd02
runtest/syscalls-ipc +1 -0
@@ -19,6 +19,7 @@ msgrcv05 msgrcv05 msgrcv06 msgrcv06 msgrcv07 msgrcv07 msgrcv08 msgrcv08 +msgrcv09 msgrcv09 msgsnd01 msgsnd01 msgsnd02 msgsnd02
testcases/kernel/syscalls/ipc/msgrcv/.gitignore +1 -0
@@ -4,3 +4,4 @@ /msgrcv06 /msgrcv07 /msgrcv08 +/msgrcv09
testcases/kernel/syscalls/ipc/msgrcv/msgrcv09.c new file +93 -0
93 lines not on this page · raw message
Signature · 1 line
2.23.0
PATCH 3/3 syscalls/msgrcv09: Add error test for MSG_COPY flag
Hi!
testcases/kernel/syscalls/ipc/msgrcv/msgrcv09.c line 93
Quoted 13 lines
testcases/kernel/syscalls/ipc/msgrcv/msgrcv09.c new file +13
-0+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...
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 3/3 syscalls/msgrcv09: Add error test for MSG_COPY flag
Hi Cyril
Quoted 17 lines
Hi!
testcases/kernel/syscalls/ipc/msgrcv/msgrcv09.c line 93
Quoted 13 lines
testcases/kernel/syscalls/ipc/msgrcv/msgrcv09.c new file +13
-0+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_kverandCONFIG_CHECKPOINT_RESTORE? Wouldn't beCONFIG_CHECKPOINT_RESTOREenough?
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.
Quoted 2 lines
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).
Quoted 1 line
PATCH 3/3 syscalls/msgrcv09: Add error test for MSG_COPY flag
Hi!
Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
testcases/kernel/syscalls/ipc/msgrcv/msgrcv09.c new file +8
-0+static struct tst_test test = { + .needs_tmpdir =1 , + .needs_root =1 , + .needs_kconfigs = (const char *[]) { +"CONFIG_CHECKPOINT_RESTORE" , +NULL + }, + .min_kver ="3.8.0" ,Quoted 8 lines
testcases/kernel/syscalls/ipc/msgrcv/msgrcv09.c line 93
Quoted 5 lines
testcases/kernel/syscalls/ipc/msgrcv/msgrcv09.c new file +5
-0+ .tcnt = ARRAY_SIZE(tcases), + .test = verify_msgrcv, + .setup = setup, + .cleanup = cleanup, +};Do we need both
min_kverandCONFIG_CHECKPOINT_RESTORE? Wouldn't beCONFIG_CHECKPOINT_RESTOREenough?
Quoted 4 lines
I think we need both because the
CONFIG_CHECKPOINT_RESTOREmacro was not introduced since 3.8. Before 3.8, we can enable this config but the kernel does not support thisMSG_COPYFLAG.
also using "CONFIG_CHECKPOINT_RESTORE=y" is better.
Ah, makes sense. I wonder if this worth a comment in the top level test description.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 3/3 syscalls/msgrcv09: Add error test for MSG_COPY flag
Hi Cyril
Quoted 17 lines
Hi!
Quoted 16 lines
Quoted 16 lines
testcases/kernel/syscalls/ipc/msgrcv/msgrcv09.c line 93
Quoted 13 lines
testcases/kernel/syscalls/ipc/msgrcv/msgrcv09.c new file +13
-0+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_kverandCONFIG_CHECKPOINT_RESTORE? Wouldn't beCONFIG_CHECKPOINT_RESTOREenough?
Quoted 7 lines
Quoted 4 lines
I think we need both because the
CONFIG_CHECKPOINT_RESTOREmacro was not introduced since 3.8. Before 3.8, we can enable this config but the kernel does not support thisMSG_COPYFLAG.
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.
Quoted 1 line
PATCH v2 1/1 syscalls/msgrcv03: Add error test for MSG_COPY flag
In reply to Cyril HrubisThe 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.
---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
include/lapi/msg.h new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. +* Author: Yang Xu <[email protected]> +*/ +#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
runtest/syscalls +1 -0
@@ -815,6 +815,7 @@ msgget05 msgget05 msgrcv01 msgrcv01 msgrcv02 msgrcv02 +msgrcv03 msgrcv03 msgrcv05 msgrcv05 msgrcv06 msgrcv06 msgrcv07 msgrcv07
runtest/syscalls-ipc +1 -0
@@ -17,6 +17,7 @@ msgget05 msgget05 msgrcv01 msgrcv01 msgrcv02 msgrcv02 +msgrcv03 msgrcv03 msgrcv05 msgrcv05 msgrcv06 msgrcv06 msgrcv07 msgrcv07
testcases/kernel/syscalls/ipc/msgrcv/.gitignore +1 -0
@@ -1,5 +1,6 @@ /msgrcv01 /msgrcv02 +/msgrcv03 /msgrcv05 /msgrcv06 /msgrcv07
testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c new file +102 -0
102 lines not on this page · raw message
Signature · 1 line
2.23.0
PATCH v2 1/1 syscalls/msgrcv03: Add error test for MSG_COPY flag
Hi Cyril
Do you have some comments for this v2 patch?
Best Regards
Yang Xu
Quoted 186 lines
The
MSG_COPYflag was added in 3.8 for the implementation of the kernel checkpoint-restore facility and is available only if the kernel was built with theCONFIG_CHECKPOINT_RESTOREoption.On old kernel without this support, it only ignores this flag and doesn't report ENOSYS/EINVAL error, so I add kconfig and
min_kvercheck.Signed-off-by Yang Xu <[email protected]>---
v1->v2:
1.Renamemsgrcv09->msgrcv03
2.add comment on top level for why we both needmin_kerneland kconfig checkinclude/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 100644testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.cinclude/lapi/msg.h new file +15
-0@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. +* Author: Yang Xu <[email protected]> +*/ +#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 runtest/syscalls +1
-0@@ -815,6 +815,7 @@ msgget05 msgget05 msgrcv01 msgrcv01 msgrcv02 msgrcv02 +msgrcv03 msgrcv03 msgrcv05 msgrcv05 msgrcv06 msgrcv06 msgrcv07 msgrcv07runtest/syscalls-ipc +1
-0@@ -17,6 +17,7 @@ msgget05 msgget05 msgrcv01 msgrcv01 msgrcv02 msgrcv02 +msgrcv03 msgrcv03 msgrcv05 msgrcv05 msgrcv06 msgrcv06 msgrcv07 msgrcv07testcases/kernel/syscalls/ipc/msgrcv/.gitignore +1
-0@@ -1,5 +1,6 @@ /msgrcv01 /msgrcv02 +/msgrcv03 /msgrcv05 /msgrcv06 /msgrcv07testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c new file +102
-0@@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. +* Author: Yang Xu <[email protected]> +* +* 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, +};
PATCH v2 1/1 syscalls/msgrcv03: Add error test for MSG_COPY flag
Hi
Ping.
Quoted 206 lines
Hi Cyril
Do you have some comments for this v2 patch?
Best Regards
Yang XuQuoted 197 lines
The
MSG_COPYflag was added in 3.8 for the implementation of the kernel checkpoint-restore facility and is available only if the kernel was built with theCONFIG_CHECKPOINT_RESTOREoption.On old kernel without this support, it only ignores this flag and doesn't report ENOSYS/EINVAL error, so I add kconfig and
min_kvercheck.Signed-off-by Yang Xu <[email protected]>---
v1->v2:
1.Renamemsgrcv09->msgrcv03
2.add comment on top level for why we both needmin_kerneland 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 100644include/lapi/msg.h
? create mode 100644testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.cinclude/lapi/msg.h new file +15
-0@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. +* Author: Yang Xu <[email protected]> +*/ +#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 runtest/syscalls +0
-0@@ -815,6 +815,7 @@ msgget05 msgget05? msgrcv01 msgrcv01
? msgrcv02 msgrcv02
+msgrcv03 msgrcv03
? msgrcv05 msgrcv05
? msgrcv06 msgrcv06
? msgrcv07 msgrcv07runtest/syscalls-ipc +0
-0@@ -17,6 +17,7 @@ msgget05 msgget05? msgrcv01 msgrcv01
? msgrcv02 msgrcv02
+msgrcv03 msgrcv03
? msgrcv05 msgrcv05
? msgrcv06 msgrcv06
? msgrcv07 msgrcv07testcases/kernel/syscalls/ipc/msgrcv/.gitignore +0
-0@@ -1,5 +1,6 @@? /msgrcv01
? /msgrcv02
+/msgrcv03
? /msgrcv05
? /msgrcv06
? /msgrcv07testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c new file +7
-0@@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. +* Author: Yang Xu <[email protected]> +* +* 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_RESTOREoption.
+ * On old kernel without this support, it only ignores this flag and doesn't
+ * report ENOSYS/EINVAL error. TheCONFIG_CHECKPOINT_RESTOREhas existed
+ * before kernel 3.8.
+ * So for using this flag, kernel should greater than 3.8 and enable
+ *CONFIG_CHECKPOINT_RESTOREtogether.
+ *
+ * 1)msgrcv(2) fails and sets errno to EINVAL ifIPC_NOWAITwas not specified
+ *?? in msgflag.
+ * 2)msgrcv(2) fails and sets errno to EINVAL ifIPC_EXCEPTwas specified
+ *?? in msgflag.
+ * 3)msgrcv(2) fails and set errno to ENOMSG ifIPC_NOWAITandMSG_COPYwere
+ *? specified in msgflg and the queue contains less than msgtyp messages.
+ */testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c new file +26
-0+ +#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 bothMSG_COPYandMSG_EXCEPT"},testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c new file +12
-0+ +??? {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;
+??? }testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c new file +34
-0+ +??? 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, +};
PATCH v2 1/1 syscalls/msgrcv03: Add error test for MSG_COPY flag
In reply to Yang XuHi!
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.
Signature · 2 lines
Cyril Hrubis [email protected]
cover increase msgrcv coverage
In reply to Yang XuHI!
This patchset is based on my previous msgrcv cleanup patch.
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
Quoted 23 lines
1. The first patch add check for
msg_lrpidandmsg_rtime.
2. The second patch tests different msgtyp.
3. The third patch testsMSG_COPYflag(basic error test),not functional test because kernel selftest[1] has tested this.Yang Xu (3):
syscalls/msgrcv: Add check formsg_lrpidandmsg_rtimesyscalls/msgrcv07: Add different msgtyp test syscalls/msgrcv09: Add error test forMSG_COPYflaginclude/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 100644testcases/kernel/syscalls/ipc/msgrcv/msgrcv09.c
cover increase msgrcv coverage
In reply to Yang XuHi!
Quoted 6 lines
1. The first patch add check for
msg_lrpidandmsg_rtime.
2. The second patch tests different msgtyp.
3. The third patch testsMSG_COPYflag(basic error test),not functional test because kernel selftest[1] has tested this.
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.
Signature · 2 lines
Cyril Hrubis [email protected]
cover increase msgrcv coverage
HI Cyril
Quoted 11 lines
Hi!
Quoted 6 lines
1. The first patch add check for
msg_lrpidandmsg_rtime.
2. The second patch tests different msgtyp.
3. The third patch testsMSG_COPYflag(basic error test),not functional test because kernel selftest[1] has tested this.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_COPYin LTP.
Quoted 8 lines
We can put a simple one into msgrcv07 we would call
msgrcv()withMSG_COPYif we got an EINVAL we will skip the test sinceMSG_COPYis 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).