From: Wanlong G. <gao...@cn...> - 2012-02-08 09:15:11
|
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 <gao...@cn...> Reviewed-by: Caspar Zhang <ca...@ca...> --- runtest/hugetlb | 2 +- testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c | 53 +++++++++++++------- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/runtest/hugetlb b/runtest/hugetlb index 7003afb..3fdc366 100644 --- a/runtest/hugetlb +++ b/runtest/hugetlb @@ -1,7 +1,7 @@ hugemmap01 hugemmap01 hugemmap02 hugemmap02 hugemmap03 hugemmap03 -I2 -hugemmap04 hugemmap04 -H/tmp +hugemmap04 hugemmap04 hugemmap05 hugemmap05 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c index 7d2b5d3..ddec060 100644 --- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c @@ -58,12 +58,14 @@ #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" -static char *TEMPFILE = "mmapfile"; +static char TEMPFILE[MAXPATHLEN]; char *TCID = "hugemmap04"; int TST_TOTAL = 1; @@ -74,10 +76,11 @@ static int freepages; static int beforetest; static int aftertest; static int hugepagesmapped; +static long hugepages = 128; +static long orig_hugepages; static char *Hopt; +static char *nr_opt; -static void setup(void); -static void cleanup(void); static void help(void); int main(int ac, char **av) @@ -85,21 +88,30 @@ int main(int ac, char **av) int lc; char *msg; int Hflag = 0; + int sflag = 0; int huge_pagesize = 0; 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); + if (((hugepages == LONG_MAX || hugepages == LONG_MIN) && + errno == ERANGE) || (errno != 0 && hugepages == 0)) + tst_brkm(TBROK|TERRNO, NULL, "strtol"); + } /* Check number of hugepages */ if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0) @@ -138,6 +150,7 @@ int main(int ac, char **av) sleep(2); if (addr == MAP_FAILED) { tst_resm(TFAIL|TERRNO, "mmap() Failed on %s", TEMPFILE); + close(fildes); continue; } else { tst_resm(TPASS, "Succeeded mapping file using %d pages", @@ -169,26 +182,28 @@ 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); + orig_hugepages = get_sys_tune("nr_hugepages"); + 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); + set_sys_tune("nr_hugepages", orig_hugepages, 0); + umount(Hopt); + tst_rmdir(); } static void help(void) -- 1.7.9 |