libs/libltpnewipc: Use safe macros
PATCH 1/2 libs/libltpnewipc: Use safe macros
--- libs/libltpnewipc/libnewipc.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-)
libs/libltpnewipc/libnewipc.c +9 -19
@@ -21,6 +21,8 @@#include "tst_test.h" #include "libnewipc.h" +#include "tst_safe_stdio.h" +#include "tst_safe_sysv_ipc.h" #define BUFSIZE 1024
@@ -31,7 +33,7 @@ key_t getipckey(const char *file, const int lineno)int id;static int count; -SAFE_GETCWD (buf,BUFSIZE ); +safe_getcwd (file, lineno,NULL , buf,BUFSIZE ); id = count %26 + (int )'a' ; count++;
@@ -51,11 +53,7 @@ int get_used_queues(const char *file, const int lineno)int used_queues =-1 ;char buf[BUFSIZE ]; - fp =fopen ("/proc/sysvipc/msg" ,"r" ); -if (fp ==NULL ) { -tst_brk (TBROK |TERRNO , -"fopen() failed at %s:%d" , file, lineno); - } + fp =safe_fopen (file, lineno,NULL ,"/proc/sysvipc/msg" ,"r" );while (fgets (buf,BUFSIZE , fp) !=NULL ) used_queues++;
@@ -78,19 +76,11 @@ void *probe_free_addr(const char *file, const int lineno) probe_key =GETIPCKEY (); - shm_id =shmget (probe_key,SHMLBA *2 ,SHM_RW |IPC_CREAT |IPC_EXCL ); -if (shm_id ==-1 ) -tst_brk (TBROK ,"probe: shmget() failed at %s:%d" , file, lineno); - - addr =shmat (shm_id,NULL ,0 ); -if (addr == (void *)-1 ) -tst_brk (TBROK ,"probe: shmat() failed at %s:%d" , file, lineno); - -if (shmdt (addr) ==-1 ) -tst_brk (TBROK ,"probe: shmdt() failed at %s:%d" , file, lineno); - -if (shmctl (shm_id,IPC_RMID ,NULL ) ==-1 ) -tst_brk (TBROK ,"probe: shmctl() failed at %s:%d" , file, lineno); + shm_id =safe_shmget (file, lineno, probe_key,SHMLBA *2 , +SHM_RW |IPC_CREAT |IPC_EXCL ); + addr =safe_shmat (file, lineno, shm_id,NULL ,0 ); +safe_shmdt (file, lineno, addr); +safe_shmctl (file, lineno, shm_id,IPC_RMID ,NULL ); addr = (void *)(((unsigned long )(addr) + (SHMLBA -1 )) & ~(SHMLBA -1 ));
Signature · 1 line
2.23.0
PATCH 2/2 libs/libltpnewipc: Add libmsgctl.c into new ipc library
Add libmsgctl.c into new ipc library, so we can use it in new api msgstress test case.
--- include/libnewipc.h | 28 ++++------ libs/libltpnewipc/libnewipc.c | 101 ++++++++++++++++++++++++++++++++-- 2 files changed, 109 insertions(+), 20 deletions(-)
include/libnewipc.h +12 -16
@@ -1,21 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * 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. -*/ - -/* * common definitions for the IPC system calls. */
@@ -56,4 +42,14 @@ void *probe_free_addr(const char *file, const int lineno);#define PROBE_FREE_ADDR () \ probe_free_addr(__FILE__, __LINE__) -#endif /* newlibipc.h */ +void do_read (const char *file,const int lineno,long key,int tid, \ +long type,int child,int nreps); +#define DO_READ (key, tid, type, child, nreps) \ + do_read(__FILE__, __LINE__, (key), (tid), (type), (child), (nreps)) + +void do_writer (const char *file,const int lineno,long key,int tid, \ +long type,int child,int nreps); +#define DO_WRITER (key, tid, type, child, nreps) \ + do_writer(__FILE__, __LINE__, (key), (tid), (type), (child), (nreps)) + +#endif /* libnewipc.h */
libs/libltpnewipc/libnewipc.c +97 -4
116 lines not on this page · raw message
Signature · 1 line
2.23.0
PATCH 2/2 libs/libltpnewipc: Add libmsgctl.c into new ipc library
Hi Xu,
Quoted 3 lines · Yang Xu
Add
libmsgctl.cinto new ipc library, so we can use it in new api msgstress test case.
It's fine to maintain only a single System V IPC library in LTP. BTW, do you have a plan to remove the old libmsgctl.c after merging this? Series:
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20200729/41bb5323/attachment.htm>
PATCH 2/2 libs/libltpnewipc: Add libmsgctl.c into new ipc library
Hi Li
Quoted 11 lines
Hi Xu,
On Tue, Jul 28, 2020 at 12:40 PM Yang Xu <[email protected] <mailto:[email protected]>> wrote:
Add
libmsgctl.cinto new ipc library, so we can use it in new api msgstress test case.It's fine to maintain only a single System V IPC library in LTP. BTW, do you have a plan to remove the old
libmsgctl.cafter merging this?
Yes. I have a plan[1] to remove this old libmsgctl when I clean up msgstress case(I am doing it).
Also, I plan to remove get_max_msgqueues() function in old libipc.c because we can directly use SAFE_FILE_SCANF("/proc/sys/kernel/msgmni", "%d", &nr_msgqs) in test case.
[1]https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
Best Regards
Yang Xu
Quoted 6 lines
Series:
Reviewed-by Li Wang <[email protected] <mailto:[email protected]>>Signature · 2 lines
Regards, Li Wang
PATCH 2/2 libs/libltpnewipc: Add libmsgctl.c into new ipc library
Quoted 6 lines · Yang Xu
...
Quoted 2 lines
It's fine to maintain only a single System V IPC library in LTP. BTW, do you have a plan to remove the old
libmsgctl.cafter merging this?Yes. I have a plan[1] to remove this old libmsgctl when I clean up msgstress case(I am doing it).
Great, thank you!
Quoted 4 lines
Also, I plan to remove
get_max_msgqueues()function in oldlibipc.cbecause we can directly useSAFE_FILE_SCANF("/proc/sys/kernel/msgmni", "%d", &nr_msgqs)in test case.
+1
Or, maybe if you'd like to do more in next, the libipc.c also could be merged into libnewipc.c since they have some overlaps too. Anyway, it depends on your thoughts :).
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20200729/8710f6e6/attachment.htm>
PATCH 2/2 libs/libltpnewipc: Add libmsgctl.c into new ipc library
Hi Li
Quoted 19 lines
Yang Xu <[email protected]
<mailto:[email protected]>> wrote:...
> It's fine to maintain only a single System V IPC library in LTP. > BTW, do you have a plan to remove the oldlibmsgctl.cafter
merging this?
Yes. I have a plan[1] to? remove this old libmsgctl when I clean up msgstress case(I am doing it).Great, thank you!
Also, I plan to remove
get_max_msgqueues()? function in oldlibipc.cbecause we can directly useSAFE_FILE_SCANF("/proc/sys/kernel/msgmni", "%d", &nr_msgqs)in test case.
Quoted 5 lines
+1
Or, maybe if you'd like to do more in next, the
libipc.calso could be merged intolibnewipc.csince they have some overlaps too. Anyway, it depends on your thoughts :).
I have this idea[1].
I think we should plan to remove old libipc.c when we cleanup all ipc test case.
Cyril has cleanup shmctl and Viresh has cleanup semop today, I also have a patchset to cleanup msgrcv. It seems we only have semget,shmget,semctl,shmdt case that use old ipc.
# grep -nsr LTPLIBS semget/Makefile:6:LTPLIBS = ltpipc msgget/Makefile:6:LTPLIBS = ltpnewipc msgsnd/Makefile:6:LTPLIBS = ltpnewipc shmget/Makefile:6:LTPLIBS = ltpipc shmctl/Makefile:6:LTPLIBS = ltpipc ltpnewipc msgstress/Makefile:6:LTPLIBS = ltpipc ltpnewipc msgrcv/Makefile:6:LTPLIBS = ltpipc msgctl/Makefile:6:LTPLIBS = ltpnewipc semctl/Makefile:6:LTPLIBS = ltpipc ltpnewipc shmat/Makefile:6:LTPLIBS = ltpnewipc shmdt/Makefile:6:LTPLIBS = ltpipc semop/Makefile:6:LTPLIBS = ltpipc #
[1]http://lists.linux.it/pipermail/ltp/2020-July/018063.html
Quoted 4 lines
Signature · 3 lines
-- Regards, Li Wang
PATCH 2/2 libs/libltpnewipc: Add libmsgctl.c into new ipc library
In reply to Yang XuHi!
Quoted 5 lines
Signed-off-by Yang Xu <[email protected]>--- include/libnewipc.h | 28 ++++------ libs/libltpnewipc/libnewipc.c | 101 ++++++++++++++++++++++++++++++++-- 2 files changed, 109 insertions(+), 20 deletions(-)
Just FYI we do not have to put all the code into a single *.c file, we can have as many as we want in the library directory...
Quoted 17 lines
include/libnewipc.h +1
-7@@ -1,21 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * 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
include/libnewipc.h line 6
Quoted 10 lines
include/libnewipc.h +0
-8-* 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. -*/ - -/* * common definitions for the IPC system calls. */
Ideally the changes in comments should be in a separate patch from functional changes.
Quoted 4 lines
include/libnewipc.h +0
-0@@ -56,4 +42,14 @@ void *probe_free_addr(const char *file, const int lineno);#define PROBE_FREE_ADDR () \ probe_free_addr(__FILE__, __LINE__)
include/libnewipc.h void *probe_free_addr(const char *file, const int lineno); · line 53
Quoted 10 lines
include/libnewipc.h +9
-1-#endif /* newlibipc.h */ +void do_read (const char *file,const int lineno,long key,int tid, \ +long type,int child,int nreps); +#define DO_READ (key, tid, type, child, nreps) \ + do_read(__FILE__, __LINE__, (key), (tid), (type), (child), (nreps)) + +void do_writer (const char *file,const int lineno,long key,int tid, \ +long type,int child,int nreps); +#define DO_WRITER (key, tid, type, child, nreps) \ + do_writer(__FILE__, __LINE__, (key), (tid), (type), (child), (nreps))
The naming here is a bit inconsistent, either we should have do_reader() and do_writer() or do_read() and do_write(), but mixing them like this is strange choice.
Quoted 132 lines
include/libnewipc.h +1
-0+#endif /* libnewipc.h */ libs/libltpnewipc/libnewipc.c +97
-4@@ -1,10 +1,7 @@// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2016 Xiao Yang <[email protected]> -*/ - -/* -* DESCRIPTION +* * common routines for the IPC system call tests. */ @@ -26,6 +23,14 @@#define BUFSIZE 1024 +struct mbuffer { +long type; +struct { +char len; +char pbytes[99 ]; + } data; +}; +key_t getipckey (const char *file,const int lineno) {char buf[BUFSIZE ];@@ -86,3 +91,91 @@ void *probe_free_addr(const char *file, const int lineno)return addr; } + +int verify (char *buf,char val,int size,int child) +{ +while (size-- >0 ) { +if (*buf++ != val) { +tst_res (TFAIL ,"Verify error in child %d, *buf = %x, " +"val = %x, size = %d\n" , child, *buf, val, + size); +return 1 ; + } + } +return 0 ; +} + +void do_reader (const char *file,const int lineno,long key,int tid, +long type,int child,int nreps) +{ +int i, size; +int id; +struct mbuffer buffer; + + id =safe_msgget (file, lineno, key,0 ); +if (id != tid) { +tst_res (TFAIL , +"Message queue mismatch in the reader of child group" +" %d for message queue id %d\n" , child, id); +return ; + } +for (i =0 ; i < nreps; i++) { +memset (&buffer,0 ,sizeof (buffer)); + + size =safe_msgrcv (file, lineno, id, &buffer,100 , type,0 ); +if (buffer.type != type) { +tst_res (TFAIL ,"Type mismatch in child %d, read #%d, " +"for message got %ld, exected %ld" , + child, (i +1 ), buffer.type, type); +return ; + } +if (buffer.data.len +1 != size) { +tst_res (TFAIL ,"Size mismatch in child %d, read #%d, " +"for message got %d, expected %d" , + child, (i +1 ), buffer.data.len +1 , size); +return ; + } +if (verify (buffer.data.pbytes, (key %255 ), size -1 , child)) { +tst_res (TFAIL ,"Verify failed in child %d read # = %d, " +"key = %lx\n" , child, (i +1 ), key); +return ; + } + key++; + } +} + +void fill_buffer (char *buf,char val,int size) +{ +int i; + +for (i =0 ; i < size; i++) + buf[i] = val; +} + +void do_writer (const char *file,const int lineno,long key,int tid, +long type,int child,int nreps) +{ +int i, size; +int id; +struct mbuffer buffer; + + id =safe_msgget (file, lineno, key,0 ); +if (id != tid) { +tst_res (TFAIL ,"Message queue mismatch in the reader of child" +" group %d for message queue id %d\n" , child, id); +return ; + } + +for (i =0 ; i < nreps; i++) { +memset (&buffer,0 ,sizeof (buffer)); + +do { + size = (lrand48 () %99 ); + }while (size ==0 ); +fill_buffer (buffer.data.pbytes, (key %255 ), size); + buffer.data.len = size; + buffer.type = type; +safe_msgsnd (file, lineno, id, &buffer, size +1 ,0 ); + key++; + } +}Signature · 7 lines
2.23.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 2/2 libs/libltpnewipc: Add libmsgctl.c into new ipc library
Hi Cyril
Quoted 9 lines
Hi!
Quoted 5 lines
Signed-off-by Yang Xu <[email protected]>--- include/libnewipc.h | 28 ++++------ libs/libltpnewipc/libnewipc.c | 101 ++++++++++++++++++++++++++++++++-- 2 files changed, 109 insertions(+), 20 deletions(-)Just FYI we do not have to put all the code into a single *.c file, we can have as many as we want in the library directory...
I remember you have some comments on my previous patach as below:
------------------------------
So unless we plan to use it from different tests it does not make much sense to export it to the top level include and libs.
Or alternatively we do have libltpnewipc we can pust put the libnewmsgctl.c to that directory and with that we will have a single System V IPC helper library.
------------------------------
So I merge libnewmsgctl.c into libnewipc.c.
ps: IMO, libnewipc has only three functions(getipckey,get_used_queues, probe_free_addr) ,It's hard to call it a LIBS library. Can we put it into lib directory and named it as tst_ipc.c?
@LI, What do you think about this?
Quoted 23 lines
Quoted 23 lines
include/libnewipc.h +1
-12@@ -1,21 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * 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.
Quoted 8 lines
include/libnewipc.h line 6
Quoted 5 lines
include/libnewipc.h +0
-3-*/ - -/* * common definitions for the IPC system calls. */ Ideally the changes in comments should be in a separate patch from functional changes.
Yes.
Quoted 5 lines
Quoted 5 lines
include/libnewipc.h +0
-0@@ -56,4 +42,14 @@ void *probe_free_addr(const char *file, const int lineno);#define PROBE_FREE_ADDR () \ probe_free_addr(__FILE__, __LINE__)
Quoted 14 lines
include/libnewipc.h void *probe_free_addr(const char *file, const int lineno); · line 53
Quoted 10 lines
include/libnewipc.h +9
-1-#endif /* newlibipc.h */ +void do_read (const char *file,const int lineno,long key,int tid, \ +long type,int child,int nreps); +#define DO_READ (key, tid, type, child, nreps) \ + do_read(__FILE__, __LINE__, (key), (tid), (type), (child), (nreps)) + +void do_writer (const char *file,const int lineno,long key,int tid, \ +long type,int child,int nreps); +#define DO_WRITER (key, tid, type, child, nreps) \ + do_writer(__FILE__, __LINE__, (key), (tid), (type), (child), (nreps))The naming here is a bit inconsistent, either we should have
do_reader()anddo_writer()ordo_read()anddo_write(), but mixing them like this is strange choice.
Sorry. Yes, I did't notice this. I will do_writer/do_reader pair.
Quoted 134 lines
Quoted 133 lines
include/libnewipc.h +1
-0+#endif /* libnewipc.h */ libs/libltpnewipc/libnewipc.c +97
-4@@ -1,10 +1,7 @@// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2016 Xiao Yang <[email protected]> -*/ - -/* -* DESCRIPTION +* * common routines for the IPC system call tests. */ @@ -26,6 +23,14 @@#define BUFSIZE 1024 +struct mbuffer { +long type; +struct { +char len; +char pbytes[99 ]; + } data; +}; +key_t getipckey (const char *file,const int lineno) {char buf[BUFSIZE ];@@ -86,3 +91,91 @@ void *probe_free_addr(const char *file, const int lineno)return addr; } + +int verify (char *buf,char val,int size,int child) +{ +while (size-- >0 ) { +if (*buf++ != val) { +tst_res (TFAIL ,"Verify error in child %d, *buf = %x, " +"val = %x, size = %d\n" , child, *buf, val, + size); +return 1 ; + } + } +return 0 ; +} + +void do_reader (const char *file,const int lineno,long key,int tid, +long type,int child,int nreps) +{ +int i, size; +int id; +struct mbuffer buffer; + + id =safe_msgget (file, lineno, key,0 ); +if (id != tid) { +tst_res (TFAIL , +"Message queue mismatch in the reader of child group" +" %d for message queue id %d\n" , child, id); +return ; + } +for (i =0 ; i < nreps; i++) { +memset (&buffer,0 ,sizeof (buffer)); + + size =safe_msgrcv (file, lineno, id, &buffer,100 , type,0 ); +if (buffer.type != type) { +tst_res (TFAIL ,"Type mismatch in child %d, read #%d, " +"for message got %ld, exected %ld" , + child, (i +1 ), buffer.type, type); +return ; + } +if (buffer.data.len +1 != size) { +tst_res (TFAIL ,"Size mismatch in child %d, read #%d, " +"for message got %d, expected %d" , + child, (i +1 ), buffer.data.len +1 , size); +return ; + } +if (verify (buffer.data.pbytes, (key %255 ), size -1 , child)) { +tst_res (TFAIL ,"Verify failed in child %d read # = %d, " +"key = %lx\n" , child, (i +1 ), key); +return ; + } + key++; + } +} + +void fill_buffer (char *buf,char val,int size) +{ +int i; + +for (i =0 ; i < size; i++) + buf[i] = val; +} + +void do_writer (const char *file,const int lineno,long key,int tid, +long type,int child,int nreps) +{ +int i, size; +int id; +struct mbuffer buffer; + + id =safe_msgget (file, lineno, key,0 ); +if (id != tid) { +tst_res (TFAIL ,"Message queue mismatch in the reader of child" +" group %d for message queue id %d\n" , child, id); +return ; + } + +for (i =0 ; i < nreps; i++) { +memset (&buffer,0 ,sizeof (buffer)); + +do { + size = (lrand48 () %99 ); + }while (size ==0 ); +fill_buffer (buffer.data.pbytes, (key %255 ), size); + buffer.data.len = size; + buffer.type = type; +safe_msgsnd (file, lineno, id, &buffer, size +1 ,0 ); + key++; + } +}Signature · 7 lines
2.23.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/2 libs/libltpnewipc: Add libmsgctl.c into new ipc library
Hi Xu,
Quoted 22 lines · Yang Xu
Hi Cyril
Quoted 9 lines
Hi!
Quoted 5 lines
Signed-off-by Yang Xu <[email protected]>--- include/libnewipc.h | 28 ++++------ libs/libltpnewipc/libnewipc.c | 101 ++++++++++++++++++++++++++++++++-- 2 files changed, 109 insertions(+), 20 deletions(-)Just FYI we do not have to put all the code into a single *.c file, we can have as many as we want in the library directory...
I remember you have some comments on my previous patach as below:
------------------------------
So unless we plan to use it from different tests it does not make much sense to export it to the top level include and libs.Or alternatively we do have libltpnewipc we can pust put the
libnewmsgctl.cto that directory and with that we will have a single System V IPC helper library.
------------------------------
Quoted 7 lines
So I merge
libnewmsgctl.cintolibnewipc.c.ps: IMO, libnewipc has only three
functions(getipckey,get_used_queues, probe_free_addr),It's hard to call it a LIBS library. Can we put it into lib directory and named it astst_ipc.c?
@LI, What do you think about this?
I have no objection to this.
The reason to move it to LIBS is to support both new and old test cases in same directory, so if you're going to move back into the general LTP lib, we have to convert all the old-tests into new API. Then it will be fine.
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20200803/33a860d8/attachment.htm>
PATCH 1/2 libs/libltpnewipc: Use safe macros
In reply to Yang XuHi!
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]