Signed-off-by: Tang Chen <[email protected]>
---
testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c | 66 ++++++++------------
1 files changed, 27 insertions(+), 39 deletions(-)
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c
b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c
index cac94b0..5e085a0 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c
@@ -54,54 +54,31 @@
#include "test.h"
#include "usctest.h"
#include "system_specific_hugepages_info.h"
+#include "lib/libmnt.h"
#define HIGH_ADDR (void *)(0x1000000000000)
-char* TEMPFILE="mmapfile";
+char TEMPFILE[MAXPATHLEN];
char *TCID="hugemmap03"; /* Test program identifier. */
int TST_TOTAL=1; /* Total number of test cases. */
unsigned long *addr; /* addr of memory mapped region */
int fildes; /* file descriptor for tempfile */
-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; /* loop counter */
- char *msg; /* message returned from parse_opts */
- int Hflag=0; /* binary flag: opt or not */
int page_sz;
#if __WORDSIZE==32 /* 32-bit compiled */
tst_brkm(TCONF, NULL, "This test is only for 64bit");
#endif
- 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. */
- msg = parse_opts(ac, av, options, &help);
- if (msg != (char *) NULL) {
- tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s, use -help",
msg);
- tst_exit();
- }
-
- if (Hflag == 0) {
- tst_brkm(TBROK, NULL, "-H option is REQUIRED for this test, use
-h for options help");
- tst_exit();
- }
-
page_sz = getpagesize();
setup();
@@ -122,8 +99,15 @@ main(int ac, char **av)
addr = mmap(HIGH_ADDR, page_sz, PROT_READ,
MAP_SHARED | MAP_FIXED, fildes, 0);
if (addr != MAP_FAILED) {
- tst_resm(TFAIL, "Normal mmap() into high region
unexpectedly succeeded on %s, errno=%d : %s",
- TEMPFILE, errno, strerror(errno));
+ tst_resm(TFAIL, "Normal mmap() into high region
unexpectedly "
+ "succeeded on %s, errno=%d : %s",
+ TEMPFILE, errno, strerror(errno));
+
+ /* Unmap the mapped memory */
+ if (munmap(addr, page_sz) != 0) {
+ tst_brkm(TFAIL, NULL, "munmap() fails to unmap
the "
+ "memory, errno=%d : %s", errno,
strerror(errno));
+ }
continue;
} else {
tst_resm(TPASS, "Normal mmap() into high region failed
correctly");
@@ -133,6 +117,7 @@ main(int ac, char **av)
close(fildes);
}
+ close(fildes);
cleanup();
tst_exit();
@@ -149,18 +134,20 @@ main(int ac, char **av)
* Write some known data into file and get the size of the file.
*/
void
-setup()
+setup(void)
{
- char mypid[40];
-
- sprintf(mypid,"/%d",getpid());
- TEMPFILE=strcat(mypid,TEMPFILE);
- TEMPFILE=strcat(Hopt,TEMPFILE);
-
+ 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());
}
/*
@@ -169,7 +156,7 @@ setup()
* Remove the temporary directory created.
*/
void
-cleanup()
+cleanup(void)
{
/*
* print timing stats if that option was specified.
@@ -177,5 +164,6 @@ cleanup()
TEST_CLEANUP;
unlink(TEMPFILE);
-
+ umount_hugetlbfs(mount_point);
+ tst_rmdir();
}
--
1.7.1
--
Best Regards,
Tang chen
>From 4e4c3d7e20ac36664869ea7547fcacbe678cc67e Mon Sep 17 00:00:00 2001
From: Tang Chen <[email protected]>
Date: Tue, 2 Aug 2011 10:34:51 +0800
Subject: [PATCH 5/6] hugemmap03.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/hugemmap03.c | 66 ++++++++------------
1 files changed, 27 insertions(+), 39 deletions(-)
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c
b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c
index cac94b0..5e085a0 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap03.c
@@ -54,54 +54,31 @@
#include "test.h"
#include "usctest.h"
#include "system_specific_hugepages_info.h"
+#include "lib/libmnt.h"
#define HIGH_ADDR (void *)(0x1000000000000)
-char* TEMPFILE="mmapfile";
+char TEMPFILE[MAXPATHLEN];
char *TCID="hugemmap03"; /* Test program identifier. */
int TST_TOTAL=1; /* Total number of test cases. */
unsigned long *addr; /* addr of memory mapped region */
int fildes; /* file descriptor for tempfile */
-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; /* loop counter */
- char *msg; /* message returned from parse_opts */
- int Hflag=0; /* binary flag: opt or not */
int page_sz;
#if __WORDSIZE==32 /* 32-bit compiled */
tst_brkm(TCONF, NULL, "This test is only for 64bit");
#endif
- 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. */
- msg = parse_opts(ac, av, options, &help);
- if (msg != (char *) NULL) {
- tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s, use -help",
msg);
- tst_exit();
- }
-
- if (Hflag == 0) {
- tst_brkm(TBROK, NULL, "-H option is REQUIRED for this test, use
-h for options help");
- tst_exit();
- }
-
page_sz = getpagesize();
setup();
@@ -122,8 +99,15 @@ main(int ac, char **av)
addr = mmap(HIGH_ADDR, page_sz, PROT_READ,
MAP_SHARED | MAP_FIXED, fildes, 0);
if (addr != MAP_FAILED) {
- tst_resm(TFAIL, "Normal mmap() into high region
unexpectedly succeeded on %s, errno=%d : %s",
- TEMPFILE, errno, strerror(errno));
+ tst_resm(TFAIL, "Normal mmap() into high region
unexpectedly "
+ "succeeded on %s, errno=%d : %s",
+ TEMPFILE, errno, strerror(errno));
+
+ /* Unmap the mapped memory */
+ if (munmap(addr, page_sz) != 0) {
+ tst_brkm(TFAIL, NULL, "munmap() fails to unmap
the "
+ "memory, errno=%d : %s", errno,
strerror(errno));
+ }
continue;
} else {
tst_resm(TPASS, "Normal mmap() into high region failed
correctly");
@@ -133,6 +117,7 @@ main(int ac, char **av)
close(fildes);
}
+ close(fildes);
cleanup();
tst_exit();
@@ -149,18 +134,20 @@ main(int ac, char **av)
* Write some known data into file and get the size of the file.
*/
void
-setup()
+setup(void)
{
- char mypid[40];
-
- sprintf(mypid,"/%d",getpid());
- TEMPFILE=strcat(mypid,TEMPFILE);
- TEMPFILE=strcat(Hopt,TEMPFILE);
-
+ 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());
}
/*
@@ -169,7 +156,7 @@ setup()
* Remove the temporary directory created.
*/
void
-cleanup()
+cleanup(void)
{
/*
* print timing stats if that option was specified.
@@ -177,5 +164,6 @@ cleanup()
TEST_CLEANUP;
unlink(TEMPFILE);
-
+ umount_hugetlbfs(mount_point);
+ tst_rmdir();
}
--
1.7.1
------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
The must-attend event for mobile developers. Connect with experts.
Get tools for creating Super Apps. See the latest technologies.
Sessions, hands-on labs, demos & much more. Register early & save!
http://p.sf.net/sfu/rim-blackberry-1
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list