v2:mmap2.c coding style cleanups
PATCH 1/1 v2:mmap2.c coding style cleanups
cleanup the coding style
--- testcases/kernel/mem/mtest06/mmap2.c | 402 ++++++++++++++-------------------- 1 files changed, 164 insertions(+), 238 deletions(-)
testcases/kernel/mem/mtest06/mmap2.c +164 -238
@@ -45,18 +45,17 @@/* we are done with the test - Paul Larson */ /* email:[email protected] */ /* File: mmap2.c */ -/* */ +/* */ /* Description: Test the LINUX memory manager. The program is aimed at */ /* stressing the memory manager by repeaded map/write/unmap of a */ /* of a large gb size file. */ -/* */ +/* */ /* Create a file of the specified size in gb, map the file, */ /* change the contents of the file and unmap it. This is repeated*/ /* several times for the specified number of hours. */ -/* */ +/* */ /******************************************************************************/ -/* Include Files */ #include <stdio.h> #include <sys/types.h> #include <sys/stat.h>
@@ -74,7 +73,6 @@#include "test.h" #include "usctest.h" -/* Defines */ #define GB 1000000000#ifndef TRUE #define TRUE 1
@@ -83,261 +81,189 @@#define FALSE 0#endif -/******************************************************************************/ -/* */ -/* Function: mkfile */ -/* */ -/* Description: Create a temparory file of required size. */ -/* */ -/* Input: size - size of the temp file to be created in giga bytes */ -/* */ -/* Return: int fd - file descriptor if the file was created. */ -/* -1 - if it failed to create. */ -/* */ -/******************************************************************************/ -static int -mkfile (int size)/* size of the file to be generated in GB */ +static int mkfile (int size) { -int fd;/* file descriptior of tmpfile */ -int index =0 ;/* index into the file, fill it with a's */ -char buff[4096 ];/* buffer that will be written to the file. */ -char template[PATH_MAX ];/* template for temp file name */ +int fd; +int index =0 ; +char buff[4096 ]; +char template[PATH_MAX ]; -/* fill the buffer with a's and open a temp file */ -memset (buff,'a' ,4096 ); -snprintf (template,PATH_MAX ,"ashfileXXXXXX" ); -if ((fd =mkstemp (template)) ==-1 ) - { -perror ("mkfile(): mkstemp()" ); -return -1 ; - } -else - { -unlink (template); -fprintf (stdout,"creating tmp file and writing 'a' to it " ); - } +memset (buff,'a' ,4096 ); +snprintf (template,PATH_MAX ,"ashfileXXXXXX" ); + fd =mkstemp (template); +if (fd ==-1 ) { +perror ("mkfile(): mkstemp()" ); +return -1 ; } +else { +unlink (template); +fprintf (stdout,"creating tmp file and writing 'a' to it " ); + } -/* fill the file with the character a */ -while (index < (size *GB )) - { - index +=4096 ; -if (write (fd, buff,4096 ) ==-1 ) - { -perror ("mkfile(): write()" ); -return -1 ; +while (index < (size *GB )) { + index +=4096 ; +if (write (fd, buff,4096 ) ==-1 ) { +perror ("mkfile(): write()" ); +return -1 ; + } } - } -fprintf (stdout,"created file of size %d\n" -"content of the file is 'a'\n" , index); +fprintf (stdout,"created file of size %d\n" +"content of the file is 'a'\n" , index); -/* make sure a's are written to the file. */ -if (fsync (fd) ==-1 ) - { -perror ("mkfile(): fsync()" ); -return -1 ; - } -return fd; +if (fsync (fd) ==-1 ) { +perror ("mkfile(): fsync()" ); +return -1 ; + } +return fd; } -/******************************************************************************/ -/* */ -/* Function: sig_handler */ -/* */ -/* Description: handle SIGALRM raised by set_timer(), SIGALRM is raised when */ -/* the timer expires. If any other signal is recived exit the */ -/* test. */ -/* *//* Input: signal - signal number, intrested in SIGALRM! */ -/* */ -/* Return: exit 1 if unexpected signal is recived */ -/* exit 0 if SIGALRM is recieved */ -/* */ -/******************************************************************************/ -static void -sig_handler (int signal)/* signal number, set to handle SIGALRM */ { -if (signal !=SIGALRM ) - { -fprintf (stderr,"sig_handlder(): unexpected signal caught [%d]\n" , - signal); -exit (-1 ); - } -else -fprintf (stdout,"Test ended, success\n" ); -exit (0 ); +static void sig_handler (int signal) +{ +if (signal !=SIGALRM ) { +fprintf (stderr,"sig_handlder(): unexpected signal caught" +"[%d]\n" , signal); +exit (-1 ); } +else +fprintf (stdout,"Test ended, success\n" ); +exit (0 ); } -/******************************************************************************//* */ -/* Function: usage */ -/* */ -/* Description: Print the usage message. */ -/* */ -/* Return: exits with -1 */ -/* */ -/******************************************************************************/ -static void -usage (char *progname)/* name of this program */ { -fprintf (stderr, -"Usage: %s -h -s -x\n" -"\t -a set map_flags to MAP_ANONYMOUS\n" -"\t -h help, usage message.\n" -"\t -p set map_flag to MAP_PRIVATE.\tdefault: MAP_SHARED\n" -"\t -s size of the file/memory to be mmaped.\tdefault: 1GB\n" -"\t -x time for which test is to be run.\tdefault: 24 Hrs\n" , - progname); -exit (-1 ); +static void usage (char *progname) +{ +fprintf (stderr, +"Usage: %s -h -s -x\n" +"\t -a set map_flags to MAP_ANONYMOUS\n" +"\t -h help, usage message.\n" +"\t -p set map_flag to MAP_PRIVATE.\tdefault:" +"MAP_SHARED\n" +"\t -s size of the file/memory to be mmaped.\tdefault:" +"1GB\n" +"\t -x time for which test is to be run.\tdefault:" +"24 Hrs\n" , + progname); +exit (-1 ); } -/******************************************************************************/ -/* */ -/* Function: main */ -/* */ -/* Descrption: Create a large file of size in Giga Bytes. Fill it with 'a's */ -/* (lower case alphabet a). Map the file and change the contents */ -/* to 'A's (upper case alphabet), write the contents to the file,*/ -/* and unmap the file from memory. Continue map/write/unmap */ -/* operation for user specified number of times. */ -/* */ -/* Return: exits with -1 on error */ -/* exits with a 0 o success. */ -/* */ -/******************************************************************************/ -int main (int argc,/* number of input parameters. */ -char **argv)/* pointer to the command line arguments. */ +int main (int argc,char **argv) { -int fd;/* descriptor of temp file. */ -int fsize =1 ;/* size of the temp file created. default 1GB */ -float exec_time =24 ;/* period of execution, default 24 hours. */ -int c;/* command line options */ -int sig_ndx;/* index into signal handler structure. */ -int map_flags =/* type of mapping, defaut is MAP_SHARED . */ -MAP_SHARED ; -int map_anon = FALSE;/* do not map anonymous memory,map file by default*/ -int run_once = TRUE;/* run the test once. (dont repeat) */ -char *memptr;/* address of the mapped file. */ -extern char *optarg;/* arguments passed to each option */ -struct sigaction sigptr;/* set up signal, for interval timer */ +int fd; +int fsize =1 ; +float exec_time =24 ; +int c; +int sig_ndx; +int map_flags =MAP_SHARED ; +int map_anon = FALSE; +int run_once = TRUE; +char *memptr; +extern char *optarg; +struct sigaction sigptr; -static struct signal_info - { -int signum;/* signal number that hasto be handled */ -char *signame;/* name of the signal to be handled. */ - } sig_info[] = - { - {SIGHUP ,"SIGHUP" }, - {SIGINT ,"SIGINT" }, - {SIGQUIT ,"SIGQUIT" }, - {SIGABRT ,"SIGABRT" }, - {SIGBUS ,"SIGBUS" }, - {SIGSEGV ,"SIGSEGV" }, - {SIGALRM ,"SIGALRM" }, - {SIGUSR1 ,"SIGUSR1" }, - {SIGUSR2 ,"SIGUSR2" }, - {-1 ,"ENDSIG" } - }; +static struct signal_info + { +int signum; +char *signame; + } sig_info[] = { + {SIGHUP ,"SIGHUP" }, + {SIGINT ,"SIGINT" }, + {SIGQUIT ,"SIGQUIT" }, + {SIGABRT ,"SIGABRT" }, + {SIGBUS ,"SIGBUS" }, + {SIGSEGV ,"SIGSEGV" }, + {SIGALRM ,"SIGALRM" }, + {SIGUSR1 ,"SIGUSR1" }, + {SIGUSR2 ,"SIGUSR2" }, + {-1 ,"ENDSIG" } + }; -while ((c =getopt (argc, argv,"ahps:x:" )) !=-1 ) - { -switch (c) - { -case 'a' : - map_anon = TRUE; -break ; -case 'h' : -usage (argv[0 ]); -exit (-1 ); -break ; -case 'p' : - map_flags =MAP_PRIVATE ; -break ; -case 's' : -if ((fsize =atoi (optarg)) ==0 ) -fprintf (stderr,"Using default fsize %d GB\n" , fsize =1 ); -break ; -case 'x' : -if ((exec_time =atof (optarg)) ==0 ) -fprintf (stderr,"Using default exec time %f hrs" , - exec_time = (float )24 ); - run_once = FALSE; -break ; -default : -usage (argv[0 ]); -break ; +while ((c =getopt (argc, argv,"ahps:x:" )) !=-1 ) { +switch (c) { +case 'a' : + map_anon = TRUE; +break ; +case 'h' : +usage (argv[0 ]); +exit (-1 ); +break ; +case 'p' : + map_flags =MAP_PRIVATE ; +break ; +case 's' : + fsize =atoi (optarg); +if (fsize ==0 ) +fprintf (stderr,"Using default " +"fsize %d GB\n" , fsize =1 ); +break ; +case 'x' : + exec_time =atof (optarg); +if (exec_time ==0 ) +fprintf (stderr,"Using default exec " +"time %f hrs" , + exec_time = (float )24 ); + run_once = FALSE; +break ; +default : +usage (argv[0 ]); +break ; + } } - } -fprintf (stdout,"MM Stress test, map/write/unmap large file\n" -"\tTest scheduled to run for: %f\n" -"\tSize of temp file in GB: %d\n" , +fprintf (stdout,"MM Stress test, map/write/unmap large file\n" +"\tTest scheduled to run for: %f\n" +"\tSize of temp file in GB: %d\n" , exec_time, fsize); -/* set up time for which test has to be run */ -alarm (exec_time *3600.00 ); - -/* set up signals */ - sigptr.sa_handler = (void (*)(int signal))sig_handler; -sigfillset (&sigptr.sa_mask); - sigptr.sa_flags =0 ; -for (sig_ndx =0 ; sig_info[sig_ndx].signum !=-1 ; sig_ndx++) - { -sigaddset (&sigptr.sa_mask, sig_info[sig_ndx].signum); -if (sigaction (sig_info[sig_ndx].signum, &sigptr, - (struct sigaction *)NULL ) ==-1 ) - { -perror ("man(): sigaction()" ); -fprintf (stderr,"could not set handler for SIGALRM, errno = %d\n" , - errno); -exit (-1 ); - } - } +alarm (exec_time *3600.00 ); -do - { -if (!map_anon) - { -/* create a new file of giga byte size */ -if ((fd =mkfile (fsize)) ==-1 ) - { -fprintf (stderr, -"main(): mkfile(): Failed to create temp file.\n" ); -exit (-1 ); - } - } -else - { -/* mapping anonymous, MAP_SHARED or MAP_PRIVATE must be also set */ - fd =-1 ; - map_flags = map_flags|MAP_ANONYMOUS ; - } + sigptr.sa_handler = (void (*)(int signal))sig_handler; +sigfillset (&sigptr.sa_mask); + sigptr.sa_flags =0 ; +for (sig_ndx =0 ; sig_info[sig_ndx].signum !=-1 ; sig_ndx++) { +sigaddset (&sigptr.sa_mask, sig_info[sig_ndx].signum); +if (sigaction (sig_info[sig_ndx].signum, &sigptr, \ + (struct sigaction *)NULL ) ==-1 ) { +perror ("man(): sigaction()" ); +fprintf (stderr,"could not set handler for SIGALRM," +"errno = %d\n" , errno); +exit (-1 ); + } + } -if ((memptr = (char *)mmap (0 ,(fsize *GB ),PROT_READ |PROT_WRITE , - map_flags, fd,0 )) == (char *)-1 ) - { -perror ("main(): mmap()" ); -exit (-1 ); - } -else -fprintf (stdout,"file mapped at %p\n" -"changing file content to 'A'\n" , memptr); +do { +if (!map_anon) { + fd =mkfile (fsize); +if (fd ==-1 ) { +fprintf (stderr,"main(): mkfile(): Failed " +"to create temp file.\n" ); +exit (-1 ); + } } +else { + fd =-1 ; + map_flags = map_flags|MAP_ANONYMOUS ; + } + memptr = (char *)mmap (0 , (fsize *GB ),PROT_READ |PROT_WRITE , + map_flags, fd,0 ); +if (memptr == (char *)-1 ) { +perror ("main(): mmap()" ); +exit (-1 ); + }else +fprintf (stdout,"file mapped at %p\n" +"changing file content to 'A'\n" , memptr); -/* Change the content of the file with A's, and commit changes */ -memset (memptr,'A' , ((fsize *GB )/sizeof (char ))); +memset (memptr,'A' , ((fsize *GB )/sizeof (char ))); -if (msync (memptr, ((fsize *GB )/sizeof (char )), -MS_SYNC |MS_INVALIDATE ) ==-1 ) - { -perror ("main(): msync()" ); -exit (-1 ); - } +if (msync (memptr, ((fsize *GB )/sizeof (char )), +MS_SYNC |MS_INVALIDATE ) ==-1 ) { +perror ("main(): msync()" ); +exit (-1 ); + } -if (munmap (memptr, (fsize *GB )/sizeof (char )) ==-1 ) - { -perror ("main(): munmap()" ); -exit (-1 ); - } -else -fprintf (stdout,"unmapped file at %p\n" , memptr); +if (munmap (memptr, (fsize *GB )/sizeof (char )) ==-1 ) { +perror ("main(): munmap()" ); +exit (-1 ); + }else +fprintf (stdout,"unmapped file at %p\n" , memptr); -close (fd); -sync (); - }while (TRUE && !run_once); -exit (0 ); +close (fd); +sync (); + }while (TRUE && !run_once); +exit (0 ); }
Signature · 13 lines
1.6.3.1 ------------------------------------------------------------------------------ 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
Hi!
That is certainly better than what we have, see some comments bellow.
Quoted 81 lines
Signed-off-by Shang Yanfeng <[email protected]>--- testcases/kernel/mem/mtest06/mmap2.c | 402 ++++++++++++++-------------------- 1 files changed, 164 insertions(+), 238 deletions(-)testcases/kernel/mem/mtest06/mmap2.c +8
-36@@ -45,18 +45,17 @@/* we are done with the test - Paul Larson */ /* email:[email protected] */ /* File: mmap2.c */ -/* */ +/* */ /* Description: Test the LINUX memory manager. The program is aimed at */ /* stressing the memory manager by repeaded map/write/unmap of a */ /* of a large gb size file. */ -/* */ +/* */ /* Create a file of the specified size in gb, map the file, */ /* change the contents of the file and unmap it. This is repeated*/ /* several times for the specified number of hours. */ -/* */ +/* */ /******************************************************************************/ -/* Include Files */ #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> @@ -74,7 +73,6 @@#include "test.h" #include "usctest.h" -/* Defines */ #define GB 1000000000#ifndef TRUE #define TRUE 1@@ -83,261 +81,189 @@#define FALSE 0#endif -/******************************************************************************/ -/* */ -/* Function: mkfile */ -/* */ -/* Description: Create a temparory file of required size. */ -/* */ -/* Input: size - size of the temp file to be created in giga bytes */ -/* */ -/* Return: int fd - file descriptor if the file was created. */ -/* -1 - if it failed to create. */ -/* */ -/******************************************************************************/ -static int -mkfile (int size)/* size of the file to be generated in GB */ +static int mkfile (int size) { -int fd;/* file descriptior of tmpfile */ -int index =0 ;/* index into the file, fill it with a's */ -char buff[4096 ];/* buffer that will be written to the file. */ -char template[PATH_MAX ];/* template for temp file name */ +int fd; +int index =0 ; +char buff[4096 ]; +char template[PATH_MAX ]; -/* fill the buffer with a's and open a temp file */ -memset (buff,'a' ,4096 ); -snprintf (template,PATH_MAX ,"ashfileXXXXXX" ); -if ((fd =mkstemp (template)) ==-1 ) - { -perror ("mkfile(): mkstemp()" ); -return -1 ; - } -else - { -unlink (template); -fprintf (stdout,"creating tmp file and writing 'a' to it " ); - }
testcases/kernel/mem/mtest06/mmap2.c line 100
Quoted 10 lines
testcases/kernel/mem/mtest06/mmap2.c +10
-0+memset (buff,'a' ,4096 ); +snprintf (template,PATH_MAX ,"ashfileXXXXXX" ); + fd =mkstemp (template); +if (fd ==-1 ) { +perror ("mkfile(): mkstemp()" ); +return -1 ; } +else { +unlink (template); +fprintf (stdout,"creating tmp file and writing 'a' to it " ); + }
Here the placement of curly brackents is screewed up (I wonder why checpatch wasn't complaining here).
Quoted 5 lines
testcases/kernel/mem/mtest06/mmap2.c +0
-5-/* fill the file with the character a */ -while (index < (size *GB )) - { - index +=4096 ; -if (write (fd, buff,4096 ) ==-1 )
testcases/kernel/mem/mtest06/mmap2.c line 108
Quoted 10 lines
testcases/kernel/mem/mtest06/mmap2.c +6
-3- { -perror ("mkfile(): write()" ); -return -1 ; +while (index < (size *GB )) { + index +=4096 ; +if (write (fd, buff,4096 ) ==-1 ) { +perror ("mkfile(): write()" ); +return -1 ; + } }
I would prefere not having the extra spaces before the opening curly bracket ({).
Quoted 8 lines
testcases/kernel/mem/mtest06/mmap2.c +2
-5- } -fprintf (stdout,"created file of size %d\n" -"content of the file is 'a'\n" , index); +fprintf (stdout,"created file of size %d\n" +"content of the file is 'a'\n" , index); -/* make sure a's are written to the file. */ -if (fsync (fd) ==-1 )
testcases/kernel/mem/mtest06/mmap2.c line 116
Quoted 10 lines
testcases/kernel/mem/mtest06/mmap2.c +5
-5- { -perror ("mkfile(): fsync()" ); -return -1 ; - } -return fd; +if (fsync (fd) ==-1 ) { +perror ("mkfile(): fsync()" ); +return -1 ; + } +return fd;
Here as well.
Quoted 25 lines
testcases/kernel/mem/mtest06/mmap2.c +0
-23} -/******************************************************************************/ -/* */ -/* Function: sig_handler */ -/* */ -/* Description: handle SIGALRM raised by set_timer(), SIGALRM is raised when */ -/* the timer expires. If any other signal is recived exit the */ -/* test. */ -/* *//* Input: signal - signal number, intrested in SIGALRM! */ -/* */ -/* Return: exit 1 if unexpected signal is recived */ -/* exit 0 if SIGALRM is recieved */ -/* */ -/******************************************************************************/ -static void -sig_handler (int signal)/* signal number, set to handle SIGALRM */ { -if (signal !=SIGALRM ) - { -fprintf (stderr,"sig_handlder(): unexpected signal caught [%d]\n" , - signal); -exit (-1 ); - } -else -fprintf (stdout,"Test ended, success\n" );
testcases/kernel/mem/mtest06/mmap2.c line 127
Quoted 10 lines
testcases/kernel/mem/mtest06/mmap2.c +9
-1-exit (0 ); +static void sig_handler (int signal) +{ +if (signal !=SIGALRM ) { +fprintf (stderr,"sig_handlder(): unexpected signal caught" +"[%d]\n" , signal); +exit (-1 ); } +else +fprintf (stdout,"Test ended, success\n" ); +exit (0 );
Hmm, here the closing curly bracket should rather be before the else keyword. I guess I would need to see checkpatch source to figure out why it has ingored this one.
Quoted 67 lines
testcases/kernel/mem/mtest06/mmap2.c +15
-47} -/******************************************************************************//* */ -/* Function: usage */ -/* */ -/* Description: Print the usage message. */ -/* */ -/* Return: exits with -1 */ -/* */ -/******************************************************************************/ -static void -usage (char *progname)/* name of this program */ { -fprintf (stderr, -"Usage: %s -h -s -x\n" -"\t -a set map_flags to MAP_ANONYMOUS\n" -"\t -h help, usage message.\n" -"\t -p set map_flag to MAP_PRIVATE.\tdefault: MAP_SHARED\n" -"\t -s size of the file/memory to be mmaped.\tdefault: 1GB\n" -"\t -x time for which test is to be run.\tdefault: 24 Hrs\n" , - progname); -exit (-1 ); +static void usage (char *progname) +{ +fprintf (stderr, +"Usage: %s -h -s -x\n" +"\t -a set map_flags to MAP_ANONYMOUS\n" +"\t -h help, usage message.\n" +"\t -p set map_flag to MAP_PRIVATE.\tdefault:" +"MAP_SHARED\n" +"\t -s size of the file/memory to be mmaped.\tdefault:" +"1GB\n" +"\t -x time for which test is to be run.\tdefault:" +"24 Hrs\n" , + progname); +exit (-1 ); } -/******************************************************************************/ -/* */ -/* Function: main */ -/* */ -/* Descrption: Create a large file of size in Giga Bytes. Fill it with 'a's */ -/* (lower case alphabet a). Map the file and change the contents */ -/* to 'A's (upper case alphabet), write the contents to the file,*/ -/* and unmap the file from memory. Continue map/write/unmap */ -/* operation for user specified number of times. */ -/* */ -/* Return: exits with -1 on error */ -/* exits with a 0 o success. */ -/* */ -/******************************************************************************/ -int main (int argc,/* number of input parameters. */ -char **argv)/* pointer to the command line arguments. */ +int main (int argc,char **argv) { -int fd;/* descriptor of temp file. */ -int fsize =1 ;/* size of the temp file created. default 1GB */ -float exec_time =24 ;/* period of execution, default 24 hours. */ -int c;/* command line options */ -int sig_ndx;/* index into signal handler structure. */ -int map_flags =/* type of mapping, defaut is MAP_SHARED . */ -MAP_SHARED ; -int map_anon = FALSE;/* do not map anonymous memory,map file by default*/ -int run_once = TRUE;/* run the test once. (dont repeat) */ -char *memptr;/* address of the mapped file. */ -extern char *optarg;/* arguments passed to each option */ -struct sigaction sigptr;/* set up signal, for interval timer */
testcases/kernel/mem/mtest06/mmap2.c line 157
Quoted 10 lines
testcases/kernel/mem/mtest06/mmap2.c +10
-0+int fd; +int fsize =1 ; +float exec_time =24 ; +int c; +int sig_ndx; +int map_flags =MAP_SHARED ; +int map_anon = FALSE; +int run_once = TRUE; +char *memptr; +extern char *optarg;
You should include getopt.h rather than defining optarg as extern.
Quoted 134 lines
testcases/kernel/mem/mtest06/mmap2.c +51
-76+struct sigaction sigptr; -static struct signal_info - { -int signum;/* signal number that hasto be handled */ -char *signame;/* name of the signal to be handled. */ - } sig_info[] = - { - {SIGHUP ,"SIGHUP" }, - {SIGINT ,"SIGINT" }, - {SIGQUIT ,"SIGQUIT" }, - {SIGABRT ,"SIGABRT" }, - {SIGBUS ,"SIGBUS" }, - {SIGSEGV ,"SIGSEGV" }, - {SIGALRM ,"SIGALRM" }, - {SIGUSR1 ,"SIGUSR1" }, - {SIGUSR2 ,"SIGUSR2" }, - {-1 ,"ENDSIG" } - }; +static struct signal_info + { +int signum; +char *signame; + } sig_info[] = { + {SIGHUP ,"SIGHUP" }, + {SIGINT ,"SIGINT" }, + {SIGQUIT ,"SIGQUIT" }, + {SIGABRT ,"SIGABRT" }, + {SIGBUS ,"SIGBUS" }, + {SIGSEGV ,"SIGSEGV" }, + {SIGALRM ,"SIGALRM" }, + {SIGUSR1 ,"SIGUSR1" }, + {SIGUSR2 ,"SIGUSR2" }, + {-1 ,"ENDSIG" } + }; -while ((c =getopt (argc, argv,"ahps:x:" )) !=-1 ) - { -switch (c) - { -case 'a' : - map_anon = TRUE; -break ; -case 'h' : -usage (argv[0 ]); -exit (-1 ); -break ; -case 'p' : - map_flags =MAP_PRIVATE ; -break ; -case 's' : -if ((fsize =atoi (optarg)) ==0 ) -fprintf (stderr,"Using default fsize %d GB\n" , fsize =1 ); -break ; -case 'x' : -if ((exec_time =atof (optarg)) ==0 ) -fprintf (stderr,"Using default exec time %f hrs" , - exec_time = (float )24 ); - run_once = FALSE; -break ; -default : -usage (argv[0 ]); -break ; +while ((c =getopt (argc, argv,"ahps:x:" )) !=-1 ) { +switch (c) { +case 'a' : + map_anon = TRUE; +break ; +case 'h' : +usage (argv[0 ]); +exit (-1 ); +break ; +case 'p' : + map_flags =MAP_PRIVATE ; +break ; +case 's' : + fsize =atoi (optarg); +if (fsize ==0 ) +fprintf (stderr,"Using default " +"fsize %d GB\n" , fsize =1 ); +break ; +case 'x' : + exec_time =atof (optarg); +if (exec_time ==0 ) +fprintf (stderr,"Using default exec " +"time %f hrs" , + exec_time = (float )24 ); + run_once = FALSE; +break ; +default : +usage (argv[0 ]); +break ; + } } - } -fprintf (stdout,"MM Stress test, map/write/unmap large file\n" -"\tTest scheduled to run for: %f\n" -"\tSize of temp file in GB: %d\n" , +fprintf (stdout,"MM Stress test, map/write/unmap large file\n" +"\tTest scheduled to run for: %f\n" +"\tSize of temp file in GB: %d\n" , exec_time, fsize); -/* set up time for which test has to be run */ -alarm (exec_time *3600.00 ); - -/* set up signals */ - sigptr.sa_handler = (void (*)(int signal))sig_handler; -sigfillset (&sigptr.sa_mask); - sigptr.sa_flags =0 ; -for (sig_ndx =0 ; sig_info[sig_ndx].signum !=-1 ; sig_ndx++) - { -sigaddset (&sigptr.sa_mask, sig_info[sig_ndx].signum); -if (sigaction (sig_info[sig_ndx].signum, &sigptr, - (struct sigaction *)NULL ) ==-1 ) - { -perror ("man(): sigaction()" ); -fprintf (stderr,"could not set handler for SIGALRM, errno = %d\n" , - errno); -exit (-1 ); - } - } +alarm (exec_time *3600.00 ); - do - { - if (!map_anon) - { - /* create a new file of giga byte size */ - if ((fd = mkfile(fsize)) == -1) - { - fprintf(stderr, - "main(): mkfile(): Failed to create temp file.\n");
testcases/kernel/mem/mtest06/mmap2.c line 216
Quoted 10 lines
testcases/kernel/mem/mtest06/mmap2.c +1
-9-exit (-1 ); - } - } -else - { -/* mapping anonymous, MAP_SHARED or MAP_PRIVATE must be also set */ - fd =-1 ; - map_flags = map_flags|MAP_ANONYMOUS ; - } + sigptr.sa_handler = (void (*)(int signal))sig_handler;
That cast shouldn't be needed.
testcases/kernel/mem/mtest06/mmap2.c line 222
Quoted 6 lines
testcases/kernel/mem/mtest06/mmap2.c +6
-0+sigfillset (&sigptr.sa_mask); + sigptr.sa_flags =0 ; +for (sig_ndx =0 ; sig_info[sig_ndx].signum !=-1 ; sig_ndx++) { +sigaddset (&sigptr.sa_mask, sig_info[sig_ndx].signum); +if (sigaction (sig_info[sig_ndx].signum, &sigptr, \ + (struct sigaction *)NULL ) ==-1 ) {
The \ shouldn't be needed here.
Quoted 18 lines
testcases/kernel/mem/mtest06/mmap2.c +8
-9+perror ("man(): sigaction()" ); +fprintf (stderr,"could not set handler for SIGALRM," +"errno = %d\n" , errno); +exit (-1 ); + } + } -if ((memptr = (char *)mmap (0 ,(fsize *GB ),PROT_READ |PROT_WRITE , - map_flags, fd,0 )) == (char *)-1 ) - { -perror ("main(): mmap()" ); -exit (-1 ); - } -else -fprintf (stdout,"file mapped at %p\n" -"changing file content to 'A'\n" , memptr); + do { + if (!map_anon) {
testcases/kernel/mem/mtest06/mmap2.c line 241
Quoted 10 lines
testcases/kernel/mem/mtest06/mmap2.c +10
-0+ fd =mkfile (fsize); +if (fd ==-1 ) { +fprintf (stderr,"main(): mkfile(): Failed " +"to create temp file.\n" ); +exit (-1 ); + } } +else { + fd =-1 ; + map_flags = map_flags|MAP_ANONYMOUS ; + }
Again misplaced closing curly bracket.
testcases/kernel/mem/mtest06/mmap2.c line 243
Quoted 2 lines
testcases/kernel/mem/mtest06/mmap2.c +2
-0+ memptr = (char *)mmap (0 , (fsize *GB ),PROT_READ |PROT_WRITE , + map_flags, fd,0 );
Another useless cast I think.
testcases/kernel/mem/mtest06/mmap2.c line 244
Quoted 1 line
testcases/kernel/mem/mtest06/mmap2.c +1
-0+if (memptr == (char *)-1 ) {
It's a slightly better to use MAP_FAILED instead of (char *)-1.
Quoted 44 lines
testcases/kernel/mem/mtest06/mmap2.c +20
-19+perror ("main(): mmap()" ); +exit (-1 ); + }else +fprintf (stdout,"file mapped at %p\n" +"changing file content to 'A'\n" , memptr); -/* Change the content of the file with A's, and commit changes */ -memset (memptr,'A' , ((fsize *GB )/sizeof (char ))); +memset (memptr,'A' , ((fsize *GB )/sizeof (char ))); -if (msync (memptr, ((fsize *GB )/sizeof (char )), -MS_SYNC |MS_INVALIDATE ) ==-1 ) - { -perror ("main(): msync()" ); -exit (-1 ); - } +if (msync (memptr, ((fsize *GB )/sizeof (char )), +MS_SYNC |MS_INVALIDATE ) ==-1 ) { +perror ("main(): msync()" ); +exit (-1 ); + } -if (munmap (memptr, (fsize *GB )/sizeof (char )) ==-1 ) - { -perror ("main(): munmap()" ); -exit (-1 ); - } -else -fprintf (stdout,"unmapped file at %p\n" , memptr); +if (munmap (memptr, (fsize *GB )/sizeof (char )) ==-1 ) { +perror ("main(): munmap()" ); +exit (-1 ); + }else +fprintf (stdout,"unmapped file at %p\n" , memptr); -close (fd); -sync (); - }while (TRUE && !run_once); -exit (0 ); +close (fd); +sync (); + }while (TRUE && !run_once); +exit (0 ); }
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ Keep Your Developer Skills Current with LearnDevNow! 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-d2d _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list