All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] Fix for msgctl test case msgctl11 on the target with more than 4G memory
@ 2012-02-01  7:28 Jin Li
  2012-02-01  7:28 ` [LTP] [PATCH] " Jin Li
  0 siblings, 1 reply; 6+ messages in thread
From: Jin Li @ 2012-02-01  7:28 UTC (permalink / raw)
  To: ltp-list; +Cc: haotian.zhang, jin.li


Hi all 

Please ignore the last email which miss the  signiture 

Thanks

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH] Fix for msgctl test case msgctl11 on the target with more than 4G memory
  2012-02-01  7:28 [LTP] Fix for msgctl test case msgctl11 on the target with more than 4G memory Jin Li
@ 2012-02-01  7:28 ` Jin Li
  2012-02-01 16:09   ` Cyril Hrubis
  0 siblings, 1 reply; 6+ messages in thread
From: Jin Li @ 2012-02-01  7:28 UTC (permalink / raw)
  To: ltp-list; +Cc: haotian.zhang, jin.li

The test msgctl11 will fail with log as follows once it is on the
target with more than 4G memory and use default maximum pid value 32768.
Because in this case, the maxnkids is always 0 which will cause fail
and exit.

maxnkids = ((free_pids / 4) / MSGMNI);

The fix will update the maximum pid value to meet the basic need of
free pids on the target with more than 4G memory.

Test msgctl11 fail log

"msgctl11    1  TBROK  :  Not enough free pids"

Signed-off-by: Jin Li <jin.li@windriver.com>
---
 lib/system_specific_process_info.c              |   27 ++++++++++++++++++++++
 testcases/kernel/syscalls/ipc/msgctl/msgctl11.c |   28 +++++++++++++++++++++-
 2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/lib/system_specific_process_info.c b/lib/system_specific_process_info.c
index d3c9638..aaa7f8b 100644
--- a/lib/system_specific_process_info.c
+++ b/lib/system_specific_process_info.c
@@ -59,6 +59,33 @@ int get_max_pids(void)
 }
 
 
+int set_max_pids(int pids_max)
+{
+#ifdef __linux__
+
+        FILE *f;
+        char buf[BUFSIZE]={0};
+
+	snprintf(buf, sizeof(buf), "%d\n", pids_max);
+
+        f = fopen("/proc/sys/kernel/pid_max", "w+");
+        if (!f) {
+                tst_resm(TBROK, "Could not open /proc/sys/kernel/pid_max");
+                return -1;
+        }
+        if (!(fwrite(buf, BUFSIZE,1,f))) {
+                fclose(f);
+                tst_resm(TBROK, "Could not write /proc/sys/kernel/pid_max");
+                return -1;
+        }
+        fclose(f);
+        return atoi(buf);
+#else
+        return SHRT_MAX;
+#endif
+}
+
+
 int get_free_pids(void)
 {
 	FILE *f;
diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c
index 57bd184..eb6cb71 100644
--- a/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c
+++ b/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c
@@ -79,6 +79,9 @@ int TST_TOTAL = 1;		/* Total number of test cases. */
 
 int exp_enos[] = { 0 };		/* List must end with 0 */
 int maxnkids = MAXNKIDS;	/* Used if pid_max is exceeded */
+int max_pids;
+int adjust_max_pids = 0 ;
+
 
 key_t keyarray[MAXNPROCS];
 
@@ -641,14 +644,29 @@ void setup()
 		tst_exit();
 	}
 
+	max_pids = get_max_pids();
 	if ((MSGMNI * MAXNKIDS * 2) > (free_pids / 2)) {
+            if ( nr_msgqs < 8192 ) {
 		maxnkids = ((free_pids / 4) / MSGMNI);
 		if (!maxnkids) {
 			tst_resm(TBROK, "Not enough free pids");
 			tst_exit();
 		}
-	}
+	    } else  {
+		maxnkids = 1;
+
+		/* After the update of maximum pid number, the free pids
+                 * will be MSGMNI * 2 * 2.
+                 */
+                adjust_max_pids = MSGMNI * 2 * 2 + max_pids - free_pids ;
+		if ( (set_max_pids (adjust_max_pids)) < 0 ) {
+                    tst_resm(TBROK, "cannot adjust max pids");
+		    tst_exit();
+		}
+                free_pids = get_free_pids();
+            }
 
+        }
 	tst_resm(TINFO, "Using upto %d pids", free_pids / 2);
 }
 
@@ -682,4 +700,10 @@ void cleanup()
 	fflush(stdout);
 	tst_rmdir();
 
-}
\ No newline at end of file
+	if ( adjust_max_pids > max_pids ) {
+	    if ( ! set_max_pids(max_pids) ) {
+                tst_resm(TBROK, "cannot restore the max pids");
+                tst_exit();
+	    }
+        }
+}
-- 
1.6.3.1


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH] Fix for msgctl test case msgctl11 on the target with more than 4G memory
  2012-02-01  7:28 ` [LTP] [PATCH] " Jin Li
@ 2012-02-01 16:09   ` Cyril Hrubis
  0 siblings, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2012-02-01 16:09 UTC (permalink / raw)
  To: Jin Li; +Cc: ltp-list, haotian.zhang

Hi!
> The test msgctl11 will fail with log as follows once it is on the
> target with more than 4G memory and use default maximum pid value 32768.
> Because in this case, the maxnkids is always 0 which will cause fail
> and exit.
> 
> maxnkids = ((free_pids / 4) / MSGMNI);
> 
> The fix will update the maximum pid value to meet the basic need of
> free pids on the target with more than 4G memory.
> 
> Test msgctl11 fail log
> 
> "msgctl11    1  TBROK  :  Not enough free pids"
> 
> Signed-off-by: Jin Li <jin.li@windriver.com>

First of all, pretty please learn to use checkpatch.pl, it doesn't catch
all the problems, but it's a good start.

> ---
>  lib/system_specific_process_info.c              |   27 ++++++++++++++++++++++
>  testcases/kernel/syscalls/ipc/msgctl/msgctl11.c |   28 +++++++++++++++++++++-
>  2 files changed, 53 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/system_specific_process_info.c b/lib/system_specific_process_info.c
> index d3c9638..aaa7f8b 100644
> --- a/lib/system_specific_process_info.c
> +++ b/lib/system_specific_process_info.c
> @@ -59,6 +59,33 @@ int get_max_pids(void)
>  }
>  
>  
> +int set_max_pids(int pids_max)
> +{
> +#ifdef __linux__
> +
> +        FILE *f;
> +        char buf[BUFSIZE]={0};
> +
> +	snprintf(buf, sizeof(buf), "%d\n", pids_max);
> +
> +        f = fopen("/proc/sys/kernel/pid_max", "w+");
> +        if (!f) {
> +                tst_resm(TBROK, "Could not open /proc/sys/kernel/pid_max");
> +                return -1;
> +        }
> +        if (!(fwrite(buf, BUFSIZE,1,f))) {
> +                fclose(f);
> +                tst_resm(TBROK, "Could not write /proc/sys/kernel/pid_max");
> +                return -1;
> +        }
> +        fclose(f);
> +        return atoi(buf);
> +#else
> +        return SHRT_MAX;
> +#endif
> +}

Heh, that is overly compicated, once you open the proc file with fopen,
you can use fprintf() directly without any additional buffers nd you
should check from return value from fclose() here.

And what exactly is return value from this function? Returns -1 on
failure, that's okay, but isn't the atoi(buf) same as pids_max?

Also I'm missing the function prototype from headers in include.

>  int get_free_pids(void)
>  {
>  	FILE *f;
> diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c
> index 57bd184..eb6cb71 100644
> --- a/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c
> +++ b/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c
> @@ -79,6 +79,9 @@ int TST_TOTAL = 1;		/* Total number of test cases. */
>  
>  int exp_enos[] = { 0 };		/* List must end with 0 */
>  int maxnkids = MAXNKIDS;	/* Used if pid_max is exceeded */
> +int max_pids;
> +int adjust_max_pids = 0 ;
> +
>  
>  key_t keyarray[MAXNPROCS];
>  
> @@ -641,14 +644,29 @@ void setup()
>  		tst_exit();
>  	}
>  
> +	max_pids = get_max_pids();
>  	if ((MSGMNI * MAXNKIDS * 2) > (free_pids / 2)) {
> +            if ( nr_msgqs < 8192 ) {
>  		maxnkids = ((free_pids / 4) / MSGMNI);
>  		if (!maxnkids) {
>  			tst_resm(TBROK, "Not enough free pids");
>  			tst_exit();
>  		}
> -	}
> +	    } else  {
> +		maxnkids = 1;
> +
> +		/* After the update of maximum pid number, the free pids
> +                 * will be MSGMNI * 2 * 2.
> +                 */
> +                adjust_max_pids = MSGMNI * 2 * 2 + max_pids - free_pids ;
> +		if ( (set_max_pids (adjust_max_pids)) < 0 ) {
> +                    tst_resm(TBROK, "cannot adjust max pids");
> +		    tst_exit();
> +		}
> +                free_pids = get_free_pids();
> +            }

Hmm, I'm thinking if this could possible make some problems. Anyway what
exactly does this change do? It computes some limit on maximal pid
number but how does that fix the testing? More verbose patch description
would sure help.

> +        }
>  	tst_resm(TINFO, "Using upto %d pids", free_pids / 2);
>  }
>  
> @@ -682,4 +700,10 @@ void cleanup()
>  	fflush(stdout);
>  	tst_rmdir();
>  
> -}
> \ No newline at end of file
> +	if ( adjust_max_pids > max_pids ) {
> +	    if ( ! set_max_pids(max_pids) ) {
> +                tst_resm(TBROK, "cannot restore the max pids");
> +                tst_exit();

Use tst_brkm() instead of these two.

> +	    }
> +        }
> +}

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH] Fix for msgctl test case msgctl11 on the target with more than 4G memory
@ 2012-02-02  8:03 Jin Li
  0 siblings, 0 replies; 6+ messages in thread
From: Jin Li @ 2012-02-02  8:03 UTC (permalink / raw)
  To: ltp-list; +Cc: jin.li

The test msgctl11 will fail with log as follows once it is on the
target with more than 4G memory and use default maximum pid value 32768.
Because in this case, the maxnkids is always 0 which will cause fail
and exit.

maxnkids = ((free_pids / 4) / MSGMNI);

Test msgctl11 fail log

"msgctl11    1  TBROK  :  Not enough free pids"

This fix will update the maximum pid value to meet the need of
free pids on the target with more than 4G memory.

For example, on the target with 16G memory

nprocs = MSGMNI = 32768

and every message queue need read and write child process.

So need MSGMNI * 2 pids.

when nkids = maxnkids = 1,

the max pids will be updated to MSGMNI * 2 * 2 and give enought pids to

the test.

Signed-off-by: Jin Li <jin.li@windriver.com>
---
 include/system_specific_process_info.h          |    3 ++
 lib/system_specific_process_info.c              |   22 +++++++++++++++
 testcases/kernel/syscalls/ipc/msgctl/msgctl11.c |   32 ++++++++++++++++++----
 3 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/include/system_specific_process_info.h b/include/system_specific_process_info.h
index 956d90f..dddcac0 100644
--- a/include/system_specific_process_info.h
+++ b/include/system_specific_process_info.h
@@ -26,4 +26,7 @@ int get_max_pids(void);
 /* Returns number of free pids */
 int get_free_pids(void);
 
+/* Set max pid count to /proc/sys/kernel/pid_max */
+int set_max_pids(int);
+
 #endif
diff --git a/lib/system_specific_process_info.c b/lib/system_specific_process_info.c
index d3c9638..d631340 100644
--- a/lib/system_specific_process_info.c
+++ b/lib/system_specific_process_info.c
@@ -59,6 +59,28 @@ int get_max_pids(void)
 }
 
 
+int set_max_pids(int pids_max)
+{
+	FILE *f;
+
+	f = fopen("/proc/sys/kernel/pid_max", "w+");
+	if (!f) {
+		tst_resm(TBROK, "Could not open /proc/sys/kernel/pid_max");
+		return -1;
+	}
+	if (!fprintf(f, "%d", pids_max)) {
+		fclose(f);
+		tst_resm(TBROK, "Could not write to /proc/sys/kernel/pid_max");
+		return -1;
+	}
+	if (fclose(f)) {
+		tst_resm(TBROK, "Fail to close file /proc/sys/kernel/pid_max");
+		return -1;
+	}
+	return 0;
+}
+
+
 int get_free_pids(void)
 {
 	FILE *f;
diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c
index 57bd184..d587376 100644
--- a/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c
+++ b/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c
@@ -79,6 +79,9 @@ int TST_TOTAL = 1;		/* Total number of test cases. */
 
 int exp_enos[] = { 0 };		/* List must end with 0 */
 int maxnkids = MAXNKIDS;	/* Used if pid_max is exceeded */
+int max_pids;
+int adjust_max_pids;
+
 
 key_t keyarray[MAXNPROCS];
 
@@ -641,14 +644,27 @@ void setup()
 		tst_exit();
 	}
 
+	max_pids = get_max_pids();
+	adjust_max_pids = 0;
 	if ((MSGMNI * MAXNKIDS * 2) > (free_pids / 2)) {
-		maxnkids = ((free_pids / 4) / MSGMNI);
-		if (!maxnkids) {
-			tst_resm(TBROK, "Not enough free pids");
-			tst_exit();
+		if (nr_msgqs < 8192) {
+			maxnkids = ((free_pids / 4) / MSGMNI);
+			if (!maxnkids)
+				tst_brkm(TBROK, cleanup, "No enough free pids");
+		} else  {
+			maxnkids = 1;
+
+			/* After the update of maximum pid number, the free
+			 * pids will be MSGMNI * 2 * 2
+			 */
+			adjust_max_pids = MSGMNI * 2 * 2 + max_pids - free_pids;
+			if ((set_max_pids(adjust_max_pids)) < 0) {
+				tst_brkm(TBROK, cleanup, "cannot adjust"
+								" max pids");
+			}
+			free_pids = get_free_pids();
 		}
 	}
-
 	tst_resm(TINFO, "Using upto %d pids", free_pids / 2);
 }
 
@@ -682,4 +698,8 @@ void cleanup()
 	fflush(stdout);
 	tst_rmdir();
 
-}
\ No newline at end of file
+	if (adjust_max_pids > max_pids) {
+		if (set_max_pids(max_pids) < 0)
+			tst_brkm(TBROK, NULL, "cannot restore the max pids");
+	}
+}
-- 
1.6.3.1


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH] Fix for msgctl test case msgctl11 on the target with more than 4G memory
  2012-02-02  3:56 [LTP] " Jin Li
@ 2012-02-02  3:56 ` Jin Li
  0 siblings, 0 replies; 6+ messages in thread
From: Jin Li @ 2012-02-02  3:56 UTC (permalink / raw)
  To: ltp-list; +Cc: jin.li

The test msgctl11 will fail with log as follows once it is on the
target with more than 4G memory and use default maximum pid value 32768.
Because in this case, the maxnkids is always 0 which will cause fail
and exit.

maxnkids = ((free_pids / 4) / MSGMNI);

Test msgctl11 fail log

"msgctl11    1  TBROK  :  Not enough free pids"

This fix will update the maximum pid value to meet the need of
free pids on the target with more than 4G memory.

For example, on the target with 16G memory

nprocs = MSGMNI = 32768

and every message queue need read and write child process.

So need MSGMNI * 2 pids.

when nkids = maxnkids = 1,

the max pids will be updated to MSGMNI * 2 * 2 and give enought pids to

the test.

Signed-off-by: Jin Li <jin.li@windriver.com>
---
 include/system_specific_process_info.h          |    3 ++
 lib/system_specific_process_info.c              |   22 ++++++++++++++
 testcases/kernel/syscalls/ipc/msgctl/msgctl11.c |   36 +++++++++++++++++++----
 3 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/include/system_specific_process_info.h b/include/system_specific_process_info.h
index 956d90f..dddcac0 100644
--- a/include/system_specific_process_info.h
+++ b/include/system_specific_process_info.h
@@ -26,4 +26,7 @@ int get_max_pids(void);
 /* Returns number of free pids */
 int get_free_pids(void);
 
+/* Set max pid count to /proc/sys/kernel/pid_max */
+int set_max_pids(int);
+
 #endif
diff --git a/lib/system_specific_process_info.c b/lib/system_specific_process_info.c
index d3c9638..d631340 100644
--- a/lib/system_specific_process_info.c
+++ b/lib/system_specific_process_info.c
@@ -59,6 +59,28 @@ int get_max_pids(void)
 }
 
 
+int set_max_pids(int pids_max)
+{
+	FILE *f;
+
+	f = fopen("/proc/sys/kernel/pid_max", "w+");
+	if (!f) {
+		tst_resm(TBROK, "Could not open /proc/sys/kernel/pid_max");
+		return -1;
+	}
+	if (!fprintf(f, "%d", pids_max)) {
+		fclose(f);
+		tst_resm(TBROK, "Could not write to /proc/sys/kernel/pid_max");
+		return -1;
+	}
+	if (fclose(f)) {
+		tst_resm(TBROK, "Fail to close file /proc/sys/kernel/pid_max");
+		return -1;
+	}
+	return 0;
+}
+
+
 int get_free_pids(void)
 {
 	FILE *f;
diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c
index 57bd184..cfa0096 100644
--- a/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c
+++ b/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c
@@ -79,6 +79,9 @@ int TST_TOTAL = 1;		/* Total number of test cases. */
 
 int exp_enos[] = { 0 };		/* List must end with 0 */
 int maxnkids = MAXNKIDS;	/* Used if pid_max is exceeded */
+int max_pids;
+int adjust_max_pids;
+
 
 key_t keyarray[MAXNPROCS];
 
@@ -641,14 +644,29 @@ void setup()
 		tst_exit();
 	}
 
+	max_pids = get_max_pids();
+	adjust_max_pids = 0;
 	if ((MSGMNI * MAXNKIDS * 2) > (free_pids / 2)) {
-		maxnkids = ((free_pids / 4) / MSGMNI);
-		if (!maxnkids) {
-			tst_resm(TBROK, "Not enough free pids");
-			tst_exit();
+		if (nr_msgqs < 8192) {
+			maxnkids = ((free_pids / 4) / MSGMNI);
+			if (!maxnkids) {
+				tst_resm(TBROK, "Not enough free pids");
+				tst_exit();
+			}
+		} else  {
+			maxnkids = 1;
+
+			/* After the update of maximum pid number, the free
+			 * pids will be MSGMNI * 2 * 2
+			 */
+			adjust_max_pids = MSGMNI * 2 * 2 + max_pids - free_pids;
+			if ((set_max_pids(adjust_max_pids)) < 0) {
+				tst_resm(TBROK, "cannot adjust max pids");
+				tst_exit();
+			}
+			free_pids = get_free_pids();
 		}
 	}
-
 	tst_resm(TINFO, "Using upto %d pids", free_pids / 2);
 }
 
@@ -682,4 +700,10 @@ void cleanup()
 	fflush(stdout);
 	tst_rmdir();
 
-}
\ No newline at end of file
+	if (adjust_max_pids > max_pids) {
+		if (set_max_pids(max_pids) < 0) {
+			tst_resm(TBROK, "cannot restore the max pids");
+			tst_exit();
+		}
+	}
+}
-- 
1.6.3.1


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH] Fix for msgctl test case msgctl11 on the target with more than 4G memory
@ 2012-02-01  7:24 Jin Li
  0 siblings, 0 replies; 6+ messages in thread
From: Jin Li @ 2012-02-01  7:24 UTC (permalink / raw)
  To: ltp-list; +Cc: haotian.zhang, jin.li

The test msgctl11 will fail with log as follows once it is on the
target with more than 4G memory and use default maximum pid value 32768.
Because in this case, the maxnkids is always 0 which will cause fail
and exit.

maxnkids = ((free_pids / 4) / MSGMNI);

The fix will update the maximum pid value to meet the basic need of
free pids on the target with more than 4G memory.

Test msgctl11 fail log

"msgctl11    1  TBROK  :  Not enough free pids"
---
 lib/system_specific_process_info.c              |   27 ++++++++++++++++++++++
 testcases/kernel/syscalls/ipc/msgctl/msgctl11.c |   28 +++++++++++++++++++++-
 2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/lib/system_specific_process_info.c b/lib/system_specific_process_info.c
index d3c9638..aaa7f8b 100644
--- a/lib/system_specific_process_info.c
+++ b/lib/system_specific_process_info.c
@@ -59,6 +59,33 @@ int get_max_pids(void)
 }
 
 
+int set_max_pids(int pids_max)
+{
+#ifdef __linux__
+
+        FILE *f;
+        char buf[BUFSIZE]={0};
+
+	snprintf(buf, sizeof(buf), "%d\n", pids_max);
+
+        f = fopen("/proc/sys/kernel/pid_max", "w+");
+        if (!f) {
+                tst_resm(TBROK, "Could not open /proc/sys/kernel/pid_max");
+                return -1;
+        }
+        if (!(fwrite(buf, BUFSIZE,1,f))) {
+                fclose(f);
+                tst_resm(TBROK, "Could not write /proc/sys/kernel/pid_max");
+                return -1;
+        }
+        fclose(f);
+        return atoi(buf);
+#else
+        return SHRT_MAX;
+#endif
+}
+
+
 int get_free_pids(void)
 {
 	FILE *f;
diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c
index 57bd184..eb6cb71 100644
--- a/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c
+++ b/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c
@@ -79,6 +79,9 @@ int TST_TOTAL = 1;		/* Total number of test cases. */
 
 int exp_enos[] = { 0 };		/* List must end with 0 */
 int maxnkids = MAXNKIDS;	/* Used if pid_max is exceeded */
+int max_pids;
+int adjust_max_pids = 0 ;
+
 
 key_t keyarray[MAXNPROCS];
 
@@ -641,14 +644,29 @@ void setup()
 		tst_exit();
 	}
 
+	max_pids = get_max_pids();
 	if ((MSGMNI * MAXNKIDS * 2) > (free_pids / 2)) {
+            if ( nr_msgqs < 8192 ) {
 		maxnkids = ((free_pids / 4) / MSGMNI);
 		if (!maxnkids) {
 			tst_resm(TBROK, "Not enough free pids");
 			tst_exit();
 		}
-	}
+	    } else  {
+		maxnkids = 1;
+
+		/* After the update of maximum pid number, the free pids
+                 * will be MSGMNI * 2 * 2.
+                 */
+                adjust_max_pids = MSGMNI * 2 * 2 + max_pids - free_pids ;
+		if ( (set_max_pids (adjust_max_pids)) < 0 ) {
+                    tst_resm(TBROK, "cannot adjust max pids");
+		    tst_exit();
+		}
+                free_pids = get_free_pids();
+            }
 
+        }
 	tst_resm(TINFO, "Using upto %d pids", free_pids / 2);
 }
 
@@ -682,4 +700,10 @@ void cleanup()
 	fflush(stdout);
 	tst_rmdir();
 
-}
\ No newline at end of file
+	if ( adjust_max_pids > max_pids ) {
+	    if ( ! set_max_pids(max_pids) ) {
+                tst_resm(TBROK, "cannot restore the max pids");
+                tst_exit();
+	    }
+        }
+}
-- 
1.6.3.1


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2012-02-02  8:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-01  7:28 [LTP] Fix for msgctl test case msgctl11 on the target with more than 4G memory Jin Li
2012-02-01  7:28 ` [LTP] [PATCH] " Jin Li
2012-02-01 16:09   ` Cyril Hrubis
  -- strict thread matches above, loose matches on Subject: below --
2012-02-02  8:03 Jin Li
2012-02-02  3:56 [LTP] " Jin Li
2012-02-02  3:56 ` [LTP] [PATCH] " Jin Li
2012-02-01  7:24 Jin Li

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.