public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: "Mitani" <mitani@ryobi.co.jp>
To: ltp-list@lists.sourceforge.net
Cc: "當座 健市" <toza@ryobi.co.jp>
Subject: [LTP] [PATCH] fix "hugeshmget03" test
Date: Fri, 13 Aug 2010 17:15:38 +0900	[thread overview]
Message-ID: <000701cb3abf$b6862400$23926c00$@co.jp> (raw)

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

Hi,

I tried to run hugeshmget03 testcase, but it failed in several environment.
This testcase failed in following systems:
   - RHEL5.5-x86
   - RHEL5.5-x86_64
   - RHEL5.5-ia64

On the other hand, this testcase succeeded in following RHEL4.8 systems:
   - RHEL4.8-x86
   - RHEL4.8-x86_64
   - RHEL4.8-ia64


I used following git:
   ltp-dev-22b12b3f972569361dfa28361fe0685bf0eca259.tar.gz
This testcase failed also in previous gits.


RHEL5.5-x86 log (failed case):
------------
[...]
hugeshmget03    0  TINFO  :  errno = 12 : Cannot allocate memory
hugeshmget03    1  TBROK  :  Didn't get ENOSPC in test setup
[...]
------------

RHEL4.8-x86 log (succeeded case):
------------
[...]
hugeshmget03    1  TPASS  :  expected failure - errno = 28 : No space left
on device
hugeshmget03    1  TPASS  :  expected failure - errno = 28 : No space left
on device
hugeshmget03    1  TPASS  :  expected failure - errno = 28 : No space left
on device
hugeshmget03    1  TPASS  :  expected failure - errno = 28 : No space left
on device
hugeshmget03    1  TPASS  :  expected failure - errno = 28 : No space left
on device
hugeshmget03    1  TPASS  :  expected failure - errno = 28 : No space left
on device
hugeshmget03    1  TPASS  :  expected failure - errno = 28 : No space left
on device
hugeshmget03    1  TPASS  :  expected failure - errno = 28 : No space left
on device
hugeshmget03    1  TPASS  :  expected failure - errno = 28 : No space left
on device
hugeshmget03    1  TPASS  :  expected failure - errno = 28 : No space left
on device
[...]
------------

This test expected that "shmget()" returns ENOSPC after "shmget()" called 
till it reached SHMMNI or SHMALL.
In RHEL4.8 system, "shmget()" returned ENOSPC.
But in RHEL5.5 system, shmget() didn't return ENOSPC.

I used strace command in RHEL5.5, and noticed that "shmget()" returned
ENOMEM:
------------
[root@RHEL55-LTP-x86 ltp]# strace -o git0719-shmget03-strace.txt -s 256 -T
-tt testcases/bin/hugeshmget03 hugeshmget03 -i 10
hugeshmget03    0  TINFO  :  errno = 12 : Cannot allocate memory
hugeshmget03    1  TBROK  :  Didn't get ENOSPC in test setup


17:20:27.939953 gettimeofday({1279614027, 939985}, {4294966756, 0}) = 0
<0.000023>
17:20:27.940089 stat64("/tmp/hugWojTGq", {st_mode=S_IFDIR|0777,
st_size=4096, ...}) = 0 <0.000024>
17:20:27.940386 shmget(IPC_PRIVATE, 4194304,
IPC_CREAT|IPC_EXCL|SHM_HUGETLB|0600) = 276463619 <0.000041>
17:20:27.940518 shmget(IPC_PRIVATE, 4194304,
IPC_CREAT|IPC_EXCL|SHM_HUGETLB|0600) = 276496388 <0.000026>
17:20:27.940648 shmget(IPC_PRIVATE, 4194304,
IPC_CREAT|IPC_EXCL|SHM_HUGETLB|0600) = -1 ENOMEM (Cannot allocate memory)
<0.000032>
17:20:27.940861 fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 1),
...}) = 0 <0.000026>
17:20:27.941106 mmap2(NULL, 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f45000 <0.000024>
17:20:27.941233 write(1, "hugeshmget03    0  TINFO  :  errno = 12 : Cannot
allocate memory\n", 65) = 65 <0.000270>
17:20:27.941693 write(1, "hugeshmget03    1  TBROK  :  Didn't get ENOSPC in
test setup\n", 61) = 61 <0.000093>
[...]
------------


The confirmation of free Hugepage obeys followings, I think:
   1. Compare necessary pages and the number of Hugepages.
      If necessary pages exceeded Hugepage, ENOMEM is returned. 
   2. Compare of necessary memory and the limit of shared memory "SHMMNI".
      If necessary memory exceeded SHMMNI, ENOSPC is returned.

The comparison logic of necessary pages and the number of Hugepages 
is different from RHEL4.X system and RHEL5.X system.

In RHEL4.8:
   It is the comparison of "necessary pages" and "HugePages_Free".
   The opportunity of ENOMEM is "necessary pages > HugePages_Free".

   "HugePages_Free" doesn't decrease when "shmget()" is called.
   It decreases only when "shmat()" is called.

   Therefore, ENOMEM is not returned, and ENOSPC occurs when reaching 
   the limit of SHMMNI.

In RHEL5.4:
   "HugePages_Psvd" is added. This parameter is the number of Hugepages 
   which are planned to allocate but aren't yet allocated.
   The opportunity of ENOMEM is "necessary pages + HugePages_Rsvd >
HugePages_Free"

   "HugePages_Psvd" increases when "shmget()" is called.

   Therfore, "shmget()" returns with ENOMEM, and doesn't return with ENOSPC.


I thought that it is necessary to change a judgment condition:
   - When "/proc/meminfo" doesn't have "HugePages_Rsvd" (case of RHEL4.X),
     ENOSPC is OK.
   - When "/proc/meminfo" has "HugePages_Rsvd" (case of RHEL5.X), 
     ENOMEM is OK.


Signed-off-by: Tomonori Mitani <mitani@ryobi.co.jp>

============
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c	2010-08-05
22:28:15.000000000 +0900
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c	2010-08-11
15:06:11.000000000 +0900
@@ -71,6 +71,8 @@
 
 int shm_id_arr[MAXIDS];
 
+/* If HugePages_Rsvd exists in /proc/meminfo, hp_rsvd is 1. */
+int hp_rsvd = 0;
 
 int main(int ac, char **av)
 {
@@ -109,16 +111,18 @@
 
 		TEST_ERROR_LOG(TEST_ERRNO);
 
-		switch(TEST_ERRNO) {
-		case ENOSPC:
+		/*
+		 * errno is ENOSPC and hp_rsvd is 0 -> PASS
+		 * errno is ENOMEM and hp_rsvd is 1 -> PASS
+		 * others                           -> FAIL
+		 */
+		if ((errno == ENOSPC && hp_rsvd == 0) || (errno == ENOMEM &&
hp_rsvd == 1)){
 			tst_resm(TPASS, "expected failure - errno = "
 				 "%d : %s", TEST_ERRNO,
strerror(TEST_ERRNO));
-			break;
-		default:
+		} else {
 			tst_resm(TFAIL, "call failed with an "
 				 "unexpected error - %d : %s",
 				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
 		}		
 	}
 
@@ -141,6 +145,19 @@
 	/* Pause if that option was specified */
 	TEST_PAUSE;
 
+	/* Check whether HugePages_Rsvd exists in /proc/meminfo or not. */
+	FILE *fp;
+	char s[50];
+	if ((fp = fopen("/proc/meminfo", "r")) == NULL) {
+		tst_brkm(TBROK, tst_exit, "Cannot open /proc/meminfo.");
+	}
+	while (fgets(s, 50, fp) != NULL) {
+		if (strstr(s, "HugePages_Rsvd") != NULL) {
+			hp_rsvd = 1;
+		}
+	}
+	fclose(fp);
+	
 	/*
 	 * Create a temporary directory and cd into it.
 	 * This helps to ensure that a unique msgkey is created.
@@ -166,11 +183,13 @@
 	}
 
 	/*
-	 * If the errno is other than ENOSPC, then something else is wrong.
+	 * errno is ENOSPC and hp_rsvd is 0 -> OK
+	 * errno is ENOMEM and hp_rsvd is 1 -> OK
+	 * others                           -> NG
 	 */
-	if (errno != ENOSPC) {
+	if (!(errno == ENOSPC && hp_rsvd == 0) && !(errno == ENOMEM &&
hp_rsvd == 1)){
 		tst_resm(TINFO, "errno = %d : %s", errno, strerror(errno));
-		tst_brkm(TBROK, cleanup, "Didn't get ENOSPC in test setup");
+		tst_brkm(TBROK, cleanup, "Didn't get ENOSPC or ENOMEM in
test setup");
 	}
 }
 
============



Regards--


-Tomonori Mitani

[-- Attachment #2: hugeshmget03.patch --]
[-- Type: application/octet-stream, Size: 2129 bytes --]

--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c	2010-08-05 22:28:15.000000000 +0900
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c	2010-08-11 15:06:11.000000000 +0900
@@ -71,6 +71,8 @@
 
 int shm_id_arr[MAXIDS];
 
+/* If HugePages_Rsvd exists in /proc/meminfo, hp_rsvd is 1. */
+int hp_rsvd = 0;
 
 int main(int ac, char **av)
 {
@@ -109,16 +111,18 @@
 
 		TEST_ERROR_LOG(TEST_ERRNO);
 
-		switch(TEST_ERRNO) {
-		case ENOSPC:
+		/*
+		 * errno is ENOSPC and hp_rsvd is 0 -> PASS
+		 * errno is ENOMEM and hp_rsvd is 1 -> PASS
+		 * others                           -> FAIL
+		 */
+		if ((errno == ENOSPC && hp_rsvd == 0) || (errno == ENOMEM && hp_rsvd == 1)){
 			tst_resm(TPASS, "expected failure - errno = "
 				 "%d : %s", TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		default:
+		} else {
 			tst_resm(TFAIL, "call failed with an "
 				 "unexpected error - %d : %s",
 				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
 		}		
 	}
 
@@ -141,6 +145,19 @@
 	/* Pause if that option was specified */
 	TEST_PAUSE;
 
+	/* Check whether HugePages_Rsvd exists in /proc/meminfo or not. */
+	FILE *fp;
+	char s[50];
+	if ((fp = fopen("/proc/meminfo", "r")) == NULL) {
+		tst_brkm(TBROK, tst_exit, "Cannot open /proc/meminfo.");
+	}
+	while (fgets(s, 50, fp) != NULL) {
+		if (strstr(s, "HugePages_Rsvd") != NULL) {
+			hp_rsvd = 1;
+		}
+	}
+	fclose(fp);
+	
 	/*
 	 * Create a temporary directory and cd into it.
 	 * This helps to ensure that a unique msgkey is created.
@@ -166,11 +183,13 @@
 	}
 
 	/*
-	 * If the errno is other than ENOSPC, then something else is wrong.
+	 * errno is ENOSPC and hp_rsvd is 0 -> OK
+	 * errno is ENOMEM and hp_rsvd is 1 -> OK
+	 * others                           -> NG
 	 */
-	if (errno != ENOSPC) {
+	if (!(errno == ENOSPC && hp_rsvd == 0) && !(errno == ENOMEM && hp_rsvd == 1)){
 		tst_resm(TINFO, "errno = %d : %s", errno, strerror(errno));
-		tst_brkm(TBROK, cleanup, "Didn't get ENOSPC in test setup");
+		tst_brkm(TBROK, cleanup, "Didn't get ENOSPC or ENOMEM in test setup");
 	}
 }
 

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

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 

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

                 reply	other threads:[~2010-08-13  8:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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='000701cb3abf$b6862400$23926c00$@co.jp' \
    --to=mitani@ryobi.co.jp \
    --cc=ltp-list@lists.sourceforge.net \
    --cc=toza@ryobi.co.jp \
    /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