All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] V2: mq_open/16-1: use tmp file to share info
@ 2012-09-06  5:29 Kang Kai
  2012-09-06  5:29 ` [LTP] [PATCH] " Kang Kai
  0 siblings, 1 reply; 12+ messages in thread
From: Kang Kai @ 2012-09-06  5:29 UTC (permalink / raw)
  To: jstancek; +Cc: ltp-list

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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH] mq_open/16-1: use tmp file to share info
  2012-09-06  5:29 [LTP] [PATCH] V2: mq_open/16-1: use tmp file to share info Kang Kai
@ 2012-09-06  5:29 ` Kang Kai
  2012-09-06  8:08   ` Jan Stancek
  0 siblings, 1 reply; 12+ messages in thread
From: Kang Kai @ 2012-09-06  5:29 UTC (permalink / raw)
  To: jstancek; +Cc: ltp-list

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 <kai.kang@windriver.com>
---
 .../conformance/interfaces/mq_open/16-1.c          |   39 +++++++++++++++++++-
 1 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
index e07ce86..eadac81 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
@@ -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;
 	}
 
-- 
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH] mq_open/16-1: use tmp file to share info
  2012-09-06  5:29 ` [LTP] [PATCH] " Kang Kai
@ 2012-09-06  8:08   ` Jan Stancek
  2012-09-06  9:45     ` Kang Kai
  0 siblings, 1 reply; 12+ messages in thread
From: Jan Stancek @ 2012-09-06  8:08 UTC (permalink / raw)
  To: Kang Kai; +Cc: ltp-list

On 09/06/2012 07:29 AM, Kang Kai wrote:
> 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 <kai.kang@windriver.com>

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

> ---
>  .../conformance/interfaces/mq_open/16-1.c          |   39 +++++++++++++++++++-
>  1 files changed, 37 insertions(+), 2 deletions(-)
> 
> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
> index e07ce86..eadac81 100644
> --- a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
> +++ b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
> @@ -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 {

Here we are in child. No close(fd) and munmap()?

> @@ -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;

You could close(fd), munmap() here, then you can remove it from
all cases below.

>  		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;
>  	}
>  


------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH] mq_open/16-1: use tmp file to share info
  2012-09-06  8:08   ` Jan Stancek
@ 2012-09-06  9:45     ` Kang Kai
  0 siblings, 0 replies; 12+ messages in thread
From: Kang Kai @ 2012-09-06  9:45 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list

On 2012年09月06日 16:08, Jan Stancek wrote:
> On 09/06/2012 07:29 AM, Kang Kai wrote:
>> 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<kai.kang@windriver.com>
> This version looks OK to me.

Hi Jan,

>
> 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.

>
> Regards,
> Jan
>
>> ---
>>   .../conformance/interfaces/mq_open/16-1.c          |   39 +++++++++++++++++++-
>>   1 files changed, 37 insertions(+), 2 deletions(-)
>>
>> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
>> index e07ce86..eadac81 100644
>> --- a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
>> +++ b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
>> @@ -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 {
> 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.


>
>> @@ -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;
> You could close(fd), munmap() here, then you can remove it from
> all cases below.
OK.

Regards,
Kai

>
>>   		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;
>>   	}
>>
>


------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH] mq_open/16-1: use tmp file to share info
  2012-09-06  9:50 ` [LTP] [PATCH] " Kang Kai
@ 2012-09-13  1:20   ` Wanlong Gao
  0 siblings, 0 replies; 12+ messages in thread
From: Wanlong Gao @ 2012-09-13  1:20 UTC (permalink / raw)
  To: Kang Kai; +Cc: ltp-list

On 09/06/2012 05:50 PM, Kang Kai wrote:
> 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 <kai.kang@windriver.com>

Pushed, thank you .

Wanlong Gao


------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH] mq_open/16-1: use tmp file to share info
  2012-09-06  9:50 [LTP] [PATCH] V3: " Kang Kai
@ 2012-09-06  9:50 ` Kang Kai
  2012-09-13  1:20   ` Wanlong Gao
  0 siblings, 1 reply; 12+ messages in thread
From: Kang Kai @ 2012-09-06  9:50 UTC (permalink / raw)
  To: jstancek; +Cc: ltp-list

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 <kai.kang@windriver.com>
---
 .../conformance/interfaces/mq_open/16-1.c          |   36 ++++++++++++++++++-
 1 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
index e07ce86..9aae29b 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
@@ -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,6 +129,10 @@ int main()
 		mq_close(childqueue);
 		mq_unlink(qname);
 
+		succeeded = *(int *)pa;
+		close(fd);
+		munmap(pa, sizeof(int));
+
 		if (succeeded == 0) {
 			printf("Test FAILED - mq_open() never succeeded\n");
 			return PTS_FAIL;
-- 
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH] mq_open/16-1: use tmp file to share info
  2012-09-06  1:17 ` Wanlong Gao
@ 2012-09-06  3:23   ` Kang Kai
  0 siblings, 0 replies; 12+ messages in thread
From: Kang Kai @ 2012-09-06  3:23 UTC (permalink / raw)
  To: gaowanlong; +Cc: ltp-list, Zhenfeng.Zhao

On 2012年09月06日 09:17, Wanlong Gao wrote:
> On 09/04/2012 05:52 PM, Kang Kai wrote:
>> 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.
> Jan, do you have more question about this patch?
> Kang, can you please rebase the patch against the newest tree?
Sorry, fine.

Small tweak:
I'll update it to write array "fname" to fd that avoid to declare a new 
char array.

Regards,
Kai

>
> Thanks,
> Wanlong Gao
>
>> Signed-off-by: Kang Kai<kai.kang@windriver.com>
>> ---
>>   .../conformance/interfaces/mq_open/16-1.c          |   40 ++++++++++++++++++--
>>   1 files changed, 36 insertions(+), 4 deletions(-)
>>
>> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
>> index b9a3215..51b954e 100644
>> --- a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
>> +++ b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
>> @@ -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,16 @@
>>   #include "posixtest.h"
>>
>>   #define NAMESIZE 50
>> +#define TNAME "mq_open/16-1.c"
>>
>>   int main()
>>   {
>>          	char qname[NAMESIZE];
>> +	char fname[NAMESIZE];
>> +	char buf[NAMESIZE];
>>   	int pid, succeeded=0;
>> +	int fd;
>> +	void *pa = NULL;
>>   	mqd_t childqueue, queue;
>>
>>   	/*
>> @@ -47,6 +54,27 @@ 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" */
>> +	memset(buf, '\0', NAMESIZE);
>> +	write(fd, buf, 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;
>> +
>>   	if ((pid = fork()) == 0) {
>>   		sigset_t mask;
>>   		int sig;
>> @@ -62,7 +90,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 {
>> @@ -79,7 +107,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 {
>> @@ -93,13 +121,15 @@ int main()
>>   			mq_close(queue);
>>   			mq_close(childqueue);
>>   			mq_unlink(qname);
>> +			close(fd);
>> +			munmap(pa, sizeof(int));
>>   			return PTS_UNRESOLVED;
>>   		}
>>
>>   		mq_close(queue);
>>   		mq_close(childqueue);
>>   		mq_unlink(qname);
>> -
>> +		succeeded = *(int *)pa;
>>   		if (succeeded==0) {
>>   			printf("Test FAILED - mq_open() never succeeded\n");
>>   			return PTS_FAIL;
>> @@ -111,8 +141,10 @@ int main()
>>   		}
>>
>>           	printf("Test PASSED\n");
>> +		close(fd);
>> +		munmap(pa, sizeof(int));
>>           	return PTS_PASS;
>>   	}
>>
>>   	return PTS_UNRESOLVED;
>> -}
>> \ No newline at end of file
>> +}
>>
>


------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH] mq_open/16-1: use tmp file to share info
  2012-09-04  9:52 Kang Kai
@ 2012-09-06  1:17 ` Wanlong Gao
  2012-09-06  3:23   ` Kang Kai
  0 siblings, 1 reply; 12+ messages in thread
From: Wanlong Gao @ 2012-09-06  1:17 UTC (permalink / raw)
  To: Kang Kai, jstancek; +Cc: ltp-list, Zhenfeng.Zhao

On 09/04/2012 05:52 PM, Kang Kai wrote:
> 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.

Jan, do you have more question about this patch?
Kang, can you please rebase the patch against the newest tree?

Thanks,
Wanlong Gao

> 
> Signed-off-by: Kang Kai <kai.kang@windriver.com>
> ---
>  .../conformance/interfaces/mq_open/16-1.c          |   40 ++++++++++++++++++--
>  1 files changed, 36 insertions(+), 4 deletions(-)
> 
> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
> index b9a3215..51b954e 100644
> --- a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
> +++ b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
> @@ -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,16 @@
>  #include "posixtest.h"
>  
>  #define NAMESIZE 50
> +#define TNAME "mq_open/16-1.c"
>  
>  int main()
>  {
>         	char qname[NAMESIZE];
> +	char fname[NAMESIZE];
> +	char buf[NAMESIZE];
>  	int pid, succeeded=0;
> +	int fd;
> +	void *pa = NULL;
>  	mqd_t childqueue, queue;
>  
>  	/*
> @@ -47,6 +54,27 @@ 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" */
> +	memset(buf, '\0', NAMESIZE);
> +	write(fd, buf, 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;
> +
>  	if ((pid = fork()) == 0) {
>  		sigset_t mask;
>  		int sig;
> @@ -62,7 +90,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 {
> @@ -79,7 +107,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 {
> @@ -93,13 +121,15 @@ int main()
>  			mq_close(queue);
>  			mq_close(childqueue);
>  			mq_unlink(qname);
> +			close(fd);
> +			munmap(pa, sizeof(int));
>  			return PTS_UNRESOLVED;
>  		}
>  
>  		mq_close(queue);
>  		mq_close(childqueue);
>  		mq_unlink(qname);
> -
> +		succeeded = *(int *)pa;
>  		if (succeeded==0) {
>  			printf("Test FAILED - mq_open() never succeeded\n");
>  			return PTS_FAIL;
> @@ -111,8 +141,10 @@ int main()
>  		}
>  
>          	printf("Test PASSED\n");
> +		close(fd);
> +		munmap(pa, sizeof(int));
>          	return PTS_PASS;
>  	}
>  
>  	return PTS_UNRESOLVED;
> -}
> \ No newline at end of file
> +}
> 


------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH] mq_open/16-1: use tmp file to share info
@ 2012-09-04  9:52 Kang Kai
  2012-09-06  1:17 ` Wanlong Gao
  0 siblings, 1 reply; 12+ messages in thread
From: Kang Kai @ 2012-09-04  9:52 UTC (permalink / raw)
  To: jstancek; +Cc: ltp-list, Zhenfeng.Zhao

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 <kai.kang@windriver.com>
---
 .../conformance/interfaces/mq_open/16-1.c          |   40 ++++++++++++++++++--
 1 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
index b9a3215..51b954e 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
@@ -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,16 @@
 #include "posixtest.h"
 
 #define NAMESIZE 50
+#define TNAME "mq_open/16-1.c"
 
 int main()
 {
        	char qname[NAMESIZE];
+	char fname[NAMESIZE];
+	char buf[NAMESIZE];
 	int pid, succeeded=0;
+	int fd;
+	void *pa = NULL;
 	mqd_t childqueue, queue;
 
 	/*
@@ -47,6 +54,27 @@ 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" */
+	memset(buf, '\0', NAMESIZE);
+	write(fd, buf, 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;
+
 	if ((pid = fork()) == 0) {
 		sigset_t mask;
 		int sig;
@@ -62,7 +90,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 {
@@ -79,7 +107,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 {
@@ -93,13 +121,15 @@ int main()
 			mq_close(queue);
 			mq_close(childqueue);
 			mq_unlink(qname);
+			close(fd);
+			munmap(pa, sizeof(int));
 			return PTS_UNRESOLVED;
 		}
 
 		mq_close(queue);
 		mq_close(childqueue);
 		mq_unlink(qname);
-
+		succeeded = *(int *)pa;
 		if (succeeded==0) {
 			printf("Test FAILED - mq_open() never succeeded\n");
 			return PTS_FAIL;
@@ -111,8 +141,10 @@ int main()
 		}
 
         	printf("Test PASSED\n");
+		close(fd);
+		munmap(pa, sizeof(int));
         	return PTS_PASS;
 	}
 
 	return PTS_UNRESOLVED;
-}
\ No newline at end of file
+}
-- 
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH] mq_open/16-1: use tmp file to share info
@ 2012-08-06  8:45 Kang Kai
  0 siblings, 0 replies; 12+ messages in thread
From: Kang Kai @ 2012-08-06  8:45 UTC (permalink / raw)
  To: ltp-list; +Cc: Zhenfeng.Zhao

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 <kai.kang@windriver.com>
---
 .../conformance/interfaces/mq_open/16-1.c          |   38 +++++++++++++++++--
 1 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
index b9a3215..ebd697b 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
@@ -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, "\0", 1);
+	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;
+
 	if ((pid = fork()) == 0) {
 		sigset_t mask;
 		int sig;
@@ -62,7 +88,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 {
@@ -79,7 +105,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 {
@@ -93,13 +119,15 @@ int main()
 			mq_close(queue);
 			mq_close(childqueue);
 			mq_unlink(qname);
+			close(fd);
+			munmap(pa, sizeof(int));
 			return PTS_UNRESOLVED;
 		}
 
 		mq_close(queue);
 		mq_close(childqueue);
 		mq_unlink(qname);
-
+		succeeded = *(int *)pa;
 		if (succeeded==0) {
 			printf("Test FAILED - mq_open() never succeeded\n");
 			return PTS_FAIL;
@@ -111,8 +139,10 @@ int main()
 		}
 
         	printf("Test PASSED\n");
+		close(fd);
+		munmap(pa, sizeof(int));
         	return PTS_PASS;
 	}
 
 	return PTS_UNRESOLVED;
-}
\ No newline at end of file
+}
-- 
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH] mq_open/16-1: use tmp file to share info
  2012-08-06  7:49 Kang Kai
@ 2012-08-06  8:06 ` Kang Kai
  0 siblings, 0 replies; 12+ messages in thread
From: Kang Kai @ 2012-08-06  8:06 UTC (permalink / raw)
  To: Kang Kai; +Cc: ltp-list, Zhenfeng.Zhao

On 2012年08月06日 15:49, Kang Kai wrote:

Please ignore this commit, I'll send V2 with little tweak.

Thanks,
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<kai.kang@windriver.com>
> ---
>   .../conformance/interfaces/mq_open/16-1.c          |   38 +++++++++++++++++--
>   1 files changed, 34 insertions(+), 4 deletions(-)
>
> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
> index b9a3215..c7760bc 100644
> --- a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
> +++ b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
> @@ -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, "0", 1);
> +	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;
> +
>   	if ((pid = fork()) == 0) {
>   		sigset_t mask;
>   		int sig;
> @@ -62,7 +88,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 {
> @@ -79,7 +105,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 {
> @@ -93,13 +119,15 @@ int main()
>   			mq_close(queue);
>   			mq_close(childqueue);
>   			mq_unlink(qname);
> +			close(fd);
> +			munmap(pa, sizeof(int));
>   			return PTS_UNRESOLVED;
>   		}
>
>   		mq_close(queue);
>   		mq_close(childqueue);
>   		mq_unlink(qname);
> -
> +		succeeded = *(int *)pa;
>   		if (succeeded==0) {
>   			printf("Test FAILED - mq_open() never succeeded\n");
>   			return PTS_FAIL;
> @@ -111,8 +139,10 @@ int main()
>   		}
>
>           	printf("Test PASSED\n");
> +		close(fd);
> +		munmap(pa, sizeof(int));
>           	return PTS_PASS;
>   	}
>
>   	return PTS_UNRESOLVED;
> -}
> \ No newline at end of file
> +}


------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH] mq_open/16-1: use tmp file to share info
@ 2012-08-06  7:49 Kang Kai
  2012-08-06  8:06 ` Kang Kai
  0 siblings, 1 reply; 12+ messages in thread
From: Kang Kai @ 2012-08-06  7:49 UTC (permalink / raw)
  To: ltp-list; +Cc: Zhenfeng.Zhao

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 <kai.kang@windriver.com>
---
 .../conformance/interfaces/mq_open/16-1.c          |   38 +++++++++++++++++--
 1 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
index b9a3215..c7760bc 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
@@ -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, "0", 1);
+	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;
+
 	if ((pid = fork()) == 0) {
 		sigset_t mask;
 		int sig;
@@ -62,7 +88,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 {
@@ -79,7 +105,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 {
@@ -93,13 +119,15 @@ int main()
 			mq_close(queue);
 			mq_close(childqueue);
 			mq_unlink(qname);
+			close(fd);
+			munmap(pa, sizeof(int));
 			return PTS_UNRESOLVED;
 		}
 
 		mq_close(queue);
 		mq_close(childqueue);
 		mq_unlink(qname);
-
+		succeeded = *(int *)pa;
 		if (succeeded==0) {
 			printf("Test FAILED - mq_open() never succeeded\n");
 			return PTS_FAIL;
@@ -111,8 +139,10 @@ int main()
 		}
 
         	printf("Test PASSED\n");
+		close(fd);
+		munmap(pa, sizeof(int));
         	return PTS_PASS;
 	}
 
 	return PTS_UNRESOLVED;
-}
\ No newline at end of file
+}
-- 
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2012-09-13  1:20 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-06  5:29 [LTP] [PATCH] V2: mq_open/16-1: use tmp file to share info Kang Kai
2012-09-06  5:29 ` [LTP] [PATCH] " Kang Kai
2012-09-06  8:08   ` Jan Stancek
2012-09-06  9:45     ` Kang Kai
  -- strict thread matches above, loose matches on Subject: below --
2012-09-06  9:50 [LTP] [PATCH] V3: " Kang Kai
2012-09-06  9:50 ` [LTP] [PATCH] " Kang Kai
2012-09-13  1:20   ` Wanlong Gao
2012-09-04  9:52 Kang Kai
2012-09-06  1:17 ` Wanlong Gao
2012-09-06  3:23   ` Kang Kai
2012-08-06  8:45 Kang Kai
2012-08-06  7:49 Kang Kai
2012-08-06  8:06 ` Kang Kai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.