Skip to contentSkip to conversation

Patches for posix test cases

LTP In review Kang Kai 3 participants 18 messages Aug 9, 2012 – Sep 4, 2012

lore
Share & tools
lore

Kang Kai

author
#0 lore raw

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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

author
#1 lore raw

PATCH 1/3 pthread_cond_signal/1-1: use sched_yield to sync threads

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.

---
 .../interfaces/pthread_cond_signal/1-1.c           |   44 +++++++++++++++++++-
 1 files changed, 42 insertions(+), 2 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c +42 -2
index bf55b31..77374bf 100644
@@ -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
+}
Signature · 13 lines
1.7.5.4


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
author
#5 lore raw

PATCH 2/3 mq_open/16-1: use tmp file to share info

In reply to Kang Kai

In this test case, it uses a variable to share data between child and parent processes. But after fork there is a copy of the variable in child process and modify it will not affect the variable in the parent process. Then when the child process call mq_open() before parent process, the case will fail.

Use tmp file to replace the variable. Any modification in child process can be seen in parent process.

---
 .../conformance/interfaces/mq_open/16-1.c          |   38 +++++++++++++++++--
 1 files changed, 34 insertions(+), 4 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +34 -4
index b9a3215..ebd697b 100644
@@ -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
+}
Signature · 13 lines
1.7.5.4


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
author
#15 lore raw

PATCH 3/3 timer_settime/5-3: fix test hung

In reply to Kang Kai

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.

---
 .../conformance/interfaces/timer_settime/5-3.c     |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/timer_settime/5-3.c +2 -2
index 0ad1957..4a47458 100644
@@ -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
+}
Signature · 13 lines
1.7.5.4


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Reviewed-by on v1 3/3
#16 lore raw

Re: [LTP] [PATCH 3/3] timer_settime/5-3: fix test hung

----- Original Message -----

Quoted 18 lines

From: "Kang Kai" <[email protected]>
To: [email protected]
Cc: "Zhenfeng Zhao" <[email protected]>
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.

Quoted 3 lines

Decrease LONGSLEEPTIME value to avoid this issue.

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

Quoted 32 lines
---
 .../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

testcases/open_posix_testsuite/conformance/interfaces/timer_settime/5-3.c +2 -3
@@ -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

Quoted 13 lines

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#6 lore raw

Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info

In reply to Kang Kai

----- Original Message -----

Quoted 65 lines

From: "Kang Kai" <[email protected]>
To: [email protected]
Cc: "Zhenfeng Zhao" <[email protected]>
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.

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

testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +2 -0
@@ -20,9 +20,11 @@
  * this is fine (will have some false positives, but no false
  negatives).
  */
 
+#include <sys/mman.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <mqueue.h>

#include <signal.h>

testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +4 -0
@@ -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());
 

testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 65

Quoted 10 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +10 -0
+	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

Quoted 66 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +10 -0
+	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;
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +8 -5
 		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

Quoted 13 lines

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#2 lore raw

Re: [LTP] [PATCH 1/3] pthread_cond_signal/1-1: use sched_yield to sync threads

In reply to Kang Kai

Hi,

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

testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c +1 -9
index bf55b31..266d42f 100644
@@ -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

Quoted 101 lines · Kang Kai

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.

---
 .../interfaces/pthread_cond_signal/1-1.c           |   44 +++++++++++++++++++-
 1 files changed, 42 insertions(+), 2 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c +37 -1
index bf55b31..77374bf 100644
@@ -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);
 		}

testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c int main() · line 203

Quoted 10 lines
testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c +5 -1
 	}
+
+	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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

author
#3 lore raw

Re: [LTP] [PATCH 1/3] pthread_cond_signal/1-1: use sched_yield to sync threads

Quoted 1 line · Jan Stancek

Hi,

Hi Jan,

Thanks for your reply.

Quoted 2 lines

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

Quoted 148 lines
testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c +1 -9
index bf55b31..266d42f 100644
@@ -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

Quoted 101 lines · Kang Kai

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.

---
  .../interfaces/pthread_cond_signal/1-1.c           |   44 +++++++++++++++++++-
  1 files changed, 42 insertions(+), 2 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c +37 -1
index bf55b31..77374bf 100644
@@ -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);
  		}

testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c int main() · line 203

Quoted 10 lines
testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_signal/1-1.c +5 -1
  	}
+
+	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

Quoted 9 lines

Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#17 lore raw

Re: [LTP] [PATCH 3/3] timer_settime/5-3: fix test hung

In reply to Jan Stancek
Quoted 20 lines · Jan Stancek

----- Original Message -----

Quoted 18 lines
Quoted 18 lines

From: "Kang Kai" <[email protected]>
To: [email protected]
Cc: "Zhenfeng Zhao" <[email protected]>
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.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

Decrease LONGSLEEPTIME value to avoid this issue.

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

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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#4 lore raw

Re: [LTP] [PATCH 1/3] pthread_cond_signal/1-1: use sched_yield to sync threads

In reply to Kang Kai
Quoted 8 lines · Kang Kai
Quoted 1 line · Jan Stancek
Quoted 1 line

Hi,

Hi Jan,

Thanks for your reply.

Quoted 2 lines
Quoted 2 lines

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

Quoted 4 lines

Regards,
Kai

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

author
#7 lore raw

Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info

In reply to Kang Kai

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

Hi Wanlong,

Quoted 8 lines

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

Quoted 103 lines
---
  .../conformance/interfaces/mq_open/16-1.c          |   38 +++++++++++++++++--
  1 files changed, 34 insertions(+), 4 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +31 -3
index b9a3215..ebd697b 100644
@@ -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()
  		}
 

testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 148

Quoted 10 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +3 -1
          	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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#10 lore raw

Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info

In reply to Kang Kai
Quoted 9 lines · Kang Kai

In this test case, it uses a variable to share data between child and parent processes. But after fork there is a copy of the variable in child process and modify it will not affect the variable in the parent process. Then when the child process call mq_open() before parent process, the case will fail.

Use tmp file to replace the variable. Any modification in child process can be seen in parent process.

Looks Ok in general.
A bit comment below.

Quoted 44 lines
---
 .../conformance/interfaces/mq_open/16-1.c          |   38 +++++++++++++++++--
 1 files changed, 34 insertions(+), 4 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +9 -0
index b9a3215..ebd697b 100644
@@ -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,

testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 68

Quoted 10 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +10 -0
+		 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

Quoted 49 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +12 -3
+	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()
 		}
 

testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 148

Quoted 10 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +3 -1
         	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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#8 lore raw

Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info

In reply to Kang Kai

----- Original Message -----

Quoted 19 lines

From: "Kang Kai" <[email protected]>
To: "Kang Kai" <[email protected]>
Cc: [email protected], "Zhenfeng Zhao" <[email protected]>
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,

Quoted 9 lines

In this test case, it uses a variable to share data between child and
parent processes. But after fork there is a copy of the variable in child process and modify it will not affect the variable in the parent
process. Then when the child process call mq_open() before parent process,
the case will fail.

Quoted 5 lines
Quoted 3 lines

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

Quoted 130 lines

Thanks,
Kai

Quoted 110 lines
---
  .../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

(quoted diff) +2 -0
@@ -20,9 +20,11 @@
   * this is fine (will have some false positives, but no false
   negatives).
   */
 
+#include<sys/mman.h>
  #include<sys/stat.h>
  #include<sys/types.h>
  #include<sys/wait.h>
+#include<errno.h>
  #include<fcntl.h>
  #include<mqueue.h>
  #include<signal.h>
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +24 -0
@@ -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;

testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +5 -3
@@ -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()
  		}
 

testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 148

Quoted 10 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +3 -1
          	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.

Quoted 9 lines

Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

author
#11 lore raw

Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info

In reply to Wanlong Gao
Quoted 54 lines · Wanlong Gao
Quoted 9 lines · Kang Kai

In this test case, it uses a variable to share data between child and parent processes. But after fork there is a copy of the variable in child process and modify it will not affect the variable in the parent process. Then when the child process call mq_open() before parent process, the case will fail.

Use tmp file to replace the variable. Any modification in child process can be seen in parent process.

Looks Ok in general.
A bit comment below.

Quoted 41 lines
---
  .../conformance/interfaces/mq_open/16-1.c          |   38 +++++++++++++++++--
  1 files changed, 34 insertions(+), 4 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +6 -0
index b9a3215..ebd697b 100644
@@ -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());
 
Quoted 14 lines

testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 68

Quoted 13 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +13 -0
+	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

Quoted 60 lines

Thanks,
Wanlong Gao

Quoted 54 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +14 -3
+	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;
  	}
 
Quoted 6 lines

testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 148

Quoted 5 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +1 -1
  	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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

author
#12 lore raw

Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info

In reply to Wanlong Gao
Quoted 54 lines · Wanlong Gao
Quoted 9 lines · Kang Kai

In this test case, it uses a variable to share data between child and parent processes. But after fork there is a copy of the variable in child process and modify it will not affect the variable in the parent process. Then when the child process call mq_open() before parent process, the case will fail.

Use tmp file to replace the variable. Any modification in child process can be seen in parent process.

Looks Ok in general.
A bit comment below.

Quoted 41 lines
---
  .../conformance/interfaces/mq_open/16-1.c          |   38 +++++++++++++++++--
  1 files changed, 34 insertions(+), 4 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +6 -0
index b9a3215..ebd697b 100644
@@ -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());
 
Quoted 13 lines

testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 68

Quoted 13 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +13 -0
+	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,

Quoted 1 line

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

Quoted 60 lines

Thanks,
Wanlong Gao

Quoted 54 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +14 -3
+	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;
  	}
 
Quoted 6 lines

testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 148

Quoted 5 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +1 -1
  	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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#13 lore raw

Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info

Quoted 6 lines · Kang Kai

Hi Wanlong,

Quoted 1 line

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

Quoted 3 lines

Regards,
Kai

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

author
#14 lore raw

Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info

Quoted 6 lines · Wanlong Gao
Quoted 4 lines · Kang Kai

Hi Wanlong,

Quoted 1 line

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

Quoted 7 lines

Thanks,
Wanlong Gao

Quoted 2 lines

Regards,
Kai

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

author
#9 lore raw

Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info

In reply to Jan Stancek
Quoted 81 lines · Jan Stancek

----- Original Message -----

Quoted 19 lines

From: "Kang Kai"<[email protected]>
To: "Kang Kai"<[email protected]>
Cc: [email protected], "Zhenfeng Zhao"<[email protected]>
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,

Quoted 9 lines

In this test case, it uses a variable to share data between child and
parent processes. But after fork there is a copy of the variable in child process and modify it will not affect the variable in the parent
process. Then when the child process call mq_open() before parent process,
the case will fail.

Quoted 4 lines
Quoted 3 lines

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

Quoted 50 lines

Thanks,
Kai

Quoted 47 lines
---
   .../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

(quoted diff) +2 -0
@@ -20,9 +20,11 @@
    * this is fine (will have some false positives, but no false
    negatives).
    */
 
+#include<sys/mman.h>
   #include<sys/stat.h>
   #include<sys/types.h>
   #include<sys/wait.h>
+#include<errno.h>
   #include<fcntl.h>
   #include<mqueue.h>
   #include<signal.h>
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +4 -0
@@ -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());
 
Quoted 8 lines
Quoted 8 lines

testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 63

Quoted 8 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +8 -0
+	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

Quoted 2 lines
Quoted 2 lines

testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 65

Quoted 2 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +2 -0
+	/* 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.

Quoted 9 lines
Quoted 9 lines

testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 73

Quoted 9 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +8 -0
+	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:

Quoted 2 lines
Quoted 2 lines

testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 75

Quoted 2 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +2 -0
+	*(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

Quoted 57 lines
Quoted 57 lines
Quoted 41 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +0 -0
   	if ((pid = fork()) == 0) {
   		sigset_t mask;
   		int sig;
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +5 -3
@@ -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()
   		}
 

testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c int main() · line 148

Quoted 10 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +3 -1
           	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

Quoted 8 lines
Quoted 8 lines

will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list