Signed-off-by: Tang Chen <[email protected]>
---
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c |   47 +++++++-------------
 1 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c 
b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
index 45cddf7..3bbbc46 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
@@ -63,6 +63,7 @@
 #include "test.h"
 #include "usctest.h"
 #include "system_specific_hugepages_info.h"
+#include "libmnt.h"
 
 #define LOW_ADDR       (void *)(0x80000000)
 #define LOW_ADDR2      (void *)(0x90000000)
@@ -77,38 +78,17 @@ unsigned long *addrlist[5]; /* list of addresses of memory 
mapped region */
 int i;
 int fildes;                    /* file descriptor for tempfile */
 int nfildes;                   /* file descriptor for /dev/zero */
-char *Hopt;                     /* location of hugetlbfs */
+char *mount_point = NULL;
 
-void setup();                  /* Main setup function of test */
-void cleanup();                        /* cleanup function for the test */
-
-void help()
-{
-       printf("  -H /..  Location of hugetlbfs, i.e. -H /var/hugetlbfs \n");
-}
+void setup(void);                      /* Main setup function of test */
+void cleanup(void);                    /* cleanup function for the test */
 
 int
 main(int ac, char **av)
 {
        int lc;
-       char *msg;
-        int Hflag = 0;
        int page_sz, map_sz;
 
-               option_t options[] = {
-               { "H:",   &Hflag, &Hopt },    /* Required for location of 
hugetlbfs */
-               { NULL, NULL, NULL }          /* NULL required to end array */
-               };
-
-       /* Parse standard options given to run the test. */
-       if ((msg = parse_opts(ac, av, options, &help)) != NULL)
-               tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s, use -help", 
msg);
-
-       if (Hflag == 0) {
-               tst_brkm(TBROK, NULL,
-                   "-H option is REQUIRED for this test, use -h for options 
help");
-       }
-
        page_sz = getpagesize();
        map_sz = 2 * 1024 * hugepages_size();
 
@@ -206,15 +186,20 @@ main(int ac, char **av)
  *          Write some known data into file and get the size of the file.
  */
 void
-setup()
+setup(void)
 {
-       tst_tmpdir();
-
-       snprintf(TEMPFILE, sizeof(TEMPFILE), "%s/mmapfile%d", Hopt, getpid());
-
+       tst_require_root(NULL);
        tst_sig(FORK, DEF_HANDLER, cleanup);
 
        TEST_PAUSE;
+
+       tst_tmpdir();
+       mount_point = get_tst_tmpdir();
+
+       mount_hugetlbfs(mount_point);
+       hugepage_alloc(1024);
+
+       snprintf(TEMPFILE, sizeof(TEMPFILE), "%s/mmapfile%d", mount_point, 
getpid());
 }
 
 /*
@@ -223,7 +208,7 @@ setup()
  *            Remove the temporary directory created.
  */
 void
-cleanup()
+cleanup(void)
 {
        /*
         * print timing stats if that option was specified.
@@ -231,6 +216,6 @@ cleanup()
        TEST_CLEANUP;
 
        unlink(TEMPFILE);
-
+       umount_hugetlbfs(mount_point);
        tst_rmdir();
 }
-- 
1.7.1

-- 
Best Regards,
Tang chen
>From 064d439c22ca2e138c7ea131dd378cffb08d9dc4 Mon Sep 17 00:00:00 2001
From: Tang Chen <[email protected]>
Date: Tue, 16 Aug 2011 14:20:24 +0800
Subject: [PATCH 4/6] hugemmap02.c : Automatically mount hugetlbfs on /huge.

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 temp directory with name including the current PID, 
automatically mounts hugetlbfs on the directory before test starts, and umounts 
it when the test is over.

Signed-off-by: Tang Chen <[email protected]>
---
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c |   47 +++++++-------------
 1 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c 
b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
index 45cddf7..3bbbc46 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
@@ -63,6 +63,7 @@
 #include "test.h"
 #include "usctest.h"
 #include "system_specific_hugepages_info.h"
+#include "libmnt.h"
 
 #define LOW_ADDR       (void *)(0x80000000)
 #define LOW_ADDR2      (void *)(0x90000000)
@@ -77,38 +78,17 @@ unsigned long *addrlist[5]; /* list of addresses of memory 
mapped region */
 int i;
 int fildes;                    /* file descriptor for tempfile */
 int nfildes;                   /* file descriptor for /dev/zero */
-char *Hopt;                     /* location of hugetlbfs */
+char *mount_point = NULL;
 
-void setup();                  /* Main setup function of test */
-void cleanup();                        /* cleanup function for the test */
-
-void help()
-{
-       printf("  -H /..  Location of hugetlbfs, i.e. -H /var/hugetlbfs \n");
-}
+void setup(void);                      /* Main setup function of test */
+void cleanup(void);                    /* cleanup function for the test */
 
 int
 main(int ac, char **av)
 {
        int lc;
-       char *msg;
-        int Hflag = 0;
        int page_sz, map_sz;
 
-               option_t options[] = {
-               { "H:",   &Hflag, &Hopt },    /* Required for location of 
hugetlbfs */
-               { NULL, NULL, NULL }          /* NULL required to end array */
-               };
-
-       /* Parse standard options given to run the test. */
-       if ((msg = parse_opts(ac, av, options, &help)) != NULL)
-               tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s, use -help", 
msg);
-
-       if (Hflag == 0) {
-               tst_brkm(TBROK, NULL,
-                   "-H option is REQUIRED for this test, use -h for options 
help");
-       }
-
        page_sz = getpagesize();
        map_sz = 2 * 1024 * hugepages_size();
 
@@ -206,15 +186,20 @@ main(int ac, char **av)
  *          Write some known data into file and get the size of the file.
  */
 void
-setup()
+setup(void)
 {
-       tst_tmpdir();
-
-       snprintf(TEMPFILE, sizeof(TEMPFILE), "%s/mmapfile%d", Hopt, getpid());
-
+       tst_require_root(NULL);
        tst_sig(FORK, DEF_HANDLER, cleanup);
 
        TEST_PAUSE;
+
+       tst_tmpdir();
+       mount_point = get_tst_tmpdir();
+
+       mount_hugetlbfs(mount_point);
+       hugepage_alloc(1024);
+
+       snprintf(TEMPFILE, sizeof(TEMPFILE), "%s/mmapfile%d", mount_point, 
getpid());
 }
 
 /*
@@ -223,7 +208,7 @@ setup()
  *            Remove the temporary directory created.
  */
 void
-cleanup()
+cleanup(void)
 {
        /*
         * print timing stats if that option was specified.
@@ -231,6 +216,6 @@ cleanup()
        TEST_CLEANUP;
 
        unlink(TEMPFILE);
-
+       umount_hugetlbfs(mount_point);
        tst_rmdir();
 }
-- 
1.7.1

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model 
configuration take the hassle out of deploying and managing Subversion and 
the tools developers use with it. Learn more about uberSVN and get a free 
download at:  http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to