Hi guys,

I've attached some patches that I created for LTP at work. Most of them
simply add command-line options to specify the amount of memory/pages to
use for tests. However, there's one fix that works around a bug in
uClibc's pthread implementation.

ltp-testsuite-make-memsize-configurable.patch:
        Allow the amount of memory to be used to be passed as a
        command-line argument.

ltp-testsuite-mmap1-safe-exit.patch:
        It can be unsafe to call exit(3) from a signal handler. Call
        _exit(2) instead.

ltp-testsuite-mmstress-optional-pages.patch:
        Allow the number of pages to use for the test to be specified on
        the command-line. Fix a memory leak.

        Also, call _exit(2) from child processes which avoids the child
        calling the atexit functions that the pthread library setup.
        This fixes an issue where the pthread manager thread would begin 
        exiting at the same time as a child thread. The child thread would 
        run the atexit functions which cause it to wait for a signal to be 
        sent from the thread manager. As the thread manager was trying to 
        exit that signal would never be sent. Calling _exit(2) from the child 
        avoids this whole mess.

ltp-testsuite-nanosleep-no-slop.patch:
        Don't place an upper limit on the amount of time a nanosleep(2)
        call should take. The nanosleep(2) call will suspend execution for
        _at least_ the specified time, no upper limit is guaranteed.
       
ltp-testsuite-nptl-configure-num-loops.patch:
        Allow the number of iterations to be specified on the command
        line.

ltp-testsuite-syscall32.patch:
        Check for SYS_getuid32 and SYS_getgid32, these are the versions
        provided by some architectures.

--- ltp-full-20080531/testcases/kernel/mem/mem/mem02.c.orig     2008-06-20 
14:10:17.000000000 +0100
+++ ltp-full-20080531/testcases/kernel/mem/mem/mem02.c  2008-06-20 
15:09:26.000000000 +0100
@@ -58,9 +58,16 @@
 int TST_TOTAL=1;                       /* Total number of test cases. */
 extern int Tst_count;                  /* Test Case counter for tst_* routines 
*/
 
+static void
+usage(char *progname)
+{
+       fprintf(stderr, "usage: %s -m memsize\n", progname);
+       fprintf(stderr, "\t-m specify the size of memory to allocate, in MB\n");
+       exit(1);
+}
 
 /*--------------------------------------------------------------------*/
-int main()                                     /***** BEGINNING OF MAIN. *****/
+int main(int argc, char **argv)                        /***** BEGINNING OF 
MAIN. *****/
 {
        int i;
        char *pm1,*pm2,*pm3,*pm4,*pm5;
@@ -70,27 +77,49 @@
        int iteration_count;
        int size;               /* Size to memory to be valloced */
        int pagesize = 12;      /* 2^12 = 4096, PAGESIZE      */
+       int memsize = MEMSIZE;  /* Size of memory to allocate */
+       extern char *optarg;    /* getopt() function global variables */
+       extern int optopt;      /* stores bad option passed to the program */
+       int ch;
 
 /*--------------------------------------------------------------------*/
 
+       optarg = NULL;
+       opterr = 0;
+
+       while ((ch = getopt(argc, argv, "m:")) != -1) {
+               switch(ch) {
+               case 'm': 
+                       if (optarg)
+                               memsize = atoi(optarg) * 1024 * 1024;
+                       else
+                               fprintf(stderr, "%s: option -%c requires " \
+                                               "an argument\n", argv[0], 
optopt);
+                       break;
+               default:
+                       usage(argv[0]);
+                       exit(1);
+               }
+       }
+
        /* check out calloc/free */
-       if((pm2=pm1=(char *)calloc(MEMSIZE,1)) == NULL) {
+       if((pm2=pm1=(char *)calloc(memsize,1)) == NULL) {
 
-               tst_resm(TFAIL, "calloc - alloc of %dMB failed", 
MEMSIZE/1024/1024);
+               tst_resm(TFAIL, "calloc - alloc of %dMB failed", 
memsize/1024/1024);
                             tst_exit();
        } 
 
-       for(i=0; i<MEMSIZE; i++)
+       for(i=0; i<memsize; i++)
                if(*pm2++ != 0) {
                        tst_resm(TFAIL, "calloc returned non zero memory");
                                     tst_exit();
                }
 
        pm2=pm1;
-       for(i=0; i<MEMSIZE; i++)
+       for(i=0; i<memsize; i++)
                *pm2++ = 'X';
        pm2=pm1;
-       for(i=0; i<MEMSIZE; i++)
+       for(i=0; i<memsize; i++)
                if(*pm2++ != 'X') {
                         tst_resm(TFAIL, "could not write/verify memory ");
                                     tst_exit();
@@ -99,7 +128,7 @@
        pm2=pm1;
        free(pm1);
 
-       if((pm1=(char *)calloc(MEMSIZE,1)) == NULL) {
+       if((pm1=(char *)calloc(memsize,1)) == NULL) {
                tst_resm(TFAIL, "calloc did not alloc memory ");
                             tst_exit();
        }
@@ -112,20 +141,20 @@
        free(pm1);
         
         tst_resm(TPASS,"calloc - calloc of %uMB of memory succeeded",
-                            MEMSIZE/1024/1024);
+                            memsize/1024/1024);
         
 /*--------------------------------------------------------------------*/
 
        /* check out malloc/free */
-       if((pm2=pm1=(char *)malloc(MEMSIZE)) == NULL) {
+       if((pm2=pm1=(char *)malloc(memsize)) == NULL) {
                tst_resm(TFAIL, "malloc did not alloc memory ");
                             tst_exit();
        }             
 
-       for(i=0; i<MEMSIZE; i++)
+       for(i=0; i<memsize; i++)
                *pm2++ = 'X';
        pm2=pm1;
-       for(i=0; i<MEMSIZE; i++)
+       for(i=0; i<memsize; i++)
                if(*pm2++ != 'X') {
                        tst_resm(TFAIL, "could not write/verify memory ");
                             tst_exit();
@@ -134,7 +163,7 @@
        pm2=pm1;
        free(pm1);
 
-       if((pm1=(char *)malloc(MEMSIZE)) == NULL) {
+       if((pm1=(char *)malloc(memsize)) == NULL) {
                tst_resm(TFAIL, "malloc did not alloc memory ");
                             tst_exit();
        }
@@ -146,7 +175,7 @@
        free(pm1);
 
         tst_resm(TPASS,"malloc - malloc of %uMB of memory succeeded",
-                            MEMSIZE/1024/1024);
+                            memsize/1024/1024);
         
 /*--------------------------------------------------------------------*/
 
@@ -168,8 +197,7 @@
                }
        }
 
-        tst_resm(TPASS,"realloc - realloc of %dMB succeeded",
-                            pm6/1024/1024);
+        tst_resm(TPASS,"realloc - realloc of 5 bytes succeeded");
         
        /* realloc with increased size after fragmenting memory */
        pm5=(char *)malloc(1);
@@ -184,7 +212,7 @@
                }
        }
        
-        tst_resm(TPASS,"realloc - realloc of %dMB succeeded",
+        tst_resm(TPASS,"realloc - realloc of 15 bytes succeeded",
                             pm6/1024/1024);
 
 /*--------------------------------------------------------------------*/
--- ltp-full-20080531/testcases/kernel/mem/mtest06/mmap1.c.orig 2008-07-02 
16:04:49.000000000 +0100
+++ ltp-full-20080531/testcases/kernel/mem/mtest06/mmap1.c      2008-07-02 
16:06:01.000000000 +0100
@@ -168,7 +168,7 @@
     {
         case SIGALRM:
              tst_resm(TPASS, "Test ended, success");
-             exit(0);
+             _exit(0);
 
         case SIGSEGV:
              if (info->si_code == SEGV_MAPERR &&
@@ -182,7 +182,7 @@
         default:
             fprintf(stderr, "caught unexpected signal - %d --- exiting\n",
                      signal);
-            exit(-1);
+            _exit(-1);
     }
 }
 
--- ltp-full-20080531/testcases/kernel/mem/mtest05/mmstress.c.orig      
2008-06-19 17:26:08.000000000 +0100
+++ ltp-full-20080531/testcases/kernel/mem/mtest05/mmstress.c   2008-07-02 
15:36:32.000000000 +0100
@@ -30,9 +30,10 @@
 /*               system and can be easily ported to work on other operating   
*/
 /*               systems as well.                                             
*/
 /*                                                                            
*/
-/* Usage:        mmstress -h -n TEST NUMBER -t EXECUTION TIME -v -V           
*/
+/* Usage:        mmstress -h -n TEST NUMBER -p NPAGES -t EXECUTION TIME -v -V 
*/
 /*                        -h                - Help                            
*/
 /*                        -n TEST NUMBER    - Execute a particular testcase   
*/
+/*                        -p NPAGES         - Use NPAGES pages for tests    */
 /*                        -t EXECUTION TIME - Execute test for a certain time 
*/
 /*                        -v                - Verbose output                  
*/
 /*                        -V                - Version of this program         
*/
@@ -145,6 +146,8 @@
 static   int  thread_begin = 0;      /* used to coordinate threads            
*/
 static   int  verbose_print = FALSE; /* print more test information           
*/
 
+static   int    pages_num = NUMPAGES; /* number of pages to use for tests     
*/
+
 char *TCID = "mmstress";
 int TST_TOTAL = 6;
 
@@ -199,6 +202,8 @@
     fprintf(stderr, "\t-h displays all options\n");
     fprintf(stderr, "\t-n test number, if no test number\n"
             "\t   is specified, all the tests will be run\n");
+    fprintf(stderr, "\t-p specify the number of pages to\n"
+            "\t   use for allocation\n");
     fprintf(stderr, "\t-t specify the time in hours\n");
     fprintf(stderr, "\t-v verbose output\n");
     fprintf(stderr, "\t-V program version\n");
@@ -265,7 +270,7 @@
     caddr_t start_addr           /* start address of the page                 
*/
                          = (caddr_t)(local_args[MAPADDR] 
                                      + (int)local_args[THNUM] 
-                                     * (NUMPAGES/NUMTHREAD) 
+                                     * (pages_num/NUMTHREAD) 
                                      * local_args[PAGESIZ]);
     char    read_from_addr = 0;  /* address to which read from page is done   
*/
     char    write_to_addr[] = {'a'}; /* character to be writen to the page    
*/
@@ -284,7 +289,7 @@
     while (wait_thread) 
         sched_yield();
 
-    for (; pgnum_ndx < (NUMPAGES/NUMTHREAD); pgnum_ndx++)
+    for (; pgnum_ndx < (pages_num/NUMTHREAD); pgnum_ndx++)
     {
         /* if the fault to be generated is READ_FAULT, read from the page     
*/
         /* else write a character to the page.                                
*/
@@ -318,7 +323,7 @@
 remove_files(char *filename, char * addr)    /* name of the file that is to be 
removed     */
 {
     if (addr)
-                    if (munmap(addr, sysconf(_SC_PAGESIZE)*NUMPAGES) < 0) {
+                    if (munmap(addr, sysconf(_SC_PAGESIZE)*pages_num) < 0) {
                                     perror("map_and_thread(): munmap()");
                                     return FAILED;
                     }
@@ -375,7 +380,7 @@
     int  thrd_ndx   = 0;         /* index to the number of threads created    
*/
     int  map_type   = 0;         /* specifies the type of the mapped object   
*/
     int  *th_status = 0;         /* status of the thread when it is finished  
*/
-    long th_args[NUMTHREAD];     /* argument list passed to  thread_fault()   
*/
+    long th_args[5];           /* argument list passed to  thread_fault()   */
     char *empty_buf = NULL;      /* empty buffer used to fill temp file       
*/
     long pagesize                /* contains page size at runtime             
*/
                     = sysconf(_SC_PAGESIZE);        
@@ -398,9 +403,9 @@
             return retinfo;
         }
 
-        /* Write pagesize * NUMPAGES bytes to the file */
-        empty_buf = (char *)malloc(pagesize*NUMPAGES);
-        if (write(fd, empty_buf, pagesize*NUMPAGES) != (pagesize*NUMPAGES))
+        /* Write pagesize * pages_num bytes to the file */
+        empty_buf = (char *)malloc(pagesize*pages_num);
+        if (write(fd, empty_buf, pagesize*pages_num) != (pagesize*pages_num))
         {
             perror("map_and_thread(): write()");
             free(empty_buf);
@@ -417,7 +422,7 @@
         /* generated map the file with read protection else map with read -   
*/
         /* write protection.                               */
     
-        if ((map_addr = (caddr_t)mmap(0, pagesize*NUMPAGES, 
+        if ((map_addr = (caddr_t)mmap(0, pagesize*pages_num, 
                         ((fault_type == READ_FAULT) ? 
                        PROT_READ : PROT_READ|PROT_WRITE),
                         map_type, fd, 0)) 
@@ -536,11 +541,13 @@
     if (remove_files(tmpfile, map_addr) == FAILED)
     {
         free(empty_buf);
+        free(th_status);
         retinfo->status = FAILED;
         return retinfo;
     }
 
     free(empty_buf);
+    free(th_status);
     close(fd);
     retinfo->status = SUCCESS;
     return retinfo;
@@ -695,14 +702,14 @@
         fflush(NULL);
         return FAILED;
     }
-   
+
     /* fork NUMTHREAD number of processes, assumption is on SMP each will get 
*/
     /* a separate CPU if NRCPUS = NUMTHREAD. The child does nothing; exits    
*/
     /* immediately, parent waits for child to complete execution.             
*/
     do
     {
         if (!(pid = fork()))
-            exit (0);
+            _exit (0);
         else
         {
             if (pid != -1)
@@ -884,7 +891,7 @@
     if (argc < 2)
     tst_resm(TINFO, "run %s -h for all options", argv[0]);
 
-    while ((ch = getopt(argc, argv, "hn:t:vV")) != -1)
+    while ((ch = getopt(argc, argv, "hn:p:t:vV")) != -1)
     {
         switch(ch)
         {
@@ -895,6 +902,11 @@
                       else
                           OPT_MISSING(prog_name, optopt);
                       break;
+            case 'p': if (optarg)
+                          pages_num = atoi(optarg);
+                      else
+                          OPT_MISSING(prog_name, optopt);
+                      break;
             case 't': if (optarg)
                       {
                           tst_resm(TINFO, "Test is scheduled to run for %d 
hours",
--- ltp-full-20080531/testcases/kernel/syscalls/nanosleep/nanosleep01.c.orig    
2008-06-30 12:21:48.000000000 +0100
+++ ltp-full-20080531/testcases/kernel/syscalls/nanosleep/nanosleep01.c 
2008-06-30 12:22:54.000000000 +0100
@@ -148,14 +148,13 @@
    if (STD_FUNCTIONAL_TEST) {
     /*
      * Verify whether child execution was 
-     * actually suspended to desired interval
-     * plus or minus SLOP_MS milliseconds.
+     * actually suspended to desired interval.
      */
        long want_ms, got_ms;
        want_ms = timereq.tv_sec * 1000 + timereq.tv_nsec / 1000000;
        got_ms = ntime.tv_sec * 1000 + ntime.tv_usec / 1000;
        got_ms -= otime.tv_sec * 1000 + otime.tv_usec / 1000;
-       if ( (got_ms < (want_ms - SLOP_MS)) || (got_ms > (want_ms + SLOP_MS)) ) 
{
+       if (got_ms < want_ms) {
      retval=1;
      tst_resm(TFAIL, "Child execution not "
        "suspended for %d seconds.  (Wanted %ld ms, got %ld ms)",
--- ltp-full-20080531/testcases/kernel/sched/nptl/nptl01.c.orig 2008-06-30 
11:21:56.000000000 +0100
+++ ltp-full-20080531/testcases/kernel/sched/nptl/nptl01.c      2008-06-30 
11:34:16.000000000 +0100
@@ -203,12 +203,35 @@
     tst_brkm(TFAIL, cleanup, "Test hang longer than %d sec detected", MAXTIME);
 }
 
+static void
+usage(const char *progname)
+{
+    fprintf(stderr, "usage: %s -l loops\n", progname);
+    fprintf(stderr, "\t-l specify the number of loops to carry out\n");
+}
+
 int main(int argc, char** argv)
 {
 #ifdef USING_NPTL
     char buf[1024];
     int i;
+    extern char *optarg;
+    int numloops = NUMLOOPS;
 
+    while ((i = getopt(argc, argv, "l:")) != -1) {
+        switch(i) {
+        case 'l':
+            if (optarg)
+                numloops = atoi(optarg);
+            else
+                fprintf(stderr, "%s: option -l requires an argument\n", 
argv[0]);    
+            break;
+        default:
+            usage(argv[0]);
+            exit(1);
+        }
+    }
+         
     signal(SIGALRM, trap_alarm);
     alarm(MAXTIME);
 
@@ -223,7 +246,7 @@
     create_child_thread(buf, sizeof(buf));
 
     tst_resm(TINFO,"Starting test, please wait.");
-    for (i = 0; i < NUMLOOPS; i++) {
+    for (i = 0; i < numloops; i++) {
        while (idle_count == 0) {
            call_cond_wait(&parent, &ack, buf, sizeof(buf));
        };
@@ -238,8 +261,8 @@
 #ifdef DEBUG
        tst_resm(TINFO,"Success in loop %d",i);
 #else
-       if (((i % (NUMLOOPS / 10)) == 0) && (i != 0))
-         tst_resm(TINFO,"Success thru loop %d of %i",i,NUMLOOPS);
+       if (((i % (numloops / 10)) == 0) && (i != 0))
+         tst_resm(TINFO,"Success thru loop %d of %i",i,numloops);
 #endif
        call_mutex_lock(&ack, buf, sizeof(buf));
     }
--- ltp-full-20080531/testcases/kernel/syscalls/syscall/syscall01.c.orig        
2008-06-19 14:58:18.000000000 +0100
+++ ltp-full-20080531/testcases/kernel/syscalls/syscall/syscall01.c     
2008-06-27 11:18:45.000000000 +0100
@@ -106,10 +106,14 @@
 /*--------------------------------------------------------------*/
        blenter();
 
-#if defined(SYS_getuid)
+#if defined(SYS_getuid) || defined(SYS_getuid32)
        for (i=0; i < ITER; i++) {
                v1 = getuid();
+#if defined(SYS_getuid)
                v2 = syscall(SYS_getuid);
+#else
+               v2 = syscall(SYS_getuid32);
+#endif
                if (v1 != v2) {
                        fprintf(temp, "\tgetuid syscall failed.\n");
                        fprintf(temp, "\t  iteration %d\n", i);
@@ -119,17 +123,21 @@
        }
 #else
         fprintf(temp,"\tgetuid syscall failed.\n");
-         fprintf(temp,"\tSYS_getuid not defined\n");
+         fprintf(temp,"\tSYS_getuid and SYS_getuid32 not defined\n");
          local_flag = FAILED;
 #endif
        blexit();
 /*--------------------------------------------------------------*/
        blenter();
 
-#if defined(SYS_getgid)
+#if defined(SYS_getgid) || defined(SYS_getgid32)
        for (i=0; i < ITER; i++) {
                v1 = getgid();
+#if defined(SYS_getgid)
                v2 = syscall(SYS_getgid);
+#else
+               v2 = syscall(SYS_getgid32);
+#endif
                if (v1 != v2) {
                        fprintf(temp, "\tgetgid syscall failed.\n");
                        fprintf(temp, "\t  iteration %d\n", i);
@@ -139,7 +147,7 @@
        }
 #else
                 fprintf(temp,"\tgetgid syscall failed.\n");
-                fprintf(temp,"\tSYS_getgid not defined\n");
+                fprintf(temp,"\tSYS_getgid and SYS_getgid32 not defined\n");
                  local_flag = FAILED; 
 #endif
 
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to