public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: DAN LI <li.dan@cn.fujitsu.com>
To: LTP list <ltp-list@lists.sourceforge.net>
Subject: [LTP] [PATCH V2 2/2] shmat/shmat01.c: Test for specifying NULL to shmaddr
Date: Fri, 17 May 2013 13:39:32 +0800	[thread overview]
Message-ID: <5195C294.2040809@cn.fujitsu.com> (raw)
In-Reply-To: <51944C16.5080607@cn.fujitsu.com>


Test for statement:
"If shmaddr is NULL, the system chooses a suitable (unused) address
at which to attach the segment."

Signed-off-by: DAN LI <li.dan@cn.fujitsu.com>
---
 testcases/kernel/syscalls/ipc/shmat/shmat01.c | 60 +++++++++++++++++----------
 1 file changed, 38 insertions(+), 22 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/shmat/shmat01.c b/testcases/kernel/syscalls/ipc/shmat/shmat01.c
index 3461782..3c09817 100644
--- a/testcases/kernel/syscalls/ipc/shmat/shmat01.c
+++ b/testcases/kernel/syscalls/ipc/shmat/shmat01.c
@@ -46,7 +46,7 @@
 #define CASE1		20

 char *TCID = "shmat01";
-int TST_TOTAL = 3;
+int TST_TOTAL = 4;

 int shm_id_1 = -1;

@@ -62,6 +62,7 @@ static struct test_case_t {
 	int *shmid;
 	int offset;
 	int flags;
+	int getbase;
 } *TC;

 static void check_functionality(int);
@@ -70,6 +71,7 @@ int main(int argc, char *argv[])
 {
 	int lc, i;
 	char *msg;
+	void *attchaddr;

 	msg = parse_opts(argc, argv, NULL, NULL);
 	if (msg != NULL)
@@ -83,12 +85,16 @@ int main(int argc, char *argv[])

 		for (i = 0; i < TST_TOTAL; i++) {

-			base_addr = probe_free_addr();
+			if (TC[i].getbase) {
+				base_addr = probe_free_addr();
+				attchaddr = base_addr + TC[i].offset;
+			} else {
+				attchaddr = NULL;
+			}

-			addr = shmat(*(TC[i].shmid), base_addr + TC[i].offset,
-				     TC[i].flags);
-			TEST_ERRNO = errno;
+			addr = shmat(*(TC[i].shmid), attchaddr, TC[i].flags);

+			TEST_ERRNO = errno;
 			if (addr == (void *)-1) {
 				tst_brkm(TFAIL | TTERRNO, cleanup,
 					 "shmat call failed");
@@ -142,35 +148,36 @@ static void check_functionality(int i)
 	/* check for specific conditions depending on the type of attach */
 	switch (i) {
 	case 0:
+	case 1:
 		/*
-		 * Check the functionality of the first call by simply
-		 * "writing" a value to the shared memory space.
+		 * Check the functionality of shmat by simply "writing"
+		 * a value to the shared memory space.
 		 * If this fails the program will get a SIGSEGV, dump
 		 * core and exit.
 		 */

 		*shared = CASE0;
 		break;
-	case 1:
+	case 2:
 		/*
-		 * Check the functionality of the second call by writing
-		 * a value to the shared memory space and then checking
-		 * that the original address given was rounded down as
+		 * Check the functionality of shmat by writing a value
+		 * to the shared memory space and then checking that
+		 * the original address given was rounded down as
 		 * specified in the man page.
 		 */

 		*shared = CASE1;
-		orig_add = addr + ((unsigned long)TC[1].offset % SHMLBA);
-		if (orig_add != base_addr + TC[1].offset) {
+		orig_add = addr + ((unsigned long)TC[2].offset % SHMLBA);
+		if (orig_add != base_addr + TC[2].offset) {
 			tst_resm(TFAIL, "shared memory address is not "
 				 "correct");
 			fail = 1;
 		}
 		break;
-	case 2:
+	case 3:
 		/*
 		 * This time the shared memory is read only.  Read the value
-		 * and check that it is equal to the value set in case #2,
+		 * and check that it is equal to the value set in last case,
 		 * because shared memory is persistent.
 		 */

@@ -195,20 +202,29 @@ void setup(void)
 	if (TC == NULL)
 		tst_brkm(TFAIL | TERRNO, cleanup, "failed to allocate memory");

-	/* a straight forward read/write attach */
+	/* set NULL as attaching address*/
 	TC[0].shmid = &shm_id_1;
 	TC[0].offset = 0;
 	TC[0].flags = 0;
+	TC[0].getbase = 0;

-	/* an attach using unaligned memory */
+	/* a straight forward read/write attach */
 	TC[1].shmid = &shm_id_1;
-	TC[1].offset = SHMLBA - 1;
-	TC[1].flags = SHM_RND;
+	TC[1].offset = 0;
+	TC[1].flags = 0;
+	TC[1].getbase = 1;

-	/* a read only attach */
+	/* an attach using unaligned memory */
 	TC[2].shmid = &shm_id_1;
-	TC[2].offset = 0;
-	TC[2].flags = SHM_RDONLY;
+	TC[2].offset = SHMLBA - 1;
+	TC[2].flags = SHM_RND;
+	TC[2].getbase = 1;
+
+	/* a read only attach */
+	TC[3].shmid = &shm_id_1;
+	TC[3].offset = 0;
+	TC[3].flags = SHM_RDONLY;
+	TC[3].getbase = 1;

 	tst_tmpdir();

-- 
1.8.1

------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  parent reply	other threads:[~2013-05-17  5:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-16  3:01 [LTP] [PATCH 1/2] shmat/shmat01.c: cleanup DAN LI
2013-05-16  3:09 ` [LTP] [PATCH 2/2] shmat/shmat01.c: Test for specifying NULL to shmaddr DAN LI
2013-05-16  7:23   ` Jan Stancek
2013-05-17  5:39 ` DAN LI [this message]
2013-05-17  7:06   ` [LTP] [PATCH V2 " Jan Stancek
2013-05-17  7:24   ` Wanlong Gao
2013-05-17  7:24 ` [LTP] [PATCH 1/2] shmat/shmat01.c: cleanup Wanlong Gao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5195C294.2040809@cn.fujitsu.com \
    --to=li.dan@cn.fujitsu.com \
    --cc=ltp-list@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox