Hi,

hugemmap test could fail because I didn't mount hugetlbfs by myself. And 
I need to umount it after test.

In my opinion,
firstly, mounting hugetlbfs on /tmp is not a good idea, because lots of 
programs could use /tmp for other purpose. This could cause other tests 
fail;
secondly, mounting hugetlbfs could be done automatically.
This patch creates a directory /huge, automatically mounts hugetlbfs on 
/huge before test starts, and umounts it when the test is over.

Signed-off-by: tangchen <[email protected]>
---
  runtest/hugetlb                                    |    2 +-
  testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c |   38 
+++++++++++++++++++-
  2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 1347f32..1490bda 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -1,4 +1,4 @@
-hugemmap01 hugemmap01 -H/tmp
+hugemmap01 hugemmap01 -H/huge
  hugemmap02 hugemmap02 -H/tmp -c10
  hugemmap03 hugemmap03 -H/tmp -I2 -c10
  hugemmap04 hugemmap04 -H/tmp
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c 
b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c
index a9b8a36..0ac411d 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c
@@ -69,6 +69,7 @@
  #include <sys/stat.h>
  #include <sys/mman.h>
  #include <sys/types.h>
+#include <sys/mount.h>

  #include "test.h"
  #include "usctest.h"
@@ -85,6 +86,9 @@ char *Hopt;                     /* location of 
hugetlbfs */
  int beforetest=0;        /* Amount of free huge pages before testing */
  int aftertest=0;        /* Amount of free huge pages after testing */
  int hugepagesmapped=0;        /* Amount of huge pages mapped after 
testing */
+FILE *nr_hugepages_file = NULL; /* Used for allocate enough hugepages 
for test. */
+char *mount_point = NULL;    /* The location where we mount hugetlbfs. */
+int mkdir_err = 0;        /* Used to judge if we need to remove the 
mount point. */

  void setup();            /* Main setup function of test */
  int getfreehugepages();        /* Reads free huge pages */
@@ -121,6 +125,7 @@ main(int ac, char **av)
          tst_exit();
      }

+    mount_point = (char *)malloc(sizeof(char) * 50);
      setup();

      for (lc = 0; TEST_LOOPING(lc); lc++) {
@@ -195,6 +200,33 @@ setup()
  {
      char mypid[40];

+    mount_point = strcpy(mount_point, Hopt);
+
+    tst_require_root(tst_exit);
+
+    int ret = mkdir(mount_point, 0755);
+    mkdir_err = errno;
+    if (ret < 0 && mkdir_err != EEXIST) {
+        tst_brkm(TBROK, NULL, "mkdir() Failed on %s, errno=%d : %s",
+            mount_point, errno, strerror(errno));
+    }
+
+    if (mount("none", mount_point, "hugetlbfs", 0, NULL) < 0) {
+        tst_brkm(TBROK, NULL, "mount() Failed on %s, errno=%d : %s",
+            mount_point, errno, strerror(errno));
+    }
+
+    nr_hugepages_file = fopen("/proc/sys/vm/nr_hugepages", "w+");
+    if (nr_hugepages_file == NULL) {
+        tst_brkm(TBROK, NULL, "fopen() Failed on 
/proc/sys/vm/nr_hugepages, "
+            "errno=%d : %s", errno, strerror(errno));
+    }
+    if (fprintf(nr_hugepages_file, "%d", 1024) < 0) {
+        tst_brkm(TBROK, NULL, "fprintf() Failed on 
/proc/sys/vm/nr_hugepages, "
+            "errno=%d : %s", errno, strerror(errno));
+    }
+    fclose(nr_hugepages_file);
+
      sprintf(mypid,"/%d",getpid());
      TEMPFILE=strcat(mypid,TEMPFILE);
      TEMPFILE=strcat(Hopt,TEMPFILE);
@@ -275,5 +307,9 @@ cleanup()
      TEST_CLEANUP;

      unlink(TEMPFILE);
+    umount(mount_point);

-}
\ No newline at end of file
+    if (mkdir_err != EEXIST) {
+        remove(mount_point);
+    }
+}
-- 
1.7.1

-- 
Best Regards,
Tang chen
--------------------------------------------------
Tang Chen
Development Dept.I
Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST)
No.6 Wenzhu Road, Nanjing, 210012, China
TEL: +86+25-86630566-8513
FUJITSU INTERNAL: 7998-8513
FAX: +86+25-83317685
EMail: [email protected]
--------------------------------------------------
This communication is for use by the intended recipient(s) only and may contain 
information that is privileged, confidential and exempt from disclosure under 
applicable law. If you are not an intended recipient of this communication, you 
are hereby notified that any dissemination, distribution or copying hereof is 
strictly prohibited.  If you have received this communication in error, please 
notify me by reply e-mail, permanently delete this communication from your 
system, and destroy any hard copies you may have printed



------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to