ipc/lib: add header files for new API
PATCH 1/4 ipc/lib: add header files for new API
1) add tst_ipcmsg.h for new API
2) add tst_ipcsem.h for new API
3)add tst_ipcshm.h for new API
4) fix libipc.c for new API
--- testcases/kernel/syscalls/ipc/lib/libipc.c | 6 +-- testcases/kernel/syscalls/ipc/lib/tst_ipcmsg.h | 61 ++++++++++++++++++++++++++ testcases/kernel/syscalls/ipc/lib/tst_ipcsem.h | 52 ++++++++++++++++++++++ testcases/kernel/syscalls/ipc/lib/tst_ipcshm.h | 47 ++++++++++++++++++++ 4 files changed, 163 insertions(+), 3 deletions(-) create mode 100644 testcases/kernel/syscalls/ipc/lib/tst_ipcmsg.h create mode 100644 testcases/kernel/syscalls/ipc/lib/tst_ipcsem.h create mode 100644 testcases/kernel/syscalls/ipc/lib/tst_ipcshm.h
testcases/kernel/syscalls/ipc/lib/libipc.c +3 -3
@@ -58,7 +58,7 @@ key_t getipckey(void)static int count =0 ;if (NULL == (curdir =getcwd (curdir, size))) { -tst_brkm (TBROK , cleanup,"Can't get current directory " +tst_brkm (TBROK ,NULL ,"Can't get current directory " "in getipckey()" ); }
@@ -72,7 +72,7 @@ key_t getipckey(void) count++;if ((ipc_key =ftok (curdir, proj_id)) ==-1 ) { -tst_brkm (TBROK , cleanup,"Can't get msgkey from ftok()" ); +tst_brkm (TBROK ,NULL ,"Can't get msgkey from ftok()" ); }return (ipc_key);
@@ -145,7 +145,7 @@ int getuserid(char *user)/* get the uid value for the user */ if ((ent =getpwnam (user)) ==NULL ) { -tst_brkm (TBROK , cleanup,"Couldn't get password entry for %s" , +tst_brkm (TBROK ,NULL ,"Couldn't get password entry for %s" , user); }
testcases/kernel/syscalls/ipc/lib/tst_ipcmsg.h new file +61 -0
61 lines not on this page · raw message
testcases/kernel/syscalls/ipc/lib/tst_ipcsem.h new file +52 -0
52 lines not on this page · raw message
testcases/kernel/syscalls/ipc/lib/tst_ipcshm.h new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 2/4 ipc/msgget01.c: cleanup && convert to new API
--- testcases/kernel/syscalls/ipc/msgget/msgget01.c | 188 ++++++------------------ 1 file changed, 45 insertions(+), 143 deletions(-)
testcases/kernel/syscalls/ipc/msgget/msgget01.c +45 -143
@@ -1,186 +1,88 @@/* +* Copyright (c) International Business Machines Corp., 2001 * -* Copyright (c) International Business Machines Corp., 2001 +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. * -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* You should have received a copy of the GNU General Public License +* along with this program. */ /* -* NAME -* msgget01.c +* NAME: msgget01.c * * DESCRIPTION -* msgget01 - create a message queue, write a message to it and -* read it back. -* -* ALGORITHM -* loop if that option was specified -* create a message queue -* check the return code -* if failure, issue a FAIL message. -* otherwise, -* if doing functionality testing by writting a message to the queue, -* reading it back and comparing the two. -* if the messages are the same, -* issue a PASS message -* otherwise -* issue a FAIL message -* call cleanup -* -* USAGE: <for command-line> -* msgget01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -f : Turn off functionality Testing. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 03/2001 - Written by Wayne Boyer +* create a message queue, write a message to it and +* read it back. * -* RESTRICTIONS -* none */ -#include "ipcmsg.h" -#include <string.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/msg.h> + +#include "tst_ipcmsg.h" +#include "tst_test.h" -char *TCID ="msgget01" ; -int TST_TOTAL =1 ; +static int msg_q_1 =-1 ; -int msg_q_1 =-1 ;/* to hold the message queue ID */ +static void check_functionality (void ); -int main (int ac,char **av) +static void verify_msgget (void ) { -int lc; -void check_functionality (void ); - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup ();/* global setup */ - -/* The following loop checks looping state if -i option given */ - -for (lc =0 ;TEST_LOOPING (lc); lc++) { -/* reset tst_count in case we are looping */ - tst_count =0 ; - -/* -* Use TEST macro to make the call to create the message queue -*/ - -TEST (msgget (msgkey,IPC_CREAT |IPC_EXCL |MSG_RD |MSG_WR )); - -if (TEST_RETURN ==-1 ) { -tst_resm (TFAIL ,"%s call failed - errno = %d : %s" , -TCID ,TEST_ERRNO ,strerror (TEST_ERRNO )); - }else { - msg_q_1 =TEST_RETURN ; -/* -* write a message to the queue. -* read back the message. -* PASS the test if they are the same. -*/ -check_functionality (); - } - -/* -* remove the message queue that was created and mark the ID -* as invalid. -*/ -if (msg_q_1 !=-1 ) { -rm_queue (msg_q_1); - msg_q_1 =-1 ; - } + msgkey =getipckey (); + +TEST (msgget (msgkey,IPC_CREAT |IPC_EXCL |MSG_RD |MSG_WR )); + +if (TEST_RETURN ==-1 ) { +tst_res (TFAIL |TTERRNO ,"msgget() failed" ); + }else { + msg_q_1 =TEST_RETURN ; + +check_functionality (); } -cleanup (); -tst_exit (); +rm_queue (msg_q_1); } -/* -* check_functionality() - check the functionality of the tested system call. -*/ -void check_functionality (void ) +static void check_functionality (void ) { -int i =0 ;MSGBUF snd_buf, rcv_buf; -/* EAGLE: Houston, Tranquility Base here. The Eagle has landed! */ char *queue_msg ="Qston, check_functionality here. The message has queued!" ; -/* -* copy our message into the buffer and then set the type. -*/ -do { - snd_buf.mtext[i++] = *queue_msg; - }while (*queue_msg++ !='\0' ); +strcpy (snd_buf.mtext, queue_msg); snd_buf.mtype =MSGTYPE ; -/* send the message */ if (msgsnd (msg_q_1, &snd_buf,MSGSIZE ,0 ) ==-1 ) { -tst_brkm (TBROK , cleanup,"Could not send a message in the " +tst_brk (TBROK ,"Could not send a message in the " "check_functionality() routine." ); } -/* receive the message */ if (msgrcv (msg_q_1, &rcv_buf,MSGSIZE ,MSGTYPE ,IPC_NOWAIT ) ==-1 ) { -tst_brkm (TBROK , cleanup,"Could not read a messages in the " +tst_brk (TBROK ,"Could not read a messages in the " "check_functionality() routine." ); }if (strcmp (snd_buf.mtext, rcv_buf.mtext) ==0 ) { -tst_resm (TPASS ,"message received = message sent" ); +tst_res (TPASS ,"message received = message sent" ); }else { -tst_resm (TFAIL ,"message received != message sent" ); +tst_res (TFAIL ,"message received != message sent" ); } } -/* -* setup() - performs all the ONE TIME setup for this test. -*/ -void setup (void ) -{ - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* -* Create a temporary directory and cd into it. -* This helps to ensure that a unique msgkey is created. -* See ../lib/libipc.c for more information. -*/ -tst_tmpdir (); - - msgkey =getipckey (); -} - -/* -* cleanup() - performs all the ONE TIME cleanup for this test at completion -* or premature exit. -*/ -void cleanup (void ) -{ -/* if it exists, remove the message queue that was created */ -rm_queue (msg_q_1); - -tst_rmdir (); - -} +static struct tst_test test = { + .tid ="msgget01" , + .test_all = verify_msgget, + .needs_tmpdir =1 +};
Signature · 1 line
1.8.3.1
PATCH 2/4 ipc/msgget01.c: cleanup && convert to new API
Hi!
testcases/kernel/syscalls/ipc/msgget/msgget01.c line 46
Quoted 6 lines
testcases/kernel/syscalls/ipc/msgget/msgget01.c +6
-0+ msgkey =getipckey (); + +TEST (msgget (msgkey,IPC_CREAT |IPC_EXCL |MSG_RD |MSG_WR )); + +if (TEST_RETURN ==-1 ) { +tst_res (TFAIL |TTERRNO ,"msgget() failed" );
Just do return; here so that we can omit the else branch.
testcases/kernel/syscalls/ipc/msgget/msgget01.c line 50
Quoted 4 lines
testcases/kernel/syscalls/ipc/msgget/msgget01.c +4
-0+ }else { + msg_q_1 =TEST_RETURN ; + +check_functionality ();
There is no reason to keep the check in the separate funciton now, we can just do it here instead.
Quoted 24 lines
testcases/kernel/syscalls/ipc/msgget/msgget01.c +2
-12} -cleanup (); -tst_exit (); +rm_queue (msg_q_1); } -/* -* check_functionality() - check the functionality of the tested system call. -*/ -void check_functionality (void ) +static void check_functionality (void ) { -int i =0 ;MSGBUF snd_buf, rcv_buf; -/* EAGLE: Houston, Tranquility Base here. The Eagle has landed! */ char *queue_msg ="Qston, check_functionality here. The message has queued!" ; -/* -* copy our message into the buffer and then set the type. -*/ - do {
testcases/kernel/syscalls/ipc/msgget/msgget01.c line 68
Quoted 10 lines
testcases/kernel/syscalls/ipc/msgget/msgget01.c +2
-4- snd_buf.mtext[i++] = *queue_msg; - }while (*queue_msg++ !='\0' ); +strcpy (snd_buf.mtext, queue_msg); snd_buf.mtype =MSGTYPE ; -/* send the message */ if (msgsnd (msg_q_1, &snd_buf,MSGSIZE ,0 ) ==-1 ) { - tst_brkm(TBROK, cleanup, "Could not send a message in the " + tst_brk(TBROK, "Could not send a message in the "
^
TBROK | TERRNO
Quoted 1 line
"
check_functionality()routine.");
^
We shoud print something shorter and more to the point, such as:
tst_brk(TBROK|TERRNO, "msgsnd() failed");
testcases/kernel/syscalls/ipc/msgget/msgget01.c line 74
Quoted 7 lines
testcases/kernel/syscalls/ipc/msgget/msgget01.c +1
-2} -/* receive the message */ if (msgrcv (msg_q_1, &rcv_buf,MSGSIZE ,MSGTYPE ,IPC_NOWAIT ) ==-1 ) { -tst_brkm (TBROK , cleanup,"Could not read a messages in the " +tst_brk (TBROK ,"Could not read a messages in the " "check_functionality() routine." );
here as well
Quoted 33 lines
testcases/kernel/syscalls/ipc/msgget/msgget01.c +2
-24}if (strcmp (snd_buf.mtext, rcv_buf.mtext) ==0 ) { -tst_resm (TPASS ,"message received = message sent" ); +tst_res (TPASS ,"message received = message sent" ); }else { -tst_resm (TFAIL ,"message received != message sent" ); +tst_res (TFAIL ,"message received != message sent" ); } } -/* -* setup() - performs all the ONE TIME setup for this test. -*/ -void setup (void ) -{ - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* -* Create a temporary directory and cd into it. -* This helps to ensure that a unique msgkey is created. -* See ../lib/libipc.c for more information. -*/ -tst_tmpdir (); - - msgkey =getipckey (); -} - -/* -* cleanup() - performs all the ONE TIME cleanup for this test at completion
testcases/kernel/syscalls/ipc/msgget/msgget01.c line 186
Quoted 10 lines
testcases/kernel/syscalls/ipc/msgget/msgget01.c +0
-10-* or premature exit. -*/ -void cleanup (void ) -{ -/* if it exists, remove the message queue that was created */ -rm_queue (msg_q_1); - -tst_rmdir (); - -}
We should keep the rm_queue() in the cleanup function and add the cleanup to the test structure as well, so that the queue is removed if some part of the test called tst_brk().
And we should also set the msg_q_1 to -1 after the rm_qeueue() in the verify_msgget() since otherwise we may attempt to remove already removed queue when the test is called with -i and the test function is called repeatedly.
Quoted 13 lines
testcases/kernel/syscalls/ipc/msgget/msgget01.c +5
-0+static struct tst_test test = { + .tid ="msgget01" , + .test_all = verify_msgget, + .needs_tmpdir =1 +};Signature · 7 lines
1.8.3.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 3/4 ipc/msgget02.c: reconstruct && convert to new API
In reply to Xiao Yang1) merge msgget04 into msgget02
2) take use of some SAFE Marcos
--- runtest/ltplite | 1 - runtest/stress.part3 | 1 - runtest/syscalls | 1 - runtest/syscalls-ipc | 1 - testcases/kernel/syscalls/.gitignore | 1 - testcases/kernel/syscalls/ipc/msgget/msgget02.c | 225 +++++++++--------------- testcases/kernel/syscalls/ipc/msgget/msgget04.c | 169 ------------------ 7 files changed, 84 insertions(+), 315 deletions(-) delete mode 100644 testcases/kernel/syscalls/ipc/msgget/msgget04.c
runtest/ltplite +0 -1
@@ -503,7 +503,6 @@ msgctl09 msgctl09 msgget01 msgget01 msgget02 msgget02 msgget03 msgget03 -msgget04 msgget04 msgrcv01 msgrcv01 msgrcv02 msgrcv02
runtest/stress.part3 +0 -1
@@ -419,7 +419,6 @@ msgctl09 msgctl09 msgget01 msgget01 msgget02 msgget02 msgget03 msgget03 -msgget04 msgget04 msgrcv01 msgrcv01 msgrcv02 msgrcv02
runtest/syscalls +0 -1
@@ -674,7 +674,6 @@ msgctl13 msgctl13 msgget01 msgget01 msgget02 msgget02 msgget03 msgget03 -msgget04 msgget04 msgrcv01 msgrcv01 msgrcv02 msgrcv02
runtest/syscalls-ipc +0 -1
@@ -15,7 +15,6 @@ msgctl13 msgctl13 msgget01 msgget01 msgget02 msgget02 msgget03 msgget03 -msgget04 msgget04 msgrcv01 msgrcv01 msgrcv02 msgrcv02
testcases/kernel/syscalls/.gitignore +0 -1
@@ -402,7 +402,6 @@ /ipc/msgget/msgget01 /ipc/msgget/msgget02 /ipc/msgget/msgget03 -/ipc/msgget/msgget04 /ipc/msgrcv/msgrcv01 /ipc/msgrcv/msgrcv02 /ipc/msgrcv/msgrcv03
testcases/kernel/syscalls/ipc/msgget/msgget02.c +84 -141
260 lines not on this page · raw message
testcases/kernel/syscalls/ipc/msgget/msgget04.c deleted +0 -169
169 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 3/4 ipc/msgget02.c: reconstruct && convert to new API
Hi!
Quoted 173 lines
testcases/kernel/syscalls/ipc/msgget/msgget02.c +49
-97@@ -1,176 +1,119 @@/* +* Copyright (c) International Business Machines Corp., 2001 * -* Copyright (c) International Business Machines Corp., 2001 +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. * -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* You should have received a copy of the GNU General Public License +* along with this program. */ /* -* NAME -* msgget02.c +* NAME: msgget02.c * * DESCRIPTION -* msgget02 - test for EEXIST and ENOENT errors -* -* ALGORITHM -* create a message queue -* loop if that option was specified -* try to recreate the same queue - test #1 -* try to access a queue that doesn't exist - tests #2 & #3 -* check the errno value -* issue a PASS message if we get EEXIST or ENOENT depening on test -* otherwise, the tests fails -* issue a FAIL message -* break any remaining tests -* call cleanup -* -* USAGE: <for command-line> -* msgget02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 03/2001 - Written by Wayne Boyer +* 1) msgget(2) fails if a message queue exists for key and msgflg +* specified both IPC_CREAT and IPC_EXCL. +* 2) msgget(2) fails if no message queue exists for key and msgflg +* did not specify IPC_CREAT. +* 3) msgget(2) fails if a message queue exists for key, but the +* calling process does not have permission to access the queue, +* and does not have the CAP_IPC_OWNER capability. * -* 28/03/2008 Renaud Lottiaux ([email protected]) -* - Fix concurrency issue. The second key used for this test was -* sometime conflicting with the key from another task. -* Generate a valid second key through getipckey to avoid conflicts. -* -* RESTRICTIONS -* none */ -#include "test.h" +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/msg.h> +#include <pwd.h> -#include "ipcmsg.h" +#include "tst_ipcmsg.h" +#include "tst_test.h" -char *TCID ="msgget02" ; -int TST_TOTAL =3 ; +static key_t msgkey1; +static int msg_q_1 =-1 ; -struct test_case_t { -int error; -int msgkey; +static struct tcase { +int *key;int flags; -}TC [] = { - { -EEXIST ,0 ,IPC_CREAT |IPC_EXCL }, { -ENOENT ,1 ,IPC_PRIVATE }, { -ENOENT ,1 ,IPC_EXCL } +int exp_err; +} tcases[] = { + {&msgkey,IPC_CREAT |IPC_EXCL ,EEXIST }, + {&msgkey1,IPC_PRIVATE ,ENOENT }, + {&msgkey1,IPC_EXCL ,ENOENT }, + {&msgkey,MSG_RD ,EACCES }, + {&msgkey,MSG_WR ,EACCES }, + {&msgkey,MSG_RD |MSG_WR ,EACCES } }; -key_t msgkey1; -int msg_q_1 =-1 ;/* The message queue id created in setup */ - -int main (int ac,char **av) +static void verify_msgget (struct tcase *tc) { -int lc; -int i; -key_t key; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup ();/* global setup */ +TEST (msgget (*tc->key, tc->flags)); -/* The following loop checks looping state if -i option given */ - -for (lc =0 ;TEST_LOOPING (lc); lc++) { -/* reset tst_count in case we are looping */ - tst_count =0 ; - -/* loop through the test cases */ - -for (i =0 ; i <TST_TOTAL ; i++) { - -if (TC [i].msgkey ==0 ) - key = msgkey; -else - key = msgkey1; - -TEST (msgget (key,TC [i].flags)); +if (TEST_RETURN !=-1 ) { +tst_res (TFAIL ,"msgget() succeeded unexpectedly" ); +return ; + } -if (TEST_RETURN !=-1 ) { -tst_resm (TFAIL ,"msgget() call succeeded " -"on expected fail" ); -continue ; - } +if (TEST_ERRNO == tc->exp_err) +tst_res (TPASS |TTERRNO ,"msgget() failed as expected" ); +else +tst_res (TFAIL |TTERRNO ,"msgget() failed unexpectedly," +" expected %s" ,tst_strerrno (tc->exp_err)); +} -switch (TEST_ERRNO ) { -case ENOENT : -/*FALLTHROUGH*/ case EEXIST : -if (TEST_ERRNO ==TC [i].error) { - tst_resm(TPASS, "expected failure - " - "errno = %d : %s", TEST_ERRNO,
testcases/kernel/syscalls/ipc/msgget/msgget02.c line 72
Quoted 10 lines
testcases/kernel/syscalls/ipc/msgget/msgget02.c +1
-9- strerror(TEST_ERRNO)); -break ; - } -/*FALLTHROUGH*/ default : -tst_resm (TFAIL ,"call failed with an " -"unexpected error - %d : %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); -break ; - } +static void verify_access (unsigned int n)
^
The function name is confusing, we do not test access() call here. I would have just called this do_test() or something.
testcases/kernel/syscalls/ipc/msgget/msgget02.c line 79
Quoted 7 lines
testcases/kernel/syscalls/ipc/msgget/msgget02.c +7
-0+{ +pid_t pid; +uid_t uid; +struct passwd *pw; +struct tcase *tc = &tcases[n]; + +if (tc->exp_err !=EACCES ) {
Switching on the expected errno is kind of confusing. I would rather see as_nobody bitflag in the tcases structure that is set to 1 for this particular case.
testcases/kernel/syscalls/ipc/msgget/msgget02.c line 83
Quoted 4 lines
testcases/kernel/syscalls/ipc/msgget/msgget02.c +4
-0+verify_msgget (tc); + }else { + pw =SAFE_GETPWNAM ("nobody" ); + uid = pw->pw_uid;
This should be done in the test setup()
testcases/kernel/syscalls/ipc/msgget/msgget02.c line 87
Quoted 3 lines
testcases/kernel/syscalls/ipc/msgget/msgget02.c +3
-0+ pid =SAFE_FORK (); +if (pid) { +SAFE_WAITPID (pid,NULL ,0 );
If you do not want to check the child return value here you should rather call tst_reap_children() that will do that for you.
testcases/kernel/syscalls/ipc/msgget/msgget02.c line 90
Quoted 3 lines
testcases/kernel/syscalls/ipc/msgget/msgget02.c +3
-0+ }else { +SAFE_SETUID (uid); +verify_msgget (tc);
Missing exit(0) here?
Quoted 39 lines
testcases/kernel/syscalls/ipc/msgget/msgget02.c +4
-26} } - -cleanup (); - -tst_exit (); } -/* -* setup() - performs all the ONE TIME setup for this test. -*/ -void setup (void ) +static void setup (void ) { - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* -* Create a temporary directory and cd into it. -* This helps to ensure that a unique msgkey is created. -* See ../lib/libipc.c for more information. -*/ -tst_tmpdir (); - msgkey =getipckey (); msgkey1 =getipckey (); -/* now we have a key, so let's create a message queue */ -if ((msg_q_1 =msgget (msgkey,IPC_CREAT |IPC_EXCL )) ==-1 ) { -system ("ipcs > /tmp/toto" ); -system ("ps -aux >> /tmp/toto" ); -tst_brkm (TBROK , cleanup,"Can't create message queue" ); - } + msg_q_1 =msgget (msgkey,IPC_CREAT |IPC_EXCL ); +if (msg_q_1 ==-1 ) +tst_brk (TBROK ,"Can't create message queue" ); }
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 4/4 ipc/msgget03.c: cleanup && convert to new API
In reply to Xiao Yang--- testcases/kernel/syscalls/ipc/msgget/msgget03.c | 192 ++++++++---------------- 1 file changed, 60 insertions(+), 132 deletions(-)
testcases/kernel/syscalls/ipc/msgget/msgget03.c +60 -132
@@ -1,168 +1,96 @@/* +* Copyright (c) International Business Machines Corp., 2001 * -* Copyright (c) International Business Machines Corp., 2001 +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. * -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* You should have received a copy of the GNU General Public License +* along with this program. */ /* -* NAME -* msgget03.c +* NAME: msgget03.c * * DESCRIPTION -* msgget03 - test for an ENOSPC error by using up all available -* message queues. -* -* ALGORITHM -* Get all the message queues that can be allocated -* loop if that option was specified -* Try to get one more message queue -* check the errno value -* issue a PASS message if we get ENOSPC -* otherwise, the tests fails -* issue a FAIL message -* break any remaining tests -* call cleanup -* -* USAGE: <for command-line> -* msgget03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. +* test for an ENOSPC error by using up all available +* message queues. * -* HISTORY -* 03/2001 - Written by Wayne Boyer -* -* RESTRICTIONS -* none */ -#include "test.h" - -#include "ipcmsg.h" - -char *TCID ="msgget03" ; -int TST_TOTAL =1 ; +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/msg.h> +#include <stdlib.h> -int maxmsgs =0 ; +#include "tst_ipcmsg.h" +#include "tst_test.h" -int *msg_q_arr =NULL ;/* hold the id's that we create */ -int num_queue =0 ;/* count the queues created */ +static int maxmsgs; +static int *msg_q_arr; -int main (int ac,char **av) +static void verify_msgget (void ) { -int lc; -int msg_q; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup ();/* global setup */ - -/* The following loop checks looping state if -i option given */ - -for (lc =0 ;TEST_LOOPING (lc); lc++) { -/* reset tst_count in case we are looping */ - tst_count =0 ; - -/* -* Use a while loop to create the maximum number of queues. -* When we get an error, check for ENOSPC. -*/ -while ((msg_q = -msgget (msgkey + num_queue, -IPC_CREAT |IPC_EXCL )) !=-1 ) { - msg_q_arr[num_queue] = msg_q; -if (num_queue == maxmsgs) { -tst_resm (TINFO ,"The maximum number of message" -" queues (%d) has been reached" , - maxmsgs); -break ; - } - num_queue++; - } - -switch (errno) { -case ENOSPC : -tst_resm (TPASS ,"expected failure - errno = %d : %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); -break ; -default : -tst_resm (TFAIL ,"call failed with an " -"unexpected error - %d : %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); -break ; - } - } - -cleanup (); - -tst_exit (); +TEST (msgget (msgkey + maxmsgs,IPC_CREAT |IPC_EXCL )); +if (TEST_RETURN !=-1 ) +tst_res (TFAIL ,"msgget() succeeded unexpectedly" ); + +if (TEST_ERRNO ==ENOSPC ) +tst_res (TPASS |TTERRNO ,"msgget() failed as expected" ); +else +tst_res (TFAIL |TTERRNO ,"msgget() failed unexpectedly," +" expected %s" ,tst_strerrno (ENOSPC )); } -/* -* setup() - performs all the ONE TIME setup for this test. -*/ -void setup (void ) +static void setup (void ) { - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* -* Create a temporary directory and cd into it. -* This helps to ensure that a unique msgkey is created. -* See ../lib/libipc.c for more information. -*/ -tst_tmpdir (); +int res, num; msgkey =getipckey (); maxmsgs =get_max_msgqueues ();if (maxmsgs <0 ) -tst_brkm (TBROK , cleanup,"get_max_msgqueues failed" ); +tst_brk (TBROK ,"get_max_msgqueues failed" ); msg_q_arr = (int *)calloc (maxmsgs,sizeof (int )); -if (msg_q_arr ==NULL ) { -tst_brkm (TBROK , cleanup,"Couldn't allocate memory " +if (!msg_q_arr) { +tst_brk (TBROK ,"Couldn't allocate memory " "for msg_q_arr: calloc() failed" ); } + +for (num =0 ; num < maxmsgs; num++) { + msg_q_arr[num] =-1 ; + + res =msgget (msgkey + num,IPC_CREAT |IPC_EXCL ); +if (res !=-1 ) + msg_q_arr[num] = res; + } + +tst_res (TINFO ,"The maximum number of message queues (%d) has been reached" , maxmsgs); } -/* -* cleanup() - performs all the ONE TIME cleanup for this test@completion -* or premature exit. -*/ -void cleanup (void ) +static void cleanup (void ) { -int i; +int num; -/* -* remove the message queues if they were created -*/ +if (msg_q_arr) { +for (num =0 ; num < maxmsgs; num++) +rm_queue (msg_q_arr[num]); -if (msg_q_arr !=NULL ) { -for (i =0 ; i < num_queue; i++) { -rm_queue (msg_q_arr[i]); - } (void )free (msg_q_arr); } - -tst_rmdir (); - } + +static struct tst_test test = { + .tid ="msgget03" , + .needs_tmpdir =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = verify_msgget +};
Signature · 1 line
1.8.3.1
PATCH 4/4 ipc/msgget03.c: cleanup && convert to new API
Hi!
Quoted 1 line
+ * NAME:
msgget03.c
This is redundand and obvious information, I would have removed this line as well.
Quoted 129 lines
* DESCRIPTION
- * msgget03 - test for an ENOSPC error by using up all available
- * message queues.
- *
- * ALGORITHM
- * Get all the message queues that can be allocated
- * loop if that option was specified
- * Try to get one more message queue
- * check the errno value
- * issue a PASS message if we get ENOSPC
- * otherwise, the tests fails- * issue a FAIL message - * break any remaining tests - * call cleanup- *
- * USAGE: <for command-line>
- * msgget03 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- * where, -c n : Run n copies concurrently.
- * -e : Turn on errno logging.- * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing.+ * test for an ENOSPC error by using up all available
+ * message queues.
*
- * HISTORY
- * 03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- * none
*/testcases/kernel/syscalls/ipc/msgget/msgget03.c +19
-70-#include "test.h" - -#include "ipcmsg.h" - -char *TCID ="msgget03" ; -int TST_TOTAL =1 ; +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/msg.h> +#include <stdlib.h> -int maxmsgs =0 ; +#include "tst_ipcmsg.h" +#include "tst_test.h" -int *msg_q_arr =NULL ;/* hold the id's that we create */ -int num_queue =0 ;/* count the queues created */ +static int maxmsgs; +static int *msg_q_arr; -int main (int ac,char **av) +static void verify_msgget (void ) { -int lc; -int msg_q; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup ();/* global setup */ - -/* The following loop checks looping state if -i option given */ - -for (lc =0 ;TEST_LOOPING (lc); lc++) { -/* reset tst_count in case we are looping */ - tst_count =0 ; - -/* -* Use a while loop to create the maximum number of queues. -* When we get an error, check for ENOSPC. -*/ -while ((msg_q = -msgget (msgkey + num_queue, -IPC_CREAT |IPC_EXCL )) !=-1 ) { - msg_q_arr[num_queue] = msg_q; -if (num_queue == maxmsgs) { -tst_resm (TINFO ,"The maximum number of message" -" queues (%d) has been reached" , - maxmsgs); -break ; - } - num_queue++; - } - -switch (errno) { -case ENOSPC : -tst_resm (TPASS ,"expected failure - errno = %d : %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); -break ; -default : -tst_resm (TFAIL ,"call failed with an " -"unexpected error - %d : %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); -break ; - } - } - -cleanup (); - -tst_exit (); +TEST (msgget (msgkey + maxmsgs,IPC_CREAT |IPC_EXCL )); +if (TEST_RETURN !=-1 ) +tst_res (TFAIL ,"msgget() succeeded unexpectedly" ); + +if (TEST_ERRNO ==ENOSPC ) +tst_res (TPASS |TTERRNO ,"msgget() failed as expected" ); +else +tst_res (TFAIL |TTERRNO ,"msgget() failed unexpectedly," +" expected %s" ,tst_strerrno (ENOSPC )); } -/* -* setup() - performs all the ONE TIME setup for this test. -*/ -void setup (void ) +static void setup (void ) { - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* -* Create a temporary directory and cd into it. -* This helps to ensure that a unique msgkey is created. -* See ../lib/libipc.c for more information. -*/
testcases/kernel/syscalls/ipc/msgget/msgget03.c line 61
Quoted 10 lines
testcases/kernel/syscalls/ipc/msgget/msgget03.c +2
-2-tst_tmpdir (); +int res, num; msgkey =getipckey (); maxmsgs =get_max_msgqueues ();if (maxmsgs <0 ) -tst_brkm (TBROK , cleanup,"get_max_msgqueues failed" ); +tst_brk (TBROK ,"get_max_msgqueues failed" ); msg_q_arr = (int *)calloc (maxmsgs,sizeof (int ));
Just drop the cast to (int *) here.
testcases/kernel/syscalls/ipc/msgget/msgget03.c line 65
Quoted 6 lines
testcases/kernel/syscalls/ipc/msgget/msgget03.c +2
-2-if (msg_q_arr ==NULL ) { -tst_brkm (TBROK , cleanup,"Couldn't allocate memory " +if (!msg_q_arr) { +tst_brk (TBROK ,"Couldn't allocate memory " "for msg_q_arr: calloc() failed" ); }
We do have SAFE_MALLOC(), we should just do:
msg_q_arr = SAFE_MALLOC(maxmsgs * sizeof(int));
Quoted 23 lines
testcases/kernel/syscalls/ipc/msgget/msgget03.c +11
-8+for (num =0 ; num < maxmsgs; num++) { + msg_q_arr[num] =-1 ; + + res =msgget (msgkey + num,IPC_CREAT |IPC_EXCL ); +if (res !=-1 ) + msg_q_arr[num] = res; + } + +tst_res (TINFO ,"The maximum number of message queues (%d) has been reached" , maxmsgs); } -/* -* cleanup() - performs all the ONE TIME cleanup for this test at completion -* or premature exit. -*/ -void cleanup (void ) +static void cleanup (void ) { -int i; +int num; -/* -* remove the message queues if they were created
testcases/kernel/syscalls/ipc/msgget/msgget03.c line 86
Quoted 10 lines
testcases/kernel/syscalls/ipc/msgget/msgget03.c +3
-5-*/ +if (msg_q_arr) { +for (num =0 ; num < maxmsgs; num++) +rm_queue (msg_q_arr[num]); -if (msg_q_arr !=NULL ) { -for (i =0 ; i < num_queue; i++) { -rm_queue (msg_q_arr[i]); - } (void )free (msg_q_arr);
Just drop the cast to (void) here.
testcases/kernel/syscalls/ipc/msgget/msgget03.c line 96
Quoted 13 lines
testcases/kernel/syscalls/ipc/msgget/msgget03.c +8
-3} - -tst_rmdir (); - } + +static struct tst_test test = { + .tid ="msgget03" , + .needs_tmpdir =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = verify_msgget +};
Otherwise from the things I pointed out, this series looks good.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/4 ipc/lib: add header files for new API
In reply to Xiao YangHi!
Quoted 3 lines
1) add
tst_ipcmsg.hfor new API
2) addtst_ipcsem.hfor new API
3???addtst_ipcshm.hfor new API
Hmm, why can't we add just one libipc.h?
Also I do not think that it's a good idea to prefix anything that is not in the top level library with tst_, that is kind of confusing.
Quoted 36 lines
4) fix
libipc.cfor new APISigned-off-by Xiao Yang <[email protected]>--- testcases/kernel/syscalls/ipc/lib/libipc.c | 6 +-- testcases/kernel/syscalls/ipc/lib/tst_ipcmsg.h | 61 ++++++++++++++++++++++++++ testcases/kernel/syscalls/ipc/lib/tst_ipcsem.h | 52 ++++++++++++++++++++++ testcases/kernel/syscalls/ipc/lib/tst_ipcshm.h | 47 ++++++++++++++++++++ 4 files changed, 163 insertions(+), 3 deletions(-) create mode 100644 testcases/kernel/syscalls/ipc/lib/tst_ipcmsg.h create mode 100644 testcases/kernel/syscalls/ipc/lib/tst_ipcsem.h create mode 100644 testcases/kernel/syscalls/ipc/lib/tst_ipcshm.htestcases/kernel/syscalls/ipc/lib/libipc.c +2
-2@@ -58,7 +58,7 @@ key_t getipckey(void)static int count =0 ;if (NULL == (curdir =getcwd (curdir, size))) { -tst_brkm (TBROK , cleanup,"Can't get current directory " +tst_brkm (TBROK ,NULL ,"Can't get current directory " "in getipckey()" ); }@@ -72,7 +72,7 @@ key_t getipckey(void) count++;if ((ipc_key =ftok (curdir, proj_id)) ==-1 ) { -tst_brkm (TBROK , cleanup,"Can't get msgkey from ftok()" ); +tst_brkm (TBROK ,NULL ,"Can't get msgkey from ftok()" ); }return (ipc_key);
testcases/kernel/syscalls/ipc/lib/libipc.c int getuserid(char *user) · line 150
Quoted 7 lines
testcases/kernel/syscalls/ipc/lib/libipc.c +1
-1@@ -145,7 +145,7 @@ int getuserid(char *user)/* get the uid value for the user */ if ((ent =getpwnam (user)) ==NULL ) { -tst_brkm (TBROK , cleanup,"Couldn't get password entry for %s" , +tst_brkm (TBROK ,NULL ,"Couldn't get password entry for %s" , user); }
Hmm, so when we fail here the oldlib testcases that are using this will fail to cleanup and the test will leave directory and some IPC objects on the system.
Maybe it would be better to copy the whole lib directory over to libipc, clean it and link converted testcases against the newly created libipc, then, once the last ipc testcase is converved finally remove the old lib.
Quoted 186 lines
testcases/kernel/syscalls/ipc/lib/tst_ipcmsg.h new file +61
-0@@ -0,0 +1,61 @@ +/* +* Copyright (c) 2016 Xiao Yang <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. +*/ + +/* +* ipcmsg.h - common definitions for the IPC message tests. +*/ + +#ifndef __IPCMSG_H +#define __IPCMSG_H 1 + +#include <errno.h> +#include <sys/ipc.h> +#include <sys/msg.h> +#include <sys/types.h> + +#define MSG_RD 0400/* read permission for the queue */ +#define MSG_WR 0200/* write permission for the queue */ +#define MSG_RW (MSG_RD | MSG_WR) + +#define MSGSIZE 1024/* a resonable size for a message */ +#define MSGTYPE 1/* a type ID for a message */ + +#define NR_MSGQUEUES 16/* MSGMNI as defined in linux/msg.h */ + +#define min (a, b) (((a) < (b)) ? @ : (b)) + +typedef struct mbuf {/* a generic message structure */ +long mtype; +char mtext[MSGSIZE +1 ];/* add 1 here so the message can be 1024 */ +}MSGBUF ;/* characters long with a '\0' termination */ + +#ifdef LIBIPC +key_t msgkey;/* the ftok() generated message key */ +#else +extern key_t msgkey;/* the ftok() generated message key */ +#endif + +void init_buf (MSGBUF *m_buf,int type,int size); +void rm_queue (int queue_id); + +key_t getipckey (void ); +int getuserid (char *user); + +int get_max_msgqueues (void ); +int get_used_msgqueues (void ); + +#endif /* ipcmsg.h */ testcases/kernel/syscalls/ipc/lib/tst_ipcsem.h new file +52
-0@@ -0,0 +1,52 @@ +/* +* Copyright (c) 2016 Xiao Yang <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. +*/ + +/* +* ipcsem.h - common definitions for the IPC semaphore tests +*/ + +#ifndef __IPCSEM_H +#define __IPCSEM_H + +#include <errno.h> +#include <sys/ipc.h> +#include <sys/sem.h> + +#include "lapi/semun.h" + +#define SEM_RD 0400 +#define SEM_ALT 0200 +#define SEM_RA (SEM_RD | SEM_ALT) + +/* +* a reasonable value for the number of +* "primitive semaphores" per ID +*/ +#define PSEMS 10 + +#ifdef LIBIPC +key_t semkey;/* an IPC key generated by ftok() */ +#else +extern key_t semkey;/* an IPC key generated by ftok() */ +#endif + +void rm_sema (int sem_id); + +int getipckey (void ); +int getuserid (char *user); + +#endif /* ipcsem.h */ testcases/kernel/syscalls/ipc/lib/tst_ipcshm.h new file +47
-0@@ -0,0 +1,47 @@ +/* +* Copyright (c) 2016 Xiao Yang <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. +*/ + +/* +* ipcshm.h - common definitions for the IPC shared memory tests +*/ + +#ifndef __IPCSHM_H +#define __IPCSHM_H + +#include <errno.h> +#include <wait.h> +#include <sys/ipc.h> +#include <sys/shm.h> + +#define SHM_RD 0400 +#define SHM_WR 0200 +#define SHM_RW (SHM_RD | SHM_WR) + +#define SHM_SIZE 2048/* a resonable size for a memory segment */ +#define INT_SIZE 4/* instead of sizeof(int) */ + +#define MODE_MASK 0x01FF/* to get the lower nine permission bits */ +/* from shmid_ds.ipc_perm.mode */ + +key_t shmkey;/* an IPC key generated by ftok() */ + +void rm_shm (int shm_id); + +int getipckey (void ); +int getuserid (char *user); + +#endif /* ipcshm.h */ Signature · 7 lines
1.8.3.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/5 tst_test.h: move test result description to tst_res.h
Move test result description to tst_res.h so that we can use them independently for new ipc.
--- include/tst_res.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/tst_test.h | 30 +----------------------------- 2 files changed, 51 insertions(+), 29 deletions(-) create mode 100644 include/tst_res.h
include/tst_res.h new file +50 -0
@@ -0,0 +1,50 @@ +/* +* Copyright (c) 2016 Xiao Yang <[email protected]> +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef TST_RES_H__ +#define TST_RES_H__ + +/* +* Reports testcase result. +*/ +void tst_res_ (const char *file,const int lineno,int ttype, +const char *fmt, ...) + __attribute__ ((format (printf,4 ,5 ))); + +#define tst_res (ttype, arg_fmt, ...) \ + tst_res_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__) + +void tst_resm_hexd_ (const char *file,const int lineno,int ttype, +const void *buf,size_t size,const char *arg_fmt, ...) + __attribute__ ((format (printf,6 ,7 ))); + +#define tst_res_hexd (ttype, buf, size, arg_fmt, ...) \ + tst_resm_hexd_(__FILE__, __LINE__, (ttype), (buf), (size), \ + (arg_fmt), ##__VA_ARGS__) + +/* +* Reports result and exits a test. +*/ +void tst_brk_ (const char *file,const int lineno,int ttype, +const char *fmt, ...) + __attribute__ ((format (printf,4 ,5 ))) + __attribute__ ((noreturn)); + +#define tst_brk (ttype, arg_fmt, ...) \ + tst_brk_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__) + +#endif /* TST_RES_H__ */
include/tst_test.h +1 -29
@@ -22,6 +22,7 @@#include "tst_common.h" #include "tst_res_flags.h" +#include "tst_res.h" #include "tst_checkpoint.h" #include "tst_device.h" #include "tst_mkfs.h"
@@ -34,35 +35,6 @@#include "tst_kvercmp.h" #include "tst_clone.h" -/* -* Reports testcase result. -*/ -void tst_res_ (const char *file,const int lineno,int ttype, -const char *fmt, ...) - __attribute__ ((format (printf,4 ,5 ))); - -#define tst_res (ttype, arg_fmt, ...) \ - tst_res_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__) - -void tst_resm_hexd_ (const char *file,const int lineno,int ttype, -const void *buf,size_t size,const char *arg_fmt, ...) - __attribute__ ((format (printf,6 ,7 ))); - -#define tst_res_hexd (ttype, buf, size, arg_fmt, ...) \ - tst_resm_hexd_(__FILE__, __LINE__, (ttype), (buf), (size), \ - (arg_fmt), ##__VA_ARGS__) - -/* -* Reports result and exits a test. -*/ -void tst_brk_ (const char *file,const int lineno,int ttype, -const char *fmt, ...) - __attribute__ ((format (printf,4 ,5 ))) - __attribute__ ((noreturn)); - -#define tst_brk (ttype, arg_fmt, ...) \ - tst_brk_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__) -pid_t safe_fork (const char *filename,unsigned int lineno);#define SAFE_FORK () \ safe_fork(__FILE__, __LINE__)
Signature · 1 line
1.8.3.1
PATCH v2 2/5 syscalls/ipc: add newipc library for new API
--- testcases/kernel/syscalls/ipc/Makefile | 40 +++--- testcases/kernel/syscalls/ipc/libnewipc/Makefile | 24 ++++ .../kernel/syscalls/ipc/libnewipc/libnewipc.c | 145 +++++++++++++++++++++ .../kernel/syscalls/ipc/libnewipc/libnewipc.h | 52 ++++++++ 4 files changed, 240 insertions(+), 21 deletions(-) create mode 100644 testcases/kernel/syscalls/ipc/libnewipc/Makefile create mode 100644 testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c create mode 100644 testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h
testcases/kernel/syscalls/ipc/Makefile +19 -21
@@ -1,19 +1,18 @@ # -# Copyright (c) International Business Machines Corp., 2001 +# Copyright (c) International Business Machines Corp., 2001 # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -# the GNU General Public License for more details. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# You should have received a copy of the GNU General Public License +# along with this program. # top_srcdir ?= ../../../..
@@ -21,20 +20,19 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/env_pre.mk LIBDIR := lib -FILTER_OUT_DIRS := $(LIBDIR) -LIB := $(LIBDIR)/libipc.a $(LIBDIR)/libmsgctl.a +NEWLIBDIR := libnewipc +LIB := $(LIBDIR)/libipc.a $(LIBDIR)/libmsgctl.a $(NEWLIBDIR)/libnewipc.a -$(LIBDIR): - mkdir -p "$@" - -$(LIB): $(LIBDIR) - $(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" all +$(LIB): $(LIBDIR) $(NEWLIBDIR) + $(MAKE) -C $(LIBDIR) -f "$(abs_srcdir)/$(LIBDIR)/Makefile" all + $(MAKE) -C $(NEWLIBDIR) -f "$(abs_srcdir)/$(NEWLIBDIR)/Makefile" all MAKE_DEPS := $(LIB) trunk-clean:: | lib-clean -lib-clean:: $(LIBDIR) - $(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" clean +lib-clean:: $(LIBDIR) $(NEWLIBDIR) + $(MAKE) -C $(LIBDIR) -f "$(abs_srcdir)/$(LIBDIR)/Makefile" clean + $(MAKE) -C $(NEWLIBDIR) -f "$(abs_srcdir)/$(NEWLIBDIR)/Makefile" clean include $(top_srcdir)/include/mk/generic_trunk_target.mk
testcases/kernel/syscalls/ipc/libnewipc/Makefile new file +24 -0
@@ -0,0 +1,24 @@ +# +# Copyright (c) 2016 Xiao Yang <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. +# + +top_srcdir ?= ../../../../.. + +include $(top_srcdir)/include/mk/env_pre.mk + +LIB := libnewipc.a + +include $(top_srcdir)/include/mk/lib.mk
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +145 -0
145 lines not on this page · raw message
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 2/5 syscalls/ipc: add newipc library for new API
Hi!
Quoted 19 lines
include $(top_srcdir)/include/mk/generic_trunk_target.mk
testcases/kernel/syscalls/ipc/libnewipc/Makefile new file +12
-0@@ -0,0 +1,24 @@ +# +# Copyright (c) 2016 Xiao Yang <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details.
testcases/kernel/syscalls/ipc/libnewipc/Makefile line 22
Quoted 10 lines
testcases/kernel/syscalls/ipc/libnewipc/Makefile new file +10
-0+# +# You should have received a copy of the GNU General Public License +# along with this program. +# + +top_srcdir ?= ../../../../.. + +include $(top_srcdir)/include/mk/env_pre.mk + +LIB := libnewipc.a
Should be INTERNAL_LIB so that it's skipped at installation phase.
Quoted 25 lines
testcases/kernel/syscalls/ipc/libnewipc/Makefile new file +1
-0+include $(top_srcdir)/include/mk/lib.mktestcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +18
-0@@ -0,0 +1,145 @@ +/* +* Copyright (c) 2016 Xiao Yang <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. +*/ + +/*
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c line 28
Quoted 10 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +10
-0+* DESCRIPTION +* common routines for the IPC system call tests. +* +* The library contains the following routines: +* getipckey() +* rm_queue() +* rm_sema() +* rm_shm() +* get_used_msgqueues() +* get_max_msgqueues()
This is kind of redundant information, pretty much anybody can see what functions are implemented here.
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c line 31
Quoted 3 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +3
-0+*/ + +#define NEWLIBIPC
This macro seems to be unused.
Quoted 12 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +12
-0+#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdlib.h> +#include <pwd.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/msg.h> +#include <sys/shm.h> +#include <sys/sem.h> + +#include "libnewipc.h"
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c line 54
Quoted 10 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +10
-0+#include "tst_res_flags.h" +#include "tst_res.h" +#include "tst_safe_macros.h" +#include "lapi/semun.h" + +#define BUFSIZE 512 + +key_t getipckey (void ) +{ +int ascii_a = (int )'a' ;
Eh, why do you store the value into an variable when you can just use the (int) 'a' in the computation directly...
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c line 63
Quoted 9 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +9
-0+char buf[BUFSIZE ]; +key_t key; +int id; +static int count; + +SAFE_GETCWD (buf,BUFSIZE ); + + id = count %26 + ascii_a; + count++;
This could be written just as:
id = (count++) % 26 + (int)'a';
Quoted 4 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +4
-0+ key =ftok (buf, id); +if (key ==-1 ) +tst_brk (TBROK |TERRNO ,"ftok() failed" ); +
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c line 78
Quoted 10 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +10
-0+return key; +} + +void rm_queue (int queue_id) +{ +if (queue_id ==-1 ) +return ; + +if (msgctl (queue_id,IPC_RMID ,NULL ) ==-1 ) { +tst_res (TINFO ,"WARNING: message queue deletion failed." );
^
This really should be TWARN, even the message includes 'WARNING' in the string. And we should include errno with TERRNO as well.
Or even better we should exit the test with TBROK here.
Quoted 4 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +4
-0+tst_res (TINFO ,"This could lead to IPC resource problems." ); +tst_res (TINFO ,"id = %d" , queue_id); + } +}
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c line 92
Quoted 10 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +10
-0+ +void rm_sema (int sem_id) +{ +union semun arr; + +if (sem_id ==-1 ) +return ; + +if (semctl (sem_id,0 ,IPC_RMID , arr) ==-1 ) { +tst_res (TINFO ,"WARNING: semaphore deletion failed." );
^
Here as well.
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c line 104
Quoted 12 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +12
-0+tst_res (TINFO ,"This could lead to IPC resource problems." ); +tst_res (TINFO ,"id = %d" , sem_id); + } +} + +void rm_shm (int shm_id) +{ +if (shm_id ==-1 ) +return ; + +if (shmctl (shm_id,IPC_RMID ,NULL ) ==-1 ) { +tst_res (TINFO ,"WARNING: shared memory deletion failed." );
^
And here as well.
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c line 108
Quoted 4 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +4
-0+tst_res (TINFO ,"This could lead to IPC resource problems." ); +tst_res (TINFO ,"id = %d" , shm_id); + } +}
Moreover these there calls should really be implemented in a similar style as SAFE_MACROS. I.e. macro RM_SHM() would pass filename and lineno to the actuall function so that it can be printed in the resulting error message.
Quoted 4 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +4
-0+int get_used_msgqueues (void ) +{ +FILE *f; +int used_queues;
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c line 123
Quoted 10 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +10
-0+char buf[BUFSIZE ]; + + f =popen ("ipcs -q" ,"r" ); +if (!f) +tst_brk (TBROK |TERRNO ,"pipe failed" ); + +/* FIXME: Start at -4 because ipcs prints four lines of header */ +for (used_queues =-4 ;fgets (buf,BUFSIZE , f); used_queues++); + +pclose (f);
Parsing output of a ipcs looks quite fragile to me. Why can't we use /proc/sysvipc/msg directly instead?
Quoted 10 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +10
-0+if (used_queues <0 ) { +tst_brk (TBROK ,"Could not read output of 'ipcs' to " +"calculate used message queues" ); + } + +return used_queues; +} + +int get_max_msgqueues (void ) +{
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c line 144
Quoted 10 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +10
-0+int fd; +char buf[BUFSIZE ]; + + fd =SAFE_OPEN ("/proc/sys/kernel/msgmni" ,O_RDONLY ); + +SAFE_READ (0 , fd, buf,BUFSIZE ); + +SAFE_CLOSE (fd); + +return atoi (buf);
We have SAFE_FILE_SCANF() exactly for this purpose.
Quoted 20 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +1
-0+}testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h new file +13
-0@@ -0,0 +1,52 @@ +/* +* Copyright (c) 2016 Xiao Yang <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +*
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h line 23
Quoted 10 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h new file +10
-0+* You should have received a copy of the GNU General Public License +* along with this program. +*/ + +/* +* common definitions for the IPC system calls. +*/ + +#ifndef __NEWIPC_H +#define __NEWIPC_H 1
Identifiers starting with underscore are reserved for system libraries such as libc. Use something as LIBNEWIPC_H__ here.
Quoted 33 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h new file +28
-0+#define MSG_RD 0400 +#define MSG_WR 0200 +#define MSG_RW (MSG_RD | MSG_WR) +#define MSGSIZE 1024 +#define MSGTYPE 1 +#define NR_MSGQUEUES 16 +#define min (a, b) (((a) < (b)) ? @ : (b)) + +#define SEM_RD 0400 +#define SEM_ALT 0200 +#define SEM_RA (SEM_RD | SEM_ALT) +#define PSEMS 10 + +#define SHM_RD 0400 +#define SHM_WR 0200 +#define SHM_RW (SHM_RD | SHM_WR) +#define SHM_SIZE 2048 +#define INT_SIZE 4 +#define MODE_MASK 0x01FF + +key_t getipckey (void ); +void rm_queue (int queue_id); +void rm_sem (int sem_id); +void rm_shm (int shm_id); +int get_used_msgqueues (void ); +int get_max_msgqueues (void ); + +#endif /* newlibipc.h */ Signature · 1 line
1.8.3.1
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 2/5 syscalls/ipc: add newipc library for new API
Hi!
Quoted 12 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c line 78
Quoted 7 lines
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +7
-0+void rm_queue (int queue_id) +{ +if (queue_id ==-1 ) +return ; + +if (msgctl (queue_id,IPC_RMID ,NULL ) ==-1 ) { +tst_res (TINFO ,"WARNING: message queue deletion failed." );^
This really should be TWARN, even the message includes 'WARNING' in the string. And we should include errno with TERRNO as well.
Quoted 2 lines
Or even better we should exit the test with TBROK here.
I see that these functions are used in the cleanup, hence TWARN is the one that should be used here.
But even so, why can't we just do:
if (queue_id != -1 && msgctl(queue_id, IPC_RMID, NULL))
tst_res(TWARN | TERRNO, "Failed to delete message queue %i", queue_id);
In the test cleanup?
Is this really worth of creating a library function?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 3/5 ipc/msgget01.c: cleanup && convert to new API
In reply to Xiao Yang--- testcases/kernel/syscalls/ipc/msgget/Makefile | 31 ++-- testcases/kernel/syscalls/ipc/msgget/msgget01.c | 209 ++++++------------------ 2 files changed, 72 insertions(+), 168 deletions(-)
testcases/kernel/syscalls/ipc/msgget/Makefile +18 -13
@@ -1,23 +1,28 @@ # -# Copyright (c) International Business Machines Corp., 2001 +# Copyright (c) International Business Machines Corp., 2001 # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -# the GNU General Public License for more details. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# You should have received a copy of the GNU General Public License +# along with this program. # top_srcdir ?= ../../../../.. include $(top_srcdir)/include/mk/testcases.mk -include $(abs_srcdir)/../Makefile.inc + +LDLIBS += -lnewipc +NEWDIR := ../libnewipc + +CPPFLAGS += -I$(abs_srcdir)/$(NEWDIR) +LDFLAGS += -L$(abs_builddir)/$(NEWDIR) + include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/ipc/msgget/msgget01.c +54 -155
240 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 3/5 ipc/msgget01.c: cleanup && convert to new API
testcases/kernel/syscalls/ipc/msgget/Makefile line 26
Quoted 10 lines
top_srcdir?= ../../../../..include $(top_srcdir)/include/mk/testcases.mk
testcases/kernel/syscalls/ipc/msgget/Makefile +6
-1-include $(abs_srcdir)/../Makefile.inc + +LDLIBS += -lnewipc +NEWDIR := ../libnewipc + +CPPFLAGS += -I$(abs_srcdir)/$(NEWDIR) +LDFLAGS += -L$(abs_builddir)/$(NEWDIR)
I guess that we can simply write:
CPPFLAGS += -I$(abs_srcdir)/../libnewipc
LDFLAGS += -L$(abs_builddir)/../libnewipc
It's not longer than defining the dir variable anyway.
Quoted 212 lines
include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/ipc/msgget/msgget01.c +42
-140@@ -1,186 +1,85 @@/* +* Copyright (c) International Business Machines Corp., 2001 * -* Copyright (c) International Business Machines Corp., 2001 +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. * -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* You should have received a copy of the GNU General Public License +* along with this program. */ /* -* NAME -* msgget01.c -* * DESCRIPTION -* msgget01 - create a message queue, write a message to it and -* read it back. -* -* ALGORITHM -* loop if that option was specified -* create a message queue -* check the return code -* if failure, issue a FAIL message. -* otherwise, -* if doing functionality testing by writting a message to the queue, -* reading it back and comparing the two. -* if the messages are the same, -* issue a PASS message -* otherwise -* issue a FAIL message -* call cleanup -* -* USAGE: <for command-line> -* msgget01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -f : Turn off functionality Testing. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 03/2001 - Written by Wayne Boyer -* -* RESTRICTIONS -* none +* create a message queue, write a message to it and +* read it back. */ -#include "ipcmsg.h" - +#include <errno.h> #include <string.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/msg.h> -char *TCID ="msgget01" ; -int TST_TOTAL =1 ; +#include "libnewipc.h" +#include "tst_test.h" -int msg_q_1 =-1 ;/* to hold the message queue ID */ +static int msg_q_1 =-1 ; +static key_t msgkey; -int main (int ac,char **av) +static struct buf { +long type; +char text[MSGSIZE +1 ]; +} snd_buf, rcv_buf; + +static void verify_msgget (void ) { -int lc; -void check_functionality (void ); - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup ();/* global setup */ - -/* The following loop checks looping state if -i option given */ - -for (lc =0 ;TEST_LOOPING (lc); lc++) { -/* reset tst_count in case we are looping */ - tst_count =0 ; - -/* -* Use TEST macro to make the call to create the message queue -*/ - -TEST (msgget (msgkey,IPC_CREAT |IPC_EXCL |MSG_RD |MSG_WR )); - -if (TEST_RETURN ==-1 ) { -tst_resm (TFAIL ,"%s call failed - errno = %d : %s" , -TCID ,TEST_ERRNO ,strerror (TEST_ERRNO )); - }else { - msg_q_1 =TEST_RETURN ; -/* -* write a message to the queue. -* read back the message. -* PASS the test if they are the same. -*/ -check_functionality (); - } - -/* -* remove the message queue that was created and mark the ID -* as invalid. -*/ -if (msg_q_1 !=-1 ) { -rm_queue (msg_q_1); - msg_q_1 =-1 ; - } +TEST (msgget (msgkey,IPC_CREAT |MSG_RW )); +if (TEST_RETURN ==-1 ) { +tst_res (TFAIL |TTERRNO ,"msgget() failed" ); +return ; } -cleanup (); -tst_exit (); -} + msg_q_1 =TEST_RETURN ; -/* -* check_functionality() - check the functionality of the tested system call. -*/ -void check_functionality (void ) -{ -int i =0 ; -MSGBUF snd_buf, rcv_buf; - -/* EAGLE: Houston, Tranquility Base here. The Eagle has landed! */ -char *queue_msg = -"Qston, check_functionality here. The message has queued!" ; - -/* -* copy our message into the buffer and then set the type. -*/ -do { - snd_buf.mtext[i++] = *queue_msg; - }while (*queue_msg++ !='\0' ); - - snd_buf.mtype =MSGTYPE ; - -/* send the message */ -if (msgsnd (msg_q_1, &snd_buf,MSGSIZE ,0 ) ==-1 ) { -tst_brkm (TBROK , cleanup,"Could not send a message in the " -"check_functionality() routine." ); - } +if (msgsnd (msg_q_1, &snd_buf,MSGSIZE ,0 ) ==-1 ) +tst_brk (TBROK |TERRNO ,"msgsnd() failed" ); -/* receive the message */ -if (msgrcv (msg_q_1, &rcv_buf,MSGSIZE ,MSGTYPE ,IPC_NOWAIT ) ==-1 ) { -tst_brkm (TBROK , cleanup,"Could not read a messages in the " -"check_functionality() routine." ); - } +if (msgrcv (msg_q_1, &rcv_buf,MSGSIZE ,MSGTYPE ,IPC_NOWAIT ) ==-1 ) +tst_brk (TBROK |TERRNO ,"msgrcv() failed" ); -if (strcmp (snd_buf.mtext, rcv_buf.mtext) ==0 ) { -tst_resm (TPASS ,"message received = message sent" ); - }else { -tst_resm (TFAIL ,"message received != message sent" ); - } +if (strcmp (snd_buf.text, rcv_buf.text) ==0 ) +tst_res (TPASS ,"message received = message sent" ); +else +tst_res (TFAIL ,"message received != message sent" ); } -/* -* setup() - performs all the ONE TIME setup for this test. -*/ -void setup (void ) +static void setup (void ) { + msgkey =getipckey (); -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; -
testcases/kernel/syscalls/ipc/msgget/msgget01.c line 69
Quoted 10 lines
testcases/kernel/syscalls/ipc/msgget/msgget01.c +2
-7-/* -* Create a temporary directory and cd into it. -* This helps to ensure that a unique msgkey is created. -* See ../lib/libipc.c for more information. -*/ -tst_tmpdir (); +strcpy (snd_buf.text,"hello world" ); - msgkey =getipckey (); + snd_buf.type =MSGTYPE ;
You can initialize the snd_buf statically.
Quoted 5 lines
testcases/kernel/syscalls/ipc/msgget/msgget01.c +0
-3} -/* -* cleanup() - performs all the ONE TIME cleanup for this test at completion -* or premature exit.
testcases/kernel/syscalls/ipc/msgget/msgget01.c line 76
Quoted 10 lines
testcases/kernel/syscalls/ipc/msgget/msgget01.c +2
-5-*/ -void cleanup (void ) +static void cleanup (void ) { -/* if it exists, remove the message queue that was created */ rm_queue (msg_q_1); -tst_rmdir (); - + msg_q_1 =-1 ;
There is no reason to reset msg_q_1 here, since we will never get back to the test code once we call cleanup in the test library.
Quoted 14 lines
testcases/kernel/syscalls/ipc/msgget/msgget01.c +8
-0} + +static struct tst_test test = { + .tid ="msgget01" , + .setup = setup, + .cleanup = cleanup, + .test_all = verify_msgget, + .needs_tmpdir =1 +};Signature · 1 line
1.8.3.1
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 4/5 ipc/msgget02.c: reconstruct && convert to new API
In reply to Xiao Yang1) merge msgget04 into msgget02
2) take use of some SAFE Marcos
--- runtest/ltplite | 1 - runtest/stress.part3 | 1 - runtest/syscalls | 1 - runtest/syscalls-ipc | 1 - testcases/kernel/syscalls/.gitignore | 1 - testcases/kernel/syscalls/ipc/msgget/msgget02.c | 235 +++++++++--------------- testcases/kernel/syscalls/ipc/msgget/msgget04.c | 169 ----------------- 7 files changed, 90 insertions(+), 319 deletions(-) delete mode 100644 testcases/kernel/syscalls/ipc/msgget/msgget04.c
runtest/ltplite +0 -1
@@ -503,7 +503,6 @@ msgctl09 msgctl09 msgget01 msgget01 msgget02 msgget02 msgget03 msgget03 -msgget04 msgget04 msgrcv01 msgrcv01 msgrcv02 msgrcv02
runtest/stress.part3 +0 -1
@@ -419,7 +419,6 @@ msgctl09 msgctl09 msgget01 msgget01 msgget02 msgget02 msgget03 msgget03 -msgget04 msgget04 msgrcv01 msgrcv01 msgrcv02 msgrcv02
runtest/syscalls +0 -1
@@ -682,7 +682,6 @@ msgctl13 msgctl13 msgget01 msgget01 msgget02 msgget02 msgget03 msgget03 -msgget04 msgget04 msgrcv01 msgrcv01 msgrcv02 msgrcv02
runtest/syscalls-ipc +0 -1
@@ -15,7 +15,6 @@ msgctl13 msgctl13 msgget01 msgget01 msgget02 msgget02 msgget03 msgget03 -msgget04 msgget04 msgrcv01 msgrcv01 msgrcv02 msgrcv02
testcases/kernel/syscalls/.gitignore +0 -1
@@ -405,7 +405,6 @@ /ipc/msgget/msgget01 /ipc/msgget/msgget02 /ipc/msgget/msgget03 -/ipc/msgget/msgget04 /ipc/msgrcv/msgrcv01 /ipc/msgrcv/msgrcv02 /ipc/msgrcv/msgrcv03
testcases/kernel/syscalls/ipc/msgget/msgget02.c +90 -145
266 lines not on this page · raw message
testcases/kernel/syscalls/ipc/msgget/msgget04.c deleted +0 -169
169 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 4/5 ipc/msgget02.c: reconstruct && convert to new API
Hi!
testcases/kernel/syscalls/ipc/msgget/msgget02.c line 109
Quoted 8 lines
testcases/kernel/syscalls/ipc/msgget/msgget02.c +2
-3+static void cleanup (void ) { -/* if it exists, remove the message queue that was created. */ rm_queue (msg_q_1); -tst_rmdir (); - + msg_q_1 =-1 ;
Here again, no need to reset the msg_q_1 to -1, otherwise it looks good.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 5/5 ipc/msgget03.c: cleanup && convert to new API
In reply to Xiao Yang--- testcases/kernel/syscalls/ipc/msgget/msgget03.c | 199 ++++++++---------------- 1 file changed, 63 insertions(+), 136 deletions(-)
testcases/kernel/syscalls/ipc/msgget/msgget03.c +63 -136
@@ -1,168 +1,95 @@/* +* Copyright (c) International Business Machines Corp., 2001 * -* Copyright (c) International Business Machines Corp., 2001 +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. * -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* You should have received a copy of the GNU General Public License +* along with this program. */ /* -* NAME -* msgget03.c -* * DESCRIPTION -* msgget03 - test for an ENOSPC error by using up all available -* message queues. -* -* ALGORITHM -* Get all the message queues that can be allocated -* loop if that option was specified -* Try to get one more message queue -* check the errno value -* issue a PASS message if we get ENOSPC -* otherwise, the tests fails -* issue a FAIL message -* break any remaining tests -* call cleanup -* -* USAGE: <for command-line> -* msgget03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. +* test for an ENOSPC error by using up all available +* message queues. * -* HISTORY -* 03/2001 - Written by Wayne Boyer -* -* RESTRICTIONS -* none */ -#include "test.h" - -#include "ipcmsg.h" - -char *TCID ="msgget03" ; -int TST_TOTAL =1 ; +#include <errno.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/msg.h> +#include <stdlib.h> -int maxmsgs =0 ; +#include "libnewipc.h" +#include "tst_test.h" -int *msg_q_arr =NULL ;/* hold the id's that we create */ -int num_queue =0 ;/* count the queues created */ +static int maxmsgs; +static int *msg_q_arr; +static key_t msgkey; -int main (int ac,char **av) +static void verify_msgget (void ) { -int lc; -int msg_q; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup ();/* global setup */ - -/* The following loop checks looping state if -i option given */ - -for (lc =0 ;TEST_LOOPING (lc); lc++) { -/* reset tst_count in case we are looping */ - tst_count =0 ; - -/* -* Use a while loop to create the maximum number of queues. -* When we get an error, check for ENOSPC. -*/ -while ((msg_q = -msgget (msgkey + num_queue, -IPC_CREAT |IPC_EXCL )) !=-1 ) { - msg_q_arr[num_queue] = msg_q; -if (num_queue == maxmsgs) { -tst_resm (TINFO ,"The maximum number of message" -" queues (%d) has been reached" , - maxmsgs); -break ; - } - num_queue++; - } - -switch (errno) { -case ENOSPC : -tst_resm (TPASS ,"expected failure - errno = %d : %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); -break ; -default : -tst_resm (TFAIL ,"call failed with an " -"unexpected error - %d : %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); -break ; - } - } - -cleanup (); - -tst_exit (); +TEST (msgget (msgkey + maxmsgs,IPC_CREAT |IPC_EXCL )); +if (TEST_RETURN !=-1 ) +tst_res (TFAIL ,"msgget() succeeded unexpectedly" ); + +if (TEST_ERRNO ==ENOSPC ) +tst_res (TPASS |TTERRNO ,"msgget() failed as expected" ); +else +tst_res (TFAIL |TTERRNO ,"msgget() failed unexpectedly," +" expected %s" ,tst_strerrno (ENOSPC )); } -/* -* setup() - performs all the ONE TIME setup for this test. -*/ -void setup (void ) +static void setup (void ) { - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* -* Create a temporary directory and cd into it. -* This helps to ensure that a unique msgkey is created. -* See ../lib/libipc.c for more information. -*/ -tst_tmpdir (); +int res, num; msgkey =getipckey (); maxmsgs =get_max_msgqueues ();if (maxmsgs <0 ) -tst_brkm (TBROK , cleanup,"get_max_msgqueues failed" ); +tst_brk (TBROK ,"get_max_msgqueues failed" ); - msg_q_arr = (int *)calloc (maxmsgs,sizeof (int )); -if (msg_q_arr ==NULL ) { -tst_brkm (TBROK , cleanup,"Couldn't allocate memory " -"for msg_q_arr: calloc() failed" ); + msg_q_arr =SAFE_MALLOC (maxmsgs *sizeof (int )); + +for (num =0 ; num < maxmsgs; num++) { + msg_q_arr[num] =-1 ; + + res =msgget (msgkey + num,IPC_CREAT |IPC_EXCL ); +if (res !=-1 ) + msg_q_arr[num] = res; } + +tst_res (TINFO ,"The maximum number of message queues (%d) reached" , + maxmsgs); } -/* -* cleanup() - performs all the ONE TIME cleanup for this test@completion -* or premature exit. -*/ -void cleanup (void ) +static void cleanup (void ) { -int i; +int num; -/* -* remove the message queues if they were created -*/ - -if (msg_q_arr !=NULL ) { -for (i =0 ; i < num_queue; i++) { -rm_queue (msg_q_arr[i]); +if (msg_q_arr) { +for (num =0 ; num < maxmsgs; num++) { +rm_queue (msg_q_arr[num]); + msg_q_arr[num] =-1 ; } - (void )free (msg_q_arr); - } - -tst_rmdir (); +free (msg_q_arr); + } } + +static struct tst_test test = { + .tid ="msgget03" , + .needs_tmpdir =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = verify_msgget +};
Signature · 1 line
1.8.3.1
PATCH v2 5/5 ipc/msgget03.c: cleanup && convert to new API
Hi!
testcases/kernel/syscalls/ipc/msgget/msgget03.c line 48
Quoted 9 lines
testcases/kernel/syscalls/ipc/msgget/msgget03.c +9
-0+TEST (msgget (msgkey + maxmsgs,IPC_CREAT |IPC_EXCL )); +if (TEST_RETURN !=-1 ) +tst_res (TFAIL ,"msgget() succeeded unexpectedly" ); + +if (TEST_ERRNO ==ENOSPC ) +tst_res (TPASS |TTERRNO ,"msgget() failed as expected" ); +else +tst_res (TFAIL |TTERRNO ,"msgget() failed unexpectedly," +" expected %s" ,tst_strerrno (ENOSPC ));
^
This just generates "ENOSPC" we can as well just write it directly to the message string.
And as the tst_res() spans across two lines it would be better to use curly braces around the if blocks.
Quoted 57 lines
}
testcases/kernel/syscalls/ipc/msgget/msgget03.c +16
-27-/* -* setup() - performs all the ONE TIME setup for this test. -*/ -void setup (void ) +static void setup (void ) { - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* -* Create a temporary directory and cd into it. -* This helps to ensure that a unique msgkey is created. -* See ../lib/libipc.c for more information. -*/ -tst_tmpdir (); +int res, num; msgkey =getipckey (); maxmsgs =get_max_msgqueues ();if (maxmsgs <0 ) -tst_brkm (TBROK , cleanup,"get_max_msgqueues failed" ); +tst_brk (TBROK ,"get_max_msgqueues failed" ); - msg_q_arr = (int *)calloc (maxmsgs,sizeof (int )); -if (msg_q_arr ==NULL ) { -tst_brkm (TBROK , cleanup,"Couldn't allocate memory " -"for msg_q_arr: calloc() failed" ); + msg_q_arr =SAFE_MALLOC (maxmsgs *sizeof (int )); + +for (num =0 ; num < maxmsgs; num++) { + msg_q_arr[num] =-1 ; + + res =msgget (msgkey + num,IPC_CREAT |IPC_EXCL ); +if (res !=-1 ) + msg_q_arr[num] = res; } + +tst_res (TINFO ,"The maximum number of message queues (%d) reached" , + maxmsgs); } -/* -* cleanup() - performs all the ONE TIME cleanup for this test at completion -* or premature exit. -*/ -void cleanup (void ) +static void cleanup (void ) { -int i; +int num; -/*
testcases/kernel/syscalls/ipc/msgget/msgget03.c line 82
Quoted 10 lines
testcases/kernel/syscalls/ipc/msgget/msgget03.c +4
-6-* remove the message queues if they were created -*/ - -if (msg_q_arr !=NULL ) { -for (i =0 ; i < num_queue; i++) { -rm_queue (msg_q_arr[i]); +if (msg_q_arr) { +for (num =0 ; num < maxmsgs; num++) { +rm_queue (msg_q_arr[num]); + msg_q_arr[num] =-1 ;
Again, no need to reset the message queue identifier here.
Otherwise it looks good.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/5 tst_test.h: move test result description to tst_res.h
In reply to Xiao YangHi!
Quoted 2 lines
Move test result description to
tst_res.hso that we can use them independently for new ipc.
Isn't definining TST_NO_DEFAULT_MAIN before you include tst_test.h enough? Is there any other problem?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/4 syscalls/ipc: add newipc library for new API
--- testcases/kernel/syscalls/ipc/Makefile | 40 +++++------ testcases/kernel/syscalls/ipc/libnewipc/Makefile | 24 +++++++ .../kernel/syscalls/ipc/libnewipc/libnewipc.c | 81 ++++++++++++++++++++++ .../kernel/syscalls/ipc/libnewipc/libnewipc.h | 53 ++++++++++++++ 4 files changed, 177 insertions(+), 21 deletions(-) create mode 100644 testcases/kernel/syscalls/ipc/libnewipc/Makefile create mode 100644 testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c create mode 100644 testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h
testcases/kernel/syscalls/ipc/Makefile +19 -21
@@ -1,19 +1,18 @@ # -# Copyright (c) International Business Machines Corp., 2001 +# Copyright (c) International Business Machines Corp., 2001 # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -# the GNU General Public License for more details. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# You should have received a copy of the GNU General Public License +# along with this program. # top_srcdir ?= ../../../..
@@ -21,20 +20,19 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/env_pre.mk LIBDIR := lib -FILTER_OUT_DIRS := $(LIBDIR) -LIB := $(LIBDIR)/libipc.a $(LIBDIR)/libmsgctl.a +NEWLIBDIR := libnewipc +LIB := $(LIBDIR)/libipc.a $(LIBDIR)/libmsgctl.a $(NEWLIBDIR)/libnewipc.a -$(LIBDIR): - mkdir -p "$@" - -$(LIB): $(LIBDIR) - $(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" all +$(LIB): $(LIBDIR) $(NEWLIBDIR) + $(MAKE) -C $(LIBDIR) -f "$(abs_srcdir)/$(LIBDIR)/Makefile" all + $(MAKE) -C $(NEWLIBDIR) -f "$(abs_srcdir)/$(NEWLIBDIR)/Makefile" all MAKE_DEPS := $(LIB) trunk-clean:: | lib-clean -lib-clean:: $(LIBDIR) - $(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" clean +lib-clean:: $(LIBDIR) $(NEWLIBDIR) + $(MAKE) -C $(LIBDIR) -f "$(abs_srcdir)/$(LIBDIR)/Makefile" clean + $(MAKE) -C $(NEWLIBDIR) -f "$(abs_srcdir)/$(NEWLIBDIR)/Makefile" clean include $(top_srcdir)/include/mk/generic_trunk_target.mk
testcases/kernel/syscalls/ipc/libnewipc/Makefile new file +24 -0
@@ -0,0 +1,24 @@ +# +# Copyright (c) 2016 Xiao Yang <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. +# + +top_srcdir ?= ../../../../.. + +include $(top_srcdir)/include/mk/env_pre.mk + +INTERNAL_LIB := libnewipc.a + +include $(top_srcdir)/include/mk/lib.mk
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c new file +81 -0
81 lines not on this page · raw message
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 2/4 ipc/msgget01.c: cleanup && convert to new API
--- testcases/kernel/syscalls/ipc/msgget/Makefile | 30 ++-- testcases/kernel/syscalls/ipc/msgget/msgget01.c | 214 ++++++------------------ 2 files changed, 72 insertions(+), 172 deletions(-)
testcases/kernel/syscalls/ipc/msgget/Makefile +17 -13
@@ -1,23 +1,27 @@ # -# Copyright (c) International Business Machines Corp., 2001 +# Copyright (c) International Business Machines Corp., 2001 # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -# the GNU General Public License for more details. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# You should have received a copy of the GNU General Public License +# along with this program. # top_srcdir ?= ../../../../.. include $(top_srcdir)/include/mk/testcases.mk -include $(abs_srcdir)/../Makefile.inc + +LDLIBS += -lnewipc + +CPPFLAGS += -I$(abs_srcdir)/../libnewipc +LDFLAGS += -L$(abs_builddir)/../libnewipc + include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/ipc/msgget/msgget01.c +55 -159
241 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 3/4 ipc/msgget02.c: reconstruct && convert to new API
In reply to Xiao Yang1) merge msgget04 into msgget02
2) take use of some SAFE Marcos
--- runtest/ltplite | 1 - runtest/stress.part3 | 1 - runtest/syscalls | 1 - runtest/syscalls-ipc | 1 - testcases/kernel/syscalls/.gitignore | 1 - testcases/kernel/syscalls/ipc/msgget/msgget02.c | 242 +++++++++--------------- testcases/kernel/syscalls/ipc/msgget/msgget04.c | 169 ----------------- 7 files changed, 94 insertions(+), 322 deletions(-) delete mode 100644 testcases/kernel/syscalls/ipc/msgget/msgget04.c
runtest/ltplite +0 -1
@@ -502,7 +502,6 @@ msgctl09 msgctl09 msgget01 msgget01 msgget02 msgget02 msgget03 msgget03 -msgget04 msgget04 msgrcv01 msgrcv01 msgrcv02 msgrcv02
runtest/stress.part3 +0 -1
@@ -418,7 +418,6 @@ msgctl09 msgctl09 msgget01 msgget01 msgget02 msgget02 msgget03 msgget03 -msgget04 msgget04 msgrcv01 msgrcv01 msgrcv02 msgrcv02
runtest/syscalls +0 -1
@@ -681,7 +681,6 @@ msgctl13 msgctl13 msgget01 msgget01 msgget02 msgget02 msgget03 msgget03 -msgget04 msgget04 msgrcv01 msgrcv01 msgrcv02 msgrcv02
runtest/syscalls-ipc +0 -1
@@ -15,7 +15,6 @@ msgctl13 msgctl13 msgget01 msgget01 msgget02 msgget02 msgget03 msgget03 -msgget04 msgget04 msgrcv01 msgrcv01 msgrcv02 msgrcv02
testcases/kernel/syscalls/.gitignore +0 -1
@@ -404,7 +404,6 @@ /ipc/msgget/msgget01 /ipc/msgget/msgget02 /ipc/msgget/msgget03 -/ipc/msgget/msgget04 /ipc/msgrcv/msgrcv01 /ipc/msgrcv/msgrcv02 /ipc/msgrcv/msgrcv03
testcases/kernel/syscalls/ipc/msgget/msgget02.c +94 -148
270 lines not on this page · raw message
testcases/kernel/syscalls/ipc/msgget/msgget04.c deleted +0 -169
169 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 4/4 ipc/msgget03.c: cleanup && convert to new API
In reply to Xiao Yang--- testcases/kernel/syscalls/ipc/msgget/msgget03.c | 202 ++++++++---------------- 1 file changed, 65 insertions(+), 137 deletions(-)
testcases/kernel/syscalls/ipc/msgget/msgget03.c +65 -137
@@ -1,168 +1,96 @@/* +* Copyright (c) International Business Machines Corp., 2001 * -* Copyright (c) International Business Machines Corp., 2001 +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. * -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* You should have received a copy of the GNU General Public License +* along with this program. */ /* -* NAME -* msgget03.c -* * DESCRIPTION -* msgget03 - test for an ENOSPC error by using up all available -* message queues. -* -* ALGORITHM -* Get all the message queues that can be allocated -* loop if that option was specified -* Try to get one more message queue -* check the errno value -* issue a PASS message if we get ENOSPC -* otherwise, the tests fails -* issue a FAIL message -* break any remaining tests -* call cleanup +* test for an ENOSPC error by using up all available +* message queues. * -* USAGE: <for command-line> -* msgget03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 03/2001 - Written by Wayne Boyer -* -* RESTRICTIONS -* none */ -#include "test.h" - -#include "ipcmsg.h" +#include <errno.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/msg.h> +#include <stdlib.h> -char *TCID ="msgget03" ; -int TST_TOTAL =1 ; +#include "tst_test.h" +#include "libnewipc.h" -int maxmsgs =0 ; +static int maxmsgs; +static int *msg_q_arr; +static key_t msgkey; -int *msg_q_arr =NULL ;/* hold the id's that we create */ -int num_queue =0 ;/* count the queues created */ - -int main (int ac,char **av) +static void verify_msgget (void ) { -int lc; -int msg_q; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup ();/* global setup */ - -/* The following loop checks looping state if -i option given */ - -for (lc =0 ;TEST_LOOPING (lc); lc++) { -/* reset tst_count in case we are looping */ - tst_count =0 ; - -/* -* Use a while loop to create the maximum number of queues. -* When we get an error, check for ENOSPC. -*/ -while ((msg_q = -msgget (msgkey + num_queue, -IPC_CREAT |IPC_EXCL )) !=-1 ) { - msg_q_arr[num_queue] = msg_q; -if (num_queue == maxmsgs) { -tst_resm (TINFO ,"The maximum number of message" -" queues (%d) has been reached" , - maxmsgs); -break ; - } - num_queue++; - } - -switch (errno) { -case ENOSPC : -tst_resm (TPASS ,"expected failure - errno = %d : %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); -break ; -default : -tst_resm (TFAIL ,"call failed with an " -"unexpected error - %d : %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); -break ; - } +TEST (msgget (msgkey + maxmsgs,IPC_CREAT |IPC_EXCL )); +if (TEST_RETURN !=-1 ) +tst_res (TFAIL ,"msgget() succeeded unexpectedly" ); + +if (TEST_ERRNO ==ENOSPC ) { +tst_res (TPASS |TTERRNO ,"msgget() failed as expected" ); + }else { +tst_res (TFAIL |TTERRNO ,"msgget() failed unexpectedly," +" expected ENOSPC" ); } - -cleanup (); - -tst_exit (); } -/* -* setup() - performs all the ONE TIME setup for this test. -*/ -void setup (void ) +static void setup (void ) { +int res, num; -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; + msgkey =GETIPCKEY (); -/* -* Create a temporary directory and cd into it. -* This helps to ensure that a unique msgkey is created. -* See ../lib/libipc.c for more information. -*/ -tst_tmpdir (); +SAFE_FILE_SCANF ("/proc/sys/kernel/msgmni" ,"%i" , &maxmsgs); - msgkey =getipckey (); + msg_q_arr =SAFE_MALLOC (maxmsgs *sizeof (int )); - maxmsgs =get_max_msgqueues (); -if (maxmsgs <0 ) -tst_brkm (TBROK , cleanup,"get_max_msgqueues failed" ); +for (num =0 ; num < maxmsgs; num++) { + msg_q_arr[num] =-1 ; - msg_q_arr = (int *)calloc (maxmsgs,sizeof (int )); -if (msg_q_arr ==NULL ) { -tst_brkm (TBROK , cleanup,"Couldn't allocate memory " -"for msg_q_arr: calloc() failed" ); + res =msgget (msgkey + num,IPC_CREAT |IPC_EXCL ); +if (res !=-1 ) + msg_q_arr[num] = res; } + +tst_res (TINFO ,"The maximum number of message queues (%d) reached" , + maxmsgs); } -/* -* cleanup() - performs all the ONE TIME cleanup for this test@completion -* or premature exit. -*/ -void cleanup (void ) +static void cleanup (void ) { -int i; - -/* -* remove the message queues if they were created -*/ - -if (msg_q_arr !=NULL ) { -for (i =0 ; i < num_queue; i++) { -rm_queue (msg_q_arr[i]); +int num; + +if (msg_q_arr) { +for (num =0 ; num < maxmsgs; num++) { +if (msg_q_arr[num] !=-1 && +msgctl (msg_q_arr[num],IPC_RMID ,NULL )) +tst_res (TWARN |TERRNO , +"failed to delete message queue %i" , + msg_q_arr[num]); } - (void )free (msg_q_arr); +free (msg_q_arr); } - -tst_rmdir (); - } + +static struct tst_test test = { + .tid ="msgget03" , + .needs_tmpdir =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = verify_msgget +};
Signature · 1 line
1.8.3.1
PATCH v3 1/4 syscalls/ipc: add newipc library for new API
In reply to Xiao YangHi!
Quoted 50 lines
testcases/kernel/syscalls/ipc/Makefile +16
-19@@ -1,19 +1,18 @@ # -# Copyright (c) International Business Machines Corp., 2001 +# Copyright (c) International Business Machines Corp., 2001 # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -# the GNU General Public License for more details. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# You should have received a copy of the GNU General Public License +# along with this program. # top_srcdir ?= ../../../..@@ -21,20 +20,19 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/env_pre.mk LIBDIR := lib -FILTER_OUT_DIRS := $(LIBDIR) -LIB := $(LIBDIR)/libipc.a $(LIBDIR)/libmsgctl.a +NEWLIBDIR := libnewipc +LIB := $(LIBDIR)/libipc.a $(LIBDIR)/libmsgctl.a $(NEWLIBDIR)/libnewipc.a -$(LIBDIR): - mkdir -p "$@" - -$(LIB): $(LIBDIR) - $(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" all +$(LIB): $(LIBDIR) $(NEWLIBDIR) + $(MAKE) -C $(LIBDIR) -f "$(abs_srcdir)/$(LIBDIR)/Makefile" all + $(MAKE) -C $(NEWLIBDIR) -f "$(abs_srcdir)/$(NEWLIBDIR)/Makefile" all
testcases/kernel/syscalls/ipc/Makefile top_srcdir ?= ../../../.. · line 36
Quoted 10 lines
testcases/kernel/syscalls/ipc/Makefile +3
-2MAKE_DEPS := $(LIB) trunk-clean:: | lib-clean -lib-clean:: $(LIBDIR) - $(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" clean +lib-clean:: $(LIBDIR) $(NEWLIBDIR) + $(MAKE) -C $(LIBDIR) -f "$(abs_srcdir)/$(LIBDIR)/Makefile" clean + $(MAKE) -C $(NEWLIBDIR) -f "$(abs_srcdir)/$(NEWLIBDIR)/Makefile" clean
I've just found that this whole Makefile has been broken for ages and that the old library was build only by the inclusion of the Makefile.inc in the test directories, I wonder why this wasn't breaking parallel build at all. The whole reason is that MAKE_DEPS is ignored when MAKE_TARGETS is empty so the $(LIB) targets are not rebuild and removing the $(LIBDIR) from FILTER_OUT_DIRS is not solution either since that will break parallel build for sure.
I will do something about this. One solution may be to set the MAKE_TARGETS to some phony target if it's empty. Let's see if I can figure out something better.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/4 syscalls/ipc: add newipc library for new API
Hi!
Quoted 11 lines
I've just found that this whole
Makefilehas been broken for ages and that the old library was build only by the inclusion of the Makefile.inc in the test directories, I wonder why this wasn't breaking parallel build at all. The whole reason is thatMAKE_DEPSis ignored whenMAKE_TARGETSis empty so the $(LIB) targets are not rebuild and removing the $(LIBDIR) fromFILTER_OUT_DIRSis not solution either since that will break parallel build for sure.I will do something about this. One solution may be to set the
MAKE_TARGETSto some phony target if it's empty. Let's see if I can figure out something better.
And, after a bit of research, I've realized, that without introducing larger changes in the build system the only reasonable way how to build a library is by using the Makefile.inc in all test subdirectories that use it. That works since the make in subdirectories is executed in a shell loop, which means that we will never end up building the same library at the same time from several subdirectories.
So the correct way how to fix this issue is to add the libnewipc to the FILTER_OUT_DIRS and create Makefile2.inc similar to Makefile.inc. I will change the first patch to do exactly that and push the patchset.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/4 syscalls/ipc: add newipc library for new API
Hi!
Quoted 3 lines
So the correct way how to fix this issue is to add the libnewipc to the
FILTER_OUT_DIRSand create Makefile2.inc similar to Makefile.inc. I will change the first patch to do exactly that and push the patchset.
And I've pushed the patches, thanks.
I've added Makefile2.inc and also added clean target to the top level Makefile so that the libnewipc is cleaned up on make clean.
And also merged the three msgget patches into one, since once the Makefile.inc is changed for Makefile2.inc in the Makefile the rest of the msgget testcases fails to build, which breaks bisecting. Ideally each commit should leave the tree in a state that at least compiles cleanly...
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/4 syscalls/ipc: add newipc library for new API
Hi Cyril
Quoted 6 lines · Cyril Hrubis
Hi!
Quoted 3 lines
So the correct way how to fix this issue is to add the libnewipc to the
FILTER_OUT_DIRSand create Makefile2.inc similar to Makefile.inc. I will change the first patch to do exactly that and push the patchset.And I've pushed the patches, thanks.
Quoted 9 lines
I've added Makefile2.inc and also added clean target to the top level
Makefileso that the libnewipc is cleaned up on make clean.And also merged the three msgget patches into one, since once the Makefile.inc is changed for Makefile2.inc in the
Makefilethe rest of the msgget testcases fails to build, which breaks bisecting. Ideally each commit should leave the tree in a state that at least compiles cleanly...
Thanks for your explanation and fix, so i got it. :-)
Best Regards,
Xiao Yang
PATCH v2 1/5 tst_test.h: move test result description to tst_res.h
In reply to Cyril HrubisQuoted 6 lines · Cyril Hrubis
Hi!
Quoted 2 lines
Move test result description to
tst_res.hso that we can use them independently for new ipc.Isn't definining
TST_NO_DEFAULT_MAINbefore you includetst_test.henough? Is there any other problem?
Hi Cyril
Thanks for your review.
I don't know that defining TST_NO_DEFAULT_MAIN can skip main function, so I remove this patch. I have rewritten other patches as your suggestions.
Thanks,
Xiao Yang