From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1SyZkk-0000k3-13 for ltp-list@lists.sourceforge.net; Tue, 07 Aug 2012 02:42:38 +0000 Received: from [222.73.24.84] (helo=song.cn.fujitsu.com) by sog-mx-1.v43.ch3.sourceforge.com with esmtp (Exim 4.76) id 1SyZki-00042I-6A for ltp-list@lists.sourceforge.net; Tue, 07 Aug 2012 02:42:38 +0000 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id q772atAi009743 for ; Tue, 7 Aug 2012 10:36:55 +0800 Message-ID: <50207F19.5080105@cn.fujitsu.com> Date: Tue, 07 Aug 2012 10:36:09 +0800 From: DAN LI MIME-Version: 1.0 References: <501A3EA1.4010902@cn.fujitsu.com> <501F8DA0.6030104@cn.fujitsu.com> In-Reply-To: <501F8DA0.6030104@cn.fujitsu.com> Subject: [LTP] [PATCH v2] pthread_cond_brodcast/1-2.c hung when mem left is not enough List-Id: Linux Test Project General Discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============5249810997177184507==" Errors-To: ltp-list-bounces@lists.sourceforge.net To: gaowanlong@cn.fujitsu.com Cc: LTP list This is a multi-part message in MIME format. --===============5249810997177184507== Content-Type: multipart/alternative; boundary="------------050908080804020602060203" This is a multi-part message in MIME format. --------------050908080804020602060203 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-8859-1; format=flowed pthread_cond_brodcast/1-2.c try to create as many childrens(thread or process) as possible,however,if current free memoryis exhausted before all childrens are started,the case will timeout and hung since it's stated with program "t0". The patch adjust count of childrens according to judgement of size of current free memory. Signed-off-by: DAN LI --- .../interfaces/pthread_cond_broadcast/1-2.c | 39 ++++++++++++++++++-- 1 files changed, 35 insertions(+), 4 deletions(-) diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_broadcast/1-2.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_broadcast/1-2.c index f6ad9df..a31dc2b 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_broadcast/1-2.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_broadcast/1-2.c @@ -48,6 +48,7 @@ #include #include #include +#include #include "../testfrmw/testfrmw.h" #include "../testfrmw/testfrmw.c" @@ -82,8 +83,8 @@ #endif /* Do not create more than this amount of children: */ -#define MAX_PROCESS_CHILDREN (200) -#define MAX_THREAD_CHILDREN (1000) +static int max_process_children = 200; +static int max_thread_children = 1000; #define TIMEOUT (180) @@ -242,6 +243,34 @@ void *timer(void *arg) FAILED_KILLALL("Operation timed out. A signal was lost."); return NULL; /* For compiler */ } +static int decide_process_children_count(void) +{ + struct sysinfo sysinforma; + int ret; + int avail_count; + unsigned long memper; + unsigned long min_stack; + + min_stack = sysconf(_SC_THREAD_STACK_MIN); + + ret = sysinfo(&sysinforma); + if (ret != 0) + UNRESOLVED(ret, "Failed to get system infomation."); + + memper = min_stack * max_thread_children; + if (memper > sysinforma.freeram) + UNTESTED("Free ram not enough for test."); + + avail_count = sysinforma.freeram / memper; + + if (avail_count < 10) + UNTESTED("Free ram not enough for test."); + + max_process_children = (avail_count < max_process_children ? + avail_count : max_process_children); + + return 0; +} int main(int argc, char *argv[]) { @@ -268,6 +297,8 @@ int main(int argc, char *argv[]) output_init(); + decide_process_children_count(); + /* check the system abilities */ pshared = sysconf(_SC_THREAD_PROCESS_SHARED); cs = sysconf(_SC_CLOCK_SELECTION); @@ -476,7 +507,7 @@ int main(int argc, char *argv[]) } else { ret = errno; } - } while ((ret == 0) && (child_count < MAX_THREAD_CHILDREN)); + } while ((ret == 0) && (child_count < max_thread_children)); #if VERBOSE > 2 output("[parent] Created %i children threads\n", child_count); #endif @@ -504,7 +535,7 @@ int main(int argc, char *argv[]) } else { ret = errno; } - } while ((ret == 0) && (child_count < MAX_PROCESS_CHILDREN)); + } while ((ret == 0) && (child_count < max_process_children)); #if VERBOSE > 2 output("[parent] Created %i children processes\n", child_count); #endif -- 1.7.7.6 --------------050908080804020602060203 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=ISO-8859-1
pthread_cond_brodcast/1-2.c try to create as many childrens(thread or process) 
as possible,however,if current free memory is exhausted before all childrens are
started,the case will timeout and hung since it's stated with program "t0".
 
The patch adjust count of childrens according to judgement of size of current free
memory.

Signed-off-by: DAN LI <li.dan@cn.fujitsu.com>
---
 .../interfaces/pthread_cond_broadcast/1-2.c        |   39 ++++++++++++++++++--
 1 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_broadcast/1-2.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_broadcast/1-2.c
index f6ad9df..a31dc2b 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_broadcast/1-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_broadcast/1-2.c
@@ -48,6 +48,7 @@
 #include <sys/mman.h>
 #include <sys/wait.h>
 #include <semaphore.h>
+#include <sys/sysinfo.h>
 
 #include "../testfrmw/testfrmw.h"
 #include "../testfrmw/testfrmw.c"
@@ -82,8 +83,8 @@
 #endif
 
 /* Do not create more than this amount of children: */
-#define MAX_PROCESS_CHILDREN  (200)
-#define MAX_THREAD_CHILDREN   (1000)
+static int max_process_children  = 200;
+static int max_thread_children = 1000;
 
 #define TIMEOUT  (180)
 
@@ -242,6 +243,34 @@ void *timer(void *arg)
 	FAILED_KILLALL("Operation timed out. A signal was lost.");
 	return NULL; /* For compiler */
 }
+static int decide_process_children_count(void)
+{
+	struct sysinfo sysinforma;
+	int ret;
+	int avail_count;
+	unsigned long memper;
+	unsigned long min_stack;
+
+	min_stack = sysconf(_SC_THREAD_STACK_MIN);
+
+	ret = sysinfo(&sysinforma);
+	if (ret != 0)
+		UNRESOLVED(ret, "Failed to get system infomation.");
+
+	memper = min_stack * max_thread_children;
+	if (memper > sysinforma.freeram)
+		UNTESTED("Free ram not enough for test.");
+
+	avail_count = sysinforma.freeram / memper;
+
+	if (avail_count < 10)
+		UNTESTED("Free ram not enough for test.");
+
+	max_process_children = (avail_count < max_process_children ?
+					avail_count : max_process_children);
+
+	return 0;
+}
 
 int main(int argc, char *argv[])
 {
@@ -268,6 +297,8 @@ int main(int argc, char *argv[])
 
 	output_init();
 
+	decide_process_children_count();
+
 	/* check the system abilities */
 	pshared = sysconf(_SC_THREAD_PROCESS_SHARED);
 	cs = sysconf(_SC_CLOCK_SELECTION);
@@ -476,7 +507,7 @@ int main(int argc, char *argv[])
 				} else {
 					ret = errno;
 				}
-			} while ((ret == 0) && (child_count < MAX_THREAD_CHILDREN));
+			} while ((ret == 0) && (child_count < max_thread_children));
 			#if VERBOSE > 2
 			output("[parent] Created %i children threads\n", child_count);
 			#endif
@@ -504,7 +535,7 @@ int main(int argc, char *argv[])
 				} else {
 					ret = errno;
 				}
-			} while ((ret == 0) && (child_count < MAX_PROCESS_CHILDREN));
+			} while ((ret == 0) && (child_count < max_process_children));
 			#if VERBOSE > 2
 			output("[parent] Created %i children processes\n", child_count);
 			#endif
-- 
1.7.7.6
--------------050908080804020602060203-- --===============5249810997177184507== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ 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/ --===============5249810997177184507== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list --===============5249810997177184507==--