public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 00/11] hugetlb multiple fixes
@ 2012-03-13  4:56 Caspar Zhang
  2012-03-13  4:56 ` [LTP] [PATCH 01/11] hugetlb/hugeshmat: cleanup codes Caspar Zhang
                   ` (10 more replies)
  0 siblings, 11 replies; 20+ messages in thread
From: Caspar Zhang @ 2012-03-13  4:56 UTC (permalink / raw)
  To: LTP List

[-- Attachment #1: Type: text/plain, Size: 2902 bytes --]


This patchset makes the following changes:

01 - 08: set and restore nr_hugepages values automatically in 
         hugeshm* tests.

09,11  : code cleanups, remove unused files and functions

10     : fix a hugeshmget03 bug.

patchset has been tested on my system, both with large free memory 
and tight memory environment.

Caspar Zhang (11):
  hugetlb/hugeshmat: cleanup codes
  hugetlb/hugeshmat: set nr_hugepages in tests
  hugetlb/hugeshmctl: cleanup codes
  hugetlb/hugeshmctl: set nr_hugepages in tests
  hugetlb/hugeshmdt: cleanup codes
  hugetlb/hugeshmdt: set nr_hugepages in tests
  hugetlb/hugeshmget: cleanup codes
  hugetlb/hugeshmget: set nr_hugepages in tests
  hugetlb/lib: cleanup codes
  hugetlb/hugeshmget03: fix broken testcase
  libltp: remove system_specific_hugepages_info

 include/system_specific_hugepages_info.h           |   30 --
 lib/system_specific_hugepages_info.c               |   93 ------
 testcases/kernel/mem/hugetlb/Makefile.inc          |   16 +-
 testcases/kernel/mem/hugetlb/hugemmap/Makefile     |    1 -
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c |   19 +-
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c |    5 +-
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c |    1 -
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c |   24 +-
 testcases/kernel/mem/hugetlb/hugeshmat/Makefile    |    2 +-
 .../kernel/mem/hugetlb/hugeshmat/hugeshmat01.c     |  173 ++++-------
 .../kernel/mem/hugetlb/hugeshmat/hugeshmat02.c     |  167 ++++-------
 .../kernel/mem/hugetlb/hugeshmat/hugeshmat03.c     |  171 ++++-------
 testcases/kernel/mem/hugetlb/hugeshmctl/Makefile   |    2 +-
 .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c   |  327 ++++++++------------
 .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c   |  150 ++++------
 .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c   |  192 +++++-------
 testcases/kernel/mem/hugetlb/hugeshmdt/Makefile    |    2 +-
 .../kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c     |  169 ++++------
 testcases/kernel/mem/hugetlb/hugeshmget/Makefile   |    2 +-
 .../kernel/mem/hugetlb/hugeshmget/hugeshmget01.c   |  124 +++-----
 .../kernel/mem/hugetlb/hugeshmget/hugeshmget02.c   |  164 ++++------
 .../kernel/mem/hugetlb/hugeshmget/hugeshmget03.c   |  160 ++++------
 .../kernel/mem/hugetlb/hugeshmget/hugeshmget05.c   |  165 ++++-------
 testcases/kernel/mem/hugetlb/lib/ipcmsg.h          |   58 ----
 testcases/kernel/mem/hugetlb/lib/ipcsem.h          |   60 ----
 testcases/kernel/mem/hugetlb/lib/ipcshm.h          |   33 ++-
 testcases/kernel/mem/hugetlb/lib/libipc.c          |  143 ++-------
 27 files changed, 823 insertions(+), 1630 deletions(-)
 delete mode 100644 include/system_specific_hugepages_info.h
 delete mode 100644 lib/system_specific_hugepages_info.c
 delete mode 100644 testcases/kernel/mem/hugetlb/lib/ipcmsg.h
 delete mode 100644 testcases/kernel/mem/hugetlb/lib/ipcsem.h

-- 
1.7.8.4



[-- Attachment #2: Type: text/plain, Size: 381 bytes --]

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

[-- Attachment #3: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH 01/11] hugetlb/hugeshmat: cleanup codes
  2012-03-13  4:56 [LTP] [PATCH 00/11] hugetlb multiple fixes Caspar Zhang
@ 2012-03-13  4:56 ` Caspar Zhang
  2012-03-13  6:17   ` Wanlong Gao
  2012-03-13  4:56 ` [LTP] [PATCH 02/11] hugetlb/hugeshmat: set nr_hugepages in tests Caspar Zhang
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Caspar Zhang @ 2012-03-13  4:56 UTC (permalink / raw)
  To: LTP List

[-- Attachment #1: Type: text/plain, Size: 412 bytes --]


Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
 testcases/kernel/mem/hugetlb/hugeshmat/Makefile    |    2 +-
 .../kernel/mem/hugetlb/hugeshmat/hugeshmat01.c     |  159 ++++++-------------
 .../kernel/mem/hugetlb/hugeshmat/hugeshmat02.c     |  151 ++++++-------------
 .../kernel/mem/hugetlb/hugeshmat/hugeshmat03.c     |  167 ++++++-------------
 4 files changed, 149 insertions(+), 330 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-hugetlb-hugeshmat-cleanup-codes.patch --]
[-- Type: text/x-patch; name="0001-hugetlb-hugeshmat-cleanup-codes.patch", Size: 18684 bytes --]

diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/Makefile b/testcases/kernel/mem/hugetlb/hugeshmat/Makefile
index a1ba46e..f51f6b9 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/Makefile
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/Makefile
@@ -20,7 +20,7 @@
 # Garrett Cooper, July 2009
 #
 
-top_srcdir              ?= ../../../../..
+top_srcdir		?= ../../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 include $(abs_srcdir)/../Makefile.inc
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c
index 67bd4b0..b92f6eb 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c
@@ -33,7 +33,7 @@
  *	otherwise,
  *	  if doing functionality testing
  *		check for the correct conditions after the call
- *	  	if correct,
+ *		if correct,
  *			issue a PASS message
  *		otherwise
  *			issue a FAIL message
@@ -61,12 +61,11 @@
 
 char *TCID = "hugeshmat01";
 int TST_TOTAL = 3;
-unsigned long huge_pages_shm_to_be_allocated;
 
 #define CASE0		10		/* values to write into the shared */
 #define CASE1		20		/* memory location.		   */
 
-#if __WORDSIZE==64
+#if __WORDSIZE == 64
 #if defined(__mips__)
 #define UNALIGNED      0x1000000eee
 #else
@@ -76,85 +75,62 @@ unsigned long huge_pages_shm_to_be_allocated;
 #define UNALIGNED      0x60000eee
 #endif
 
-int shm_id_1 = -1;
-
-void	*addr;				/* for result of shmat-call */
+static size_t shm_size;
+static int    shm_id_1 = -1;
+static void   *addr;
 
 struct test_case_t {
-	int *shmid;
+	int  *shmid;
 	void *addr;
-	int flags;
+	int  flags;
 } TC[] = {
 	/* a straight forward read/write attach */
-	{&shm_id_1, 0, 0},
+	{ &shm_id_1,	0,			0 },
 
-       /* an attach using non aligned memory */
-	{&shm_id_1, (void *)UNALIGNED, SHM_RND},
+	/* an attach using non aligned memory */
+	{ &shm_id_1,	(void *)UNALIGNED,	SHM_RND },
 
 	/* a read only attach */
-	{&shm_id_1, 0, SHM_RDONLY}
+	{ &shm_id_1,	0,			SHM_RDONLY }
 };
 
+static void check_functionality(int i);
+
 int main(int ac, char **av)
 {
-	int lc;				/* loop counter */
-	char *msg;			/* message returned from parse_opts */
-	int i;
-	void check_functionality(int);
+	int lc, i;
+	char *msg;
 
-	/* parse standard options */
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
-		tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
+	msg = parse_opts(ac, av, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
-        if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-             tst_brkm(TCONF, NULL, "Not enough available Hugepages");
-        else
-             huge_pages_shm_to_be_allocated = ( get_no_of_hugepages() * hugepages_size() * 1024) / 2 ;
+	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
+		tst_brkm(TCONF, NULL, "Not enough available Hugepages");
+	else
+		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
 
-	setup();			/* global setup */
-
-	/* The following loop checks looping state if -i option given */
+	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset Tst_count in case we are looping */
 		Tst_count = 0;
 
-		/* loop through the test cases */
-		for (i=0; i<TST_TOTAL; i++) {
-
-			/*
-			 * Use TEST macro to make the call
-			 */
-			errno = 0;
-			addr = shmat(*(TC[i].shmid), (void *)(TC[i].addr),
-				   TC[i].flags);
-			TEST_ERRNO = errno;
-
+		for (i = 0; i < TST_TOTAL; i++) {
+			addr = shmat(*(TC[i].shmid), TC[i].addr, TC[i].flags);
 			if (addr == (void *)-1) {
-				tst_brkm(TFAIL, cleanup, "%s call failed - "
-					 "errno = %d : %s", TCID, TEST_ERRNO,
-					 strerror(TEST_ERRNO));
+				tst_brkm(TFAIL|TERRNO, cleanup, "shmat");
 			} else {
-				if (STD_FUNCTIONAL_TEST) {
+				if (STD_FUNCTIONAL_TEST)
 					check_functionality(i);
-				} else {
-					tst_resm(TPASS, "call succeeded");
-				}
+				else
+					tst_resm(TPASS, "shmat call succeeded");
 			}
 
-			/*
-			 * clean up things in case we are looping - in
-			 * this case, detach the shared memory
-			 */
-			if (shmdt((const void *)addr) == -1) {
-				tst_brkm(TBROK, cleanup,
-					 "Couldn't detach shared memory");
-			}
+			if (shmdt(addr) == -1)
+				tst_brkm(TBROK|TERRNO, cleanup, "shmdt");
 		}
 	}
-
 	cleanup();
-
 	tst_exit();
 }
 
@@ -162,20 +138,17 @@ int main(int ac, char **av)
  * check_functionality - check various conditions to make sure they
  *			 are correct.
  */
-void
-check_functionality(int i)
+static void check_functionality(int i)
 {
 	void *orig_add;
 	int *shared;
-	int fail = 0;
 	struct shmid_ds buf;
 
 	shared = (int *)addr;
 
 	/* stat the shared memory ID */
-	if (shmctl(shm_id_1, IPC_STAT, &buf) == -1) {
-		tst_brkm(TBROK, cleanup, "couldn't stat shared memory");
-	}
+	if (shmctl(shm_id_1, IPC_STAT, &buf) == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "shmctl");
 
 	/* check the number of attaches */
 	if (buf.shm_nattch != 1) {
@@ -184,13 +157,13 @@ check_functionality(int i)
 	}
 
 	/* check the size of the segment */
-	if (buf.shm_segsz != huge_pages_shm_to_be_allocated) {
+	if (buf.shm_segsz != shm_size) {
 		tst_resm(TFAIL, "segment size is incorrect");
 		return;
 	}
 
 	/* check for specific conditions depending on the type of attach */
-	switch(i) {
+	switch (i) {
 	case 0:
 		/*
 		 * Check the functionality of the first call by simply
@@ -198,7 +171,6 @@ check_functionality(int i)
 		 * If this fails the program will get a SIGSEGV, dump
 		 * core and exit.
 		 */
-
 		*shared = CASE0;
 		break;
 	case 1:
@@ -208,13 +180,12 @@ check_functionality(int i)
 		 * that the original address given was rounded down as
 		 * specified in the man page.
 		 */
-
 		*shared = CASE1;
-		orig_add = addr + ((unsigned long)TC[i].addr%SHMLBA);
+		orig_add = addr + ((unsigned long)TC[i].addr % SHMLBA);
 		if (orig_add != TC[i].addr) {
 			tst_resm(TFAIL, "shared memory address is not "
-				 "correct");
-			fail = 1;
+					"correct");
+			return;
 		}
 		break;
 	case 2:
@@ -223,64 +194,34 @@ check_functionality(int i)
 		 * and check that it is equal to the value set in case #2,
 		 * because shared memory is persistent.
 		 */
-
 		if (*shared != CASE1) {
 			tst_resm(TFAIL, "shared memory value isn't correct");
-			fail = 1;
+			return;
 		}
 		break;
 	}
-
-	if (!fail) {
-		tst_resm(TPASS, "conditions and functionality are correct");
-	}
+	tst_resm(TPASS, "conditions and functionality are correct");
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void
-setup(void)
+void setup(void)
 {
-
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See ../lib/libipc.c for more information.
-	 */
 	tst_tmpdir();
 
-	/* Get an IPC resouce key */
 	shmkey = getipckey();
+	shm_id_1 = shmget(shmkey++, shm_size,
+		    SHM_HUGETLB|SHM_RW|IPC_CREAT|IPC_EXCL);
+	if (shm_id_1 == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "shmget");
 
-	/* create a shared memory resource with read and write permissions */
-	if ((shm_id_1 = shmget(shmkey++, huge_pages_shm_to_be_allocated, SHM_HUGETLB | SHM_RW | IPC_CREAT |
-	     IPC_EXCL)) == -1) {
-		tst_brkm(TBROK, cleanup, "Failed to create shared memory "
-			 "resource 1 in setup()");
-	}
+	TEST_PAUSE;
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void
-cleanup(void)
+void cleanup(void)
 {
-	/* if it exists, remove the shared memory resource */
+	TEST_CLEANUP;
+
 	rm_shm(shm_id_1);
 
 	tst_rmdir();
-
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
-	TEST_CLEANUP;
-
 }
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c
index ed0c476..6697436 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c
@@ -50,158 +50,97 @@
  *	Must be ran as root
  */
 
-#include "ipcshm.h"
 #include <pwd.h>
+#include "ipcshm.h"
 #include "system_specific_hugepages_info.h"
 
 char *TCID = "hugeshmat02";
 int TST_TOTAL = 2;
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-unsigned long huge_pages_shm_to_be_allocated;
-
-int exp_enos[] = {EINVAL, EACCES, 0};	/* 0 terminated list of */
-					/* expected errnos      */
-
-int shm_id_1 = -1;
-int shm_id_2 = -1;
-int shm_id_3 = -1;
 
-void	*addr;				/* for result of shmat-call */
-
-#if __WORDSIZE==64
-#define NADDR   0x10000000eef           /* a 64bit non alligned address value */
+#if __WORDSIZE == 64
+#define NADDR	0x10000000eef	/* a 64bit non alligned address value */
 #else
-#define NADDR	0x60000eef		/* a non alligned address value */
+#define NADDR	0x60000eef	/* a non alligned address value */
 #endif
 
+static size_t shm_size;
+static int    shm_id_1 = -1;
+static int    shm_id_2 = -1;
+static void   *addr;
+
 struct test_case_t {
-	int *shmid;
+	int  *shmid;
 	void *addr;
-	int error;
+	int  error;
 } TC[] = {
 	/* EINVAL - the shared memory ID is not valid */
-	{&shm_id_1, 0, EINVAL},
+	{ &shm_id_1,	NULL,		EINVAL },
 
 	/* EINVAL - the address is not page aligned and SHM_RND is not given */
-	{&shm_id_2, (void *)NADDR, EINVAL},
-
+	{ &shm_id_2,	(void *)NADDR,	EINVAL },
 };
 
 int main(int ac, char **av)
 {
-	int lc;				/* loop counter */
-	char *msg;			/* message returned from parse_opts */
-	int i;
-
-	/* parse standard options */
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
-		tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
+	int lc, i;
+	char *msg;
 
-        if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-             tst_brkm(TCONF, NULL, "Not enough available Hugepages");
-        else
-             huge_pages_shm_to_be_allocated = ( get_no_of_hugepages() * hugepages_size() * 1024) / 2 ;
+	msg = parse_opts(ac, av, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
-	setup();			/* global setup */
+	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
+		tst_brkm(TCONF, NULL, "Not enough available Hugepages");
+	else
+		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
 
-	/* The following loop checks looping state if -i option given */
+	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset Tst_count in case we are looping */
 		Tst_count = 0;
 
-		/* loop through the test cases */
-		for (i=0; i<TST_TOTAL; i++) {
-			/*
-			 * make the call using the TEST() macro - attempt
-			 * various invalid shared memory attaches
-			 */
- 			errno = 0;
-                       	addr = shmat(*(TC[i].shmid), (const void *)TC[i].addr, 0);
-                       	TEST_ERRNO = errno;
-
-                      	if (addr != (void *)-1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
+		for (i = 0; i < TST_TOTAL; i++) {
+			errno = 0;
+			addr = shmat(*(TC[i].shmid), TC[i].addr, 0);
+			TEST_ERRNO = errno;
+			if (addr != (void *)-1) {
+				tst_resm(TFAIL, "unexpected success");
 				continue;
 			}
-
-			TEST_ERROR_LOG(TEST_ERRNO);
-
-			if (TEST_ERRNO == TC[i].error) {
-				tst_resm(TPASS, "expected failure - errno = "
-					 "%d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TFAIL, "call failed with an "
-					 "unexpected error - %d : %s",
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-
-			}
+			if (TEST_ERRNO == TC[i].error)
+				tst_resm(TPASS|TTERRNO, "expected failure");
+			else
+				tst_resm(TFAIL|TTERRNO, "unexpected failure "
+					    "- expected errno %d, got",
+					    TC[i].error);
 		}
 	}
-
 	cleanup();
-
 	tst_exit();
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void
-setup(void)
+void setup(void)
 {
-
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	/* Set up the expected error numbers for -e option */
-	TEST_EXP_ENOS(exp_enos);
-
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See ../lib/libipc.c for more information.
-	 */
 	tst_tmpdir();
 
-	/* get an IPC resource key */
 	shmkey = getipckey();
 
 	/* create a shared memory resource with read and write permissions */
 	/* also post increment the shmkey for the next shmget call */
-	if ((shm_id_2 = shmget(shmkey++, huge_pages_shm_to_be_allocated, SHM_HUGETLB | SHM_RW | IPC_CREAT |
-	     IPC_EXCL)) == -1) {
-		tst_brkm(TBROK, cleanup, "Failed to create shared memory "
-			 "resource #1 in setup()");
-	}
+	shm_id_2 = shmget(shmkey++, shm_size,
+		    SHM_HUGETLB|SHM_RW|IPC_CREAT|IPC_EXCL);
+	if (shm_id_2 == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "shmget");
 
-	/* create a shared memory resource without read and write permissions */
-	if ((shm_id_3 = shmget(shmkey, huge_pages_shm_to_be_allocated, SHM_HUGETLB | IPC_CREAT | IPC_EXCL)) == -1) {
-		tst_brkm(TBROK, cleanup, "Failed to create shared memory "
-			 "resource #2 in setup()");
-	}
+	TEST_PAUSE;
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void
-cleanup(void)
+void cleanup(void)
 {
-	/* if they exist, remove the shared memory resources */
+	TEST_CLEANUP;
+
 	rm_shm(shm_id_2);
-	rm_shm(shm_id_3);
 
 	tst_rmdir();
-
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
-	TEST_CLEANUP;
-
-}
\ No newline at end of file
+}
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c
index 7aecefe..938ddfa 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c
@@ -62,153 +62,92 @@
 
 char *TCID = "hugeshmat03";
 int TST_TOTAL = 1;
-unsigned long huge_pages_shm_to_be_allocated;
 
-int exp_enos[] = {EACCES, 0};	/* 0 terminated list of expected errnos */
+static size_t shm_size;
+static int    shm_id_1 = -1;
+static void   *addr;
+static uid_t  ltp_uid;
+static char   *ltp_user = "nobody";
 
-int shm_id_1 = -1;
-
-void	*addr;			/* for result of shmat-call */
-
-uid_t ltp_uid;
-char *ltp_user = "nobody";
+static void do_child(void);
 
 int main(int ac, char **av)
 {
-	char *msg;			/* message returned from parse_opts */
-	int pid;
-	void do_child(void);
-
-	/* parse standard options */
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
-		tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
-
-        if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-             tst_brkm(TCONF, cleanup, "Not enough available Hugepages");
-        else
-             huge_pages_shm_to_be_allocated = ( get_no_of_hugepages() * hugepages_size() * 1024) / 2 ;
-
-	setup();			/* global setup */
-
-	if ((pid = fork()) == -1) {
-		tst_brkm(TBROK, cleanup, "could not fork");
-	}
-
-	if (pid == 0) {		/* child */
-		/* set the user ID of the child to the non root user */
-		if (setuid(ltp_uid) == -1) {
-			tst_resm(TBROK, "setuid() failed");
-			exit(1);
-		}
-
+	char *msg;
+	int status;
+	pid_t pid;
+
+	msg = parse_opts(ac, av, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
+		tst_brkm(TCONF, cleanup, "Not enough available Hugepages");
+	else
+		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
+
+	setup();
+
+	switch (pid = fork()) {
+	case -1:
+		tst_brkm(TBROK|TERRNO, cleanup, "fork");
+	case 0:
+		if (setuid(ltp_uid) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "setuid");
 		do_child();
-
-	} else {		/* parent */
-		/* wait for the child to return */
-		if (waitpid(pid, NULL, 0) == -1) {
-			tst_brkm(TBROK, cleanup, "waitpid failed");
-		}
-
-		/* if it exists, remove the shared memory resource */
-		rm_shm(shm_id_1);
-
-		tst_rmdir();
+		tst_exit();
+	default:
+		if (waitpid(pid, &status, 0) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
 	}
-
 	cleanup();
 	tst_exit();
 }
 
-/*
- * do_child - make the TEST call as the child process
- */
-void
-do_child()
+static void do_child(void)
 {
 	int lc;
 
-	/* The following loop checks looping state if -i option given */
-
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset Tst_count in case we are looping */
 		Tst_count = 0;
 
-		/*
-		 * use TEST macro to make the call
-		 */
 		errno = 0;
-		addr = shmat(shm_id_1, (const void *)0, 0);
+		addr = shmat(shm_id_1, NULL, 0);
 		TEST_ERRNO = errno;
-
-		if (addr != (char *)-1) {
-			tst_resm(TFAIL, "call succeeded when error expected");
+		if (addr != (void *)-1) {
+			tst_resm(TFAIL, "unexpected success");
 			continue;
 		}
-
-		TEST_ERROR_LOG(TEST_ERRNO);
-
-		switch(TEST_ERRNO) {
-		case EACCES:
-			tst_resm(TPASS, "expected failure - errno = "
-				 "%d : %s", TEST_ERRNO,
-				 strerror(TEST_ERRNO));
-			break;
-		default:
-			tst_resm(TFAIL, "call failed with an "
-				 "unexpected error - %d : %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		}
+		if (TEST_ERRNO == EACCES)
+			tst_resm(TPASS|TTERRNO, "expected failure");
+		else
+			tst_resm(TFAIL|TTERRNO, "unexpected failure "
+				    "- expected errno %d, got", EACCES);
 	}
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void
-setup(void)
+void setup(void)
 {
-	/* check for root as process owner */
-	check_root();
-
+	tst_require_root(NULL);
 	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	/* Set up the expected error numbers for -e option */
-	TEST_EXP_ENOS(exp_enos);
-
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See ../lib/libipc.c for more information.
-	 */
 	tst_tmpdir();
 
-	/* get an IPC resource key */
 	shmkey = getipckey();
+	shm_id_1 = shmget(shmkey, shm_size,
+		    SHM_HUGETLB|SHM_RW|IPC_CREAT|IPC_EXCL);
+	if (shm_id_1 == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "shmget");
 
-	/* create a shared memory segment with read and write permissions */
-	if ((shm_id_1 = shmget(shmkey, huge_pages_shm_to_be_allocated, SHM_HUGETLB | SHM_RW | IPC_CREAT | IPC_EXCL)) == -1) {
-		tst_brkm(TBROK, cleanup, "Failed to create shared memory "
-			 "segment in setup");
-	}
-
-	/* get the userid for a non root user */
 	ltp_uid = getuserid(ltp_user);
+
+	TEST_PAUSE;
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void
-cleanup(void)
+void cleanup(void)
 {
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
 	TEST_CLEANUP;
 
-}
\ No newline at end of file
+	rm_shm(shm_id_1);
+
+	tst_rmdir();
+}

[-- Attachment #3: Type: text/plain, Size: 381 bytes --]

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

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH 02/11] hugetlb/hugeshmat: set nr_hugepages in tests
  2012-03-13  4:56 [LTP] [PATCH 00/11] hugetlb multiple fixes Caspar Zhang
  2012-03-13  4:56 ` [LTP] [PATCH 01/11] hugetlb/hugeshmat: cleanup codes Caspar Zhang
@ 2012-03-13  4:56 ` Caspar Zhang
  2012-03-13  6:16   ` Wanlong Gao
  2012-03-13  4:56 ` [LTP] [PATCH 03/11] hugetlb/hugeshmctl: cleanup codes Caspar Zhang
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Caspar Zhang @ 2012-03-13  4:56 UTC (permalink / raw)
  To: LTP List

[-- Attachment #1: Type: text/plain, Size: 704 bytes --]


Like hugemmap tests, this patch enables nr_hugepages set/restore in each
test of hugeshmat, so that we don't need to set the values with external
commands.

Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
 testcases/kernel/mem/hugetlb/Makefile.inc          |   16 +++++-----
 .../kernel/mem/hugetlb/hugeshmat/hugeshmat01.c     |   28 +++++++++++++++-----
 .../kernel/mem/hugetlb/hugeshmat/hugeshmat02.c     |   28 +++++++++++++++-----
 .../kernel/mem/hugetlb/hugeshmat/hugeshmat03.c     |   26 ++++++++++++++----
 testcases/kernel/mem/hugetlb/lib/ipcshm.h          |    5 +++
 testcases/kernel/mem/hugetlb/lib/libipc.c          |    7 ++++-
 6 files changed, 81 insertions(+), 29 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-hugetlb-hugeshmat-set-nr_hugepages-in-tests.patch --]
[-- Type: text/x-patch; name="0002-hugetlb-hugeshmat-set-nr_hugepages-in-tests.patch", Size: 7497 bytes --]

diff --git a/testcases/kernel/mem/hugetlb/Makefile.inc b/testcases/kernel/mem/hugetlb/Makefile.inc
index bb352e5..274bd7c 100644
--- a/testcases/kernel/mem/hugetlb/Makefile.inc
+++ b/testcases/kernel/mem/hugetlb/Makefile.inc
@@ -23,19 +23,19 @@
 # DO NOT USE THIS FILE FOR hugetlb / lib!!!
 LIBIPCDIR		:= ../lib
 LIBIPC			:= $(LIBIPCDIR)/libipc_hugetlb.a
-
 $(LIBIPCDIR):
 	mkdir -p "$@"
-
 $(LIBIPC): $(LIBIPCDIR)
 	$(MAKE) -C "$^" -f "$(abs_srcdir)/$^/Makefile" all
 
-CPPFLAGS		+= -I$(abs_srcdir)/$(LIBIPCDIR)
-
-LDFLAGS			+= -L$(abs_builddir)/$(LIBIPCDIR)
-
-LDLIBS			+= -lipc_hugetlb
+LIBMEMDIR		:= ../../lib
+LIBMEM			:= $(LIBMEMDIR)/libmem.a
+$(LIBMEM): $(LIBMEMDIR)
+	$(MAKE) -C "$^" -f "$(abs_srcdir)/$^/Makefile" all
 
-MAKE_DEPS		:= $(LIBIPC)
+CPPFLAGS		+= -I$(abs_srcdir)/$(LIBIPCDIR) -I$(abs_srcdir)/../../include
+LDFLAGS			+= -L$(abs_builddir)/$(LIBIPCDIR) -L$(abs_builddir)/$(LIBMEMDIR)
+LDLIBS			+= $(NUMA_LIBS) -lmem -lltp -lipc_hugetlb
+MAKE_DEPS		+= $(LIBMEM) $(LIBIPC)
 
 # vim: syntax=make
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c
index b92f6eb..e46ae12 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c
@@ -57,7 +57,8 @@
  */
 
 #include "ipcshm.h"
-#include "system_specific_hugepages_info.h"
+#include "safe_macros.h"
+#include "mem.h"
 
 char *TCID = "hugeshmat01";
 int TST_TOTAL = 3;
@@ -79,6 +80,12 @@ static size_t shm_size;
 static int    shm_id_1 = -1;
 static void   *addr;
 
+static long hugepages = 128;
+static option_t options[] = {
+	{ "s:",	&sflag,	&nr_opt	},
+	{ NULL,	NULL,	NULL	}
+};
+
 struct test_case_t {
 	int  *shmid;
 	void *addr;
@@ -101,14 +108,11 @@ int main(int ac, char **av)
 	int lc, i;
 	char *msg;
 
-	msg = parse_opts(ac, av, NULL, NULL);
+	msg = parse_opts(ac, av, options, &help);
 	if (msg != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-
-	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-		tst_brkm(TCONF, NULL, "Not enough available Hugepages");
-	else
-		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
+	if (sflag)
+		hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);
 
 	setup();
 
@@ -205,9 +209,17 @@ static void check_functionality(int i)
 
 void setup(void)
 {
+	long hpage_size;
+
+	tst_require_root(NULL);
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 	tst_tmpdir();
 
+	orig_hugepages = get_sys_tune("nr_hugepages");
+	set_sys_tune("nr_hugepages", hugepages, 1);
+	hpage_size = read_meminfo("Hugepagesize:") * 1024;
+
+	shm_size = hpage_size * hugepages / 2;
 	shmkey = getipckey();
 	shm_id_1 = shmget(shmkey++, shm_size,
 		    SHM_HUGETLB|SHM_RW|IPC_CREAT|IPC_EXCL);
@@ -223,5 +235,7 @@ void cleanup(void)
 
 	rm_shm(shm_id_1);
 
+	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+
 	tst_rmdir();
 }
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c
index 6697436..0d00a34 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c
@@ -52,7 +52,8 @@
 
 #include <pwd.h>
 #include "ipcshm.h"
-#include "system_specific_hugepages_info.h"
+#include "safe_macros.h"
+#include "mem.h"
 
 char *TCID = "hugeshmat02";
 int TST_TOTAL = 2;
@@ -68,6 +69,12 @@ static int    shm_id_1 = -1;
 static int    shm_id_2 = -1;
 static void   *addr;
 
+static long hugepages = 128;
+static option_t options[] = {
+	{ "s:",	&sflag,	&nr_opt	},
+	{ NULL,	NULL,	NULL	}
+};
+
 struct test_case_t {
 	int  *shmid;
 	void *addr;
@@ -85,14 +92,11 @@ int main(int ac, char **av)
 	int lc, i;
 	char *msg;
 
-	msg = parse_opts(ac, av, NULL, NULL);
+	msg = parse_opts(ac, av, options, &help);
 	if (msg != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-
-	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-		tst_brkm(TCONF, NULL, "Not enough available Hugepages");
-	else
-		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
+	if (sflag)
+		hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);
 
 	setup();
 
@@ -121,9 +125,17 @@ int main(int ac, char **av)
 
 void setup(void)
 {
+	long hpage_size;
+
+	tst_require_root(NULL);
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 	tst_tmpdir();
 
+	orig_hugepages = get_sys_tune("nr_hugepages");
+	set_sys_tune("nr_hugepages", hugepages, 1);
+	hpage_size = read_meminfo("Hugepagesize:") * 1024;
+
+	shm_size = hpage_size * hugepages / 2;
 	shmkey = getipckey();
 
 	/* create a shared memory resource with read and write permissions */
@@ -142,5 +154,7 @@ void cleanup(void)
 
 	rm_shm(shm_id_2);
 
+	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+
 	tst_rmdir();
 }
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c
index 938ddfa..22832dd 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c
@@ -58,7 +58,8 @@
  */
 
 #include "ipcshm.h"
-#include "system_specific_hugepages_info.h"
+#include "safe_macros.h"
+#include "mem.h"
 
 char *TCID = "hugeshmat03";
 int TST_TOTAL = 1;
@@ -69,6 +70,12 @@ static void   *addr;
 static uid_t  ltp_uid;
 static char   *ltp_user = "nobody";
 
+static long hugepages = 128;
+static option_t options[] = {
+	{ "s:",	&sflag,	&nr_opt	},
+	{ NULL,	NULL,	NULL	}
+};
+
 static void do_child(void);
 
 int main(int ac, char **av)
@@ -77,14 +84,12 @@ int main(int ac, char **av)
 	int status;
 	pid_t pid;
 
-	msg = parse_opts(ac, av, NULL, NULL);
+	msg = parse_opts(ac, av, options, &help);
 	if (msg != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
-	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-		tst_brkm(TCONF, cleanup, "Not enough available Hugepages");
-	else
-		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
+	if (sflag)
+		hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);
 
 	setup();
 
@@ -128,10 +133,17 @@ static void do_child(void)
 
 void setup(void)
 {
+	long hpage_size;
+
 	tst_require_root(NULL);
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 	tst_tmpdir();
 
+	orig_hugepages = get_sys_tune("nr_hugepages");
+	set_sys_tune("nr_hugepages", hugepages, 1);
+	hpage_size = read_meminfo("Hugepagesize:") * 1024;
+
+	shm_size = hpage_size * hugepages / 2;
 	shmkey = getipckey();
 	shm_id_1 = shmget(shmkey, shm_size,
 		    SHM_HUGETLB|SHM_RW|IPC_CREAT|IPC_EXCL);
@@ -149,5 +161,7 @@ void cleanup(void)
 
 	rm_shm(shm_id_1);
 
+	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+
 	tst_rmdir();
 }
diff --git a/testcases/kernel/mem/hugetlb/lib/ipcshm.h b/testcases/kernel/mem/hugetlb/lib/ipcshm.h
index caac9af..1e9edbe 100644
--- a/testcases/kernel/mem/hugetlb/lib/ipcshm.h
+++ b/testcases/kernel/mem/hugetlb/lib/ipcshm.h
@@ -54,4 +54,9 @@ void check_root();
 int getipckey();
 int getuserid(char*);
 
+char *nr_opt;
+int sflag;
+long orig_hugepages;
+void help(void);
+
 #endif /* ipcshm.h */
diff --git a/testcases/kernel/mem/hugetlb/lib/libipc.c b/testcases/kernel/mem/hugetlb/lib/libipc.c
index a5d609c..cc3ca02 100644
--- a/testcases/kernel/mem/hugetlb/lib/libipc.c
+++ b/testcases/kernel/mem/hugetlb/lib/libipc.c
@@ -198,4 +198,9 @@ rm_shm(int shm_id)
 		tst_resm(TINFO, "This could lead to IPC resource problems.");
 		tst_resm(TINFO, "id = %d", shm_id);
 	}
-}
\ No newline at end of file
+}
+
+void help(void)
+{
+	printf("    -s NUM  Set the number of hugepages to be allocated\n");
+}

[-- Attachment #3: Type: text/plain, Size: 381 bytes --]

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

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH 03/11] hugetlb/hugeshmctl: cleanup codes
  2012-03-13  4:56 [LTP] [PATCH 00/11] hugetlb multiple fixes Caspar Zhang
  2012-03-13  4:56 ` [LTP] [PATCH 01/11] hugetlb/hugeshmat: cleanup codes Caspar Zhang
  2012-03-13  4:56 ` [LTP] [PATCH 02/11] hugetlb/hugeshmat: set nr_hugepages in tests Caspar Zhang
@ 2012-03-13  4:56 ` Caspar Zhang
  2012-03-13  4:56 ` [LTP] [PATCH 04/11] hugetlb/hugeshmctl: set nr_hugepages in tests Caspar Zhang
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Caspar Zhang @ 2012-03-13  4:56 UTC (permalink / raw)
  To: LTP List

[-- Attachment #1: Type: text/plain, Size: 396 bytes --]


Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
 testcases/kernel/mem/hugetlb/hugeshmctl/Makefile   |    2 +-
 .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c   |  311 +++++++-------------
 .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c   |  136 +++------
 .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c   |  173 ++++--------
 4 files changed, 205 insertions(+), 417 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0003-hugetlb-hugeshmctl-cleanup-codes.patch --]
[-- Type: text/x-patch; name="0003-hugetlb-hugeshmctl-cleanup-codes.patch", Size: 25304 bytes --]

diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/Makefile b/testcases/kernel/mem/hugetlb/hugeshmctl/Makefile
index 2f5b160..3edcd7b 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/Makefile
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/Makefile
@@ -20,7 +20,7 @@
 # Garrett Cooper, July 2009
 #
 
-top_srcdir              ?= ../../../../..
+top_srcdir		?= ../../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 include $(abs_srcdir)/../Makefile.inc
diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c
index ae5f3a8..ce8d89a 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c
@@ -36,7 +36,7 @@
  *	otherwise,
  *	  if doing functionality testing
  *		call the correct test function
- *	  	if the conditions are correct,
+ *		if the conditions are correct,
  *			issue a PASS message
  *		otherwise
  *			issue a FAIL message
@@ -66,78 +66,57 @@
 
 char *TCID = "hugeshmctl01";
 int TST_TOTAL = 4;
-unsigned long huge_pages_shm_to_be_allocated;
-
-int shm_id_1 = -1;
-struct shmid_ds buf;
-long save_time;
-
-#define FIRST	0
-#define SECOND	1
-int stat_time;		/* set to either FIRST or SECOND for IPC_STAT tests */
-
-void *set_shared;
 
+#define FIRST		0
+#define SECOND		1
 #define N_ATTACH	4
-
-pid_t pid_arr[N_ATTACH];
-
-void sighandler(int);
-
-/*
- * These are the various setup and check functions for the commands
- * that we are checking.
- */
-
-/* Setup, cleanup and check routines for IPC_STAT */
-void stat_setup(void), func_stat(void);
-void stat_cleanup(void);
-
-/* Setup and check routines for IPC_SET */
-void set_setup(void), func_set(void);
-
-/* Check routine for IPC_RMID */
-void func_rmid(void);
+#define NEWMODE		0066
+
+static size_t shm_size;
+static int shm_id_1 = -1;
+static struct shmid_ds buf;
+static time_t save_time;
+static int stat_time;
+static void *set_shared;
+static pid_t pid_arr[N_ATTACH];
+
+static void sighandler(int sig);
+static void stat_setup(void);
+static void stat_cleanup(void);
+static void set_setup(void);
+static void func_stat(void);
+static void func_set(void);
+static void func_rmid(void);
+static void *set_shmat(void);
 
 struct test_case_t {
-	int cmd;		/* the command to test */
-	void (*func_test)();	/* the test function */
-	void (*func_setup)();	/* the setup function if necessary */
+	int  cmd;
+	void (*func_test)(void);
+	void (*func_setup)(void);
 } TC[] = {
-
-	{IPC_STAT, func_stat, stat_setup},
-
-	{IPC_STAT, func_stat, stat_setup},
-
-	{IPC_SET, func_set, set_setup},
-
-	{IPC_RMID, func_rmid, NULL}
+	{ IPC_STAT,	func_stat,	stat_setup },
+	{ IPC_STAT,	func_stat,	stat_setup },
+	{ IPC_SET,	func_set,	set_setup },
+	{ IPC_RMID,	func_rmid,	NULL }
 };
 
-#define NEWMODE	0066
-
 int main(int ac, char **av)
 {
-	int lc;				/* loop counter */
-	char *msg;			/* message returned from parse_opts */
-	int i;
-	void check_functionality(void);
-
-	/* parse standard options */
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
-		tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
+	int lc, i;
+	char *msg;
 
-        if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-             tst_brkm(TCONF, NULL, "Not enough available Hugepages");
-        else
-             huge_pages_shm_to_be_allocated = ( get_no_of_hugepages() * hugepages_size() * 1024) / 2 ;
+	msg = parse_opts(ac, av, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
-	setup();			/* global setup */
+	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
+		tst_brkm(TCONF, NULL, "Not enough available Hugepages");
+	else
+		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
 
-	/* The following loop checks looping state if -i option given */
+	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset Tst_count in case we are looping */
 		Tst_count = 0;
 
 		/* initialize stat_time */
@@ -148,33 +127,21 @@ int main(int ac, char **av)
 		 * permissions.  Do this here instead of in setup()
 		 * so that looping (-i) will work correctly.
 		 */
-		if ((shm_id_1 = shmget(shmkey, huge_pages_shm_to_be_allocated, SHM_HUGETLB | IPC_CREAT | IPC_EXCL |
-				SHM_RW)) == -1) {
-			tst_brkm(TBROK, cleanup, "couldn't create the shared"
-				 " memory segment");
-		}
-
-		/* loop through the test cases */
-		for (i=0; i<TST_TOTAL; i++) {
+		shm_id_1 = shmget(shmkey, shm_size,
+			    SHM_HUGETLB|IPC_CREAT|IPC_EXCL|SHM_RW);
+		if (shm_id_1 == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "shmget");
 
+		for (i = 0; i < TST_TOTAL; i++) {
 			/*
 			 * if needed, set up any required conditions by
 			 * calling the appropriate setup function
 			 */
-			if (TC[i].func_setup != NULL) {
+			if (TC[i].func_setup != NULL)
 				(*TC[i].func_setup)();
-			}
 
-			/*
-			 * Use TEST macro to make the call
-			 */
-
-			TEST(shmctl(shm_id_1, TC[i].cmd, &buf));
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL, "%s call failed - errno "
-					 "= %d : %s", TCID, TEST_ERRNO,
-					 strerror(TEST_ERRNO));
+			if (shmctl(shm_id_1, TC[i].cmd, &buf) == -1) {
+				tst_resm(TFAIL|TERRNO, "shmctl");
 				continue;
 			}
 			if (STD_FUNCTIONAL_TEST) {
@@ -183,7 +150,7 @@ int main(int ac, char **av)
 				tst_resm(TPASS, "call succeeded");
 
 				/* now perform command related cleanup */
-				switch(TC[i].cmd) {
+				switch (TC[i].cmd) {
 				case IPC_STAT:
 					stat_cleanup();
 					break;
@@ -194,9 +161,7 @@ int main(int ac, char **av)
 			}
 		}
 	}
-
 	cleanup();
-
 	tst_exit();
 }
 
@@ -205,16 +170,13 @@ int main(int ac, char **av)
  *		 this seperate routine to avoid code duplication in
  *		 stat_setup() below.
  */
-void *
-set_shmat()
+void *set_shmat(void)
 {
 	void *rval;
 
-	/* attach the shared memory */
 	rval = shmat(shm_id_1, 0, 0);
-
 	if (rval == (void *)-1)
-		tst_brkm(TBROK|TERRNO, cleanup, "shmat() failed.");
+		tst_brkm(TBROK|TERRNO, cleanup, "shmat");
 
 	return rval;
 }
@@ -224,11 +186,10 @@ set_shmat()
  *		  Make things interesting by forking some children
  *		  that will either attach or inherit the shared memory.
  */
-void
-stat_setup()
+static void stat_setup(void)
 {
 	int i, rval;
-	void *test, *set_shmat();
+	void *test;
 	pid_t pid;
 	sigset_t newmask, oldmask;
 
@@ -259,20 +220,14 @@ stat_setup()
 	sigemptyset(&newmask);
 	sigaddset(&newmask, SIGUSR1);
 	if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
-		tst_brkm(TBROK, cleanup, "block SIGUSR1 error");
-
-	for (i=0; i<N_ATTACH; i++) {
-		if ((pid = fork()) == -1) {
-			tst_brkm(TBROK, cleanup, "could not fork");
-		}
+		tst_brkm(TBROK|TERRNO, cleanup, "block SIGUSR1 error");
 
-		if (pid == 0) {		/* child */
-
-			if (stat_time == FIRST) {
-				test = set_shmat();
-			} else {
-				test = set_shared;
-			}
+	for (i = 0; i < N_ATTACH; i++) {
+		switch (pid = fork()) {
+		case -1:
+			tst_brkm(TBROK|TERRNO, cleanup, "fork");
+		case 0:
+			test = (stat_time == FIRST) ? set_shmat() : set_shared;
 
 			/* do an assignement for fun */
 			*(int *)test = i;
@@ -284,20 +239,21 @@ stat_setup()
 			 */
 			rval = sigsuspend(&oldmask);
 			if (rval != -1)
-				tst_brkm(TBROK, cleanup, "sigsuspend error");
+				tst_brkm(TBROK|TERRNO, cleanup, "sigsuspend");
 
-			/* don't have to block SIGUSR1 any more, recover the mask */
+			/*
+			 * don't have to block SIGUSR1 any more,
+			 * recover the mask
+			 */
 			if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
-				tst_brkm(TBROK, cleanup, "children setmask error");
+				tst_brkm(TBROK|TERRNO, cleanup,
+					    "child sigprocmask");
 
 			/* now we're back - detach the memory and exit */
-			if (shmdt(test) == -1) {
-				tst_resm(TBROK, "shmdt() failed - %d", errno);
-			}
-
-			tst_exit();
-
-		} else {		/* parent */
+			if (shmdt(test) == -1)
+				tst_brkm(TBROK|TERRNO, cleanup, "shmdt");
+			exit(0);
+		default:
 			/* save the child's pid for cleanup later */
 			pid_arr[i] = pid;
 		}
@@ -305,9 +261,8 @@ stat_setup()
 
 	/* parent doesn't have to block SIGUSR1, recover the mask */
 	if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
-		tst_brkm(TBROK, cleanup, "parent setmask error");
+		tst_brkm(TBROK, cleanup, "parent sigprocmask");
 
-	/* sleep briefly to ensure correct execution order */
 	usleep(250000);
 }
 
@@ -316,24 +271,21 @@ stat_setup()
  *		 by looking at the pid of the creator, the segement size,
  *		 the number of attaches and the mode.
  */
-void
-func_stat()
+static void func_stat(void)
 {
-	int fail = 0;
 	pid_t pid;
 
 	/* check perm, pid, nattach and size */
-
 	pid = getpid();
 
 	if (buf.shm_cpid != pid) {
 		tst_resm(TFAIL, "creator pid is incorrect");
-		fail = 1;
+		goto fail;
 	}
 
-	if (!fail && buf.shm_segsz != huge_pages_shm_to_be_allocated) {
+	if (buf.shm_segsz != shm_size) {
 		tst_resm(TFAIL, "segment size is incorrect");
-		fail = 1;
+		goto fail;
 	}
 
 	/*
@@ -342,29 +294,26 @@ func_stat()
 	 * through, the parent attaches the memory and the children inherit
 	 * that memory so the attaches equal N_ATTACH + stat_time (1).
 	 */
-	if (!fail && buf.shm_nattch != N_ATTACH + stat_time) {
+	if (buf.shm_nattch != N_ATTACH + stat_time) {
 		tst_resm(TFAIL, "# of attaches is incorrect - %lu",
 			 (unsigned long)buf.shm_nattch);
-		fail = 1;
+		goto fail;
 	}
 
 	/* use MODE_MASK to make sure we are comparing the last 9 bits */
-	if (!fail && (buf.shm_perm.mode & MODE_MASK) != ((SHM_RW) & MODE_MASK)) {
+	if ((buf.shm_perm.mode & MODE_MASK) != ((SHM_RW) & MODE_MASK)) {
 		tst_resm(TFAIL, "segment mode is incorrect");
-		fail = 1;
+		goto fail;
 	}
 
+	tst_resm(TPASS, "pid, size, # of attaches and mode are correct "
+		 "- pass #%d", stat_time);
+
+fail:
 	stat_cleanup();
 
 	/* save the change time for use in the next test */
 	save_time = buf.shm_ctime;
-
-	if (fail) {
-		return;
-	}
-
-	tst_resm(TPASS, "pid, size, # of attaches and mode are correct "
-		 "- pass #%d", stat_time);
 }
 
 /*
@@ -372,33 +321,26 @@ func_stat()
  *		    have the parent make dessert, er, um, make that remove
  *		    the shared memory that is no longer needed.
  */
-void
-stat_cleanup()
+static void stat_cleanup(void)
 {
 	int i;
 
 	/* wake up the childern so they can detach the memory and exit */
-	for (i=0; i<N_ATTACH; i++) {
-		if (kill(pid_arr[i], SIGUSR1) == -1) {
-			tst_brkm(TBROK, cleanup, "kill failed");
-		}
-	}
+	for (i = 0; i < N_ATTACH; i++)
+		if (kill(pid_arr[i], SIGUSR1) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "kill with SIGUSR1");
 
 	/* remove the parent's shared memory the second time through */
-	if (stat_time == SECOND) {
-		if (shmdt(set_shared) == -1) {
-			tst_resm(TINFO, "shmdt() failed");
-		}
-	}
-
+	if (stat_time == SECOND)
+		if (shmdt(set_shared) == -1)
+			tst_resm(TBROK|TERRNO, "shmdt");
 	stat_time++;
 }
 
 /*
  * set_setup() - set up for the IPC_SET command with shmctl()
  */
-void
-set_setup()
+static void set_setup(void)
 {
 	/* set up a new mode for the shared memory segment */
 	buf.shm_perm.mode = SHM_RW | NEWMODE;
@@ -410,29 +352,22 @@ set_setup()
 /*
  * func_set() - check the functionality of the IPC_SET command with shmctl()
  */
-void
-func_set()
+static void func_set(void)
 {
-	int fail = 0;
-
 	/* first stat the shared memory to get the new data */
 	if (shmctl(shm_id_1, IPC_STAT, &buf) == -1) {
-		tst_resm(TBROK, "stat failed in func_set()");
+		tst_resm(TBROK|TERRNO, "shmctl in func_set()");
 		return;
 	}
 
 	if ((buf.shm_perm.mode & MODE_MASK) !=
 			((SHM_RW | NEWMODE) & MODE_MASK)) {
 		tst_resm(TFAIL, "new mode is incorrect");
-		fail = 1;
+		return;
 	}
 
-	if (!fail && save_time >= buf.shm_ctime) {
+	if (save_time >= buf.shm_ctime) {
 		tst_resm(TFAIL, "change time is incorrect");
-		fail = 1;
-	}
-
-	if (fail) {
 		return;
 	}
 
@@ -442,71 +377,39 @@ func_set()
 /*
  * func_rmid() - check the functionality of the IPC_RMID command with shmctl()
  */
-void
-func_rmid()
+static void func_rmid(void)
 {
 	/* Do another shmctl() - we should get EINVAL */
-	if (shmctl(shm_id_1, IPC_STAT, &buf) != -1) {
+	if (shmctl(shm_id_1, IPC_STAT, &buf) != -1)
 		tst_brkm(TBROK, cleanup, "shmctl succeeded on expected fail");
-	}
-
-	if (errno != EINVAL) {
-		tst_resm(TFAIL, "returned unexpected errno %d", errno);
-	} else {
+	if (errno != EINVAL)
+		tst_resm(TFAIL|TTERRNO, "unexpected errno, expect %d", EINVAL);
+	else
 		tst_resm(TPASS, "shared memory appears to be removed");
-	}
-
 	shm_id_1 = -1;
 }
 
-/*
- * sighandler() - handle signals, in this case SIGUSR1 is the only one expected
- */
-void
-sighandler(sig)
+static void sighandler(int sig)
 {
 	if (sig != SIGUSR1)
-		tst_resm(TINFO, "received unexpected signal %d", sig);
+		tst_resm(TFAIL, "received unexpected signal %d", sig);
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void
-setup(void)
+void setup(void)
 {
-
 	tst_sig(FORK, sighandler, cleanup);
-
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See ../lib/libipc.c for more information.
-	 */
 	tst_tmpdir();
 
-	/* get an IPC resource key */
 	shmkey = getipckey();
+
+	TEST_PAUSE;
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void
-cleanup(void)
+void cleanup(void)
 {
-	/* if it exists, remove the shared memory segment */
+	TEST_CLEANUP;
+
 	rm_shm(shm_id_1);
 
 	tst_rmdir();
-
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
-	TEST_CLEANUP;
-
 }
diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c
index 1193b82..15cadb0 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c
@@ -52,23 +52,18 @@
  *	none
  */
 
-#include "ipcshm.h"
 #include <pwd.h>
+#include "ipcshm.h"
 #include "system_specific_hugepages_info.h"
 
 char *TCID = "hugeshmctl02";
 int TST_TOTAL = 4;
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-unsigned long huge_pages_shm_to_be_allocated;
 
-int exp_enos[] = {EPERM, EACCES, EFAULT, EINVAL, 0};  /* 0 terminated list  */
-						      /* of expected errnos */
-int shm_id_1 = -1;
-int shm_id_2 = -1;
-int shm_id_3 = -1;
-
-struct shmid_ds buf;
+static size_t shm_size;
+static int shm_id_1 = -1;
+static int shm_id_2 = -1;
+static int shm_id_3 = -1;
+static struct shmid_ds buf;
 
 struct test_case_t {
 	int *shmid;
@@ -77,127 +72,78 @@ struct test_case_t {
 	int error;
 } TC[] = {
 	/* EFAULT - IPC_SET & buf isn't valid */
-	{&shm_id_2, IPC_SET, (struct shmid_ds *)-1, EFAULT},
+	{ &shm_id_2,	IPC_SET,	(struct shmid_ds *)-1,	EFAULT },
 
 	/* EFAULT - IPC_STAT & buf isn't valid */
-	{&shm_id_2, IPC_STAT, (struct shmid_ds *)-1, EFAULT},
+	{ &shm_id_2,	IPC_STAT,	(struct shmid_ds *)-1,	EFAULT },
 
 	/* EINVAL - the shmid is not valid */
-	{&shm_id_3, IPC_STAT, &buf, EINVAL},
+	{ &shm_id_3,	IPC_STAT,	&buf,			EINVAL },
 
 	/* EINVAL - the command is not valid */
-	{&shm_id_2, -1, &buf, EINVAL},
+	{ &shm_id_2,	-1,		&buf,			EINVAL },
 };
 
 int main(int ac, char **av)
 {
-	int lc;				/* loop counter */
-	char *msg;			/* message returned from parse_opts */
-	int i;
-
-	/* parse standard options */
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
-		tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
+	int lc, i;
+	char *msg;
 
-        if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-             tst_brkm(TCONF, NULL, "Not enough available Hugepages");
-        else
-             huge_pages_shm_to_be_allocated = ( get_no_of_hugepages() * hugepages_size() * 1024) / 2 ;
+	msg = parse_opts(ac, av, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
-	setup();			/* global setup */
+	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
+		tst_brkm(TCONF, NULL, "Not enough available Hugepages");
+	else
+		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
 
-	/* The following loop checks looping state if -i option given */
+	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset Tst_count in case we are looping */
 		Tst_count = 0;
 
-		/* loop through the test cases */
-		for (i=0; i<TST_TOTAL; i++) {
-			/*
-			 * use the TEST() macro to make the call
-			 */
-
+		for (i = 0; i < TST_TOTAL; i++) {
 			TEST(shmctl(*(TC[i].shmid), TC[i].cmd, TC[i].sbuf));
-
-			if ((TEST_RETURN != -1)&&(i < 5)) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
-				continue;
-			}
-
-			TEST_ERROR_LOG(TEST_ERRNO);
-
-			if (TEST_ERRNO == TC[i].error) {
-				tst_resm(TPASS, "expected failure - errno = "
-					 "%d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TFAIL, "call failed with an "
-					 "unexpected error - %d : %s",
-				 	TEST_ERRNO, strerror(TEST_ERRNO));
-			}
+			if (TEST_ERRNO == TC[i].error)
+				tst_resm(TPASS|TTERRNO, "expected failure");
+			else
+				tst_resm(TFAIL|TTERRNO, "unexpected behavior "
+					    "- expected errno = %d, got",
+					    TC[i].error);
 		}
 	}
-
 	cleanup();
-
 	tst_exit();
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void
-setup(void)
+void setup(void)
 {
-
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	/* Set up the expected error numbers for -e option */
-	TEST_EXP_ENOS(exp_enos);
-
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See ../lib/libipc.c for more information.
-	 */
 	tst_tmpdir();
 
-	/* get an IPC resource key */
 	shmkey = getipckey();
 
 	/* create a shared memory segment without read or write permissions */
-	if ((shm_id_1 = shmget(shmkey, huge_pages_shm_to_be_allocated, SHM_HUGETLB | IPC_CREAT | IPC_EXCL)) == -1) {
-		tst_brkm(TBROK, cleanup, "couldn't create shared memory "
-			 "segment #1 in setup()");
-	}
+	shm_id_1 = shmget(shmkey, shm_size, SHM_HUGETLB|IPC_CREAT|IPC_EXCL);
+	if (shm_id_1 == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "shmget #1");
 
 	/* create a shared memory segment with read and write permissions */
-	if ((shm_id_2 = shmget(shmkey + 1, huge_pages_shm_to_be_allocated, SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW)) == -1) {
-		tst_brkm(TBROK, cleanup, "couldn't create shared memory "
-			 "segment #2 in setup()");
-	}
+	shm_id_2 = shmget(shmkey + 1, shm_size,
+		    SHM_HUGETLB|IPC_CREAT|IPC_EXCL|SHM_RW);
+	if (shm_id_2 == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "shmget #2");
+
+	TEST_PAUSE;
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void
-cleanup(void)
+void cleanup(void)
 {
-	/* if they exist, remove the shared memory resources */
+	TEST_CLEANUP;
+
 	rm_shm(shm_id_1);
 	rm_shm(shm_id_2);
 
 	tst_rmdir();
-
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
-	TEST_CLEANUP;
-
-}
\ No newline at end of file
+}
diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c
index 689622f..30353b8 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c
@@ -25,8 +25,8 @@
  *	hugeshmctl03 - check for EACCES, and EPERM errors
  *
  * ALGORITHM
- *	create a large shared memory segment with root only read & write permissions
- *	fork a child process
+ *	create a large shared memory segment with root only read & write
+ *	permissions fork a child process
  *	if child
  *	  set the ID of the child process to that of "ltpuser1"
  *	  call do_child()
@@ -58,23 +58,19 @@
  *	test must be run as root
  */
 
-#include "ipcshm.h"
 #include <sys/types.h>
 #include <sys/wait.h>
+#include "ipcshm.h"
 #include "system_specific_hugepages_info.h"
 
 char *TCID = "hugeshmctl03";
 int TST_TOTAL = 3;
-unsigned long huge_pages_shm_to_be_allocated;
-
-int exp_enos[] = {EACCES, EPERM, 0};	/* 0 terminated list of */
-					/* expected errnos 	*/
-int shm_id_1 = -1;
 
-uid_t ltp_uid;
-char *ltp_user = "nobody";
-
-struct shmid_ds buf;
+static size_t shm_size;
+static int shm_id_1 = -1;
+static struct shmid_ds buf;
+static uid_t ltp_uid;
+static char *ltp_user = "nobody";
 
 struct test_case_t {
 	int *shmid;
@@ -83,150 +79,93 @@ struct test_case_t {
 	int error;
 } TC[] = {
 	/* EACCES - child has no read permission for segment */
-	{&shm_id_1, IPC_STAT, &buf, EACCES},
+	{ &shm_id_1,	IPC_STAT,	&buf,	EACCES },
 
 	/* EPERM - IPC_SET - child doesn't have permission to change segment */
-	{&shm_id_1, IPC_SET, &buf, EPERM},
+	{ &shm_id_1,	IPC_SET,	&buf,	EPERM },
 
 	/* EPERM - IPC_RMID - child can not remove the segment */
-	{&shm_id_1, IPC_RMID, &buf, EPERM},
+	{ &shm_id_1,	IPC_RMID,	&buf,	EPERM },
 };
 
+static void do_child(void);
+
 int main(int ac, char **av)
 {
-	char *msg;			/* message returned from parse_opts */
-	int pid;
-	void do_child(void);
+	char *msg;
+	pid_t pid;
+	int status;
 
-	/* parse standard options */
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
-		tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
+	msg = parse_opts(ac, av, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
-        if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-             tst_brkm(TCONF, cleanup, "Not enough available Hugepages");
-        else
-             huge_pages_shm_to_be_allocated = ( get_no_of_hugepages() * hugepages_size() * 1024) / 2 ;
+	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
+		tst_brkm(TCONF, cleanup, "Not enough available Hugepages");
+	else
+		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
 
-	setup();			/* global setup */
+	setup();
 
-	if ((pid = fork()) == -1) {
-		tst_brkm(TBROK, cleanup, "could not fork");
-	}
-
-	if (pid == 0) {		/* child */
+	switch (pid = fork()) {
+	case -1:
+		tst_brkm(TBROK|TERRNO, cleanup, "fork");
+	case 0:
 		/* set  the user ID of the child to the non root user */
-		if (setuid(ltp_uid) == -1) {
-			tst_resm(TBROK, "setuid() failed");
-			exit(1);
-		}
-
+		if (setuid(ltp_uid) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "setuid");
 		do_child();
-	} else {
-		/* wait for the child to return */
-		if (waitpid(pid, NULL, 0) == -1) {
-			tst_brkm(TBROK, cleanup, "waitpid failed");
-		}
-
-		/* if it exists, remove the shared memory resource */
-		rm_shm(shm_id_1);
-
-		tst_rmdir();
+		tst_exit();
+	default:
+		if (waitpid(pid, &status, 0) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
 	}
-
-	cleanup ();
+	cleanup();
 	tst_exit();
 }
 
-/*
- * do_child - make the call as the child process
- */
-void
-do_child()
+static void do_child(void)
 {
 	int i, lc;
 
-	/* The following loop checks looping state if -i option given */
-
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset Tst_count in case we are looping */
 		Tst_count = 0;
 
-		/* loop through the test cases */
-		for (i=0; i<TST_TOTAL; i++) {
-			/*
-			 * use the TEST() macro to make the call
-			 */
-
+		for (i = 0; i < TST_TOTAL; i++) {
 			TEST(shmctl(*(TC[i].shmid), TC[i].cmd, TC[i].sbuf));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
-				continue;
-			}
-
-			TEST_ERROR_LOG(TEST_ERRNO);
-
-			if (TEST_ERRNO == TC[i].error) {
-				tst_resm(TPASS, "expected failure - errno = "
-					 "%d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TFAIL, "call failed with an "
-					 "unexpected error - %d : %s",
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-			}
+			if (TEST_ERRNO == TC[i].error)
+				tst_resm(TPASS|TTERRNO, "expected failure");
+			else
+				tst_resm(TFAIL|TTERRNO, "unexpected behavior "
+					    "- expected errno = %d, got",
+					    TC[i].error);
 		}
 	}
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void
-setup(void)
+void setup(void)
 {
-	/* check for root as process owner */
-	check_root();
-
+	tst_require_root(NULL);
 	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	/* Set up the expected error numbers for -e option */
-	TEST_EXP_ENOS(exp_enos);
-
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See ../lib/libipc.c for more information.
-	 */
 	tst_tmpdir();
 
-	/* get an IPC resource key */
 	shmkey = getipckey();
-
-	/* create a shared memory segment with read and write permissions */
-	if ((shm_id_1 = shmget(shmkey, huge_pages_shm_to_be_allocated, SHM_HUGETLB | IPC_CREAT | IPC_EXCL |
-	     SHM_RW)) == -1) {
-		tst_brkm(TBROK, cleanup, "couldn't create shared memory "
-			 "segment in setup()");
-	}
+	shm_id_1 = shmget(shmkey, shm_size,
+		    SHM_HUGETLB|IPC_CREAT|IPC_EXCL|SHM_RW);
+	if (shm_id_1 == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "shmget");
 
 	/* get the userid for a non root user */
 	ltp_uid = getuserid(ltp_user);
+
+	TEST_PAUSE;
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void
-cleanup(void)
+void cleanup(void)
 {
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
 	TEST_CLEANUP;
 
-}
\ No newline at end of file
+	rm_shm(shm_id_1);
+
+	tst_rmdir();
+}

[-- Attachment #3: Type: text/plain, Size: 381 bytes --]

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

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH 04/11] hugetlb/hugeshmctl: set nr_hugepages in tests
  2012-03-13  4:56 [LTP] [PATCH 00/11] hugetlb multiple fixes Caspar Zhang
                   ` (2 preceding siblings ...)
  2012-03-13  4:56 ` [LTP] [PATCH 03/11] hugetlb/hugeshmctl: cleanup codes Caspar Zhang
@ 2012-03-13  4:56 ` Caspar Zhang
  2012-03-13  6:23   ` Wanlong Gao
  2012-03-13  4:56 ` [LTP] [PATCH 05/11] hugetlb/hugeshmdt: cleanup codes Caspar Zhang
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Caspar Zhang @ 2012-03-13  4:56 UTC (permalink / raw)
  To: LTP List

[-- Attachment #1: Type: text/plain, Size: 487 bytes --]


This patch enables nr_hugepages set/restore in each test of hugeshmctl,
so that we don't need to set the values with external commands.

Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
 .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c   |   28 +++++++++++++++-----
 .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c   |   28 +++++++++++++++-----
 .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c   |   27 ++++++++++++++-----
 3 files changed, 62 insertions(+), 21 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0004-hugetlb-hugeshmctl-set-nr_hugepages-in-tests.patch --]
[-- Type: text/x-patch; name="0004-hugetlb-hugeshmctl-set-nr_hugepages-in-tests.patch", Size: 5603 bytes --]

diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c
index ce8d89a..4577c30 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c
@@ -62,7 +62,8 @@
  */
 
 #include "ipcshm.h"
-#include "system_specific_hugepages_info.h"
+#include "safe_macros.h"
+#include "mem.h"
 
 char *TCID = "hugeshmctl01";
 int TST_TOTAL = 4;
@@ -89,6 +90,12 @@ static void func_set(void);
 static void func_rmid(void);
 static void *set_shmat(void);
 
+static long hugepages = 128;
+static option_t options[] = {
+	{ "s:",	&sflag,	&nr_opt	},
+	{ NULL,	NULL,	NULL	}
+};
+
 struct test_case_t {
 	int  cmd;
 	void (*func_test)(void);
@@ -105,14 +112,11 @@ int main(int ac, char **av)
 	int lc, i;
 	char *msg;
 
-	msg = parse_opts(ac, av, NULL, NULL);
+	msg = parse_opts(ac, av, options, &help);
 	if (msg != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-
-	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-		tst_brkm(TCONF, NULL, "Not enough available Hugepages");
-	else
-		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
+	if (sflag)
+		hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);
 
 	setup();
 
@@ -397,9 +401,17 @@ static void sighandler(int sig)
 
 void setup(void)
 {
+	long hpage_size;
+
+	tst_require_root(NULL);
 	tst_sig(FORK, sighandler, cleanup);
 	tst_tmpdir();
 
+	orig_hugepages = get_sys_tune("nr_hugepages");
+	set_sys_tune("nr_hugepages", hugepages, 1);
+	hpage_size = read_meminfo("Hugepagesize:") * 1024;
+
+	shm_size = hpage_size * hugepages / 2;
 	shmkey = getipckey();
 
 	TEST_PAUSE;
@@ -411,5 +423,7 @@ void cleanup(void)
 
 	rm_shm(shm_id_1);
 
+	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+
 	tst_rmdir();
 }
diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c
index 15cadb0..568f790 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c
@@ -54,7 +54,8 @@
 
 #include <pwd.h>
 #include "ipcshm.h"
-#include "system_specific_hugepages_info.h"
+#include "safe_macros.h"
+#include "mem.h"
 
 char *TCID = "hugeshmctl02";
 int TST_TOTAL = 4;
@@ -65,6 +66,12 @@ static int shm_id_2 = -1;
 static int shm_id_3 = -1;
 static struct shmid_ds buf;
 
+static long hugepages = 128;
+static option_t options[] = {
+	{ "s:",	&sflag,	&nr_opt	},
+	{ NULL,	NULL,	NULL	}
+};
+
 struct test_case_t {
 	int *shmid;
 	int cmd;
@@ -89,14 +96,11 @@ int main(int ac, char **av)
 	int lc, i;
 	char *msg;
 
-	msg = parse_opts(ac, av, NULL, NULL);
+	msg = parse_opts(ac, av, options, &help);
 	if (msg != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-
-	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-		tst_brkm(TCONF, NULL, "Not enough available Hugepages");
-	else
-		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
+	if (sflag)
+		hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);
 
 	setup();
 
@@ -119,9 +123,17 @@ int main(int ac, char **av)
 
 void setup(void)
 {
+	long hpage_size;
+
+	tst_require_root(NULL);
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 	tst_tmpdir();
 
+	orig_hugepages = get_sys_tune("nr_hugepages");
+	set_sys_tune("nr_hugepages", hugepages, 1);
+	hpage_size = read_meminfo("Hugepagesize:") * 1024;
+
+	shm_size = hpage_size * hugepages / 2;
 	shmkey = getipckey();
 
 	/* create a shared memory segment without read or write permissions */
@@ -145,5 +157,7 @@ void cleanup(void)
 	rm_shm(shm_id_1);
 	rm_shm(shm_id_2);
 
+	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+
 	tst_rmdir();
 }
diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c
index 30353b8..e0e8606 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c
@@ -61,7 +61,8 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include "ipcshm.h"
-#include "system_specific_hugepages_info.h"
+#include "safe_macros.h"
+#include "mem.h"
 
 char *TCID = "hugeshmctl03";
 int TST_TOTAL = 3;
@@ -72,6 +73,12 @@ static struct shmid_ds buf;
 static uid_t ltp_uid;
 static char *ltp_user = "nobody";
 
+static long hugepages = 128;
+static option_t options[] = {
+	{ "s:",	&sflag,	&nr_opt	},
+	{ NULL,	NULL,	NULL	}
+};
+
 struct test_case_t {
 	int *shmid;
 	int cmd;
@@ -96,14 +103,11 @@ int main(int ac, char **av)
 	pid_t pid;
 	int status;
 
-	msg = parse_opts(ac, av, NULL, NULL);
+	msg = parse_opts(ac, av, options, &help);
 	if (msg != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-
-	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-		tst_brkm(TCONF, cleanup, "Not enough available Hugepages");
-	else
-		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
+	if (sflag)
+		hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);
 
 	setup();
 
@@ -145,10 +149,17 @@ static void do_child(void)
 
 void setup(void)
 {
+	long hpage_size;
+
 	tst_require_root(NULL);
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 	tst_tmpdir();
 
+	orig_hugepages = get_sys_tune("nr_hugepages");
+	set_sys_tune("nr_hugepages", hugepages, 1);
+	hpage_size = read_meminfo("Hugepagesize:") * 1024;
+
+	shm_size = hpage_size * hugepages / 2;
 	shmkey = getipckey();
 	shm_id_1 = shmget(shmkey, shm_size,
 		    SHM_HUGETLB|IPC_CREAT|IPC_EXCL|SHM_RW);
@@ -167,5 +178,7 @@ void cleanup(void)
 
 	rm_shm(shm_id_1);
 
+	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+
 	tst_rmdir();
 }

[-- Attachment #3: Type: text/plain, Size: 381 bytes --]

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

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH 05/11] hugetlb/hugeshmdt: cleanup codes
  2012-03-13  4:56 [LTP] [PATCH 00/11] hugetlb multiple fixes Caspar Zhang
                   ` (3 preceding siblings ...)
  2012-03-13  4:56 ` [LTP] [PATCH 04/11] hugetlb/hugeshmctl: set nr_hugepages in tests Caspar Zhang
@ 2012-03-13  4:56 ` Caspar Zhang
  2012-03-13  4:56 ` [LTP] [PATCH 06/11] hugetlb/hugeshmdt: set nr_hugepages in tests Caspar Zhang
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Caspar Zhang @ 2012-03-13  4:56 UTC (permalink / raw)
  To: LTP List

[-- Attachment #1: Type: text/plain, Size: 254 bytes --]


Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
 testcases/kernel/mem/hugetlb/hugeshmdt/Makefile    |    2 +-
 .../kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c     |  153 +++++++-------------
 2 files changed, 52 insertions(+), 103 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0005-hugetlb-hugeshmdt-cleanup-codes.patch --]
[-- Type: text/x-patch; name="0005-hugetlb-hugeshmdt-cleanup-codes.patch", Size: 6547 bytes --]

diff --git a/testcases/kernel/mem/hugetlb/hugeshmdt/Makefile b/testcases/kernel/mem/hugetlb/hugeshmdt/Makefile
index cea6939..812b7f2 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmdt/Makefile
+++ b/testcases/kernel/mem/hugetlb/hugeshmdt/Makefile
@@ -20,7 +20,7 @@
 # Garrett Cooper, July 2009
 #
 
-top_srcdir              ?= ../../../../..
+top_srcdir		?= ../../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 include $(abs_srcdir)/../Makefile.inc
diff --git a/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c b/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c
index f8764b3..402aaa1 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c
@@ -35,7 +35,7 @@
  *		attempt to write a value to the large shared memory address
  *		this should generate a SIGSEGV which will be caught in
  *		    the signal handler
- *	  	if correct,
+ *		if correct,
  *			issue a PASS message
  *		otherwise
  *			issue a FAIL message
@@ -63,84 +63,62 @@
 
 char *TCID = "hugeshmdt01";
 int TST_TOTAL = 1;
-unsigned long huge_pages_shm_to_be_allocated;
 
-void sighandler(int);
+static size_t shm_size;
+static int shm_id_1 = -1;
 struct shmid_ds buf;
+static int *shared;
+static int pass;
+static sigjmp_buf env;
 
-int shm_id_1 = -1;
-int *shared;		/* variable to use for shared memory attach */
-int new;
-int pass = 0;
-sigjmp_buf env;
+static void check_functionality(void);
+static void sighandler(int sig);
 
 int main(int ac, char **av)
 {
-	int lc;				/* loop counter */
-	char *msg;			/* message returned from parse_opts */
-	void check_functionality(void);
+	int lc;
+	char *msg;
 
-	/* parse standard options */
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
-		tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
+	msg = parse_opts(ac, av, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
-        if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-             tst_brkm(TCONF, NULL, "Not enough available Hugepages");
-        else
-             huge_pages_shm_to_be_allocated = ( get_no_of_hugepages() * hugepages_size() * 1024) / 2 ;
+	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
+		tst_brkm(TCONF, NULL, "Not enough available Hugepages");
+	else
+		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
 
-	setup();			/* global setup */
-
-	/* The following loop checks looping state if -i option given */
+	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset Tst_count in case we are looping */
 		Tst_count = 0;
 
-		/*
-		 * Use TEST macro to make the shmdt() call
-		 */
-
-		TEST(shmdt((const void *)shared));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "%s call failed - errno = %d : %s",
-				 TCID, TEST_ERRNO, strerror(TEST_ERRNO));
+		if (shmdt(shared) == -1) {
+			tst_resm(TFAIL|TERRNO, "shmdt");
 		} else {
-			if (STD_FUNCTIONAL_TEST) {
+			if (STD_FUNCTIONAL_TEST)
 				check_functionality();
-			} else {
+			else
 				tst_resm(TPASS, "call succeeded");
-			}
 		}
 
 		/* reattach the shared memory segment in case we are looping */
-		shared = (int*)shmat(shm_id_1, 0, 0);
-
-		if (*shared == -1) {
-			tst_brkm(TBROK, cleanup, "memory reattach failed");
-		}
+		shared = shmat(shm_id_1, 0, 0);
+		if (shared == (void *)-1)
+			tst_brkm(TBROK|TERRNO, cleanup, "shmat #2: reattach");
 
 		/* also reset pass */
 		pass = 0;
 	}
-
 	cleanup();
-
 	tst_exit();
 }
 
-/*
- * check_functionality() - make sure the memory is detached correctly
- */
-void
-check_functionality()
+static void check_functionality(void)
 {
 	/* stat the shared memory segment */
-	if (shmctl(shm_id_1, IPC_STAT, &buf) == -1) {
-		tst_resm(TINFO, "error = %d : %s\n", errno, strerror(errno));
-		tst_brkm(TBROK, cleanup, "could not stat in signal handler");
-	}
+	if (shmctl(shm_id_1, IPC_STAT, &buf) == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "shmctl");
 
 	if (buf.shm_nattch != 0) {
 		tst_resm(TFAIL, "# of attaches is incorrect");
@@ -161,87 +139,58 @@ check_functionality()
 	 * of the signal handler and another SIGSEGV will be generated.
 	 */
 
-	if (sigsetjmp(env, 1) == 0) {
+	if (sigsetjmp(env, 1) == 0)
 		*shared = 2;
-	}
 
-	if (pass) {
+	if (pass)
 		tst_resm(TPASS, "huge shared memory detached correctly");
-	} else {
-		tst_resm(TFAIL, "huge shared memory was not detached correctly");
-	}
+	else
+		tst_resm(TFAIL, "huge shared memory was not detached "
+				"correctly");
 }
 
-/*
- * sighandler()
- */
-void
-sighandler(sig)
+static void sighandler(int sig)
 {
 	/* if we have received a SIGSEGV, we are almost done */
 	if (sig == SIGSEGV) {
 		/* set the global variable and jump back */
 		pass = 1;
 		siglongjmp(env, 1);
-	} else
-		tst_brkm(TBROK, cleanup, "received an unexpected signal");
+	} else {
+		tst_brkm(TBROK, cleanup, "unexpected signal received: %d",
+			    sig);
+	}
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void
-setup(void)
+void setup(void)
 {
-
 	tst_sig(NOFORK, sighandler, cleanup);
-
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See ../lib/libipc.c for more information.
-	 */
 	tst_tmpdir();
 
-	/* get an IPC resource key */
 	shmkey = getipckey();
 
 	/* create a shared memory resource with read and write permissions */
-	if ((shm_id_1 = shmget(shmkey, huge_pages_shm_to_be_allocated, SHM_HUGETLB | SHM_RW | IPC_CREAT |
-	     IPC_EXCL)) == -1) {
-		tst_brkm(TBROK, cleanup, "Failed to create shared memory "
-			 "resource in setup()");
-	}
+	shm_id_1 = shmget(shmkey, shm_size,
+		    SHM_HUGETLB|SHM_RW|IPC_CREAT|IPC_EXCL);
+	if (shm_id_1 == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "shmget");
 
 	/* attach the shared memory segment */
-	shared = (int*)shmat(shm_id_1, 0, 0);
-
-	if (*shared == -1) {
-		tst_brkm(TBROK, cleanup, "Couldn't attach shared memory");
-	}
+	shared = shmat(shm_id_1, 0, 0);
+	if (shared == (void *)-1)
+		tst_brkm(TBROK|TERRNO, cleanup, "shmat #1");
 
 	/* give a value to the shared memory integer */
 	*shared = 4;
+
+	TEST_PAUSE;
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void
-cleanup(void)
+void cleanup(void)
 {
-	/* if it exists, delete the shared memory resource */
+	TEST_CLEANUP;
+
 	rm_shm(shm_id_1);
 
 	tst_rmdir();
-
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
-	TEST_CLEANUP;
-
 }

[-- Attachment #3: Type: text/plain, Size: 381 bytes --]

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

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH 06/11] hugetlb/hugeshmdt: set nr_hugepages in tests
  2012-03-13  4:56 [LTP] [PATCH 00/11] hugetlb multiple fixes Caspar Zhang
                   ` (4 preceding siblings ...)
  2012-03-13  4:56 ` [LTP] [PATCH 05/11] hugetlb/hugeshmdt: cleanup codes Caspar Zhang
@ 2012-03-13  4:56 ` Caspar Zhang
  2012-03-13  6:24   ` Wanlong Gao
  2012-03-13  4:56 ` [LTP] [PATCH 07/11] hugetlb/hugeshmget: cleanup codes Caspar Zhang
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Caspar Zhang @ 2012-03-13  4:56 UTC (permalink / raw)
  To: LTP List

[-- Attachment #1: Type: text/plain, Size: 326 bytes --]


This patch enables nr_hugepages set/restore in each test of hugeshmdt,
so that we don't need to set the values with external commands.

Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
 .../kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c     |   28 +++++++++++++++-----
 1 files changed, 21 insertions(+), 7 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0006-hugetlb-hugeshmdt-set-nr_hugepages-in-tests.patch --]
[-- Type: text/x-patch; name="0006-hugetlb-hugeshmdt-set-nr_hugepages-in-tests.patch", Size: 1865 bytes --]

diff --git a/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c b/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c
index 402aaa1..c107a76 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c
@@ -59,7 +59,8 @@
 
 #include <setjmp.h>
 #include "ipcshm.h"
-#include "system_specific_hugepages_info.h"
+#include "safe_macros.h"
+#include "mem.h"
 
 char *TCID = "hugeshmdt01";
 int TST_TOTAL = 1;
@@ -71,6 +72,12 @@ static int *shared;
 static int pass;
 static sigjmp_buf env;
 
+static long hugepages = 128;
+static option_t options[] = {
+	{ "s:",	&sflag,	&nr_opt	},
+	{ NULL,	NULL,	NULL	}
+};
+
 static void check_functionality(void);
 static void sighandler(int sig);
 
@@ -79,14 +86,11 @@ int main(int ac, char **av)
 	int lc;
 	char *msg;
 
-	msg = parse_opts(ac, av, NULL, NULL);
+	msg = parse_opts(ac, av, options, &help);
 	if (msg != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-
-	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-		tst_brkm(TCONF, NULL, "Not enough available Hugepages");
-	else
-		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
+	if (sflag)
+		hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);
 
 	setup();
 
@@ -164,9 +168,17 @@ static void sighandler(int sig)
 
 void setup(void)
 {
+	long hpage_size;
+
+	tst_require_root(NULL);
 	tst_sig(NOFORK, sighandler, cleanup);
 	tst_tmpdir();
 
+	orig_hugepages = get_sys_tune("nr_hugepages");
+	set_sys_tune("nr_hugepages", hugepages, 1);
+	hpage_size = read_meminfo("Hugepagesize:") * 1024;
+
+	shm_size = hpage_size * hugepages / 2;
 	shmkey = getipckey();
 
 	/* create a shared memory resource with read and write permissions */
@@ -192,5 +204,7 @@ void cleanup(void)
 
 	rm_shm(shm_id_1);
 
+	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+
 	tst_rmdir();
 }

[-- Attachment #3: Type: text/plain, Size: 381 bytes --]

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

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH 07/11] hugetlb/hugeshmget: cleanup codes
  2012-03-13  4:56 [LTP] [PATCH 00/11] hugetlb multiple fixes Caspar Zhang
                   ` (5 preceding siblings ...)
  2012-03-13  4:56 ` [LTP] [PATCH 06/11] hugetlb/hugeshmdt: set nr_hugepages in tests Caspar Zhang
@ 2012-03-13  4:56 ` Caspar Zhang
  2012-03-13  4:56 ` [LTP] [PATCH 08/11] hugetlb/hugeshmget: set nr_hugepages in tests Caspar Zhang
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Caspar Zhang @ 2012-03-13  4:56 UTC (permalink / raw)
  To: LTP List

[-- Attachment #1: Type: text/plain, Size: 486 bytes --]


Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
 testcases/kernel/mem/hugetlb/hugeshmget/Makefile   |    2 +-
 .../kernel/mem/hugetlb/hugeshmget/hugeshmget01.c   |  108 +++++---------
 .../kernel/mem/hugetlb/hugeshmget/hugeshmget02.c   |  152 ++++++-------------
 .../kernel/mem/hugetlb/hugeshmget/hugeshmget03.c   |  136 ++++++------------
 .../kernel/mem/hugetlb/hugeshmget/hugeshmget05.c   |  154 ++++++--------------
 5 files changed, 179 insertions(+), 373 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0007-hugetlb-hugeshmget-cleanup-codes.patch --]
[-- Type: text/x-patch; name="0007-hugetlb-hugeshmget-cleanup-codes.patch", Size: 22376 bytes --]

diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/Makefile b/testcases/kernel/mem/hugetlb/hugeshmget/Makefile
index 54b5709..266bc4d 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/Makefile
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/Makefile
@@ -16,7 +16,7 @@
 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
 
-top_srcdir              ?= ../../../../..
+top_srcdir		?= ../../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 include $(abs_srcdir)/../Makefile.inc
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c
index d8160ea..9bdf029 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c
@@ -22,7 +22,8 @@
  *	hugeshmget01.c
  *
  * DESCRIPTION
- *	hugeshmget01 - test that shmget() correctly creates a large shared memory segment
+ *	hugeshmget01 - test that shmget() correctly creates a large
+ *			shared memory segment
  *
  * ALGORITHM
  *	loop if that option was specified
@@ -33,7 +34,7 @@
  *	  if doing functionality testing
  *		stat the shared memory resource
  *		check the size, creator pid and mode
- *	  	if correct,
+ *		if correct,
  *			issue a PASS message
  *		otherwise
  *			issue a FAIL message
@@ -63,61 +64,52 @@
 char *TCID = "hugeshmget01";
 int TST_TOTAL = 1;
 
-int shm_id_1 = -1;
+static int shm_id_1 = -1;
 
 int main(int ac, char **av)
 {
-	int lc;				/* loop counter */
-	char *msg;			/* message returned from parse_opts */
+	int lc;
+	char *msg;
 	struct shmid_ds buf;
-        unsigned long huge_pages_shm_to_be_allocated;
+	size_t shm_size;
 
-	huge_pages_shm_to_be_allocated = 0;
+	shm_size = 0;
 
-	/* parse standard options */
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
-		tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
+	msg = parse_opts(ac, av, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
-	/* The following loop checks looping state if -i option given */
-        if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-             tst_brkm(TCONF, NULL, "Not enough available Hugepages");
-        else
-              huge_pages_shm_to_be_allocated = ( get_no_of_hugepages() * hugepages_size() * 1024) / 2 ;
+	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
+		tst_brkm(TCONF, NULL, "Not enough available Hugepages");
+	else
+		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
 
-	setup();			/* global setup */
+	setup();
 
-        for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset Tst_count in case we are looping */
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		Tst_count = 0;
 
-		/*
-		 * Use TEST macro to make the call
-		 */
-
-                TEST(shmget(shmkey, huge_pages_shm_to_be_allocated, (SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW)));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "%s call failed - errno = %d : %s",
-				 TCID, TEST_ERRNO, strerror(TEST_ERRNO));
+		shm_id_1 = shmget(shmkey, shm_size,
+			    SHM_HUGETLB|IPC_CREAT|IPC_EXCL|SHM_RW);
+		if (shm_id_1 == -1) {
+			tst_resm(TFAIL|TERRNO, "shmget");
 		} else {
-			shm_id_1 = TEST_RETURN;
 			if (STD_FUNCTIONAL_TEST) {
 				/* do a STAT and check some info */
 				if (shmctl(shm_id_1, IPC_STAT, &buf) == -1) {
-					tst_resm(TBROK, "shmctl failed in "
-						 "functional test");
+					tst_resm(TBROK|TERRNO, "shmctl");
 					continue;
 				}
 				/* check the seqment size */
-				if (buf.shm_segsz != huge_pages_shm_to_be_allocated) {
+				if (buf.shm_segsz != shm_size) {
 					tst_resm(TFAIL, "seqment size is not "
-						 "correct");
+							"correct");
 					continue;
 				}
 				/* check the pid of the creator */
 				if (buf.shm_cpid != getpid()) {
 					tst_resm(TFAIL, "creator pid is not "
-						 "correct");
+							"correct");
 					continue;
 				}
 				/*
@@ -125,9 +117,9 @@ int main(int ac, char **av)
 				 * mask out all but the lower 9 bits
 				 */
 				if ((buf.shm_perm.mode & MODE_MASK) !=
-				    ((SHM_RW) & MODE_MASK)) {
+					    ((SHM_RW) & MODE_MASK)) {
 					tst_resm(TFAIL, "segment mode is not "
-						 "correct");
+							"correct");
 					continue;
 				}
 				/* if we get here, everything looks good */
@@ -140,56 +132,30 @@ int main(int ac, char **av)
 		/*
 		 * clean up things in case we are looping
 		 */
-		if (shmctl(shm_id_1, IPC_RMID, NULL) == -1) {
-			tst_resm(TBROK, "couldn't remove shared memory");
-		} else {
+		if (shmctl(shm_id_1, IPC_RMID, NULL) == -1)
+			tst_resm(TBROK|TERRNO, "shmctl");
+		else
 			shm_id_1 = -1;
-		}
 	}
-
 	cleanup();
-
-      tst_exit();
+	tst_exit();
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void
-setup(void)
+void setup(void)
 {
-
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See ../lib/libipc.c for more information.
-	 */
 	tst_tmpdir();
 
-	/* get an IPC resource key */
 	shmkey = getipckey();
+
+	TEST_PAUSE;
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void
-cleanup(void)
+void cleanup(void)
 {
-	/* if it exists, remove the shared memory resource */
+	TEST_CLEANUP;
+
 	rm_shm(shm_id_1);
 
 	tst_rmdir();
-
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
-	TEST_CLEANUP;
-
 }
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c
index 67f62b7..a2f3a51 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c
@@ -56,138 +56,82 @@
 
 char *TCID = "hugeshmget02";
 int TST_TOTAL = 4;
-unsigned long huge_pages_shm_to_be_allocated;
 
-int exp_enos[] = {ENOENT, EEXIST, EINVAL, 0};	/* 0 terminated list of */
-						/* expected errnos 	*/
-
-int shm_id_1 = -1;
-int shm_id_2 = -1;
-int shmkey2;
+static size_t shm_size;
+static int shm_id_1 = -1;
+static int shm_id_2 = -1;
+static key_t shmkey2;
 
 struct test_case_t {
 	int *skey;
-	int size;
+	int size_coe;
 	int flags;
 	int error;
+} TC[] = {
+	/* EINVAL - size is 0 */
+	{ &shmkey2,  0, SHM_HUGETLB|IPC_CREAT|IPC_EXCL|SHM_RW,	EINVAL },
+	/* EINVAL - size is larger than created segment */
+	{ &shmkey,   2, SHM_HUGETLB|SHM_RW,			EINVAL },
+	/* EEXIST - the segment exists and IPC_CREAT | IPC_EXCL is given */
+	{ &shmkey,   1, SHM_HUGETLB|IPC_CREAT|IPC_EXCL|SHM_RW,	EEXIST },
+	/* ENOENT - no segment exists for the key and IPC_CREAT is not given */
+	/* use shm_id_2 (-1) as the key */
+	{ &shm_id_2, 1, SHM_HUGETLB|SHM_RW,			ENOENT }
 };
 
-int main(int ac, char **av) {
-	int lc;				/* loop counter */
-	char *msg;			/* message returned from parse_opts */
-	int i;
-
-	/* parse standard options */
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
-		tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
-
-        if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-             tst_brkm(TCONF, NULL, "Not enough available Hugepages");
-        else
-             huge_pages_shm_to_be_allocated = ( get_no_of_hugepages() * hugepages_size() * 1024) / 2 ;
-
-        struct test_case_t TC[] = {
-         /* EINVAL - size is 0 */
-         {&shmkey2, 0, SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW, EINVAL},
-         /* EINVAL - size is negative */
-         //{&shmkey2, -1, SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW, EINVAL},
-         /* EINVAL - size is larger than created segment */
-         {&shmkey, huge_pages_shm_to_be_allocated * 2, SHM_HUGETLB | SHM_RW, EINVAL},
-         /* EEXIST - the segment exists and IPC_CREAT | IPC_EXCL is given */
-         {&shmkey, huge_pages_shm_to_be_allocated, SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW, EEXIST},
-         /* ENOENT - no segment exists for the key and IPC_CREAT is not given */
-         /* use shm_id_2 (-1) as the key */
-         {&shm_id_2, huge_pages_shm_to_be_allocated, SHM_HUGETLB | SHM_RW, ENOENT}
-        };
-
-	setup();			/* global setup */
-
-	/* The following loop checks looping state if -i option given */
+int main(int ac, char **av)
+{
+	int lc, i;
+	char *msg;
+
+	msg = parse_opts(ac, av, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
+		tst_brkm(TCONF, NULL, "Not enough available Hugepages");
+	else
+		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
+
+	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset Tst_count in case we are looping */
 		Tst_count = 0;
 
-		/* loop through the test cases */
-		for (i=0; i<TST_TOTAL; i++) {
-			/*
-			 * Look for a failure ...
-			 */
-
-			TEST(shmget(*(TC[i].skey), TC[i].size, TC[i].flags));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
-				continue;
-			}
-
-			TEST_ERROR_LOG(TEST_ERRNO);
-
-			if (TEST_ERRNO == TC[i].error) {
-				tst_resm(TPASS, "expected failure - errno = "
-					 "%d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TFAIL, "call failed with an "
-					 "unexpected error - %d : %s",
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-			}
+		for (i = 0; i < TST_TOTAL; i++) {
+			TEST(shmget(*(TC[i].skey), TC[i].size_coe*shm_size,
+				    TC[i].flags));
+			if (TEST_ERRNO == TC[i].error)
+				tst_resm(TPASS|TTERRNO, "expected failure");
+			else
+				tst_resm(TFAIL|TTERRNO, "unexpected behavior "
+					    "- expected errno = %d, got",
+					    TC[i].error);
 		}
 	}
-
 	cleanup();
-
 	tst_exit();
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void
-setup(void)
+void setup(void)
 {
-
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	/* Set up the expected error numbers for -e option */
-	TEST_EXP_ENOS(exp_enos);
-
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See ../lib/libipc.c for more information.
-	 */
 	tst_tmpdir();
 
-	/* get an IPC resource key */
 	shmkey = getipckey();
-
 	shmkey2 = shmkey + 1;
+	shm_id_1 = shmget(shmkey, shm_size, IPC_CREAT|IPC_EXCL|SHM_RW);
+	if (shm_id_1 == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "shmget #1");
 
-	if ((shm_id_1 = shmget(shmkey, huge_pages_shm_to_be_allocated, IPC_CREAT | IPC_EXCL | SHM_RW)) == -1) {
-		tst_brkm(TBROK, cleanup, "couldn't create shared memory segment in setup()");
-	}
-
+	TEST_PAUSE;
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void
-cleanup(void)
+void cleanup(void)
 {
-	/* if it exists, remove the shared memory resource */
+	TEST_CLEANUP;
+
 	rm_shm(shm_id_1);
 
 	tst_rmdir();
-
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
-	TEST_CLEANUP;
-
-}
\ No newline at end of file
+}
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
index 9b572fa..dfaecc5 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
@@ -25,7 +25,8 @@
  *	hugeshmget03 - test for ENOSPC error
  *
  * ALGORITHM
- *	create large shared memory segments in a loop until reaching the system limit
+ *	create large shared memory segments in a loop until reaching
+ *		the system limit
  *	loop if that option was specified
  *	  attempt to create yet another shared memory segment
  *	  check the errno value
@@ -57,139 +58,94 @@
 char *TCID = "hugeshmget03";
 int TST_TOTAL = 1;
 
-int exp_enos[] = {ENOSPC, 0};	/* 0 terminated list of expected errnos */
-void setup2(unsigned long huge_pages_shm_to_be_allocated);
 /*
  * The MAXIDS value is somewhat arbitrary and may need to be increased
  * depending on the system being tested.
  */
 #define MAXIDS	8192
 
-int shm_id_1 = -1;
-int num_shms = 0;
+static int shm_id_1 = -1;
+static int num_shms;
+static int shm_id_arr[MAXIDS];
 
-int shm_id_arr[MAXIDS];
+static void setup2(size_t shm_size);
 
 int main(int ac, char **av)
 {
-	int lc;				/* loop counter */
-	char *msg;			/* message returned from parse_opts */
-        unsigned long huge_pages_shm_to_be_allocated;
+	int lc;
+	char *msg;
+	size_t shm_size;
 
-	huge_pages_shm_to_be_allocated = 0;
+	shm_size = 0;
 
-	/* parse standard options */
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
-		tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
+	msg = parse_opts(ac, av, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
-	/* The following loop checks looping state if -i option given */
-        if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-             tst_brkm(TCONF, NULL, "Not enough available Hugepages");
-        else
-             huge_pages_shm_to_be_allocated = ( get_no_of_hugepages() * hugepages_size() * 1024) / 2 ;
+	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
+		tst_brkm(TCONF, NULL, "Not enough available Hugepages");
+	else
+		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
 
-	setup2(huge_pages_shm_to_be_allocated);			/* local  setup */
+	setup2(shm_size);
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset Tst_count in case we are looping */
 		Tst_count = 0;
 
-		/*
-		 * use the TEST() macro to make the call
-		 */
-
-		TEST(shmget(IPC_PRIVATE, huge_pages_shm_to_be_allocated, SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW));
-
+		TEST(shmget(IPC_PRIVATE, shm_size,
+			    SHM_HUGETLB|IPC_CREAT|IPC_EXCL|SHM_RW));
 		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "call succeeded when error expected");
+			tst_resm(TFAIL, "unexpected success");
 			continue;
 		}
-
-		TEST_ERROR_LOG(TEST_ERRNO);
-
-		switch(TEST_ERRNO) {
-		case ENOSPC:
-			tst_resm(TPASS, "expected failure - errno = "
-				 "%d : %s", TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		default:
-			tst_resm(TFAIL, "call failed with an "
-				 "unexpected error - %d : %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		}
+		if (TEST_ERRNO == ENOSPC)
+			tst_resm(TPASS|TERRNO, "expected failure");
+		else
+			tst_resm(TFAIL|TTERRNO, "unexpect failure "
+					"- expect errno %d, got", ENOSPC);
 	}
-
 	cleanup();
-
 	tst_exit();
 }
 
-/*
- * setup2() - performs all the ONE TIME setup for this test.
- */
-void setup2(unsigned long huge_pages_shm_to_be_allocated) {
-
+static void setup2(size_t shm_size)
+{
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	/* Set up the expected error numbers for -e option */
-	TEST_EXP_ENOS(exp_enos);
-
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See ../lib/libipc.c for more information.
-	 */
 	tst_tmpdir();
 
-	/* get an IPC resource key */
 	shmkey = getipckey();
 
 	/*
 	 * Use a while loop to create the maximum number of memory segments.
 	 * If the loop exceeds MAXIDS, then break the test and cleanup.
 	 */
-	while ((shm_id_1 = shmget(IPC_PRIVATE, huge_pages_shm_to_be_allocated, SHM_HUGETLB | IPC_CREAT |
-	     IPC_EXCL | SHM_RW)) != -1) {
+	num_shms = 0;
+	shm_id_1 = shmget(IPC_PRIVATE, shm_size,
+			SHM_HUGETLB|IPC_CREAT|IPC_EXCL|SHM_RW);
+	while (shm_id_1 != -1) {
 		shm_id_arr[num_shms++] = shm_id_1;
-		if (num_shms == MAXIDS) {
-			tst_brkm(TBROK, cleanup, "The maximum number of shared "
-				 "memory ID's has been\n\t reached.  Please "
-				 "increase the MAXIDS value in the test.");
-		}
+		if (num_shms == MAXIDS)
+			tst_brkm(TBROK, cleanup, "The maximum number of "
+				    "shared memory ID's has been reached. "
+				    "Please increase the MAXIDS value in "
+				    "the test.");
+		shm_id_1 = shmget(IPC_PRIVATE, shm_size,
+			    SHM_HUGETLB|IPC_CREAT|IPC_EXCL|SHM_RW);
 	}
+	if (errno != ENOSPC)
+		tst_brkm(TBROK|TERRNO, cleanup, "shmget #1");
 
-	/*
-	 * If the errno is other than ENOSPC, then something else is wrong.
-	 */
-	if (errno != ENOSPC) {
-		tst_resm(TINFO, "errno = %d : %s", errno, strerror(errno));
-		tst_brkm(TBROK, cleanup, "Didn't get ENOSPC in test setup");
-	}
+	TEST_PAUSE;
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void
-cleanup(void)
+void cleanup(void)
 {
 	int i;
 
-	/* remove the shared memory resources that were created */
-	for (i=0; i<num_shms; i++) {
+	TEST_CLEANUP;
+
+	for (i = 0; i < num_shms; i++)
 		rm_shm(shm_id_arr[i]);
-	}
 
 	tst_rmdir();
-
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
-	TEST_CLEANUP;
-
 }
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c
index ff98e1d..9242a34 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c
@@ -25,7 +25,8 @@
  *	hugeshmget05 - test for EACCES error
  *
  * ALGORITHM
- *	create a large shared memory segment with root only read & write permissions
+ *	create a large shared memory segment with root only read & write
+ *		permissions
  *	fork a child process
  *	if child
  *	  set the ID of the child process to that of "nobody"
@@ -57,160 +58,99 @@
  *	test must be run at root
  */
 
-#include "ipcshm.h"
 #include <sys/types.h>
 #include <sys/wait.h>
+#include "ipcshm.h"
 #include "system_specific_hugepages_info.h"
 
 char *TCID = "hugeshmget05";
 int TST_TOTAL = 1;
-unsigned long huge_pages_shm_to_be_allocated;
-
-int exp_enos[] = {EACCES, 0};	/* 0 terminated list of expected errnos */
 
-int shm_id_1 = -1;
+static size_t shm_size;
+static int shm_id_1 = -1;
+static uid_t ltp_uid;
+static char *ltp_user = "nobody";
 
-uid_t ltp_uid;
-char *ltp_user = "nobody";
+static void do_child(void);
 
 int main(int ac, char **av)
 {
-	char *msg;			/* message returned from parse_opts */
+	char *msg;
 	pid_t pid;
 	int status;
-	void do_child(void);
 
-	/* parse standard options */
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
-		tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
+	msg = parse_opts(ac, av, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
-        if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-             tst_brkm(TCONF, cleanup, "Not enough available Hugepages");
-        else
-             huge_pages_shm_to_be_allocated = ( get_no_of_hugepages() * hugepages_size() * 1024) / 2 ;
+	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
+		tst_brkm(TCONF, cleanup, "Not enough available Hugepages");
+	else
+		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
 
-	setup();			/* global setup */
-
-	if ((pid = fork()) == -1) {
-		tst_brkm(TBROK, cleanup, "could not fork");
-	}
+	setup();
 
-	if (pid == 0) {		/* child */
+	switch (pid = fork()) {
+	case -1:
+		tst_brkm(TBROK|TERRNO, cleanup, "fork");
+	case 0:
 		/* set the user ID of the child to the non root user */
-		if (setuid(ltp_uid) == -1) {
-			tst_resm(TBROK, "setuid() failed");
-			exit(1);
-		}
-
+		if (setuid(ltp_uid) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "setuid");
 		do_child();
-
 		tst_exit();
-
-	} else {		/* parent */
+	default:
 		/* wait for the child to return */
-		if (waitpid(pid, &status, 0) == -1) {
-			tst_resm(TBROK, "waitpid failed");
-		}
-		else if (status != 0) {
-			tst_resm(TFAIL,	"child process failed to exit cleanly "
-				"(exit status = %d)", status);
-		}
+		if (waitpid(pid, &status, 0) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
 	}
-
 	cleanup();
-
 	tst_exit();
 }
 
-/*
- * do_child - make the TEST call as the child process
- */
-void
-do_child()
+static void do_child(void)
 {
 	int lc;
 
-	/* The following loop checks looping state if -i option given */
-
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset Tst_count in case we are looping */
 		Tst_count = 0;
 
-		/*
-		 * Look for a failure ...
-		 */
-
-		TEST(shmget(shmkey, huge_pages_shm_to_be_allocated, SHM_HUGETLB | SHM_RW));
-
+		TEST(shmget(shmkey, shm_size, SHM_HUGETLB|SHM_RW));
 		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "call succeeded when error expected");
+			tst_resm(TFAIL, "unexpected success");
 			continue;
 		}
-
-		TEST_ERROR_LOG(TEST_ERRNO);
-
-		switch(TEST_ERRNO) {
-		case EACCES:
+		if (TEST_ERRNO == EACCES)
 			tst_resm(TPASS|TTERRNO, "expected failure");
-			break;
-		default:
-			tst_resm(TFAIL|TTERRNO, "call failed with an "
-				 "unexpected error");
-			break;
-		}
+		else
+			tst_resm(TFAIL|TTERRNO, "unexpect failure "
+					"- expect errno %d, got", EACCES);
 	}
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void
-setup(void)
+void setup(void)
 {
-	/* check for root as process owner */
-	check_root();
-
+	tst_require_root(NULL);
 	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	/* Set up the expected error numbers for -e option */
-	TEST_EXP_ENOS(exp_enos);
-
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See ../lib/libipc.c for more information.
-	 */
 	tst_tmpdir();
 
-	/* get an IPC resource key */
 	shmkey = getipckey();
+	shm_id_1 = shmget(shmkey, shm_size,
+		    SHM_HUGETLB|SHM_RW|IPC_CREAT|IPC_EXCL);
+	if (shm_id_1 == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "shmget #1");
 
-	/* create a shared memory segment with read and write permissions */
-	if ((shm_id_1 = shmget(shmkey, huge_pages_shm_to_be_allocated, SHM_HUGETLB | SHM_RW | IPC_CREAT | IPC_EXCL)) == -1) {
-		tst_brkm(TBROK, cleanup, "Failed to create shared memory "
-			 "segment in setup");
-	}
-
-	/* get the userid for a non root user */
+	/* get the userid for a non-root user */
 	ltp_uid = getuserid(ltp_user);
+
+	TEST_PAUSE;
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void
-cleanup(void)
+void cleanup(void)
 {
-	/* if it exists, remove the shared memory resource */
-	rm_shm(shm_id_1);
-
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
 	TEST_CLEANUP;
 
-}
\ No newline at end of file
+	rm_shm(shm_id_1);
+
+	tst_rmdir();
+}

[-- Attachment #3: Type: text/plain, Size: 381 bytes --]

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

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH 08/11] hugetlb/hugeshmget: set nr_hugepages in tests
  2012-03-13  4:56 [LTP] [PATCH 00/11] hugetlb multiple fixes Caspar Zhang
                   ` (6 preceding siblings ...)
  2012-03-13  4:56 ` [LTP] [PATCH 07/11] hugetlb/hugeshmget: cleanup codes Caspar Zhang
@ 2012-03-13  4:56 ` Caspar Zhang
  2012-03-13  6:25   ` Wanlong Gao
  2012-03-13  4:56 ` [LTP] [PATCH 09/11] hugetlb/lib: cleanup codes Caspar Zhang
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Caspar Zhang @ 2012-03-13  4:56 UTC (permalink / raw)
  To: LTP List

[-- Attachment #1: Type: text/plain, Size: 554 bytes --]


This patch enables nr_hugepages set/restore in each test of hugeshmget,
so that we don't need to set the values with external commands.

Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
 .../kernel/mem/hugetlb/hugeshmget/hugeshmget01.c   |   32 ++++++++++++-----
 .../kernel/mem/hugetlb/hugeshmget/hugeshmget02.c   |   28 +++++++++++----
 .../kernel/mem/hugetlb/hugeshmget/hugeshmget03.c   |   36 ++++++++++++-------
 .../kernel/mem/hugetlb/hugeshmget/hugeshmget05.c   |   27 +++++++++++----
 4 files changed, 86 insertions(+), 37 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0008-hugetlb-hugeshmget-set-nr_hugepages-in-tests.patch --]
[-- Type: text/x-patch; name="0008-hugetlb-hugeshmget-set-nr_hugepages-in-tests.patch", Size: 7554 bytes --]

diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c
index 9bdf029..36492ef 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c
@@ -59,30 +59,32 @@
  */
 
 #include "ipcshm.h"
-#include "system_specific_hugepages_info.h"
+#include "safe_macros.h"
+#include "mem.h"
 
 char *TCID = "hugeshmget01";
 int TST_TOTAL = 1;
 
+static size_t shm_size;
 static int shm_id_1 = -1;
 
+static long hugepages = 128;
+static option_t options[] = {
+	{ "s:",	&sflag,	&nr_opt	},
+	{ NULL,	NULL,	NULL	}
+};
+
 int main(int ac, char **av)
 {
 	int lc;
 	char *msg;
 	struct shmid_ds buf;
-	size_t shm_size;
-
-	shm_size = 0;
 
-	msg = parse_opts(ac, av, NULL, NULL);
+	msg = parse_opts(ac, av, options, &help);
 	if (msg != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-
-	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-		tst_brkm(TCONF, NULL, "Not enough available Hugepages");
-	else
-		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
+	if (sflag)
+		hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);
 
 	setup();
 
@@ -143,9 +145,17 @@ int main(int ac, char **av)
 
 void setup(void)
 {
+	long hpage_size;
+
+	tst_require_root(NULL);
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 	tst_tmpdir();
 
+	orig_hugepages = get_sys_tune("nr_hugepages");
+	set_sys_tune("nr_hugepages", hugepages, 1);
+	hpage_size = read_meminfo("Hugepagesize:") * 1024;
+
+	shm_size = hpage_size * hugepages / 2;
 	shmkey = getipckey();
 
 	TEST_PAUSE;
@@ -157,5 +167,7 @@ void cleanup(void)
 
 	rm_shm(shm_id_1);
 
+	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+
 	tst_rmdir();
 }
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c
index a2f3a51..503cef2 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c
@@ -52,7 +52,8 @@
  */
 
 #include "ipcshm.h"
-#include "system_specific_hugepages_info.h"
+#include "safe_macros.h"
+#include "mem.h"
 
 char *TCID = "hugeshmget02";
 int TST_TOTAL = 4;
@@ -62,6 +63,12 @@ static int shm_id_1 = -1;
 static int shm_id_2 = -1;
 static key_t shmkey2;
 
+static long hugepages = 128;
+static option_t options[] = {
+	{ "s:",	&sflag,	&nr_opt	},
+	{ NULL,	NULL,	NULL	}
+};
+
 struct test_case_t {
 	int *skey;
 	int size_coe;
@@ -84,14 +91,11 @@ int main(int ac, char **av)
 	int lc, i;
 	char *msg;
 
-	msg = parse_opts(ac, av, NULL, NULL);
+	msg = parse_opts(ac, av, options, &help);
 	if (msg != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-
-	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-		tst_brkm(TCONF, NULL, "Not enough available Hugepages");
-	else
-		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
+	if (sflag)
+		hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);
 
 	setup();
 
@@ -115,9 +119,17 @@ int main(int ac, char **av)
 
 void setup(void)
 {
+	long hpage_size;
+
+	tst_require_root(NULL);
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 	tst_tmpdir();
 
+	orig_hugepages = get_sys_tune("nr_hugepages");
+	set_sys_tune("nr_hugepages", hugepages, 1);
+	hpage_size = read_meminfo("Hugepagesize:") * 1024;
+
+	shm_size = hpage_size * hugepages / 2;
 	shmkey = getipckey();
 	shmkey2 = shmkey + 1;
 	shm_id_1 = shmget(shmkey, shm_size, IPC_CREAT|IPC_EXCL|SHM_RW);
@@ -133,5 +145,7 @@ void cleanup(void)
 
 	rm_shm(shm_id_1);
 
+	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+
 	tst_rmdir();
 }
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
index dfaecc5..57e80e3 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
@@ -53,7 +53,8 @@
  */
 
 #include "ipcshm.h"
-#include "system_specific_hugepages_info.h"
+#include "safe_macros.h"
+#include "mem.h"
 
 char *TCID = "hugeshmget03";
 int TST_TOTAL = 1;
@@ -64,30 +65,29 @@ int TST_TOTAL = 1;
  */
 #define MAXIDS	8192
 
+static size_t shm_size;
 static int shm_id_1 = -1;
 static int num_shms;
 static int shm_id_arr[MAXIDS];
 
-static void setup2(size_t shm_size);
+static long hugepages = 128;
+static option_t options[] = {
+	{ "s:",	&sflag,	&nr_opt	},
+	{ NULL,	NULL,	NULL	}
+};
 
 int main(int ac, char **av)
 {
 	int lc;
 	char *msg;
-	size_t shm_size;
 
-	shm_size = 0;
-
-	msg = parse_opts(ac, av, NULL, NULL);
+	msg = parse_opts(ac, av, options, &help);
 	if (msg != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+	if (sflag)
+		hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);
 
-	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-		tst_brkm(TCONF, NULL, "Not enough available Hugepages");
-	else
-		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
-
-	setup2(shm_size);
+	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		Tst_count = 0;
@@ -108,11 +108,19 @@ int main(int ac, char **av)
 	tst_exit();
 }
 
-static void setup2(size_t shm_size)
+void setup(void)
 {
+	long hpage_size;
+
+	tst_require_root(NULL);
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 	tst_tmpdir();
 
+	orig_hugepages = get_sys_tune("nr_hugepages");
+	set_sys_tune("nr_hugepages", hugepages, 1);
+	hpage_size = read_meminfo("Hugepagesize:") * 1024;
+
+	shm_size = hpage_size * hugepages / 2;
 	shmkey = getipckey();
 
 	/*
@@ -147,5 +155,7 @@ void cleanup(void)
 	for (i = 0; i < num_shms; i++)
 		rm_shm(shm_id_arr[i]);
 
+	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+
 	tst_rmdir();
 }
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c
index 9242a34..7d8afd2 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c
@@ -61,7 +61,8 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include "ipcshm.h"
-#include "system_specific_hugepages_info.h"
+#include "safe_macros.h"
+#include "mem.h"
 
 char *TCID = "hugeshmget05";
 int TST_TOTAL = 1;
@@ -71,6 +72,12 @@ static int shm_id_1 = -1;
 static uid_t ltp_uid;
 static char *ltp_user = "nobody";
 
+static long hugepages = 128;
+static option_t options[] = {
+	{ "s:",	&sflag,	&nr_opt	},
+	{ NULL,	NULL,	NULL	}
+};
+
 static void do_child(void);
 
 int main(int ac, char **av)
@@ -79,14 +86,11 @@ int main(int ac, char **av)
 	pid_t pid;
 	int status;
 
-	msg = parse_opts(ac, av, NULL, NULL);
+	msg = parse_opts(ac, av, options, &help);
 	if (msg != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-
-	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-		tst_brkm(TCONF, cleanup, "Not enough available Hugepages");
-	else
-		shm_size = (get_no_of_hugepages()*hugepages_size()*1024) / 2;
+	if (sflag)
+		hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);
 
 	setup();
 
@@ -130,10 +134,17 @@ static void do_child(void)
 
 void setup(void)
 {
+	long hpage_size;
+
 	tst_require_root(NULL);
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 	tst_tmpdir();
 
+	orig_hugepages = get_sys_tune("nr_hugepages");
+	set_sys_tune("nr_hugepages", hugepages, 1);
+	hpage_size = read_meminfo("Hugepagesize:") * 1024;
+
+	shm_size = hpage_size * hugepages / 2;
 	shmkey = getipckey();
 	shm_id_1 = shmget(shmkey, shm_size,
 		    SHM_HUGETLB|SHM_RW|IPC_CREAT|IPC_EXCL);
@@ -152,5 +163,7 @@ void cleanup(void)
 
 	rm_shm(shm_id_1);
 
+	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+
 	tst_rmdir();
 }

[-- Attachment #3: Type: text/plain, Size: 381 bytes --]

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

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH 09/11] hugetlb/lib: cleanup codes
  2012-03-13  4:56 [LTP] [PATCH 00/11] hugetlb multiple fixes Caspar Zhang
                   ` (7 preceding siblings ...)
  2012-03-13  4:56 ` [LTP] [PATCH 08/11] hugetlb/hugeshmget: set nr_hugepages in tests Caspar Zhang
@ 2012-03-13  4:56 ` Caspar Zhang
  2012-03-13  4:56 ` [LTP] [PATCH 10/11] hugetlb/hugeshmget03: fix broken testcase Caspar Zhang
  2012-03-13  4:56 ` [LTP] [PATCH 11/11] libltp: remove system_specific_hugepages_info Caspar Zhang
  10 siblings, 0 replies; 20+ messages in thread
From: Caspar Zhang @ 2012-03-13  4:56 UTC (permalink / raw)
  To: LTP List

[-- Attachment #1: Type: text/plain, Size: 709 bytes --]


1) removed unnecessary header files in hugetlb/lib
2) removed unnecessary functions in hugetlb/lib
3) code clean-ups for Makefiles and libs

Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
 testcases/kernel/mem/hugetlb/hugemmap/Makefile |    1 -
 testcases/kernel/mem/hugetlb/lib/ipcmsg.h      |   58 ----------
 testcases/kernel/mem/hugetlb/lib/ipcsem.h      |   60 -----------
 testcases/kernel/mem/hugetlb/lib/ipcshm.h      |   28 +++---
 testcases/kernel/mem/hugetlb/lib/libipc.c      |  136 +++++-------------------
 5 files changed, 39 insertions(+), 244 deletions(-)
 delete mode 100644 testcases/kernel/mem/hugetlb/lib/ipcmsg.h
 delete mode 100644 testcases/kernel/mem/hugetlb/lib/ipcsem.h


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0009-hugetlb-lib-cleanup-codes.patch --]
[-- Type: text/x-patch; name="0009-hugetlb-lib-cleanup-codes.patch", Size: 10250 bytes --]

diff --git a/testcases/kernel/mem/hugetlb/hugemmap/Makefile b/testcases/kernel/mem/hugetlb/hugemmap/Makefile
index 601755a..15ae693 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/Makefile
+++ b/testcases/kernel/mem/hugetlb/hugemmap/Makefile
@@ -23,7 +23,6 @@
 top_srcdir		?= ../../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
-include $(abs_srcdir)/../Makefile.inc
 
 LIBMEMDIR		:= ../../lib
 LIBMEM			:= $(LIBMEMDIR)/libmem.a
diff --git a/testcases/kernel/mem/hugetlb/lib/ipcmsg.h b/testcases/kernel/mem/hugetlb/lib/ipcmsg.h
deleted file mode 100644
index bb928db..0000000
--- a/testcases/kernel/mem/hugetlb/lib/ipcmsg.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * ipcmsg.h - common definitions for the IPC message tests.
- */
-
-#ifndef __IPCMSG_H
-#define __IPCMSG_H	1
-
-#include <errno.h>
-#include <sys/ipc.h>
-#include <sys/msg.h>
-
-#include "test.h"
-#include "usctest.h"
-
-void cleanup(void);
-void setup(void);
-
-#define MSG_RD  0400            /* read permission for the queue */
-#define MSG_WR  0200            /* write permission for the queue */
-#define MSG_RW	MSG_RD | MSG_WR
-
-#define MSGSIZE	1024		/* a resonable size for a message */
-#define MSGTYPE 1		/* a type ID for a message */
-
-typedef struct mbuf {		/* a generic message structure */
-	long mtype;
-	char mtext[MSGSIZE + 1];  /* add 1 here so the message can be 1024   */
-} MSGBUF;			  /* characters long with a '\0' termination */
-
-key_t msgkey;                   /* the ftok() generated message key */
-
-void check_root();
-void init_buf(MSGBUF *, int, int);
-void rm_queue(int);
-
-int getipckey();
-int getuserid(char *);
-
-#endif /* ipcmsg.h */
diff --git a/testcases/kernel/mem/hugetlb/lib/ipcsem.h b/testcases/kernel/mem/hugetlb/lib/ipcsem.h
deleted file mode 100644
index 63baf5f..0000000
--- a/testcases/kernel/mem/hugetlb/lib/ipcsem.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * ipcsem.h - common definitions for the IPC semaphore tests
- */
-
-#ifndef __IPCSEM_H
-#define __IPCSEM_H
-
-#include <errno.h>
-#include <sys/ipc.h>
-#include <sys/sem.h>
-
-
-#include "test.h"
-#include "usctest.h"
-
-void cleanup(void);
-void setup(void);
-
-#define SEM_RD	0400
-#define SEM_ALT	0200
-#define SEM_RA	SEM_RD | SEM_ALT
-
-#define PSEMS	10		/* a reasonable value for the number of */
-				/* "primitive semaphores" per ID 	*/
-
-key_t semkey;			/* an IPC key generated by ftok() */
-
-union semun {
-	int val;			/* value for SETVAL */
-	struct semid_ds *buf;		/* buffer for IPC_STAT & IPC_SET */
-	unsigned short *array;		/* array for GETALL & SETALL */
-	struct seminfo *ipc_buf;	/* buffer for IPC_INFO */
-};
-
-void rm_sema(int sem_id);
-void check_root();
-
-int getipckey();
-int getuserid(char *);
-
-#endif /* ipcsem.h */
diff --git a/testcases/kernel/mem/hugetlb/lib/ipcshm.h b/testcases/kernel/mem/hugetlb/lib/ipcshm.h
index 1e9edbe..29a65db 100644
--- a/testcases/kernel/mem/hugetlb/lib/ipcshm.h
+++ b/testcases/kernel/mem/hugetlb/lib/ipcshm.h
@@ -24,35 +24,35 @@
 #ifndef __IPCSHM_H
 #define __IPCSHM_H
 
-#include <errno.h>
-#include <wait.h>
 #include <sys/ipc.h>
 #include <sys/shm.h>
+#include <errno.h>
+#include <wait.h>
 #include "test.h"
 #include "usctest.h"
 
-void cleanup(void);
-void setup(void);
-
 #define SHM_RD	0400
 #define SHM_WR	0200
-#define SHM_RW	SHM_RD | SHM_WR
+#define SHM_RW	(SHM_RD|SHM_WR)
 
 #ifndef SHM_HUGETLB
-#define SHM_HUGETLB   04000    /* segment is mapped via hugetlb */
+#define SHM_HUGETLB	04000	/* segment is mapped via hugetlb */
 #endif
 
+/*
+ * to get the lower nine permission bits
+ * from shmid_ds.ipc_perm.mode
+ */
+#define MODE_MASK	0x01FF
 
-#define MODE_MASK	0x01FF			/* to get the lower nine permission bits */
-						/* from shmid_ds.ipc_perm.mode		 */
-
-key_t shmkey;					/* an IPC key generated by ftok() */
+key_t shmkey;			/* an IPC key generated by ftok() */
 
+int getipckey(void);
+int getuserid(char *user);
 void rm_shm(int shm_id);
-void check_root();
 
-int getipckey();
-int getuserid(char*);
+void cleanup(void);
+void setup(void);
 
 char *nr_opt;
 int sflag;
diff --git a/testcases/kernel/mem/hugetlb/lib/libipc.c b/testcases/kernel/mem/hugetlb/lib/libipc.c
index cc3ca02..2120770 100644
--- a/testcases/kernel/mem/hugetlb/lib/libipc.c
+++ b/testcases/kernel/mem/hugetlb/lib/libipc.c
@@ -19,7 +19,7 @@
 
 /*
  * NAME
- *	libmsg.c
+ *	libipc.c
  *
  * DESCRIPTION
  *	common routines for the IPC system call tests.
@@ -27,28 +27,23 @@
  *	The library contains the following routines:
  *
  *	getipckey()
- *	rm_queue()
- *	init_buf()
- *	rm_sema()
- *	check_root()
  *	getuserid()
  *	rm_shm()
+ *	help()
  */
 
-#include "ipcmsg.h"
-#include "ipcsem.h"
-
-#include <pwd.h>
-#include <sys/timeb.h>
+#include <sys/types.h>
 #include <sys/ipc.h>
 #include <sys/shm.h>
+#include <sys/timeb.h>
+#include <pwd.h>
+#include "ipcshm.h"
 
 /*
  * getipckey() - generates and returns a message key used by the "get"
  *		 calls to create an IPC resource.
  */
-int
-getipckey()
+int getipckey(void)
 {
 	const char a = 'a';
 	int ascii_a = (int)a;
@@ -57,10 +52,9 @@ getipckey()
 	key_t ipc_key;
 	struct timeb time_info;
 
-	if (NULL == (curdir = getcwd(curdir, size))) {
-		tst_brkm(TBROK, cleanup, "Can't get current directory "
-			 "in getipckey()");
-	}
+	curdir = getcwd(curdir, size);
+	if (curdir == NULL)
+		tst_brkm(TBROK|TERRNO, cleanup, "getcwd(curdir)");
 
 	/*
 	 * Get a Sys V IPC key
@@ -74,125 +68,45 @@ getipckey()
 	 * number is the millisecond value that is set in the timeb
 	 * structure after calling ftime().
 	 */
-	(void)ftime(&time_info);
+	ftime(&time_info);
 	srandom((unsigned int)time_info.millitm);
 
-	if ((ipc_key = ftok(curdir, ascii_a + random()%26)) == -1) {
-		tst_brkm(TBROK, cleanup, "Can't get msgkey from ftok()");
-	}
-
-	return(ipc_key);
-}
-
-/*
- * rm_queue() - removes a message queue.
- */
-void
-rm_queue(int queue_id)
-{
-	if (queue_id == -1) {		/* no queue to remove */
-		return;
-	}
+	ipc_key = ftok(curdir, ascii_a + random()%26);
+	if (ipc_key == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "ftok");
 
-	if (msgctl(queue_id, IPC_RMID, NULL) == -1) {
-		tst_resm(TINFO, "WARNING: message queue deletion failed.");
-		tst_resm(TINFO, "This could lead to IPC resource problems.");
-		tst_resm(TINFO, "id = %d", queue_id);
-	}
-}
-
-/*
- * init_buf() - initialize the message buffer with some text and a type.
- */
-void
-init_buf(MSGBUF *m_buf, int type, int size)
-{
-	int i;
-	int ascii_a = (int)'a';		/* the ascii value for 'a' */
-
-	/* this fills the message with a repeating alphabet string */
-	for (i=0; i<size; i++) {
-		m_buf->mtext[i] = ascii_a + (i % 26);
-	}
-
-	/* terminate the message */
-	m_buf->mtext[i] = '\0';
-
-	/* if the type isn't valid, set it to 1 */
-	if (type < 1) {
-		m_buf->mtype = 1;
-	} else {
-		m_buf->mtype = type;
-	}
-}
-
-/*
- * rm_sema() - removes a semaphore.
- */
-void
-rm_sema(int sem_id)
-{
-	union semun arr;
-
-	if (sem_id == -1) {		/* no semaphore to remove */
-		return;
-	}
-
-	if (semctl(sem_id, 0, IPC_RMID, arr) == -1) {
-		tst_resm(TINFO, "WARNING: semaphore deletion failed.");
-		tst_resm(TINFO, "This could lead to IPC resource problems.");
-		tst_resm(TINFO, "id = %d", sem_id);
-	}
-}
-
-/*
- * check_root() - make sure the process ID is root
- */
-void
-check_root()
-{
-	if (geteuid() != 0) {
-		tst_brkm(TBROK, cleanup, "test must be run as root");
-	}
+	return ipc_key;
 }
 
 /*
  * getuserid() - return the integer value for the "user" id
  */
-int
-getuserid(char *user)
+int getuserid(char *user)
 {
 	struct passwd *ent;
 
-	/* allocate some space for the passwd struct */
-	if ((ent = (struct passwd *)malloc(sizeof(struct passwd))) == NULL) {
-	     tst_brkm(TBROK, cleanup, "couldn't allocate space for passwd"
-		      " structure");
-        }
+	ent = (struct passwd *)malloc(sizeof(struct passwd));
+	if (ent == NULL)
+		tst_brkm(TBROK|TERRNO, cleanup, "malloc ent");
 
-	/* get the uid value for the user */
-	if ((ent = getpwnam(user)) == NULL) {
-		tst_brkm(TBROK, cleanup, "Couldn't get password entry for %s",
-			 user);
-	}
+	ent = getpwnam(user);
+	if (ent == NULL)
+		tst_brkm(TBROK|TERRNO, cleanup, "getpwnam");
 
-	return(ent->pw_uid);
+	return ent->pw_uid;
 }
 
 /*
  * rm_shm() - removes a shared memory segment.
  */
-void
-rm_shm(int shm_id)
+void rm_shm(int shm_id)
 {
-	if (shm_id == -1) {		/* no segment to remove */
+	if (shm_id == -1)
 		return;
-	}
 
 	/*
 	 * check for # of attaches ?
 	 */
-
 	if (shmctl(shm_id, IPC_RMID, NULL) == -1) {
 		tst_resm(TINFO, "WARNING: shared memory deletion failed.");
 		tst_resm(TINFO, "This could lead to IPC resource problems.");

[-- Attachment #3: Type: text/plain, Size: 381 bytes --]

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

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH 10/11] hugetlb/hugeshmget03: fix broken testcase
  2012-03-13  4:56 [LTP] [PATCH 00/11] hugetlb multiple fixes Caspar Zhang
                   ` (8 preceding siblings ...)
  2012-03-13  4:56 ` [LTP] [PATCH 09/11] hugetlb/lib: cleanup codes Caspar Zhang
@ 2012-03-13  4:56 ` Caspar Zhang
  2012-03-13 12:44   ` Caspar Zhang
  2012-03-14  1:58   ` Wanlong Gao
  2012-03-13  4:56 ` [LTP] [PATCH 11/11] libltp: remove system_specific_hugepages_info Caspar Zhang
  10 siblings, 2 replies; 20+ messages in thread
From: Caspar Zhang @ 2012-03-13  4:56 UTC (permalink / raw)
  To: LTP List

[-- Attachment #1: Type: text/plain, Size: 568 bytes --]


hugeshmget03 often returns ENOMEM, so that causes test fails. This patch
fixes the problem by making the following changes:

1) reduce shm_size to minimum (1 hugepage);
2) reduce shmmni to 1/2 * nr_hugepages.

so that when all shmids taken, memory allocated ~=

    1/2 * nr_hugepages * hugepagesize < free memory

Which means there will be no ENOMEM occurs, but ENOSPC as expected.

Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
 .../kernel/mem/hugetlb/hugeshmget/hugeshmget03.c   |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0010-hugetlb-hugeshmget03-fix-broken-testcase.patch --]
[-- Type: text/x-patch; name="0010-hugetlb-hugeshmget03-fix-broken-testcase.patch", Size: 1664 bytes --]

diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
index 57e80e3..a714032 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
@@ -64,6 +64,7 @@ int TST_TOTAL = 1;
  * depending on the system being tested.
  */
 #define MAXIDS	8192
+#define PATH_SHMMNI	"/proc/sys/kernel/shmmni"
 
 static size_t shm_size;
 static int shm_id_1 = -1;
@@ -71,6 +72,7 @@ static int num_shms;
 static int shm_id_arr[MAXIDS];
 
 static long hugepages = 128;
+static long orig_shmmni;
 static option_t options[] = {
 	{ "s:",	&sflag,	&nr_opt	},
 	{ NULL,	NULL,	NULL	}
@@ -111,6 +113,7 @@ int main(int ac, char **av)
 void setup(void)
 {
 	long hpage_size;
+	char buf[BUFSIZ];
 
 	tst_require_root(NULL);
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
@@ -120,8 +123,12 @@ void setup(void)
 	set_sys_tune("nr_hugepages", hugepages, 1);
 	hpage_size = read_meminfo("Hugepagesize:") * 1024;
 
-	shm_size = hpage_size * hugepages / 2;
-	shmkey = getipckey();
+	shm_size = hpage_size;
+
+	read_file(PATH_SHMMNI, buf);
+	orig_shmmni = SAFE_STRTOL(cleanup, buf, 0, LONG_MAX);
+	snprintf(buf, BUFSIZ, "%ld", hugepages / 2);
+	write_file(PATH_SHMMNI, buf);
 
 	/*
 	 * Use a while loop to create the maximum number of memory segments.
@@ -149,12 +156,15 @@ void setup(void)
 void cleanup(void)
 {
 	int i;
+	char buf[BUFSIZ];
 
 	TEST_CLEANUP;
 
 	for (i = 0; i < num_shms; i++)
 		rm_shm(shm_id_arr[i]);
 
+	snprintf(buf, BUFSIZ, "%ld", orig_shmmni);
+	write_file(PATH_SHMMNI, buf);
 	set_sys_tune("nr_hugepages", orig_hugepages, 0);
 
 	tst_rmdir();

[-- Attachment #3: Type: text/plain, Size: 381 bytes --]

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

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH 11/11] libltp: remove system_specific_hugepages_info
  2012-03-13  4:56 [LTP] [PATCH 00/11] hugetlb multiple fixes Caspar Zhang
                   ` (9 preceding siblings ...)
  2012-03-13  4:56 ` [LTP] [PATCH 10/11] hugetlb/hugeshmget03: fix broken testcase Caspar Zhang
@ 2012-03-13  4:56 ` Caspar Zhang
  2012-03-13  6:28   ` Wanlong Gao
  10 siblings, 1 reply; 20+ messages in thread
From: Caspar Zhang @ 2012-03-13  4:56 UTC (permalink / raw)
  To: LTP List

[-- Attachment #1: Type: text/plain, Size: 774 bytes --]


system_specific_hugepages_info is not well-implemented and has been
deprecated, all functions in it can be replaced with libmem. So removing
it.

Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
 include/system_specific_hugepages_info.h           |   30 ------
 lib/system_specific_hugepages_info.c               |   93 --------------------
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c |   19 ++--
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c |    5 +-
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c |    1 -
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c |   24 ++---
 6 files changed, 21 insertions(+), 151 deletions(-)
 delete mode 100644 include/system_specific_hugepages_info.h
 delete mode 100644 lib/system_specific_hugepages_info.c


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0011-libltp-remove-system_specific_hugepages_info.patch --]
[-- Type: text/x-patch; name="0011-libltp-remove-system_specific_hugepages_info.patch", Size: 10524 bytes --]

diff --git a/include/system_specific_hugepages_info.h b/include/system_specific_hugepages_info.h
deleted file mode 100644
index f5e3c46..0000000
--- a/include/system_specific_hugepages_info.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- *
- *   Copyright (c) International Business Machines  Corp., 2009
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef _SYS_SPECIFIC_HUGEPAGES_INFO_H_
-#define _SYS_SPECIFIC_HUGEPAGES_INFO_H_
-
-/*Returns Total No. of available Hugepages in the system from /proc/meminfo*/
-int get_no_of_hugepages(void);
-/*Returns No. of Hugepages_Free  from /proc/meminfo*/
-int get_no_of_free_hugepages(void);
-/*Returns Hugepages Size from /proc/meminfo*/
-int hugepages_size(void);
-
-#endif
diff --git a/lib/system_specific_hugepages_info.c b/lib/system_specific_hugepages_info.c
deleted file mode 100644
index 2344add..0000000
--- a/lib/system_specific_hugepages_info.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- *
- *   Copyright (c) International Business Machines  Corp., 2009
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- *   DESCRIPTION
- *               get_no_of_hugepages() --> Return No. of hugepages for this systems
- *                                         from /proc/meminfo
- *               hugepages_size()      --> Return Hugepages Size for this system
- *                                         from /proc/meminfo
- */
-
-#include <fcntl.h>
-#include <sys/types.h>
-#include <test.h>
-
-int get_no_of_hugepages() {
- #ifdef __linux__
-       FILE *f;
-       char buf[BUFSIZ];
-
-       f = popen("grep 'HugePages_Total' /proc/meminfo | cut -d ':' -f2 | tr -d ' \n'", "r");
-       if (!f)
-              tst_brkm(TBROK, NULL,
-                     "Could not get info about Total_Hugepages from /proc/meminfo");
-       if (!fgets(buf, 10, f)) {
-               fclose(f);
-               tst_brkm(TBROK, NULL,
-                     "Could not read Total_Hugepages from /proc/meminfo");
-       }
-       pclose(f);
-       return(atoi(buf));
- #else
-        return -1;
- #endif
-}
-
-int get_no_of_free_hugepages() {
- #ifdef __linux__
-       FILE *f;
-       char buf[BUFSIZ];
-
-       f = popen("grep 'HugePages_Free' /proc/meminfo | cut -d ':' -f2 | tr -d ' \n'", "r");
-       if (!f)
-               tst_brkm(TBROK, NULL,
-                     "Could not get info about HugePages_Free from /proc/meminfo");
-       if (!fgets(buf, 10, f)) {
-               fclose(f);
-               tst_brkm(TBROK, NULL,
-                     "Could not read HugePages_Free from /proc/meminfo");
-       }
-       pclose(f);
-       return(atoi(buf));
- #else
-        return -1;
- #endif
-}
-
-int hugepages_size() {
- #ifdef __linux__
-       FILE *f;
-       char buf[BUFSIZ];
-
-       f = popen("grep 'Hugepagesize' /proc/meminfo | cut -d ':' -f2 | tr -d 'kB \n'", "r");
-       if (!f)
-               tst_brkm(TBROK, NULL,
-                     "Could not get info about HugePages_Size from /proc/meminfo");
-       if (!fgets(buf, 10, f)) {
-               fclose(f);
-               tst_brkm(TBROK, NULL,
-                     "Could not read HugePages_Size from /proc/meminfo");
-       }
-       pclose(f);
-       return(atoi(buf));
- #else
-        return -1;
- #endif
-}
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c
index 90f28c8..1140d8b 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c
@@ -62,7 +62,6 @@
 #include "test.h"
 #include "usctest.h"
 #include "safe_macros.h"
-#include "system_specific_hugepages_info.h"
 #include "mem.h"
 
 static char TEMPFILE[MAXPATHLEN];
@@ -73,9 +72,9 @@ static long *addr;
 static int fildes;
 static char *Hopt;
 static char *nr_opt;
-static int beforetest;
-static int aftertest;
-static int hugepagesmapped;
+static long beforetest;
+static long aftertest;
+static long hugepagesmapped;
 static long hugepages = 128;
 static long orig_hugepages;
 
@@ -86,7 +85,7 @@ int main(int ac, char **av)
 	int lc;
 	char *msg;
 	int Hflag = 0;
-	int page_sz = 0;
+	long page_sz = 0;
 	int sflag = 0;
 
 	option_t options[] = {
@@ -119,12 +118,12 @@ int main(int ac, char **av)
 		Tst_count = 0;
 
 		/* Note the number of free huge pages BEFORE testing */
-		beforetest = get_no_of_free_hugepages();
+		beforetest = read_meminfo("HugePages_Free:");
 
 		/* Note the size of huge page size BEFORE testing */
-		page_sz = hugepages_size();
+		page_sz = read_meminfo("Hugepagesize:") * 1024;
 
-		addr = mmap(NULL, page_sz*1024, PROT_READ | PROT_WRITE,
+		addr = mmap(NULL, page_sz, PROT_READ | PROT_WRITE,
 			    MAP_SHARED, fildes, 0);
 		if (addr == MAP_FAILED) {
 			tst_resm(TFAIL|TERRNO, "mmap() Failed on %s", TEMPFILE);
@@ -141,7 +140,7 @@ int main(int ac, char **av)
 		 * Make sure the number of free huge pages
 		 * AFTER testing decreased
 		 */
-		aftertest = get_no_of_free_hugepages();
+		aftertest = read_meminfo("HugePages_Free:");
 		hugepagesmapped = beforetest - aftertest;
 		if (hugepagesmapped < 1)
 			tst_resm(TWARN, "Number of HUGEPAGES_FREE stayed the"
@@ -150,7 +149,7 @@ int main(int ac, char **av)
 
 		/* Clean up things in case we are looping */
 		/* Unmap the mapped memory */
-		if (munmap(addr, page_sz*1024) != 0)
+		if (munmap(addr, page_sz) != 0)
 			tst_brkm(TFAIL|TERRNO, NULL, "munmap failed");
 
 		close(fildes);
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
index 5a96146..7b2fb68 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
@@ -55,7 +55,6 @@
 #include "test.h"
 #include "usctest.h"
 #include "safe_macros.h"
-#include "system_specific_hugepages_info.h"
 #include "mem.h"
 
 #define LOW_ADDR       (void *)(0x80000000)
@@ -83,7 +82,7 @@ int main(int ac, char **av)
 	int lc;
 	char *msg;
 	int Hflag = 0;
-	int page_sz, map_sz;
+	long page_sz, map_sz;
 	int sflag = 0;
 
 	option_t options[] = {
@@ -105,7 +104,7 @@ int main(int ac, char **av)
 		hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);
 
 	page_sz = getpagesize();
-	map_sz = 2 * 1024 * hugepages_size();
+	map_sz = read_meminfo("Hugepagesize:") * 1024 * 2;
 
 	setup();
 
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c
index 50fe707..4b75601 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c
@@ -46,7 +46,6 @@
 #include "test.h"
 #include "usctest.h"
 #include "safe_macros.h"
-#include "system_specific_hugepages_info.h"
 #include "mem.h"
 
 #define HIGH_ADDR      (void *)(0x1000000000000)
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
index f313c60..554eaae 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
@@ -63,7 +63,6 @@
 #include "test.h"
 #include "usctest.h"
 #include "safe_macros.h"
-#include "system_specific_hugepages_info.h"
 #include "mem.h"
 
 static char TEMPFILE[MAXPATHLEN];
@@ -73,10 +72,10 @@ int TST_TOTAL = 1;
 static long *addr;
 static long long mapsize;
 static int fildes;
-static int freepages;
-static int beforetest;
-static int aftertest;
-static int hugepagesmapped;
+static long freepages;
+static long beforetest;
+static long aftertest;
+static long hugepagesmapped;
 static long hugepages = 128;
 static long orig_hugepages;
 static char *Hopt;
@@ -112,10 +111,6 @@ int main(int ac, char **av)
 
 	setup();
 
-	/* Check number of hugepages */
-	if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
-		tst_brkm(TCONF, cleanup, "Not enough available Hugepages");
-
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		/* Creat a temporary file used for huge mapping */
 		fildes = open(TEMPFILE, O_RDWR | O_CREAT, 0666);
@@ -126,11 +121,11 @@ int main(int ac, char **av)
 		Tst_count = 0;
 
 		/* Note the number of free huge pages BEFORE testing */
-		freepages = get_no_of_free_hugepages();
+		freepages = read_meminfo("HugePages_Free:");
 		beforetest = freepages;
 
 		/* Note the size of huge page size BEFORE testing */
-		huge_pagesize = hugepages_size();
+		huge_pagesize = read_meminfo("Hugepagesize:");
 		tst_resm(TINFO, "Size of huge pages is %d KB", huge_pagesize);
 
 #if __WORDSIZE == 32
@@ -150,8 +145,9 @@ int main(int ac, char **av)
 			close(fildes);
 			continue;
 		} else {
-			tst_resm(TPASS, "Succeeded mapping file using %d pages",
-				 freepages);
+			tst_resm(TPASS,
+				"Succeeded mapping file using %ld pages",
+				freepages);
 			/* force to allocate page and change HugePages_Free */
 			*(int *)addr = 0;
 		}
@@ -160,7 +156,7 @@ int main(int ac, char **av)
 		 * Make sure the number of free huge pages
 		 * AFTER testing decreased
 		 */
-		aftertest = get_no_of_free_hugepages();
+		aftertest = read_meminfo("HugePages_Free:");
 		hugepagesmapped = beforetest - aftertest;
 		if (hugepagesmapped < 1)
 			tst_resm(TWARN, "Number of HUGEPAGES_FREE stayed the"

[-- Attachment #3: Type: text/plain, Size: 381 bytes --]

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

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 02/11] hugetlb/hugeshmat: set nr_hugepages in tests
  2012-03-13  4:56 ` [LTP] [PATCH 02/11] hugetlb/hugeshmat: set nr_hugepages in tests Caspar Zhang
@ 2012-03-13  6:16   ` Wanlong Gao
  0 siblings, 0 replies; 20+ messages in thread
From: Wanlong Gao @ 2012-03-13  6:16 UTC (permalink / raw)
  To: Caspar Zhang; +Cc: LTP List

On 03/13/2012 12:56 PM, Caspar Zhang wrote:

> 
> Like hugemmap tests, this patch enables nr_hugepages set/restore in each
> test of hugeshmat, so that we don't need to set the values with external
> commands.
> 
> Signed-off-by: Caspar Zhang <caspar@casparzhang.com>


Looks good to me.

Acked-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>

> ---
>  testcases/kernel/mem/hugetlb/Makefile.inc          |   16 +++++-----
>  .../kernel/mem/hugetlb/hugeshmat/hugeshmat01.c     |   28 +++++++++++++++-----
>  .../kernel/mem/hugetlb/hugeshmat/hugeshmat02.c     |   28 +++++++++++++++-----
>  .../kernel/mem/hugetlb/hugeshmat/hugeshmat03.c     |   26 ++++++++++++++----
>  testcases/kernel/mem/hugetlb/lib/ipcshm.h          |    5 +++
>  testcases/kernel/mem/hugetlb/lib/libipc.c          |    7 ++++-
>  6 files changed, 81 insertions(+), 29 deletions(-)
> 
> 
> 
> 
> ------------------------------------------------------------------------------
> 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



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

* Re: [LTP] [PATCH 01/11] hugetlb/hugeshmat: cleanup codes
  2012-03-13  4:56 ` [LTP] [PATCH 01/11] hugetlb/hugeshmat: cleanup codes Caspar Zhang
@ 2012-03-13  6:17   ` Wanlong Gao
  0 siblings, 0 replies; 20+ messages in thread
From: Wanlong Gao @ 2012-03-13  6:17 UTC (permalink / raw)
  To: Caspar Zhang; +Cc: LTP List

On 03/13/2012 12:56 PM, Caspar Zhang wrote:

> 
> Signed-off-by: Caspar Zhang <caspar@casparzhang.com>


Looks good.

Acked-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>

> ---
>  testcases/kernel/mem/hugetlb/hugeshmat/Makefile    |    2 +-
>  .../kernel/mem/hugetlb/hugeshmat/hugeshmat01.c     |  159 ++++++-------------
>  .../kernel/mem/hugetlb/hugeshmat/hugeshmat02.c     |  151 ++++++-------------
>  .../kernel/mem/hugetlb/hugeshmat/hugeshmat03.c     |  167 ++++++-------------
>  4 files changed, 149 insertions(+), 330 deletions(-)
> 
> 
> 
> 
> ------------------------------------------------------------------------------
> 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



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

* Re: [LTP] [PATCH 04/11] hugetlb/hugeshmctl: set nr_hugepages in tests
  2012-03-13  4:56 ` [LTP] [PATCH 04/11] hugetlb/hugeshmctl: set nr_hugepages in tests Caspar Zhang
@ 2012-03-13  6:23   ` Wanlong Gao
  0 siblings, 0 replies; 20+ messages in thread
From: Wanlong Gao @ 2012-03-13  6:23 UTC (permalink / raw)
  To: Caspar Zhang; +Cc: LTP List

On 03/13/2012 12:56 PM, Caspar Zhang wrote:

> 
> This patch enables nr_hugepages set/restore in each test of hugeshmctl,
> so that we don't need to set the values with external commands.
> 
> Signed-off-by: Caspar Zhang <caspar@casparzhang.com>


Looks good. thanks

Acked-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>

> ---
>  .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c   |   28 +++++++++++++++-----
>  .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c   |   28 +++++++++++++++-----
>  .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c   |   27 ++++++++++++++-----
>  3 files changed, 62 insertions(+), 21 deletions(-)
> 
> 
> 
> 
> ------------------------------------------------------------------------------
> 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



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

* Re: [LTP] [PATCH 06/11] hugetlb/hugeshmdt: set nr_hugepages in tests
  2012-03-13  4:56 ` [LTP] [PATCH 06/11] hugetlb/hugeshmdt: set nr_hugepages in tests Caspar Zhang
@ 2012-03-13  6:24   ` Wanlong Gao
  0 siblings, 0 replies; 20+ messages in thread
From: Wanlong Gao @ 2012-03-13  6:24 UTC (permalink / raw)
  To: Caspar Zhang; +Cc: LTP List

On 03/13/2012 12:56 PM, Caspar Zhang wrote:

> 
> This patch enables nr_hugepages set/restore in each test of hugeshmdt,
> so that we don't need to set the values with external commands.
> 
> Signed-off-by: Caspar Zhang <caspar@casparzhang.com>


Looks good. thanks

Acked-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>

> ---
>  .../kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c     |   28 +++++++++++++++-----
>  1 files changed, 21 insertions(+), 7 deletions(-)
> 
> 
> 
> 
> ------------------------------------------------------------------------------
> 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



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

* Re: [LTP] [PATCH 08/11] hugetlb/hugeshmget: set nr_hugepages in tests
  2012-03-13  4:56 ` [LTP] [PATCH 08/11] hugetlb/hugeshmget: set nr_hugepages in tests Caspar Zhang
@ 2012-03-13  6:25   ` Wanlong Gao
  0 siblings, 0 replies; 20+ messages in thread
From: Wanlong Gao @ 2012-03-13  6:25 UTC (permalink / raw)
  To: Caspar Zhang; +Cc: LTP List

On 03/13/2012 12:56 PM, Caspar Zhang wrote:

> 
> This patch enables nr_hugepages set/restore in each test of hugeshmget,
> so that we don't need to set the values with external commands.
> 
> Signed-off-by: Caspar Zhang <caspar@casparzhang.com>


Looks good, thanks.

Acked-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>

> ---
>  .../kernel/mem/hugetlb/hugeshmget/hugeshmget01.c   |   32 ++++++++++++-----
>  .../kernel/mem/hugetlb/hugeshmget/hugeshmget02.c   |   28 +++++++++++----
>  .../kernel/mem/hugetlb/hugeshmget/hugeshmget03.c   |   36 ++++++++++++-------
>  .../kernel/mem/hugetlb/hugeshmget/hugeshmget05.c   |   27 +++++++++++----
>  4 files changed, 86 insertions(+), 37 deletions(-)
> 
> 
> 
> 
> ------------------------------------------------------------------------------
> 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



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

* Re: [LTP] [PATCH 11/11] libltp: remove system_specific_hugepages_info
  2012-03-13  4:56 ` [LTP] [PATCH 11/11] libltp: remove system_specific_hugepages_info Caspar Zhang
@ 2012-03-13  6:28   ` Wanlong Gao
  0 siblings, 0 replies; 20+ messages in thread
From: Wanlong Gao @ 2012-03-13  6:28 UTC (permalink / raw)
  To: Caspar Zhang; +Cc: LTP List

On 03/13/2012 12:56 PM, Caspar Zhang wrote:

> 
> system_specific_hugepages_info is not well-implemented and has been
> deprecated, all functions in it can be replaced with libmem. So removing
> it.
> 
> Signed-off-by: Caspar Zhang <caspar@casparzhang.com>


Acked-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>

> ---
>  include/system_specific_hugepages_info.h           |   30 ------
>  lib/system_specific_hugepages_info.c               |   93 --------------------
>  testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c |   19 ++--
>  testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c |    5 +-
>  testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c |    1 -
>  testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c |   24 ++---
>  6 files changed, 21 insertions(+), 151 deletions(-)
>  delete mode 100644 include/system_specific_hugepages_info.h
>  delete mode 100644 lib/system_specific_hugepages_info.c
> 
> 
> 
> 
> ------------------------------------------------------------------------------
> 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



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

* Re: [LTP] [PATCH 10/11] hugetlb/hugeshmget03: fix broken testcase
  2012-03-13  4:56 ` [LTP] [PATCH 10/11] hugetlb/hugeshmget03: fix broken testcase Caspar Zhang
@ 2012-03-13 12:44   ` Caspar Zhang
  2012-03-14  1:58   ` Wanlong Gao
  1 sibling, 0 replies; 20+ messages in thread
From: Caspar Zhang @ 2012-03-13 12:44 UTC (permalink / raw)
  To: LTP List

On 03/13/2012 12:56 PM, Caspar Zhang wrote:
> 
> hugeshmget03 often returns ENOMEM, so that causes test fails. This patch
> fixes the problem by making the following changes:
> 
> 1) reduce shm_size to minimum (1 hugepage);
> 2) reduce shmmni to 1/2 * nr_hugepages.
> 
> so that when all shmids taken, memory allocated ~=
> 
>     1/2 * nr_hugepages * hugepagesize < free memory
> 
> Which means there will be no ENOMEM occurs, but ENOSPC as expected.
> 
> Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
> ---
>  .../kernel/mem/hugetlb/hugeshmget/hugeshmget03.c   |   14 ++++++++++++--
>  1 files changed, 12 insertions(+), 2 deletions(-)
> 

Wanlong, thanks for review.

All: FYI, all the other patches except this one (10/11) pushed after
successful testing for enough times.

Caspar

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

* Re: [LTP] [PATCH 10/11] hugetlb/hugeshmget03: fix broken testcase
  2012-03-13  4:56 ` [LTP] [PATCH 10/11] hugetlb/hugeshmget03: fix broken testcase Caspar Zhang
  2012-03-13 12:44   ` Caspar Zhang
@ 2012-03-14  1:58   ` Wanlong Gao
  1 sibling, 0 replies; 20+ messages in thread
From: Wanlong Gao @ 2012-03-14  1:58 UTC (permalink / raw)
  To: Caspar Zhang; +Cc: LTP List

On 03/13/2012 12:56 PM, Caspar Zhang wrote:

> 
> hugeshmget03 often returns ENOMEM, so that causes test fails. This patch
> fixes the problem by making the following changes:
> 
> 1) reduce shm_size to minimum (1 hugepage);
> 2) reduce shmmni to 1/2 * nr_hugepages.
> 
> so that when all shmids taken, memory allocated ~=
> 
>     1/2 * nr_hugepages * hugepagesize < free memory
> 
> Which means there will be no ENOMEM occurs, but ENOSPC as expected.


Hi Caspar:

IMO, this looks good and test OK . So

Reviewed-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>

> 
> Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
> ---
>  .../kernel/mem/hugetlb/hugeshmget/hugeshmget03.c   |   14 ++++++++++++--
>  1 files changed, 12 insertions(+), 2 deletions(-)
> 
> 
> 
> 
> ------------------------------------------------------------------------------
> 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



------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2012-03-14  1:59 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-13  4:56 [LTP] [PATCH 00/11] hugetlb multiple fixes Caspar Zhang
2012-03-13  4:56 ` [LTP] [PATCH 01/11] hugetlb/hugeshmat: cleanup codes Caspar Zhang
2012-03-13  6:17   ` Wanlong Gao
2012-03-13  4:56 ` [LTP] [PATCH 02/11] hugetlb/hugeshmat: set nr_hugepages in tests Caspar Zhang
2012-03-13  6:16   ` Wanlong Gao
2012-03-13  4:56 ` [LTP] [PATCH 03/11] hugetlb/hugeshmctl: cleanup codes Caspar Zhang
2012-03-13  4:56 ` [LTP] [PATCH 04/11] hugetlb/hugeshmctl: set nr_hugepages in tests Caspar Zhang
2012-03-13  6:23   ` Wanlong Gao
2012-03-13  4:56 ` [LTP] [PATCH 05/11] hugetlb/hugeshmdt: cleanup codes Caspar Zhang
2012-03-13  4:56 ` [LTP] [PATCH 06/11] hugetlb/hugeshmdt: set nr_hugepages in tests Caspar Zhang
2012-03-13  6:24   ` Wanlong Gao
2012-03-13  4:56 ` [LTP] [PATCH 07/11] hugetlb/hugeshmget: cleanup codes Caspar Zhang
2012-03-13  4:56 ` [LTP] [PATCH 08/11] hugetlb/hugeshmget: set nr_hugepages in tests Caspar Zhang
2012-03-13  6:25   ` Wanlong Gao
2012-03-13  4:56 ` [LTP] [PATCH 09/11] hugetlb/lib: cleanup codes Caspar Zhang
2012-03-13  4:56 ` [LTP] [PATCH 10/11] hugetlb/hugeshmget03: fix broken testcase Caspar Zhang
2012-03-13 12:44   ` Caspar Zhang
2012-03-14  1:58   ` Wanlong Gao
2012-03-13  4:56 ` [LTP] [PATCH 11/11] libltp: remove system_specific_hugepages_info Caspar Zhang
2012-03-13  6:28   ` Wanlong Gao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox