cleanup the coding style
Signed-off-by: Wanlong Gao <[email protected]>
---
testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c | 189 +++++++++-----------
1 files changed, 87 insertions(+), 102 deletions(-)
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
index 45cddf7..a141e4c 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
@@ -20,32 +20,23 @@
/*
* Test Name: hugemmap02
*
- * Test Description: There is both a low hugepage region (at 2-3G for use by
32-bit
- * processes) and a high hugepage region (at 1-1.5T). The high region is
always
- * exclusively for hugepages, but the low region has to be activated before it
can
- * be used for hugepages. When the kernel attempts to do a hugepage mapping
in a
- * 32-bit process it will automatically attempt to open the low region.
However,
- * that will fail if there are any normal (non-hugepage) mappings in the region
- * already.
- * When run as a 64-bit process the kernel will still do a non-hugepage
mapping
+ * Test Description: There is both a low hugepage region (at 2-3G for use by
+ * 32-bit processes) and a high hugepage region (at 1-1.5T). The high region
+ * is always exclusively for hugepages, but the low region has to be activated
+ * before it can be used for hugepages. When the kernel attempts to do a
+ * hugepage mapping in a 32-bit process it will automatically attempt to open
+ * the low region. However, that will fail if there are any normal
+ * (non-hugepage) mappings in the region already.
+ *
+ * When run as a 64-bit process the kernel will still do a non-hugepage mapping
* in the low region, but the following hugepage mapping will succeed. This is
- * because it comes from the high region, which is available to the 64-bit
process.
- * This test case is checking this behavior.
+ * because it comes from the high region, which is available to the 64-bit
+ * process.
*
- * Usage: <for command-line>
- * hugemmap02 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- * where, -c n : Run n copies concurrently.
- * -f : Turn off functionality Testing.
- * -i n : Execute test n times.
- * -I x : Execute test for x seconds.
- * -P x : Pause for x seconds between iterations.
- * -t : Turn on syscall timing.
+ * This test case is checking this behavior.
*
* HISTORY
- * 04/2004 Written by Robbie Williamson
- *
- * RESTRICTIONS:
- * None.
+ * 04/2004 Written by Robbie Williamson
*/
#include <stdio.h>
@@ -67,47 +58,42 @@
#define LOW_ADDR (void *)(0x80000000)
#define LOW_ADDR2 (void *)(0x90000000)
-char TEMPFILE[MAXPATHLEN];
-
-char *TCID = "hugemmap02"; /* Test program identifier. */
-int TST_TOTAL = 1; /* Total number of test cases. */
-unsigned long *addr; /* addr of memory mapped region */
-unsigned long *addr2; /* addr of memory mapped region */
-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 */
+static char TEMPFILE[MAXPATHLEN];
-void setup(); /* Main setup function of test */
-void cleanup(); /* cleanup function for the test */
+char *TCID = "hugemmap02";
+int TST_TOTAL = 1;
+static unsigned long *addr;
+static unsigned long *addr2;
+static unsigned long *addrlist[5];
+static int i;
+static int fildes;
+static int nfildes;
+static char *Hopt;
-void help()
-{
- printf(" -H /.. Location of hugetlbfs, i.e. -H /var/hugetlbfs \n");
-}
+static void setup(void);
+static void cleanup(void);
+static void help(void);
-int
-main(int ac, char **av)
+int main(int ac, char **av)
{
int lc;
char *msg;
- int Hflag = 0;
+ 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 */
- };
+ option_t options[] = {
+ { "H:", &Hflag, &Hopt },
+ { NULL, NULL, NULL }
+ };
- /* 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);
+ msg = parse_opts(ac, av, options, &help);
+ if (msg != 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");
- }
+ if (!Hflag)
+ 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();
@@ -115,77 +101,72 @@ main(int ac, char **av)
setup();
for (lc = 0; TEST_LOOPING(lc); lc++) {
-
- /* Creat a temporary file used for huge mapping */
- if ((fildes = open(TEMPFILE, O_RDWR|O_CREAT, 0666)) < 0) {
+ /* Creat a temporary file used for huge mapping */
+ fildes = open(TEMPFILE, O_RDWR|O_CREAT, 0666);
+ if (fildes < 0)
tst_brkm(TBROK|TERRNO, cleanup,
- "opening %s failed", TEMPFILE);
- }
- /* Creat a file used for normal mapping */
- if ((nfildes = open("/dev/zero", O_RDONLY, 0666)) < 0) {
+ "opening %s failed", TEMPFILE);
+
+ /* Creat a file used for normal mapping */
+ nfildes = open("/dev/zero", O_RDONLY, 0666);
+ if (nfildes < 0)
tst_brkm(TBROK|TERRNO, cleanup,
- "opening /dev/zero failed");
- }
+ "opening /dev/zero failed");
Tst_count = 0;
/*
* Call mmap on /dev/zero 5 times
*/
- for (i = 0; i < 5; i++) {
- addr = mmap(0, 256*1024*1024, PROT_READ,
- MAP_SHARED, nfildes, 0);
- addrlist[i] = addr;
- }
+ for (i = 0; i < 5; i++) {
+ addr = mmap(0, 256*1024*1024, PROT_READ,
+ MAP_SHARED, nfildes, 0);
+ addrlist[i] = addr;
+ }
/* mmap using normal pages and a low memory address */
- errno = 0;
addr = mmap(LOW_ADDR, page_sz, PROT_READ,
MAP_SHARED | MAP_FIXED, nfildes, 0);
if (addr == MAP_FAILED)
- tst_brkm(TBROK, cleanup,"mmap failed on nfildes");
+ tst_brkm(TBROK|TERRNO, cleanup,
+ "mmap failed on nfildes");
/* Attempt to mmap a huge page into a low memory address */
- errno = 0;
addr2 = mmap(LOW_ADDR2, map_sz, PROT_READ | PROT_WRITE,
- MAP_SHARED, fildes, 0);
-
+ MAP_SHARED, fildes, 0);
#if __WORDSIZE == 64 /* 64-bit process */
if (addr2 == MAP_FAILED) {
- tst_resm(TFAIL|TERRNO,
- "huge mmap failed unexpectedly with %s (64-bit)",
- TEMPFILE);
+ tst_resm(TFAIL|TERRNO, "huge mmap failed unexpectedly"
+ " with %s (64-bit)", TEMPFILE);
continue;
} else {
tst_resm(TPASS, "huge mmap succeeded (64-bit)");
}
#else /* 32-bit process */
if (addr2 == MAP_FAILED)
- tst_resm(TFAIL|TERRNO,
- "huge mmap failed unexpectedly with %s (32-bit)",
- TEMPFILE);
+ tst_resm(TFAIL|TERRNO, "huge mmap failed unexpectedly"
+ " with %s (32-bit)", TEMPFILE);
else if (addr2 > 0) {
- tst_resm(TCONF, "huge mmap failed to test the
scenario");
- continue;
- } else if (addr == 0)
- tst_resm(TPASS, "huge mmap succeeded (32-bit)");
+ tst_resm(TCONF,
+ "huge mmap failed to test the scenario");
+ continue;
+ } else if (addr == 0)
+ tst_resm(TPASS, "huge mmap succeeded (32-bit)");
#endif
/* Clean up things in case we are looping */
for (i = 0; i < 5; i++) {
- if (munmap(addrlist[i], 256*1024*1024) == -1)
- tst_resm(TBROK|TERRNO,
- "munmap of addrlist[%d] failed", i);
- }
+ if (munmap(addrlist[i], 256*1024*1024) == -1)
+ tst_resm(TBROK|TERRNO,
+ "munmap of addrlist[%d] failed", i);
+ }
#if __WORDSIZE == 64
- if (munmap(addr2, map_sz) == -1) {
+ if (munmap(addr2, map_sz) == -1)
tst_brkm(TFAIL|TERRNO, NULL, "huge munmap failed");
- }
#endif
- if (munmap(addr, page_sz) == -1) {
+ if (munmap(addr, page_sz) == -1)
tst_brkm(TFAIL|TERRNO, NULL, "munmap failed");
- }
close(fildes);
}
@@ -198,15 +179,15 @@ main(int ac, char **av)
/*
* setup() - performs all ONE TIME setup for this test.
*
- * Get system page size, allocate and initialize the string dummy.
- * Initialize addr such that it is more than one page below the break
- * address of the process, and initialize one page region from addr
- * with char 'A'.
- * Creat a temporary directory and a file under it.
- * Write some known data into file and get the size of the file.
+ * Get system page size, allocate and initialize the string dummy.
+ * Initialize addr such that it is more than one page below the break
+ * address of the process, and initialize one page region from addr
+ * with char 'A'.
+ *
+ * Creat a temporary directory and a file under it.
+ * Write some known data into file and get the size of the file.
*/
-void
-setup()
+static void setup(void)
{
tst_tmpdir();
@@ -219,11 +200,10 @@ setup()
/*
* cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- * Remove the temporary directory created.
+ * completion or premature exit.
+ * Remove the temporary directory created.
*/
-void
-cleanup()
+static void cleanup(void)
{
/*
* print timing stats if that option was specified.
@@ -234,3 +214,8 @@ cleanup()
tst_rmdir();
}
+
+static void help(void)
+{
+ printf(" -H /.. Location of hugetlbfs, i.e. -H /var/hugetlbfs\n");
+}
--
1.7.9
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
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-dev2
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list