hugeshmat01 test use fixed addr for its 2nd testcase, however it does
not work on some architectures, like powerpc. I took some codes from
syscalls/shmat01, which fetches the baseaddr by running shmat first at
setup(), and use it for 2nd testcase.

Signed-off-by: Caspar Zhang <[email protected]>
---
 .../kernel/mem/hugetlb/hugeshmat/hugeshmat01.c     |   49 +++++++++++++------
 1 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c
index 6f270ce..7f3ce20 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c
@@ -66,31 +66,19 @@ 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
-#define UNALIGNED      0x10000000eee
-#else
-#define UNALIGNED      0x60000eee
-#endif
-
 int shm_id_1 = -1;
 
 void	*addr;				/* for result of shmat-call */
+void	*base_addr;
 
 struct test_case_t {
 	int *shmid;
 	void *addr;
 	int flags;
-} TC[] = {
-	/* a straight forward read/write attach */
-	{&shm_id_1, 0, 0},
-
-       /* an attach using non aligned memory */
-	{&shm_id_1, (void *)UNALIGNED, SHM_RND},
-
-	/* a read only attach */
-	{&shm_id_1, 0, SHM_RDONLY}
 };
 
+struct test_case_t TC[3];
+
 int main(int ac, char **av)
 {
 	int lc;				/* loop counter */
@@ -259,6 +247,35 @@ setup(void)
 		tst_brkm(TBROK, cleanup, "Failed to create shared memory "
 			 "resource 1 in setup()");
 	}
+
+	/* Probe an available linear address for attachment */
+	base_addr = shmat(shm_id_1, NULL, 0);
+	if (base_addr == (void *)-1)
+		tst_brkm(TBROK|TERRNO, cleanup,
+				"Couldn't attach shared memory");
+	if (shmdt((const void *)base_addr) == -1)
+		tst_brkm(TBROK|TERRNO, cleanup,
+				"Couldn't detach shared memory");
+
+	/* some architectures (e.g. parisc) are strange, so better
+	 * always align to next SHMLBA address. */
+	base_addr = (void *)(((unsigned long)base_addr + SHMLBA - 1) &
+			~(SHMLBA - 1));
+
+	/* a straight forward read/write attach */
+	TC[0].shmid = &shm_id_1;
+	TC[0].addr  = 0;
+	TC[0].flags = 0;
+
+	/* an attach using non aligned memory */
+	TC[1].shmid = &shm_id_1;
+	TC[1].addr  = (void *)(base_addr + SHMLBA - 1);
+	TC[1].flags = SHM_RND;
+
+	/* a read only attach */
+	TC[2].shmid = &shm_id_1;
+	TC[2].addr  = 0;
+	TC[2].flags = SHM_RDONLY;
 }
 
 /*
@@ -279,4 +296,4 @@ cleanup(void)
 	 */
 	TEST_CLEANUP;
 
-}
\ No newline at end of file
+}
------------------------------------------------------------------------------
EMC VNX: the world's simplest storage, starting under $10K
The only unified storage solution that offers unified management 
Up to 160% more powerful than alternatives and 25% more efficient. 
Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to