Allow to alter DEFAULT/MAX_NTHREADS values in test_malloc/stack
authorIvan Maidanski <ivmai@mail.ru>
Wed, 6 Dec 2017 21:22:41 +0000 (00:22 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 22 Dec 2017 07:42:17 +0000 (10:42 +0300)
(code refactoring)

* tests/run_parallel.h [!MAX_NTHREADS] (MAX_NTHREADS): Define (move
from test_malloc.c).
* tests/run_parallel.h [USE_PTHREADS || USE_VXTHREADS
|| USE_WINTHREADS] (run_parallel): Replace 100 with MAX_NTHREADS.
* tests/test_malloc.c (main): Add assertion that DEFAULT_NTHREADS
is not greater than MAX_NTHREADS.
* tests/test_stack.c (main): Likewise.
* tests/test_stack.c [!DEFAULT_NTHREADS] (DEFAULT_NTHREADS): Define
(to 4).
* tests/test_stack.c (main): Use DEFAULT_NTHREADS (instead of 4).

tests/run_parallel.h
tests/test_malloc.c
tests/test_stack.c

index dee7146..376b3c7 100644 (file)
 # define AO_PTRDIFF_T ptrdiff_t
 #endif
 
+#ifndef MAX_NTHREADS
+# define MAX_NTHREADS 100
+#endif
+
 typedef void * (* thr_func)(void *);
 
 typedef int (* test_func)(void);    /* Returns != 0 on success */
@@ -55,11 +59,11 @@ void * run_parallel(int nthreads, thr_func f1, test_func t, const char *name);
 void * run_parallel(int nthreads, thr_func f1, test_func t, const char *name)
 {
   pthread_attr_t attr;
-  pthread_t thr[100];
+  pthread_t thr[MAX_NTHREADS];
   int i;
 
   printf("Testing %s\n", name);
-  if (nthreads > 100)
+  if (nthreads > MAX_NTHREADS)
     {
       fprintf(stderr, "run_parallel: requested too many threads\n");
       abort();
@@ -111,11 +115,11 @@ void * run_parallel(int nthreads, thr_func f1, test_func t, const char *name)
 #ifdef USE_VXTHREADS
 void * run_parallel(int nthreads, thr_func f1, test_func t, const char *name)
 {
-  int thr[100];
+  int thr[MAX_NTHREADS];
   int i;
 
   printf("Testing %s\n", name);
-  if (nthreads > 100)
+  if (nthreads > MAX_NTHREADS)
     {
       fprintf(stderr, "run_parallel: requested too many threads\n");
       taskSuspend(0);
@@ -166,12 +170,12 @@ DWORD WINAPI tramp(LPVOID param)
 
 void * run_parallel(int nthreads, thr_func f1, test_func t, const char *name)
 {
-  HANDLE thr[100];
-  struct tramp_args args[100];
+  HANDLE thr[MAX_NTHREADS];
+  struct tramp_args args[MAX_NTHREADS];
   int i;
 
   printf("Testing %s\n", name);
-  if (nthreads > 100)
+  if (nthreads > MAX_NTHREADS)
     {
       fprintf(stderr, "run_parallel: requested too many threads\n");
       abort();
index 338b9e8..95bd1fb 100644 (file)
 #include <stdio.h>
 #include "atomic_ops_malloc.h"
 
-#ifndef MAX_NTHREADS
-# define MAX_NTHREADS 100
-#endif
-
 #ifndef DEFAULT_NTHREADS
 # ifdef HAVE_MMAP
 #   define DEFAULT_NTHREADS 10
@@ -229,6 +225,7 @@ int main(int argc, char **argv) {
 
     if (1 == argc) {
       nthreads = DEFAULT_NTHREADS;
+      assert(nthreads <= MAX_NTHREADS);
     } else if (2 == argc) {
       nthreads = atoi(argv[1]);
       if (nthreads < 1 || nthreads > MAX_NTHREADS) {
index 71c649f..66ed50a 100644 (file)
 # define MAX_NTHREADS 100
 #endif
 
+#ifndef DEFAULT_NTHREADS
+# define DEFAULT_NTHREADS 4 /* must be <= MAX_NTHREADS */
+#endif
+
 #ifdef NO_TIMES
 # define get_msecs() 0
 #elif (defined(USE_WINTHREADS) || defined(AO_USE_WIN32_PTHREADS)) \
@@ -220,7 +224,10 @@ int main(int argc, char **argv)
   int exper_n;
 
   if (1 == argc)
-    max_nthreads = 4;
+    {
+      max_nthreads = DEFAULT_NTHREADS;
+      assert(max_nthreads <= MAX_NTHREADS);
+    }
   else if (2 == argc)
     {
       max_nthreads = atoi(argv[1]);