2011-05-10 Ivan Maidanski <ivmai@mail.ru>
authorivmai <ivmai>
Tue, 10 May 2011 07:05:30 +0000 (07:05 +0000)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 25 Jul 2011 12:03:26 +0000 (16:03 +0400)
* tests/test_stack.c (MAX_NTHREADS, N_EXPERIMENTS): Do not define
unless undefined.
* tests/test_stack.c: Expand all tabs to spaces.
* tests/test_atomic_include.h: Ditto.
* tests/test_stack.c (main): Free pop'ed elements.
* tests/test_atomic_include.h (test_atomic, test_atomic_release,
test_atomic_acquire, test_atomic_read, test_atomic_write,
test_atomic_full, test_atomic_release_write,
test_atomic_acquire_read): Remove prototype.

ChangeLog
tests/test_atomic_include.h
tests/test_stack.c

index 00f0afa..554b51e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2011-05-10  Ivan Maidanski  <ivmai@mail.ru>
+
+       * tests/test_stack.c (MAX_NTHREADS, N_EXPERIMENTS): Do not define
+       unless undefined.
+       * tests/test_stack.c: Expand all tabs to spaces.
+       * tests/test_atomic_include.h: Ditto.
+       * tests/test_stack.c (main): Free pop'ed elements.
+       * tests/test_atomic_include.h (test_atomic, test_atomic_release,
+       test_atomic_acquire, test_atomic_read, test_atomic_write,
+       test_atomic_full, test_atomic_release_write,
+       test_atomic_acquire_read): Remove prototype.
+
 2011-04-22  Ivan Maidanski  <ivmai@mail.ru>
 
        * src/atomic_ops/sysdeps/gcc/ia64.h (AO_MASK): Add "volatile" for
index bc280eb..0297f23 100644 (file)
@@ -5,21 +5,12 @@
  * see doc/COPYING for details.
  */
 
-void test_atomic(void);
-void test_atomic_release(void);
-void test_atomic_acquire(void);
-void test_atomic_read(void);
-void test_atomic_write(void);
-void test_atomic_full(void);
-void test_atomic_release_write(void);
-void test_atomic_acquire_read(void);
-
 /* Some basic sanity tests.  These do not test the barrier semantics. */
 
 #undef TA_assert
 #define TA_assert(e) \
   if (!(e)) { fprintf(stderr, "Assertion failed %s:%d (barrier: )\n", \
-                   __FILE__, __LINE__), exit(1); }
+                    __FILE__, __LINE__), exit(1); }
 
 #undef MISSING
 #define MISSING(name) \
@@ -209,7 +200,7 @@ void test_atomic(void)
 }
 
 
-    
+
 /*
  * Copyright (c) 2003 by Hewlett-Packard Company.  All rights reserved.
  *
@@ -222,7 +213,7 @@ void test_atomic(void)
 #undef TA_assert
 #define TA_assert(e) \
   if (!(e)) { fprintf(stderr, "Assertion failed %s:%d (barrier: _release)\n", \
-                   __FILE__, __LINE__), exit(1); }
+                    __FILE__, __LINE__), exit(1); }
 
 #undef MISSING
 #define MISSING(name) \
@@ -412,7 +403,7 @@ void test_atomic_release(void)
 }
 
 
-    
+
 /*
  * Copyright (c) 2003 by Hewlett-Packard Company.  All rights reserved.
  *
@@ -425,7 +416,7 @@ void test_atomic_release(void)
 #undef TA_assert
 #define TA_assert(e) \
   if (!(e)) { fprintf(stderr, "Assertion failed %s:%d (barrier: _acquire)\n", \
-                   __FILE__, __LINE__), exit(1); }
+                    __FILE__, __LINE__), exit(1); }
 
 #undef MISSING
 #define MISSING(name) \
@@ -615,7 +606,7 @@ void test_atomic_acquire(void)
 }
 
 
-    
+
 /*
  * Copyright (c) 2003 by Hewlett-Packard Company.  All rights reserved.
  *
@@ -628,7 +619,7 @@ void test_atomic_acquire(void)
 #undef TA_assert
 #define TA_assert(e) \
   if (!(e)) { fprintf(stderr, "Assertion failed %s:%d (barrier: _read)\n", \
-                   __FILE__, __LINE__), exit(1); }
+                    __FILE__, __LINE__), exit(1); }
 
 #undef MISSING
 #define MISSING(name) \
@@ -818,7 +809,7 @@ void test_atomic_read(void)
 }
 
 
-    
+
 /*
  * Copyright (c) 2003 by Hewlett-Packard Company.  All rights reserved.
  *
@@ -831,7 +822,7 @@ void test_atomic_read(void)
 #undef TA_assert
 #define TA_assert(e) \
   if (!(e)) { fprintf(stderr, "Assertion failed %s:%d (barrier: _write)\n", \
-                   __FILE__, __LINE__), exit(1); }
+                    __FILE__, __LINE__), exit(1); }
 
 #undef MISSING
 #define MISSING(name) \
@@ -1021,7 +1012,7 @@ void test_atomic_write(void)
 }
 
 
-    
+
 /*
  * Copyright (c) 2003 by Hewlett-Packard Company.  All rights reserved.
  *
@@ -1034,7 +1025,7 @@ void test_atomic_write(void)
 #undef TA_assert
 #define TA_assert(e) \
   if (!(e)) { fprintf(stderr, "Assertion failed %s:%d (barrier: _full)\n", \
-                   __FILE__, __LINE__), exit(1); }
+                    __FILE__, __LINE__), exit(1); }
 
 #undef MISSING
 #define MISSING(name) \
@@ -1224,7 +1215,7 @@ void test_atomic_full(void)
 }
 
 
-    
+
 /*
  * Copyright (c) 2003 by Hewlett-Packard Company.  All rights reserved.
  *
@@ -1237,7 +1228,7 @@ void test_atomic_full(void)
 #undef TA_assert
 #define TA_assert(e) \
   if (!(e)) { fprintf(stderr, "Assertion failed %s:%d (barrier: _release_write)\n", \
-                   __FILE__, __LINE__), exit(1); }
+                    __FILE__, __LINE__), exit(1); }
 
 #undef MISSING
 #define MISSING(name) \
@@ -1427,7 +1418,7 @@ void test_atomic_release_write(void)
 }
 
 
-    
+
 /*
  * Copyright (c) 2003 by Hewlett-Packard Company.  All rights reserved.
  *
@@ -1440,7 +1431,7 @@ void test_atomic_release_write(void)
 #undef TA_assert
 #define TA_assert(e) \
   if (!(e)) { fprintf(stderr, "Assertion failed %s:%d (barrier: _acquire_read)\n", \
-                   __FILE__, __LINE__), exit(1); }
+                    __FILE__, __LINE__), exit(1); }
 
 #undef MISSING
 #define MISSING(name) \
@@ -1628,6 +1619,3 @@ void test_atomic_acquire_read(void)
     MISSING(AO_compare_and_swap_double);
 # endif
 }
-
-
-    
index 8a8ba50..3955dc3 100644 (file)
@@ -1,11 +1,11 @@
-/*  
+/*
  * Copyright (c) 2005 Hewlett-Packard Development Company, L.P.
  * Original Author: Hans Boehm
  *
  * This file may be redistributed and/or modified under the
  * terms of the GNU General Public License as published by the Free Software
  * Foundation; either version 2, or (at your option) any later version.
- * 
+ *
  * It is distributed in the hope that it will be useful, but WITHOUT ANY
  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License in the
 #include <stdio.h>
 #include "atomic_ops.h"
 #include "atomic_ops_stack.h"
-#define MAX_NTHREADS 100
+
+#ifndef MAX_NTHREADS
+# define MAX_NTHREADS 100
+#endif
 
 #ifndef NO_TIMES
-#include <time.h>
-#include <sys/time.h>
-/* Need 64-bit long long support */
-long long
-get_msecs(void)
-{
-  struct timeval tv;
+# include <time.h>
+# include <sys/time.h>
+  /* Need 64-bit long long support */
+  long long get_msecs(void)
+  {
+    struct timeval tv;
 
-  gettimeofday(&tv, 0);
-  return (long long)tv.tv_sec * 1000 + tv.tv_usec/1000;
-}
+    gettimeofday(&tv, 0);
+    return (long long)tv.tv_sec * 1000 + tv.tv_usec/1000;
+  }
 #else
 # define get_msecs() 0
 #endif
 
 typedef struct le {
-    AO_t next;
-    int data;
+  AO_t next;
+  int data;
 } list_element;
 
 AO_stack_t the_list = AO_STACK_INITIALIZER;
@@ -88,17 +90,17 @@ void check_list(int n)
     if (marks[i] != 1)
       fprintf(stderr, "Missing list element %d\n", i);
 }
-     
+
 volatile AO_t ops_performed = 0;
 
 #define LIMIT 1000000
-       /* Total number of push/pop ops in all threads per test. */
+        /* Total number of push/pop ops in all threads per test.    */
 
 #ifdef AO_HAVE_fetch_and_add
 # define fetch_and_add(addr, val) AO_fetch_and_add(addr, val)
 #else
-  /* Fake it.  This is really quite unacceptable for timing    */
-  /* purposes.  But as a correctness test, it should be OK.    */
+  /* Fake it.  This is really quite unacceptable for timing */
+  /* purposes.  But as a correctness test, it should be OK. */
   AO_INLINE AO_t fetch_and_add(volatile AO_t * addr, AO_t val)
   {
     AO_t result = AO_load(addr);
@@ -110,7 +112,7 @@ volatile AO_t ops_performed = 0;
 void * run_one_test(void * arg)
 {
   list_element * t[MAX_NTHREADS + 1];
-  list_element * aux; 
+  list_element * aux;
   long index = (long)arg;
   int i;
   int j = 0;
@@ -124,7 +126,7 @@ void * run_one_test(void * arg)
         {
           t[i] = (list_element *)AO_stack_pop(&the_list);
           if (0 == t[i])
-           {
+            {
               fprintf(stderr, "FAILED\n");
               abort();
             }
@@ -141,7 +143,9 @@ void * run_one_test(void * arg)
   return 0;
 }
 
-#define N_EXPERIMENTS 1
+#ifndef N_EXPERIMENTS
+# define N_EXPERIMENTS 1
+#endif
 
 unsigned long times[MAX_NTHREADS + 1][N_EXPERIMENTS];
 
@@ -158,8 +162,8 @@ int main(int argc, char **argv)
       max_nthreads = atoi(argv[1]);
       if (max_nthreads < 1 || max_nthreads > MAX_NTHREADS)
         {
-         fprintf(stderr, "Invalid max # of threads argument\n");
-         exit(1);
+          fprintf(stderr, "Invalid max # of threads argument\n");
+          exit(1);
         }
     }
   else
@@ -174,41 +178,43 @@ int main(int argc, char **argv)
         pthread_t thread[MAX_NTHREADS];
         int list_length = nthreads*(nthreads+1)/2;
         long long start_time;
-  
+        list_element * le;
+
         add_elements(list_length);
-  #     ifdef VERBOSE
+#       ifdef VERBOSE
           printf("Initial list (nthreads = %d):\n", nthreads);
           print_list();
-  #     endif
+#       endif
         ops_performed = 0;
         start_time = get_msecs();
         for (i = 1; i < nthreads; ++i) {
-       int code;
-  
+        int code;
+
           if ((code = pthread_create(thread+i, 0, run_one_test,
-           (void *)(long)i)) != 0) {
-             fprintf(stderr, "Thread creation failed %u\n", code);
+                                     (void *)(long)i)) != 0) {
+            fprintf(stderr, "Thread creation failed %u\n", code);
             exit(1);
           }
         }
-        /* We use the main thread to run one test.  This allows gprof  */
-        /* profiling to work, for example.                             */
-          run_one_test(0);
+        /* We use the main thread to run one test.  This allows gprof   */
+        /* profiling to work, for example.                              */
+        run_one_test(0);
         for (i = 1; i < nthreads; ++i) {
-         int code;
+          int code;
           if ((code = pthread_join(thread[i], 0)) != 0) {
-           fprintf(stderr, "Thread join failed %u\n", code);
+            fprintf(stderr, "Thread join failed %u\n", code);
           }
         }
         times[nthreads][exper_n] = (unsigned long)(get_msecs() - start_time);
   #     ifdef VERBOSE
           printf("%d %lu\n", nthreads,
-                            (unsigned long)(get_msecs() - start_time));
+                 (unsigned long)(get_msecs() - start_time));
           printf("final list (should be reordered initial list):\n");
           print_list();
   #     endif
         check_list(list_length);
-        while ((list_element *)AO_stack_pop(&the_list));
+        while ((le = AO_stack_pop(&the_list)) != 0)
+          free(le);
       }
 # ifndef NO_TIMES
     for (nthreads = 1; nthreads <= max_nthreads; ++nthreads)
@@ -216,17 +222,16 @@ int main(int argc, char **argv)
         unsigned long sum = 0;
 
         printf("About %d pushes + %d pops in %d threads:",
-               LIMIT, LIMIT, nthreads);
+               LIMIT, LIMIT, nthreads);
         for (exper_n = 0; exper_n < N_EXPERIMENTS; ++exper_n)
-         {
+          {
 #           if defined(VERBOSE)
-             printf("[%lu] ", times[nthreads][exper_n]);
-#          endif
-           sum += times[nthreads][exper_n];
+              printf("[%lu] ", times[nthreads][exper_n]);
+#           endif
+            sum += times[nthreads][exper_n];
           }
         printf(" %lu msecs\n", (sum + N_EXPERIMENTS/2)/N_EXPERIMENTS);
       }
-# endif /* NO_TIMES */
+# endif /* !NO_TIMES */
   return 0;
 }
-