From: Ivan Maidanski Date: Wed, 6 Dec 2017 21:22:41 +0000 (+0300) Subject: Allow to alter DEFAULT/MAX_NTHREADS values in test_malloc/stack X-Git-Tag: v7.6.2~33 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1c8c267f932de9c9613d35c802a333d80e21c941;p=libatomic_ops Allow to alter DEFAULT/MAX_NTHREADS values in test_malloc/stack (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). --- diff --git a/tests/run_parallel.h b/tests/run_parallel.h index dee7146..376b3c7 100644 --- a/tests/run_parallel.h +++ b/tests/run_parallel.h @@ -45,6 +45,10 @@ # 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(); diff --git a/tests/test_malloc.c b/tests/test_malloc.c index 338b9e8..95bd1fb 100644 --- a/tests/test_malloc.c +++ b/tests/test_malloc.c @@ -21,10 +21,6 @@ #include #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) { diff --git a/tests/test_stack.c b/tests/test_stack.c index 71c649f..66ed50a 100644 --- a/tests/test_stack.c +++ b/tests/test_stack.c @@ -51,6 +51,10 @@ # 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]);