V2: mq_open/16-1: use tmp file to share info
PATCH 1/1 V2: mq_open/16-1: use tmp file to share info
Hi,
V2 just remove the var buf[], and write fname[] to the tmp file. And more cleanup work when test fails.
Regards,
Kai
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
PATCH 1/1 mq_open/16-1: use tmp file to share info
In this test case, it uses a variable to share data between child and parent processes. But after fork there is a copy of the variable in child process and modify it will not affect the variable in the parent process. Then when the child process call mq_open() before parent process, the case will fail.
Use tmp file to replace the variable. Any modification in child process can be seen in parent process.
--- .../conformance/interfaces/mq_open/16-1.c | 39 +++++++++++++++++++- 1 files changed, 37 insertions(+), 2 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +37 -2
@@ -20,9 +20,11 @@* this is fine (will have some false positives, but no false negatives). */ +#include <sys/mman.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/wait.h> +#include <errno.h> #include <fcntl.h> #include <mqueue.h> #include <signal.h>
@@ -32,11 +34,15 @@#include "posixtest.h" #define NAMESIZE 50 +#define TNAME "mq_open/16-1.c"int main () {char qname[NAMESIZE ]; +char fname[NAMESIZE ];int pid, succeeded =0 ; +int fd; +void *pa =NULL ;mqd_t childqueue, queue;/*
@@ -47,6 +53,26 @@ int main()sprintf (qname,"/mq_open_16-1_%d" ,getpid ()); +sprintf (fname,"/tmp/pts_mq_open_16_1_%d" ,getpid ()); +unlink (fname); + fd =open (fname,O_CREAT |O_RDWR |O_EXCL , +S_IRUSR |S_IWUSR ); +if (fd ==-1 ) { +printf (TNAME " Error at open(): %s\n" ,strerror (errno)); +exit (PTS_UNRESOLVED ); + } +/* file is empty now, will cause "Bus error" */ +write (fd, fname,sizeof (int )); +unlink (fname); + + pa =mmap (NULL ,sizeof (int ),PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 ); +if (pa ==MAP_FAILED ) { +printf (TNAME " Error at mmap: %s\n" ,strerror (errno)); +close (fd); +exit (PTS_FAIL ); + } + *(int *)pa =0 ; + pid =fork ();if (pid ==0 ) {sigset_t mask;
@@ -63,7 +89,7 @@ int main() childqueue =mq_open (qname,O_CREAT |O_EXCL |O_RDWR ,S_IRUSR |S_IWUSR ,NULL );if (childqueue != (mqd_t) -1 ) { - succeeded++; + ++*(int *)pa;#ifdef DEBUG printf("mq_open() in child succeeded\n"); }else {
@@ -80,7 +106,7 @@ int main() queue =mq_open (qname,O_CREAT |O_EXCL |O_RDWR ,S_IRUSR |S_IWUSR ,NULL );if (queue != (mqd_t) -1 ) { - succeeded++; + ++*(int *)pa;#ifdef DEBUG printf("mq_open() in parent succeeded\n"); }else {
@@ -94,6 +120,8 @@ int main()mq_close (queue);mq_close (childqueue);mq_unlink (qname); +close (fd); +munmap (pa,sizeof (int ));return PTS_UNRESOLVED ; }
@@ -101,17 +129,24 @@ int main()mq_close (childqueue);mq_unlink (qname); + succeeded = *(int *)pa;if (succeeded ==0 ) {printf ("Test FAILED - mq_open() never succeeded\n" ); +close (fd); +munmap (pa,sizeof (int ));return PTS_FAIL ; }if (succeeded >1 ) {printf ("Test FAILED - mq_open() succeeded twice\n" ); +close (fd); +munmap (pa,sizeof (int ));return PTS_FAIL ; }printf ("Test PASSED\n" ); +close (fd); +munmap (pa,sizeof (int ));return PTS_PASS ; }
Signature · 13 lines
1.7.5.4 ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Re: [LTP] [PATCH] mq_open/16-1: use tmp file to share info
Quoted 10 lines · Kang Kai
In this test case, it uses a variable to share data between child and parent processes. But after fork there is a copy of the variable in child process and modify it will not affect the variable in the parent process. Then when the child process call
mq_open()before parent process, the case will fail.Use tmp file to replace the variable. Any modification in child process can be seen in parent process.
Signed-off-by Kang Kai <[email protected]>
This version looks OK to me.
I put 2 comments below, but it's nothing serious, in case you would do another version you can take it into consideration.
Regards,
Jan
Quoted 64 lines
--- .../conformance/interfaces/mq_open/16-1.c | 39 +++++++++++++++++++- 1 files changed, 37 insertions(+), 2 deletions(-)testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +26
-0@@ -20,9 +20,11 @@* this is fine (will have some false positives, but no false negatives). */ +#include <sys/mman.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/wait.h> +#include <errno.h> #include <fcntl.h> #include <mqueue.h> #include <signal.h> @@ -32,11 +34,15 @@#include "posixtest.h" #define NAMESIZE 50 +#define TNAME "mq_open/16-1.c"int main () {char qname[NAMESIZE ]; +char fname[NAMESIZE ];int pid, succeeded =0 ; +int fd; +void *pa =NULL ;mqd_t childqueue, queue;/* @@ -47,6 +53,26 @@ int main()sprintf (qname,"/mq_open_16-1_%d" ,getpid ()); +sprintf (fname,"/tmp/pts_mq_open_16_1_%d" ,getpid ()); +unlink (fname); + fd =open (fname,O_CREAT |O_RDWR |O_EXCL , +S_IRUSR |S_IWUSR ); +if (fd ==-1 ) { +printf (TNAME " Error at open(): %s\n" ,strerror (errno)); +exit (PTS_UNRESOLVED ); + } +/* file is empty now, will cause "Bus error" */ +write (fd, fname,sizeof (int )); +unlink (fname); + + pa =mmap (NULL ,sizeof (int ),PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 ); +if (pa ==MAP_FAILED ) { +printf (TNAME " Error at mmap: %s\n" ,strerror (errno)); +close (fd); +exit (PTS_FAIL ); + } + *(int *)pa =0 ; + pid =fork ();if (pid ==0 ) {sigset_t mask;
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 95
Quoted 8 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +1
-1@@ -63,7 +89,7 @@ int main() childqueue =mq_open (qname,O_CREAT |O_EXCL |O_RDWR ,S_IRUSR |S_IWUSR ,NULL );if (childqueue != (mqd_t) -1 ) { - succeeded++; + ++*(int *)pa;#ifdef DEBUG printf("mq_open() in child succeeded\n"); }else {
Here we are in child. No close(fd) and munmap()?
Quoted 19 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +3
-1@@ -80,7 +106,7 @@ int main() queue =mq_open (qname,O_CREAT |O_EXCL |O_RDWR ,S_IRUSR |S_IWUSR ,NULL );if (queue != (mqd_t) -1 ) { - succeeded++; + ++*(int *)pa;#ifdef DEBUG printf("mq_open() in parent succeeded\n"); }else {@@ -94,6 +120,8 @@ int main()mq_close (queue);mq_close (childqueue);mq_unlink (qname); +close (fd); +munmap (pa,sizeof (int ));return PTS_UNRESOLVED ; }
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 132
Quoted 4 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +1
-0@@ -101,17 +129,24 @@ int main()mq_close (childqueue);mq_unlink (qname); + succeeded = *(int *)pa;
You could close(fd), munmap() here, then you can remove it from all cases below.
Quoted 10 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +3
-0if (succeeded ==0 ) {printf ("Test FAILED - mq_open() never succeeded\n" ); +close (fd); +munmap (pa,sizeof (int ));return PTS_FAIL ; }if (succeeded >1 ) {printf ("Test FAILED - mq_open() succeeded twice\n" ); +close (fd);
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 152
Quoted 10 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +3
-0+munmap (pa,sizeof (int ));return PTS_FAIL ; }printf ("Test PASSED\n" ); +close (fd); +munmap (pa,sizeof (int ));return PTS_PASS ; }
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Re: [LTP] [PATCH] mq_open/16-1: use tmp file to share info
Quoted 7 lines · Jan Stancek
Quoted 6 lines · Kang Kai
In this test case, it uses a variable to share data between child and parent processes. But after fork there is a copy of the variable in child process and modify it will not affect the variable in the parent process. Then when the child process call
mq_open()before parent process, the case will fail.
Quoted 5 lines
Quoted 4 lines
Use tmp file to replace the variable. Any modification in child process can be seen in parent process.
Signed-off-by Kang Kai<[email protected]>This version looks OK to me.
Hi Jan,
Quoted 3 lines
I put 2 comments below, but it's nothing serious, in case you would do another version you can take it into consideration.
Thanks, I will send a new version. See my comments.
Quoted 69 lines
Regards,
JanQuoted 65 lines
--- .../conformance/interfaces/mq_open/16-1.c | 39 +++++++++++++++++++- 1 files changed, 37 insertions(+), 2 deletions(-)testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +26
-0@@ -20,9 +20,11 @@* this is fine (will have some false positives, but no false negatives). */ +#include <sys/mman.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/wait.h> +#include <errno.h> #include <fcntl.h> #include <mqueue.h> #include <signal.h> @@ -32,11 +34,15 @@#include "posixtest.h" #define NAMESIZE 50 +#define TNAME "mq_open/16-1.c"int main () {char qname[NAMESIZE ]; +char fname[NAMESIZE ];int pid, succeeded =0 ; +int fd; +void *pa =NULL ;mqd_t childqueue, queue;/* @@ -47,6 +53,26 @@ int main()sprintf (qname,"/mq_open_16-1_%d" ,getpid ()); +sprintf (fname,"/tmp/pts_mq_open_16_1_%d" ,getpid ()); +unlink (fname); + fd =open (fname,O_CREAT |O_RDWR |O_EXCL , +S_IRUSR |S_IWUSR ); +if (fd ==-1 ) { +printf (TNAME " Error at open(): %s\n" ,strerror (errno)); +exit (PTS_UNRESOLVED ); + } +/* file is empty now, will cause "Bus error" */ +write (fd, fname,sizeof (int )); +unlink (fname); + + pa =mmap (NULL ,sizeof (int ),PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 ); +if (pa ==MAP_FAILED ) { +printf (TNAME " Error at mmap: %s\n" ,strerror (errno)); +close (fd); +exit (PTS_FAIL ); + } + *(int *)pa =0 ; + pid =fork ();if (pid ==0 ) {sigset_t mask;@@ -63,7 +89,7 @@ int main() childqueue = mq_open(qname, O_CREAT | O_EXCL | O_RDWR,
Quoted 8 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 95
Quoted 7 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +1
-1S_IRUSR | S_IWUSR, NULL);if (childqueue != (mqd_t) -1 ) { - succeeded++; + ++*(int *)pa;#ifdef DEBUG printf("mq_open() in child succeeded\n"); }else {Here we are in child. No close(fd) and
munmap()?
I think we should NOT close(fd) and munmap().
In POSIX spec for fork():
* The child process shall have its own copy of the parent’s file descriptors. Each of the
child's file descriptors shall refer to the same open file description with the corresponding
file descriptor of the parent.
-----------------
If call close(fd), I think the fd is also closed in parent process.
* Memory mappings created in the parent shall be retained in the child process.
So munmap() affects both child and parent.
Quoted 19 lines
Quoted 19 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +3
-1@@ -80,7 +106,7 @@ int main() queue =mq_open (qname,O_CREAT |O_EXCL |O_RDWR ,S_IRUSR |S_IWUSR ,NULL );if (queue != (mqd_t) -1 ) { - succeeded++; + ++*(int *)pa;#ifdef DEBUG printf("mq_open() in parent succeeded\n"); }else {@@ -94,6 +120,8 @@ int main()mq_close (queue);mq_close (childqueue);mq_unlink (qname); +close (fd); +munmap (pa,sizeof (int ));return PTS_UNRESOLVED ; }
Quoted 7 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 132
Quoted 5 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +1
-0@@ -101,17 +129,24 @@ int main()mq_close (childqueue);mq_unlink (qname); + succeeded = *(int *)pa;You could close(fd),
munmap()here, then you can remove it from all cases below.
OK.
Regards,
Kai
Quoted 15 lines
Quoted 15 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +4
-0if (succeeded ==0 ) {printf ("Test FAILED - mq_open() never succeeded\n" ); +close (fd); +munmap (pa,sizeof (int ));return PTS_FAIL ; }if (succeeded>1 ) {printf ("Test FAILED - mq_open() succeeded twice\n" ); +close (fd); +munmap (pa,sizeof (int ));return PTS_FAIL ; }
Quoted 7 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 152
Quoted 6 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +2
-0printf ("Test PASSED\n" ); +close (fd); +munmap (pa,sizeof (int ));return PTS_PASS ; }
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list