Auto mount the temporary directory for testing:
1. auto mount can reduce bugs
2. add a option to change the default hugepages to be allocated

Signed-off-by: Wanlong Gao <[email protected]>
---
 runtest/hugetlb                                    |    2 +-
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c |   49 +++++++++++--------
 2 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 806bee8..751636f 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -1,6 +1,6 @@
 hugemmap01 hugemmap01
 hugemmap02 hugemmap02 -c10
-hugemmap03 hugemmap03 -H/tmp -I2 -c10
+hugemmap03 hugemmap03 -I2 -c10
 hugemmap04 hugemmap04 -H/tmp
 hugemmap05 hugemmap05
 hugemmap05_1 hugemmap05 -m
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c 
b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c
index b3f5172..6e90a8e 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c
@@ -41,23 +41,25 @@
 #include <sys/stat.h>
 #include <sys/mman.h>
 #include <sys/types.h>
+#include <sys/mount.h>
 
 #include "test.h"
 #include "usctest.h"
 #include "system_specific_hugepages_info.h"
+#include "../../include/mem.h"
 
 #define HIGH_ADDR      (void *)(0x1000000000000)
 
-static char *TEMPFILE = "mmapfile";
+static char TEMPFILE[MAXPATHLEN];
 
 char *TCID = "hugemmap03";
 int TST_TOTAL = 1;
 static unsigned long *addr;
 static int fildes;
 static char *Hopt;
+static char *nr_opt;
+static long hugepages = 1024;
 
-static void setup(void);
-static void cleanup(void);
 static void help(void);
 
 int main(int ac, char **av)
@@ -65,6 +67,7 @@ int main(int ac, char **av)
        int lc;
        char *msg;
        int Hflag = 0;
+       int sflag = 0;
        int page_sz;
 
 #if __WORDSIZE == 32  /* 32-bit compiled */
@@ -72,18 +75,22 @@ int main(int ac, char **av)
 #endif
 
        option_t options[] = {
-               { "H:",   &Hflag, &Hopt },
+               { "H:", &Hflag, &Hopt },
+               { "s:", &sflag, &nr_opt },
                { NULL, NULL, NULL }
        };
 
        msg = parse_opts(ac, av, options, &help);
-       if (msg != NULL)
+       if (msg)
                tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s, use -help",
                         msg);
 
-       if (!Hflag)
-               tst_brkm(TBROK, NULL, "-H option is REQUIRED for this test, "
-                        "use -h for options help");
+       if (!Hflag) {
+               tst_tmpdir();
+               Hopt = get_tst_tmpdir();
+       }
+       if (sflag)
+               hugepages = strtol(nr_opt, NULL, 10);
 
        page_sz = getpagesize();
 
@@ -106,7 +113,7 @@ int main(int ac, char **av)
                            MAP_SHARED | MAP_FIXED, fildes, 0);
                if (addr != MAP_FAILED) {
                        tst_resm(TFAIL|TERRNO, "Normal mmap() into high region"
-                                " unexpectedly succeeded on %s, TEMPFILE");
+                                " unexpectedly succeeded on %s", TEMPFILE);
                        continue;
                } else {
                        tst_resm(TPASS, "Normal mmap() into high region"
@@ -122,29 +129,29 @@ int main(int ac, char **av)
        tst_exit();
 }
 
-static void setup(void)
+void setup(void)
 {
-       char mypid[40];
-
-       sprintf(mypid, "/%d", getpid());
-       TEMPFILE = strcat(mypid, TEMPFILE);
-       TEMPFILE = strcat(Hopt, TEMPFILE);
-
-       tst_sig(FORK, DEF_HANDLER, cleanup);
-
-       TEST_PAUSE;
-
+       tst_require_root(NULL);
+       if (mount("none", Hopt, "hugetlbfs", 0, NULL) < 0)
+               tst_brkm(TBROK|TERRNO, NULL,
+                        "mount failed on %s", Hopt);
+       set_sys_tune("nr_hugepages", hugepages, 1);
+       snprintf(TEMPFILE, sizeof(TEMPFILE), "%s/mmapfile%d",
+                Hopt, getpid());
 }
 
-static void cleanup(void)
+void cleanup(void)
 {
        TEST_CLEANUP;
 
        unlink(TEMPFILE);
 
+       umount(Hopt);
+       tst_rmdir();
 }
 
 static void help(void)
 {
        printf("  -H /..  Location of hugetlbfs, i.e. -H /var/hugetlbfs\n");
+       printf("  -s num  Set the number of the been allocated hugepages\n");
 }
-- 
1.7.9


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to