From ac8d4c1632ea0f2be39d6cf75a01ccbe34ae791c Mon Sep 17 00:00:00 2001
From: Roy Lee <roylee17@gmail.com>
Date: Mon, 19 May 2008 09:39:24 +0800
Subject: [PATCH] This patch attaches the shared memory segment twice to the
 child's address space and verifies that their contents are
 the same.

---
 testcases/kernel/mem/shmt/shmt06.c |   31 ++++++++++++++++++++++++++++---
 1 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/mem/shmt/shmt06.c b/testcases/kernel/mem/shmt/shmt06.c
index 8fec106..e7a6e88 100644
--- a/testcases/kernel/mem/shmt/shmt06.c
+++ b/testcases/kernel/mem/shmt/shmt06.c
@@ -30,9 +30,9 @@
  * ALGORITHM
  * Parent process forks a child. Child pauses until parent has created
  * a shared memory segment, attached to it and written to it too. At that
- * time child gets the shared memory segment id, attaches to it at a
- * different address than the parents and verifies that its contents are
- * the same as the contents of the parent attached segment.
+ * time child gets the shared memory segment id, attaches to it at two
+ * different addresses than the parents and verifies that their contents
+ * are the same as the contents of the parent attached segment.
  *
  */
 
@@ -184,6 +184,31 @@ int child()
 			}
 		}
 
+		/*
+		 * Attach the segment to a different addresse
+		 * and verify it's contents again.
+		 */
+		cp = (char *)shmat(shmid, (void *)NULL, 0);
+
+		if (cp == (char *)-1) {
+			perror("shmat:child process");
+			tst_resm(TFAIL,
+				 "Error: shmat: errno=%d, shmid=%d, child_pid=%d\n",
+				 errno, shmid, chld_pid);
+		} else {
+			if (*cp != 'A') {
+				tst_resm(TFAIL, "child: not A\n");
+			}
+			if (*(cp + 1) != 'B') {
+				tst_resm(TFAIL, "child: not B\n");
+			}
+			if (*(cp + 2) != 'C') {
+				tst_resm(TFAIL, "child: not C\n");
+			}
+			if (*(cp + 8192) != 0) {
+				tst_resm(TFAIL, "child: not 0\n");
+			}
+		}
 	}
 	tst_exit();
 	return (0);
-- 
1.5.5.1.309.g0702

