All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] Patches for posix test cases
@ 2012-08-09 10:30 Kang Kai
  2012-08-09 10:30 ` [LTP] [PATCH 1/3] pthread_cond_signal/1-1: use sched_yield to sync threads Kang Kai
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Kang Kai @ 2012-08-09 10:30 UTC (permalink / raw)
  To: ltp-list; +Cc: Zhenfeng.Zhao

Hi all,

The first two patches are resent because no reply for now.
The third patch is for timer_settime/5-3.c. In this case the timer always expires before the caller enters sleep.
So it sleeps too long time to be reported hang. Decrease the sleep value to fix it.

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] 18+ messages in thread

* [LTP] [PATCH 1/3] pthread_cond_signal/1-1: use sched_yield to sync threads
  2012-08-09 10:30 [LTP] Patches for posix test cases Kang Kai
@ 2012-08-09 10:30 ` Kang Kai
  2012-08-10 10:22   ` Jan Stancek
  2012-08-09 10:30 ` [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info Kang Kai
  2012-08-09 10:30 ` [LTP] [PATCH 3/3] timer_settime/5-3: fix test hung Kang Kai
  2 siblings, 1 reply; 18+ messages in thread
From: Kang Kai @ 2012-08-09 10:30 UTC (permalink / raw)
  To: ltp-list; +Cc: Zhenfeng.Zhao

This case fails on mips board routerstation randomly. The root cause is
that when main thread call usleep(100) after signal the child threads,
no child thread is scheduled to run.  So the case fails.

I update it to set main thread with a lower priority and child threads
with a higher one, then call sched_yield and usleep in main thread will
make sure that one of the child threads will be scheduled.

Signed-off-by: Kang Kai <kai.kang@windriver.com>
---
 .../interfaces/pthread_cond_signal/1-1.c           |   44 +++++++++++++++++++-
 1 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
index bf55b31..77374bf 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
@@ -12,6 +12,7 @@
 
 #define _XOPEN_SOURCE 600
 
+#include <errno.h>
 #include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -20,6 +21,7 @@
 #include "posixtest.h"
 
 #define THREAD_NUM  3
+#define SCHED_POLICY SCHED_FIFO
 
 struct testdata
 {
@@ -77,6 +79,10 @@ int main()
 {
 	int i, rc;
 	struct sigaction act;
+	int pid;
+	int policy;
+	struct sched_param param;
+	pthread_attr_t attr;
 
 	if (pthread_mutex_init(&td.mutex, NULL) != 0) {
 		fprintf(stderr,"Fail to initialize mutex\n");
@@ -87,8 +93,35 @@ int main()
 		return PTS_UNRESOLVED;
 	}
 
+	pid = getpid();
+	param.sched_priority = sched_get_priority_min(SCHED_POLICY);
+	if (sched_setscheduler(pid, SCHED_POLICY, &param) != 0) {
+		fprintf(stderr, "Fail to set main thread scheduler.\n");
+		if (errno == EPERM)
+			fprintf(stderr, "Failed with EPERM: are you root?\n");
+		return PTS_UNRESOLVED;
+	}
+
+	if (pthread_attr_init(&attr) != 0) {
+		fprintf(stderr, "Fail to init child thread attribute.\n");
+		return PTS_UNRESOLVED;
+	}
+	if (pthread_attr_setschedpolicy(&attr, SCHED_POLICY) != 0) {
+		fprintf(stderr, "Fail to set child thread schedule policy attribute.\n");
+		return PTS_UNRESOLVED;
+	}
+	param.sched_priority += 10;
+	if (pthread_attr_setschedparam(&attr, &param) != 0) {
+		fprintf(stderr, "Fail to set child thread schedule priority attribute.\n");
+		return PTS_UNRESOLVED;
+	}
+	if (pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) != 0) {
+		fprintf(stderr, "Fail to set child thread inheritace attribute.\n");
+		return PTS_UNRESOLVED;
+	}
+
 	for (i=0; i<THREAD_NUM; i++) {	/* create THREAD_NUM threads */
-	    	if (pthread_create(&thread[i], NULL, thr_func, NULL) != 0) {
+		if (pthread_create(&thread[i], &attr, thr_func, NULL) != 0) {
 			fprintf(stderr,"Fail to create thread[%d]\n", i);
 			exit(PTS_UNRESOLVED);
 		}
@@ -96,6 +129,8 @@ int main()
 	while (start_num < THREAD_NUM)	/* waiting for all threads started */
 		usleep(100);
 
+	pthread_attr_destroy(&attr);
+
 	/* Acquire the mutex to make sure that all waiters are currently
 	   blocked on pthread_cond_wait */
 	if (pthread_mutex_lock(&td.mutex) != 0) {
@@ -142,6 +177,7 @@ int main()
 			fprintf(stderr,"Main failed to signal the condition\n");
 			exit(PTS_UNRESOLVED);
 		}
+		sched_yield();
 		usleep(100);
 	}
 
@@ -158,6 +194,10 @@ int main()
 			exit(PTS_UNRESOLVED);
 		}
 	}
+
+	pthread_mutex_destroy(&td.mutex);
+	pthread_cond_destroy(&td.cond);
+
 	printf("Test PASSED\n");
 	return PTS_PASS;
-}
\ 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] 18+ messages in thread

* [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info
  2012-08-09 10:30 [LTP] Patches for posix test cases Kang Kai
  2012-08-09 10:30 ` [LTP] [PATCH 1/3] pthread_cond_signal/1-1: use sched_yield to sync threads Kang Kai
@ 2012-08-09 10:30 ` Kang Kai
  2012-08-10  9:31   ` Jan Stancek
                     ` (2 more replies)
  2012-08-09 10:30 ` [LTP] [PATCH 3/3] timer_settime/5-3: fix test hung Kang Kai
  2 siblings, 3 replies; 18+ messages in thread
From: Kang Kai @ 2012-08-09 10:30 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] 18+ messages in thread

* [LTP] [PATCH 3/3] timer_settime/5-3: fix test hung
  2012-08-09 10:30 [LTP] Patches for posix test cases Kang Kai
  2012-08-09 10:30 ` [LTP] [PATCH 1/3] pthread_cond_signal/1-1: use sched_yield to sync threads Kang Kai
  2012-08-09 10:30 ` [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info Kang Kai
@ 2012-08-09 10:30 ` Kang Kai
  2012-08-10  9:16   ` Jan Stancek
  2 siblings, 1 reply; 18+ messages in thread
From: Kang Kai @ 2012-08-09 10:30 UTC (permalink / raw)
  To: ltp-list; +Cc: Zhenfeng.Zhao

This case hangs on sugarbay(intel x86_64) platform.

The root cause is that the case calls timer_settime with time which
already took place and then calls sleep. When the timer expires and
sends signal the sleep will be break.

But on sugarbay the timer always expires before the case enters sleep,
then it always sleeps NUMTESTS * LONGSLEEPTIME seconds. So it exceeds
the time limit set by auto-run test shell script, and reports that it
hangs.

Decrease LONGSLEEPTIME value to avoid this issue.

Signed-off-by: Kang Kai <kai.kang@windriver.com>
---
 .../conformance/interfaces/timer_settime/5-3.c     |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/timer_settime/5-3.c b/testcases/open_posix_testsuite/conformance/interfaces/timer_settime/5-3.c
index 0ad1957..4a47458 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/timer_settime/5-3.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/timer_settime/5-3.c
@@ -27,7 +27,7 @@
 
 #define SIGTOTEST SIGALRM
 
-#define LONGSLEEPTIME 10
+#define LONGSLEEPTIME 5
 
 #define NUMTESTS 30
 
@@ -105,4 +105,4 @@ int main(int argc, char *argv[])
 
 	printf("This code should not be executed.\n");
 	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] 18+ messages in thread

* Re: [LTP] [PATCH 3/3] timer_settime/5-3: fix test hung
  2012-08-09 10:30 ` [LTP] [PATCH 3/3] timer_settime/5-3: fix test hung Kang Kai
@ 2012-08-10  9:16   ` Jan Stancek
  2012-08-21  4:01     ` Wanlong Gao
  0 siblings, 1 reply; 18+ messages in thread
From: Jan Stancek @ 2012-08-10  9:16 UTC (permalink / raw)
  To: Kang Kai; +Cc: ltp-list, Zhenfeng Zhao



----- Original Message -----
> From: "Kang Kai" <kai.kang@windriver.com>
> To: ltp-list@lists.sourceforge.net
> Cc: "Zhenfeng Zhao" <Zhenfeng.Zhao@windriver.com>
> Sent: Thursday, 9 August, 2012 12:30:58 PM
> Subject: [LTP] [PATCH 3/3] timer_settime/5-3: fix test hung
> 
> This case hangs on sugarbay(intel x86_64) platform.
> 
> The root cause is that the case calls timer_settime with time which
> already took place and then calls sleep. When the timer expires and
> sends signal the sleep will be break.
> 
> But on sugarbay the timer always expires before the case enters
> sleep,
> then it always sleeps NUMTESTS * LONGSLEEPTIME seconds. So it exceeds
> the time limit set by auto-run test shell script, and reports that it
> hangs.
> 
> Decrease LONGSLEEPTIME value to avoid this issue.
> 
> Signed-off-by: Kang Kai <kai.kang@windriver.com>

Looks good to me, 5 secs is still enough time.

Reviewed-by: Jan Stancek <jstancek@redhat.com>

> ---
>  .../conformance/interfaces/timer_settime/5-3.c     |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git
> a/testcases/open_posix_testsuite/conformance/interfaces/timer_settime/5-3.c
> b/testcases/open_posix_testsuite/conformance/interfaces/timer_settime/5-3.c
> index 0ad1957..4a47458 100644
> ---
> a/testcases/open_posix_testsuite/conformance/interfaces/timer_settime/5-3.c
> +++
> b/testcases/open_posix_testsuite/conformance/interfaces/timer_settime/5-3.c
> @@ -27,7 +27,7 @@
>  
>  #define SIGTOTEST SIGALRM
>  
> -#define LONGSLEEPTIME 10
> +#define LONGSLEEPTIME 5
>  
>  #define NUMTESTS 30
>  
> @@ -105,4 +105,4 @@ int main(int argc, char *argv[])
>  
>  	printf("This code should not be executed.\n");
>  	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
> 

------------------------------------------------------------------------------
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] 18+ messages in thread

* Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info
  2012-08-09 10:30 ` [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info Kang Kai
@ 2012-08-10  9:31   ` Jan Stancek
  2012-09-03  8:45   ` Kang Kai
  2012-09-04  5:33   ` Wanlong Gao
  2 siblings, 0 replies; 18+ messages in thread
From: Jan Stancek @ 2012-08-10  9:31 UTC (permalink / raw)
  To: Kang Kai; +Cc: ltp-list, Zhenfeng Zhao



----- Original Message -----
> From: "Kang Kai" <kai.kang@windriver.com>
> To: ltp-list@lists.sourceforge.net
> Cc: "Zhenfeng Zhao" <Zhenfeng.Zhao@windriver.com>
> Sent: Thursday, 9 August, 2012 12:30:57 PM
> Subject: [LTP] [PATCH 2/3] 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.
> 
> 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);

Isn't there a risk of SIGBUS, when the file length is just 1 byte
and it's mapped to sizeof(int)?

   SIGBUS Attempted access to a portion of the buffer that does not correspond to the file (for  example,  beyond
          the end of the file, including the case where another process has truncated the file).

Regards,
Jan

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

------------------------------------------------------------------------------
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] 18+ messages in thread

* Re: [LTP] [PATCH 1/3] pthread_cond_signal/1-1: use sched_yield to sync threads
  2012-08-09 10:30 ` [LTP] [PATCH 1/3] pthread_cond_signal/1-1: use sched_yield to sync threads Kang Kai
@ 2012-08-10 10:22   ` Jan Stancek
  2012-08-13  2:50     ` Kang Kai
  0 siblings, 1 reply; 18+ messages in thread
From: Jan Stancek @ 2012-08-10 10:22 UTC (permalink / raw)
  To: ltp-list

Hi,

Here's a different proposal: don't count how many pthread_cond_signals it took,
if any fails SIGALRM will trigger testcase failure.

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
index bf55b31..266d42f 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
@@ -134,9 +134,7 @@ int main()
 	alarm(5);
 
 	/* loop to wake up the rest threads */
-	i=0;
-	while (waken_num < THREAD_NUM) {
-		++i;
+	for (i=1; i<THREAD_NUM; i++) {
 		fprintf(stderr,"[Main thread] signals to wake up the next thread\n");
 		if (pthread_cond_signal(&td.cond) != 0) {
 			fprintf(stderr,"Main failed to signal the condition\n");
@@ -145,12 +143,6 @@ int main()
 		usleep(100);
 	}
 
-	if (i >= THREAD_NUM) {
-		fprintf(stderr,"[Main thread] had to signal the condition %i times\n", i+1);
-		fprintf(stderr,"[Main thread] to wake up %i threads\n. Test FAILED.\n", THREAD_NUM);
-		exit(PTS_FAIL);
-	}
-
 	/* join all secondary threads */
 	for (i=0; i<THREAD_NUM; i++) {
 	    	if (pthread_join(thread[i], NULL) != 0) {

Regards,
Jan

On 08/09/2012 12:30 PM, Kang Kai wrote:
> This case fails on mips board routerstation randomly. The root cause is
> that when main thread call usleep(100) after signal the child threads,
> no child thread is scheduled to run.  So the case fails.
> 
> I update it to set main thread with a lower priority and child threads
> with a higher one, then call sched_yield and usleep in main thread will
> make sure that one of the child threads will be scheduled.
> 
> Signed-off-by: Kang Kai <kai.kang@windriver.com>
> ---
>  .../interfaces/pthread_cond_signal/1-1.c           |   44 +++++++++++++++++++-
>  1 files changed, 42 insertions(+), 2 deletions(-)
> 
> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
> index bf55b31..77374bf 100644
> --- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
> +++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
> @@ -12,6 +12,7 @@
>  
>  #define _XOPEN_SOURCE 600
>  
> +#include <errno.h>
>  #include <pthread.h>
>  #include <stdio.h>
>  #include <stdlib.h>
> @@ -20,6 +21,7 @@
>  #include "posixtest.h"
>  
>  #define THREAD_NUM  3
> +#define SCHED_POLICY SCHED_FIFO
>  
>  struct testdata
>  {
> @@ -77,6 +79,10 @@ int main()
>  {
>  	int i, rc;
>  	struct sigaction act;
> +	int pid;
> +	int policy;
> +	struct sched_param param;
> +	pthread_attr_t attr;
>  
>  	if (pthread_mutex_init(&td.mutex, NULL) != 0) {
>  		fprintf(stderr,"Fail to initialize mutex\n");
> @@ -87,8 +93,35 @@ int main()
>  		return PTS_UNRESOLVED;
>  	}
>  
> +	pid = getpid();
> +	param.sched_priority = sched_get_priority_min(SCHED_POLICY);
> +	if (sched_setscheduler(pid, SCHED_POLICY, &param) != 0) {
> +		fprintf(stderr, "Fail to set main thread scheduler.\n");
> +		if (errno == EPERM)
> +			fprintf(stderr, "Failed with EPERM: are you root?\n");
> +		return PTS_UNRESOLVED;
> +	}
> +
> +	if (pthread_attr_init(&attr) != 0) {
> +		fprintf(stderr, "Fail to init child thread attribute.\n");
> +		return PTS_UNRESOLVED;
> +	}
> +	if (pthread_attr_setschedpolicy(&attr, SCHED_POLICY) != 0) {
> +		fprintf(stderr, "Fail to set child thread schedule policy attribute.\n");
> +		return PTS_UNRESOLVED;
> +	}
> +	param.sched_priority += 10;
> +	if (pthread_attr_setschedparam(&attr, &param) != 0) {
> +		fprintf(stderr, "Fail to set child thread schedule priority attribute.\n");
> +		return PTS_UNRESOLVED;
> +	}
> +	if (pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) != 0) {
> +		fprintf(stderr, "Fail to set child thread inheritace attribute.\n");
> +		return PTS_UNRESOLVED;
> +	}
> +
>  	for (i=0; i<THREAD_NUM; i++) {	/* create THREAD_NUM threads */
> -	    	if (pthread_create(&thread[i], NULL, thr_func, NULL) != 0) {
> +		if (pthread_create(&thread[i], &attr, thr_func, NULL) != 0) {
>  			fprintf(stderr,"Fail to create thread[%d]\n", i);
>  			exit(PTS_UNRESOLVED);
>  		}
> @@ -96,6 +129,8 @@ int main()
>  	while (start_num < THREAD_NUM)	/* waiting for all threads started */
>  		usleep(100);
>  
> +	pthread_attr_destroy(&attr);
> +
>  	/* Acquire the mutex to make sure that all waiters are currently
>  	   blocked on pthread_cond_wait */
>  	if (pthread_mutex_lock(&td.mutex) != 0) {
> @@ -142,6 +177,7 @@ int main()
>  			fprintf(stderr,"Main failed to signal the condition\n");
>  			exit(PTS_UNRESOLVED);
>  		}
> +		sched_yield();
>  		usleep(100);
>  	}
>  
> @@ -158,6 +194,10 @@ int main()
>  			exit(PTS_UNRESOLVED);
>  		}
>  	}
> +
> +	pthread_mutex_destroy(&td.mutex);
> +	pthread_cond_destroy(&td.cond);
> +
>  	printf("Test PASSED\n");
>  	return PTS_PASS;
> -}
> \ 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 related	[flat|nested] 18+ messages in thread

* Re: [LTP] [PATCH 1/3] pthread_cond_signal/1-1: use sched_yield to sync threads
  2012-08-10 10:22   ` Jan Stancek
@ 2012-08-13  2:50     ` Kang Kai
  2012-08-23  1:57       ` Wanlong Gao
  0 siblings, 1 reply; 18+ messages in thread
From: Kang Kai @ 2012-08-13  2:50 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list

On 2012年08月10日 18:22, Jan Stancek wrote:
> Hi,
Hi Jan,

Thanks for your reply.
> Here's a different proposal: don't count how many pthread_cond_signals it took,
> if any fails SIGALRM will trigger testcase failure.
That is a more simple solution, and I agree with you.

Regards,
Kai

>
> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
> index bf55b31..266d42f 100644
> --- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
> +++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
> @@ -134,9 +134,7 @@ int main()
>   	alarm(5);
>
>   	/* loop to wake up the rest threads */
> -	i=0;
> -	while (waken_num<  THREAD_NUM) {
> -		++i;
> +	for (i=1; i<THREAD_NUM; i++) {
>   		fprintf(stderr,"[Main thread] signals to wake up the next thread\n");
>   		if (pthread_cond_signal(&td.cond) != 0) {
>   			fprintf(stderr,"Main failed to signal the condition\n");
> @@ -145,12 +143,6 @@ int main()
>   		usleep(100);
>   	}
>
> -	if (i>= THREAD_NUM) {
> -		fprintf(stderr,"[Main thread] had to signal the condition %i times\n", i+1);
> -		fprintf(stderr,"[Main thread] to wake up %i threads\n. Test FAILED.\n", THREAD_NUM);
> -		exit(PTS_FAIL);
> -	}
> -
>   	/* join all secondary threads */
>   	for (i=0; i<THREAD_NUM; i++) {
>   	    	if (pthread_join(thread[i], NULL) != 0) {
>
> Regards,
> Jan
>
> On 08/09/2012 12:30 PM, Kang Kai wrote:
>> This case fails on mips board routerstation randomly. The root cause is
>> that when main thread call usleep(100) after signal the child threads,
>> no child thread is scheduled to run.  So the case fails.
>>
>> I update it to set main thread with a lower priority and child threads
>> with a higher one, then call sched_yield and usleep in main thread will
>> make sure that one of the child threads will be scheduled.
>>
>> Signed-off-by: Kang Kai<kai.kang@windriver.com>
>> ---
>>   .../interfaces/pthread_cond_signal/1-1.c           |   44 +++++++++++++++++++-
>>   1 files changed, 42 insertions(+), 2 deletions(-)
>>
>> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
>> index bf55b31..77374bf 100644
>> --- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
>> +++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c
>> @@ -12,6 +12,7 @@
>>
>>   #define _XOPEN_SOURCE 600
>>
>> +#include<errno.h>
>>   #include<pthread.h>
>>   #include<stdio.h>
>>   #include<stdlib.h>
>> @@ -20,6 +21,7 @@
>>   #include "posixtest.h"
>>
>>   #define THREAD_NUM  3
>> +#define SCHED_POLICY SCHED_FIFO
>>
>>   struct testdata
>>   {
>> @@ -77,6 +79,10 @@ int main()
>>   {
>>   	int i, rc;
>>   	struct sigaction act;
>> +	int pid;
>> +	int policy;
>> +	struct sched_param param;
>> +	pthread_attr_t attr;
>>
>>   	if (pthread_mutex_init(&td.mutex, NULL) != 0) {
>>   		fprintf(stderr,"Fail to initialize mutex\n");
>> @@ -87,8 +93,35 @@ int main()
>>   		return PTS_UNRESOLVED;
>>   	}
>>
>> +	pid = getpid();
>> +	param.sched_priority = sched_get_priority_min(SCHED_POLICY);
>> +	if (sched_setscheduler(pid, SCHED_POLICY,&param) != 0) {
>> +		fprintf(stderr, "Fail to set main thread scheduler.\n");
>> +		if (errno == EPERM)
>> +			fprintf(stderr, "Failed with EPERM: are you root?\n");
>> +		return PTS_UNRESOLVED;
>> +	}
>> +
>> +	if (pthread_attr_init(&attr) != 0) {
>> +		fprintf(stderr, "Fail to init child thread attribute.\n");
>> +		return PTS_UNRESOLVED;
>> +	}
>> +	if (pthread_attr_setschedpolicy(&attr, SCHED_POLICY) != 0) {
>> +		fprintf(stderr, "Fail to set child thread schedule policy attribute.\n");
>> +		return PTS_UNRESOLVED;
>> +	}
>> +	param.sched_priority += 10;
>> +	if (pthread_attr_setschedparam(&attr,&param) != 0) {
>> +		fprintf(stderr, "Fail to set child thread schedule priority attribute.\n");
>> +		return PTS_UNRESOLVED;
>> +	}
>> +	if (pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) != 0) {
>> +		fprintf(stderr, "Fail to set child thread inheritace attribute.\n");
>> +		return PTS_UNRESOLVED;
>> +	}
>> +
>>   	for (i=0; i<THREAD_NUM; i++) {	/* create THREAD_NUM threads */
>> -	    	if (pthread_create(&thread[i], NULL, thr_func, NULL) != 0) {
>> +		if (pthread_create(&thread[i],&attr, thr_func, NULL) != 0) {
>>   			fprintf(stderr,"Fail to create thread[%d]\n", i);
>>   			exit(PTS_UNRESOLVED);
>>   		}
>> @@ -96,6 +129,8 @@ int main()
>>   	while (start_num<  THREAD_NUM)	/* waiting for all threads started */
>>   		usleep(100);
>>
>> +	pthread_attr_destroy(&attr);
>> +
>>   	/* Acquire the mutex to make sure that all waiters are currently
>>   	   blocked on pthread_cond_wait */
>>   	if (pthread_mutex_lock(&td.mutex) != 0) {
>> @@ -142,6 +177,7 @@ int main()
>>   			fprintf(stderr,"Main failed to signal the condition\n");
>>   			exit(PTS_UNRESOLVED);
>>   		}
>> +		sched_yield();
>>   		usleep(100);
>>   	}
>>
>> @@ -158,6 +194,10 @@ int main()
>>   			exit(PTS_UNRESOLVED);
>>   		}
>>   	}
>> +
>> +	pthread_mutex_destroy(&td.mutex);
>> +	pthread_cond_destroy(&td.cond);
>> +
>>   	printf("Test PASSED\n");
>>   	return PTS_PASS;
>> -}
>> \ 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
>


------------------------------------------------------------------------------
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] 18+ messages in thread

* Re: [LTP] [PATCH 3/3] timer_settime/5-3: fix test hung
  2012-08-10  9:16   ` Jan Stancek
@ 2012-08-21  4:01     ` Wanlong Gao
  0 siblings, 0 replies; 18+ messages in thread
From: Wanlong Gao @ 2012-08-21  4:01 UTC (permalink / raw)
  To: Kang Kai; +Cc: ltp-list, Zhenfeng Zhao

On 08/10/2012 05:16 PM, Jan Stancek wrote:
> 
> ----- Original Message -----
>> > From: "Kang Kai" <kai.kang@windriver.com>
>> > To: ltp-list@lists.sourceforge.net
>> > Cc: "Zhenfeng Zhao" <Zhenfeng.Zhao@windriver.com>
>> > Sent: Thursday, 9 August, 2012 12:30:58 PM
>> > Subject: [LTP] [PATCH 3/3] timer_settime/5-3: fix test hung
>> > 
>> > This case hangs on sugarbay(intel x86_64) platform.
>> > 
>> > The root cause is that the case calls timer_settime with time which
>> > already took place and then calls sleep. When the timer expires and
>> > sends signal the sleep will be break.
>> > 
>> > But on sugarbay the timer always expires before the case enters
>> > sleep,
>> > then it always sleeps NUMTESTS * LONGSLEEPTIME seconds. So it exceeds
>> > the time limit set by auto-run test shell script, and reports that it
>> > hangs.
>> > 
>> > Decrease LONGSLEEPTIME value to avoid this issue.
>> > 
>> > Signed-off-by: Kang Kai <kai.kang@windriver.com>
> Looks good to me, 5 secs is still enough time.
> 
> Reviewed-by: Jan Stancek <jstancek@redhat.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] 18+ messages in thread

* Re: [LTP] [PATCH 1/3] pthread_cond_signal/1-1: use sched_yield to sync threads
  2012-08-13  2:50     ` Kang Kai
@ 2012-08-23  1:57       ` Wanlong Gao
  0 siblings, 0 replies; 18+ messages in thread
From: Wanlong Gao @ 2012-08-23  1:57 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list, Kang Kai

On 08/13/2012 10:50 AM, Kang Kai wrote:
> On 2012年08月10日 18:22, Jan Stancek wrote:
>> > Hi,
> Hi Jan,
> 
> Thanks for your reply.
>> > Here's a different proposal: don't count how many pthread_cond_signals it took,
>> > if any fails SIGALRM will trigger testcase failure.
> That is a more simple solution, and I agree with you.

So, Jan, can you send out a patch?

Thanks,
Wanlong Gao

> 
> 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] 18+ messages in thread

* Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info
  2012-08-09 10:30 ` [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info Kang Kai
  2012-08-10  9:31   ` Jan Stancek
@ 2012-09-03  8:45   ` Kang Kai
  2012-09-04  6:35     ` Jan Stancek
  2012-09-04  5:33   ` Wanlong Gao
  2 siblings, 1 reply; 18+ messages in thread
From: Kang Kai @ 2012-09-03  8:45 UTC (permalink / raw)
  To: Kang Kai; +Cc: ltp-list, Zhenfeng.Zhao

On 2012年08月09日 18:30, Kang Kai wrote:

Hi Wanlong,

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

Any comment for this patch?

Thanks,
Kai

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


------------------------------------------------------------------------------
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] 18+ messages in thread

* Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info
  2012-08-09 10:30 ` [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info Kang Kai
  2012-08-10  9:31   ` Jan Stancek
  2012-09-03  8:45   ` Kang Kai
@ 2012-09-04  5:33   ` Wanlong Gao
  2012-09-04  7:40     ` Kang Kai
  2012-09-04  8:27     ` Kang Kai
  2 siblings, 2 replies; 18+ messages in thread
From: Wanlong Gao @ 2012-09-04  5:33 UTC (permalink / raw)
  To: Kang Kai; +Cc: ltp-list, Zhenfeng.Zhao

On 08/09/2012 06:30 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.
> 

Looks Ok in general.
A bit comment below.

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

Why not use anonymous map? in that case you will not need to create a file.


Thanks,
Wanlong Gao


> +	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] 18+ messages in thread

* Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info
  2012-09-03  8:45   ` Kang Kai
@ 2012-09-04  6:35     ` Jan Stancek
  2012-09-04  9:44       ` Kang Kai
  0 siblings, 1 reply; 18+ messages in thread
From: Jan Stancek @ 2012-09-04  6:35 UTC (permalink / raw)
  To: Kang Kai; +Cc: ltp-list, Zhenfeng Zhao



----- Original Message -----
> From: "Kang Kai" <Kai.Kang@windriver.com>
> To: "Kang Kai" <kai.kang@windriver.com>
> Cc: ltp-list@lists.sourceforge.net, "Zhenfeng Zhao" <Zhenfeng.Zhao@windriver.com>
> Sent: Monday, 3 September, 2012 10:45:58 AM
> Subject: Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info
> 
> On 2012年08月09日 18:30, Kang Kai wrote:
> 
> Hi Wanlong,
> 
> > 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.
> 
> Any comment for this patch?

I had one question, see here:
http://article.gmane.org/gmane.linux.ltp/16611

Regards,
Jan

> 
> Thanks,
> Kai
> 
> >
> > 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
> > +}
> 
> 
> ------------------------------------------------------------------------------
> 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
> 

------------------------------------------------------------------------------
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] 18+ messages in thread

* Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info
  2012-09-04  5:33   ` Wanlong Gao
@ 2012-09-04  7:40     ` Kang Kai
  2012-09-04  8:27     ` Kang Kai
  1 sibling, 0 replies; 18+ messages in thread
From: Kang Kai @ 2012-09-04  7:40 UTC (permalink / raw)
  To: gaowanlong; +Cc: ltp-list, Zhenfeng.Zhao

On 2012年09月04日 13:33, Wanlong Gao wrote:
> On 08/09/2012 06:30 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.
>>
> Looks Ok in general.
> A bit comment below.
>
>> 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);
> Why not use anonymous map? in that case you will not need to create a file.

Ok, I'll send v2 with anonymous map.

Thanks,
Kai

>
>
> Thanks,
> Wanlong Gao
>
>
>> +	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] 18+ messages in thread

* Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info
  2012-09-04  5:33   ` Wanlong Gao
  2012-09-04  7:40     ` Kang Kai
@ 2012-09-04  8:27     ` Kang Kai
  2012-09-04  8:41       ` Wanlong Gao
  1 sibling, 1 reply; 18+ messages in thread
From: Kang Kai @ 2012-09-04  8:27 UTC (permalink / raw)
  To: gaowanlong; +Cc: ltp-list, Zhenfeng.Zhao

On 2012年09月04日 13:33, Wanlong Gao wrote:
> On 08/09/2012 06:30 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.
>>
> Looks Ok in general.
> A bit comment below.
>
>> 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);

Hi Wanlong,

> Why not use anonymous map? in that case you will not need to create a file.

It seems MAP_ANONYMOS is not specified in POSIX specification.

Regards,
Kai

>
>
> Thanks,
> Wanlong Gao
>
>
>> +	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] 18+ messages in thread

* Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info
  2012-09-04  8:27     ` Kang Kai
@ 2012-09-04  8:41       ` Wanlong Gao
  2012-09-04  8:45         ` Kang Kai
  0 siblings, 1 reply; 18+ messages in thread
From: Wanlong Gao @ 2012-09-04  8:41 UTC (permalink / raw)
  To: Kang Kai; +Cc: ltp-list, Zhenfeng.Zhao

On 09/04/2012 04:27 PM, Kang Kai wrote:
> 
> Hi Wanlong,
> 
>> Why not use anonymous map? in that case you will not need to create a file.
> 
> It seems MAP_ANONYMOS is not specified in POSIX specification.

OK, but in this case, you should think about Jan's question about SIGBUS now.

Thanks,
Wanlong Gao

> 
> 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] 18+ messages in thread

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

On 2012年09月04日 16:41, Wanlong Gao wrote:
> On 09/04/2012 04:27 PM, Kang Kai wrote:
>> Hi Wanlong,
>>
>>> Why not use anonymous map? in that case you will not need to create a file.
>> It seems MAP_ANONYMOS is not specified in POSIX specification.
> OK, but in this case, you should think about Jan's question about SIGBUS now.
I am checking the SIGBUS issue.

Thanks,
Kai

>
> Thanks,
> Wanlong Gao
>
>> 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] 18+ messages in thread

* Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info
  2012-09-04  6:35     ` Jan Stancek
@ 2012-09-04  9:44       ` Kang Kai
  0 siblings, 0 replies; 18+ messages in thread
From: Kang Kai @ 2012-09-04  9:44 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list, Zhenfeng Zhao

On 2012年09月04日 14:35, Jan Stancek wrote:
>
> ----- Original Message -----
>> From: "Kang Kai"<Kai.Kang@windriver.com>
>> To: "Kang Kai"<kai.kang@windriver.com>
>> Cc: ltp-list@lists.sourceforge.net, "Zhenfeng Zhao"<Zhenfeng.Zhao@windriver.com>
>> Sent: Monday, 3 September, 2012 10:45:58 AM
>> Subject: Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info
>>
>> On 2012年08月09日 18:30, Kang Kai wrote:
>>
>> Hi Wanlong,
>>
>>> 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.
>> Any comment for this patch?
> I had one question, see here:
> http://article.gmane.org/gmane.linux.ltp/16611
>
> Regards,
> Jan
>
>> Thanks,
>> Kai
>>
>>> 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);
>>> +	}
Hi Jan,

Copy your comment here
>>> +	/* file is empty now, will cause "Bus error" */
>>> +	write(fd, "\0", 1);

| Isn't there a risk of SIGBUS, when the file length is just 1 byte
| and it's mapped to sizeof(int)?
|
|   SIGBUS Attempted access to a portion of the buffer that does not correspond to the file (for  example,  beyond
|          the end of the file, including the case where another process has truncated the file).

I think why it doen't fail:
mmap implemented on linux willl map one page size if length pass to mmap less than one page size. So we can use the memory in this one page size.
But empty file is special case cause SIGBUS.


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

I add test code here:
>>> +	*(int *)pa = 0;
>>> +
int *pi = (int *)pa;
++pi;
*pi = 4;

It still doesn't fail.

So that may implement dependent. I will update the patch to write a int 
to the file.

Regards,
Kai

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


------------------------------------------------------------------------------
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] 18+ messages in thread

end of thread, other threads:[~2012-09-04  9:44 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-09 10:30 [LTP] Patches for posix test cases Kang Kai
2012-08-09 10:30 ` [LTP] [PATCH 1/3] pthread_cond_signal/1-1: use sched_yield to sync threads Kang Kai
2012-08-10 10:22   ` Jan Stancek
2012-08-13  2:50     ` Kang Kai
2012-08-23  1:57       ` Wanlong Gao
2012-08-09 10:30 ` [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info Kang Kai
2012-08-10  9:31   ` Jan Stancek
2012-09-03  8:45   ` Kang Kai
2012-09-04  6:35     ` Jan Stancek
2012-09-04  9:44       ` Kang Kai
2012-09-04  5:33   ` Wanlong Gao
2012-09-04  7:40     ` Kang Kai
2012-09-04  8:27     ` Kang Kai
2012-09-04  8:41       ` Wanlong Gao
2012-09-04  8:45         ` Kang Kai
2012-08-09 10:30 ` [LTP] [PATCH 3/3] timer_settime/5-3: fix test hung Kang Kai
2012-08-10  9:16   ` Jan Stancek
2012-08-21  4:01     ` Wanlong Gao

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.