On 02/03/2012 09:31 AM, Wanlong Gao wrote:
> cleanup the coding style
> 
> Signed-off-by: Wanlong Gao <[email protected]>
> ---
>  testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c |  197 
> +++++++++-----------
>  1 files changed, 88 insertions(+), 109 deletions(-)
> 
> diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c 
> b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
> index 4cc6ed4..6d43b98 100644
> --- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
> +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
> @@ -21,7 +21,8 @@
>   * Test Name: hugemmap04
>   *
>   * Test Description:
> - *  Verify that, a hugetlb mmap() succeeds when used to map the largest size 
> possible.
> + *  Verify that, a hugetlb mmap() succeeds when used to map the largest
> + *  size possible.
>   *
>   * Expected Result:
>   *  mmap() should succeed returning the address of the hugetlb mapped region.
> @@ -33,29 +34,17 @@
>   *   Pause for SIGUSR1 if option specified.
>   *   Create temporary directory.
>   *
> - *  Test:
> - *   Loop if the proper options are given.
> - *   Execute system call
> - *   Check return code, if system call failed (return=-1)
> - *           Log the errno and Issue a FAIL message.
> - *  Cleanup:
> - *   Print timing stats if options given
> - *   Delete the temporary directory created.
> - *
> - * Usage:  <for command-line>
> - *  hugemmap04 [-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.
> + * Test:
> + *  Loop if the proper options are given.
> + *  Execute system call
> + *  Check return code, if system call failed (return=-1)
> + *  Log the errno and Issue a FAIL message.
> + * Cleanup:
> + *  Print timing stats if options given
> + *  Delete the temporary directory created.
>   *
>   * HISTORY
> - *   04/2004 Written by Robbie Williamson
> - *
> - * RESTRICTIONS:
> - *  None.
> + *  04/2004 Written by Robbie Williamson
>   */
>  
>  #include <stdio.h>
> @@ -74,53 +63,43 @@
>  #include "usctest.h"
>  #include "system_specific_hugepages_info.h"
>  
> -#define BUFFER_SIZE  256
> -
> -char* TEMPFILE="mmapfile";
> +static char *TEMPFILE = "mmapfile";
>  
> -char *TCID="hugemmap04";     /* Test program identifier.    */
> -int TST_TOTAL=1;             /* Total number of test cases. */
> -long *addr;                  /* addr of memory mapped region */
> -long long mapsize;           /* size of mapped region */
> -int fildes;                  /* file descriptor for tempfile */
> -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 *TCID = "hugemmap04";
> +int TST_TOTAL = 1;
> +static long *addr;
> +static long long mapsize;
> +static int fildes;
> +static int freepages;
> +static int beforetest;
> +static int aftertest;
> +static int hugepagesmapped;
> +static char *Hopt;
>  
> -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");
> -}
> +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;                 /* loop counter */
> -     char *msg;              /* message returned from parse_opts */
> -        int Hflag=0;              /* binary flag: opt or not */
> -     int huge_pagesize=0;
> +     int lc;
> +     char *msg;
> +     int Hflag = 0;
> +     int huge_pagesize = 0;
>  
> -             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. */
>       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 (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");
> -             tst_exit();
> -     }
> +     if (!Hflag)
> +             tst_brkm(TBROK, NULL, "-H option is REQUIRED for this test,"
> +                      " use -h for options help");
>  
>       /* Check number of hugepages */
>       if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
> @@ -129,15 +108,13 @@ main(int ac, char **av)
>       setup();
>  
>       for (lc = 0; TEST_LOOPING(lc); lc++) {
> +             /* Creat a temporary file used for huge mapping */
> +             fildes = open(TEMPFILE, O_RDWR | O_CREAT, 0666);
> +             if (fildes < 0)
> +                     tst_brkm(TFAIL|TERRNO, cleanup, "open %s failed",
> +                              TEMPFILE);
>  
> -             /* Creat a temporary file used for mapping */
> -             if ((fildes = open(TEMPFILE, O_RDWR | O_CREAT, 0666)) < 0) {
> -                     tst_brkm(TFAIL, cleanup,
> -                              "open() on %s Failed, errno=%d : %s",
> -                              TEMPFILE, errno, strerror(errno));
> -             }
> -
> -             Tst_count=0;
> +             Tst_count = 0;
>  
>               /* Note the number of free huge pages BEFORE testing */
>               freepages = get_no_of_free_hugepages();
> @@ -145,47 +122,46 @@ main(int ac, char **av)
>  
>               /* Note the size of huge page size BEFORE testing */
>               huge_pagesize = hugepages_size();
> -             tst_resm(TINFO,"Size of huge pages is %d KB",huge_pagesize);
> +             tst_resm(TINFO, "Size of huge pages is %d KB", huge_pagesize);
>  
> -#if __WORDSIZE==32
> -             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 __WORDSIZE == 32
> +             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
> -              */
> -             errno = 0;
> -                mapsize=(long long)freepages*huge_pagesize*1024;
> +             mapsize = (long long)freepages * huge_pagesize * 1024;
>               addr = mmap(NULL, mapsize, PROT_READ | PROT_WRITE,
>                           MAP_SHARED, fildes, 0);
> -             TEST_ERRNO = errno;
>               sleep(2);
> -             /* Check for the return value of mmap() */
>               if (addr == MAP_FAILED) {
> -                     tst_resm(TFAIL, "mmap() Failed on %s, errno=%d : %s",
> -                              TEMPFILE, errno, strerror(errno));
> +                     tst_resm(TFAIL|TERRNO, "mmap() Failed on %s, TEMPFILE");
>                       continue;
>               } else {
> -                     tst_resm(TPASS, "Succeeded mapping file using %d 
> pages",freepages);
> +                     tst_resm(TPASS, "Succeeded mapping file using %d pages",
> +                              freepages);
>                       /* force to allocate page and change HugePages_Free */
> -                     *(int*)addr = 0;
> +                     *(int *)addr = 0;
>               }
>  
> -             /* Make sure the number of free huge pages AFTER testing 
> decreased */
> +             /*
> +              * Make sure the number of free huge pages
> +              * AFTER testing decreased
> +              */
>               aftertest = get_no_of_free_hugepages();
>               hugepagesmapped = beforetest - aftertest;
> -             if (hugepagesmapped < 1) {
> -                     tst_resm(TWARN,"Number of HUGEPAGES_FREE stayed the 
> same. Okay if");
> -                     tst_resm(TWARN,"multiple copies running due to test 
> collision.");
> -             }
> +             if (hugepagesmapped < 1)
> +                     tst_resm(TWARN, "Number of HUGEPAGES_FREE stayed the"
> +                              " same. Okay if multiple copies running due"
> +                              " to test collision.");
> +
>               /* Clean up things in case we are looping */
>               /* Unmap the mapped memory */
> -             if (munmap(addr, mapsize) != 0) {
> -                     tst_brkm(TFAIL, NULL, "munmap() fails to unmap the "
> -                              "memory, errno=%d", errno);
> -             }
> +             if (munmap(addr, mapsize) != 0)
> +                     tst_brkm(TFAIL|TERRNO, NULL, "munmap failed");
> +
>               close(fildes);
>       }
>  
> @@ -196,21 +172,20 @@ 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()
> +void setup(void)

here as well

>  {
>       char mypid[40];
>  
> -     sprintf(mypid,"/%d",getpid());
> -     TEMPFILE=strcat(mypid,TEMPFILE);
> -     TEMPFILE=strcat(Hopt,TEMPFILE);
> +     sprintf(mypid, "/%d", getpid());
> +     TEMPFILE = strcat(mypid, TEMPFILE);
> +     TEMPFILE = strcat(Hopt, TEMPFILE);
>  
>       tst_sig(FORK, DEF_HANDLER, cleanup);
>  
> @@ -220,11 +195,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()
> +void cleanup(void)

here as well

>  {
>       /*
>        * print timing stats if that option was specified.
> @@ -234,3 +208,8 @@ cleanup()
>       unlink(TEMPFILE);
>  
>  }
> +
> +static void help(void)
> +{
> +     printf("  -H /..  Location of hugetlbfs, i.e. -H /var/hugetlbfs\n");
> +}


------------------------------------------------------------------------------
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

Reply via email to