Signed-off-by: tangchen <[email protected]>
---
testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c | 48 +++++++-------------
1 files changed, 17 insertions(+), 31 deletions(-)
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
index 4cc6ed4..7debb70 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
@@ -73,10 +73,11 @@
#include "test.h"
#include "usctest.h"
#include "system_specific_hugepages_info.h"
+#include "libmnt.h"
#define BUFFER_SIZE 256
-char* TEMPFILE="mmapfile";
+char TEMPFILE[MAXPATHLEN];
char *TCID="hugemmap04"; /* Test program identifier. */
int TST_TOTAL=1; /* Total number of test cases. */
@@ -87,41 +88,25 @@ int freepages=0; /* Amount of free huge pages to
use for testing */
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 */
-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 huge_pagesize=0;
- 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);
+ msg = parse_opts(ac, av, NULL, NULL);
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();
- }
-
/* Check number of hugepages */
if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
tst_brkm(TCONF, cleanup, "Not enough available Hugepages");
@@ -151,7 +136,7 @@ main(int ac, char **av)
tst_resm(TINFO,"Total amount of free huge pages is
%d",freepages);
tst_resm(TINFO,"Max number allowed for 1 mmap file in 32-bits
is 128");
if (freepages > 128)
- freepages=128;
+ freepages=128;
#endif
/*
* Call mmap
@@ -204,18 +189,18 @@ 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());
}
/*
@@ -224,7 +209,7 @@ setup()
* Remove the temporary directory created.
*/
void
-cleanup()
+cleanup(void)
{
/*
* print timing stats if that option was specified.
@@ -232,5 +217,6 @@ cleanup()
TEST_CLEANUP;
unlink(TEMPFILE);
-
+ umount_hugetlbfs(mount_point);
+ tst_rmdir();
}
--
1.7.1
--
Best Regards,
Tang chen
>From 44f19a815587ca98f164ef9173cc4aa79d871414 Mon Sep 17 00:00:00 2001
From: tangchen <[email protected]>
Date: Wed, 7 Sep 2011 09:59:25 +0800
Subject: [PATCH 6/6] hugemmap04.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: tangchen <[email protected]>
---
testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c | 48 +++++++-------------
1 files changed, 17 insertions(+), 31 deletions(-)
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
index 4cc6ed4..7debb70 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
@@ -73,10 +73,11 @@
#include "test.h"
#include "usctest.h"
#include "system_specific_hugepages_info.h"
+#include "libmnt.h"
#define BUFFER_SIZE 256
-char* TEMPFILE="mmapfile";
+char TEMPFILE[MAXPATHLEN];
char *TCID="hugemmap04"; /* Test program identifier. */
int TST_TOTAL=1; /* Total number of test cases. */
@@ -87,41 +88,25 @@ int freepages=0; /* Amount of free huge pages to
use for testing */
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 */
-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 huge_pagesize=0;
- 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);
+ msg = parse_opts(ac, av, NULL, NULL);
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();
- }
-
/* Check number of hugepages */
if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
tst_brkm(TCONF, cleanup, "Not enough available Hugepages");
@@ -151,7 +136,7 @@ main(int ac, char **av)
tst_resm(TINFO,"Total amount of free huge pages is
%d",freepages);
tst_resm(TINFO,"Max number allowed for 1 mmap file in 32-bits
is 128");
if (freepages > 128)
- freepages=128;
+ freepages=128;
#endif
/*
* Call mmap
@@ -204,18 +189,18 @@ 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());
}
/*
@@ -224,7 +209,7 @@ setup()
* Remove the temporary directory created.
*/
void
-cleanup()
+cleanup(void)
{
/*
* print timing stats if that option was specified.
@@ -232,5 +217,6 @@ cleanup()
TEST_CLEANUP;
unlink(TEMPFILE);
-
+ umount_hugetlbfs(mount_point);
+ tst_rmdir();
}
--
1.7.1
------------------------------------------------------------------------------
Using storage to extend the benefits of virtualization and iSCSI
Virtualization increases hardware utilization and delivers a new level of
agility. Learn what those decisions are and how to modernize your storage
and backup environments for virtualization.
http://www.accelacomm.com/jaw/sfnl/114/51434361/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list