From: Ivan Maidanski Date: Wed, 9 Aug 2017 21:47:18 +0000 (+0300) Subject: Allow gctest and thread_leak_test with zero NTHREADS X-Git-Tag: v8.0.0~611 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=347c1f0d0b2be5c811e7449ae2afa1b1e2d42fcc;p=gc Allow gctest and thread_leak_test with zero NTHREADS * tests/test.c [GC_PTHREADS || GC_WIN32_THREADS] (reverse_test_inner): Do not call fork_a_thread() if NTHREADS is 0. * tests/test.c (MAX_FINALIZED): Increase to be correct for the case of NTHREADS is 0. * tests/test.c [GC_PTHREADS] (main): Do not declare and do not use th, i local variables if NTHREADS is 0. * tests/thread_leak_test.c (NTHREADS): Do not define if already defined. * tests/thread_leak_test.c (main): Do not declare and do not use i, code, t, thread_id local variables if NTHREADS is 0. --- diff --git a/tests/test.c b/tests/test.c index be7d57a5..353d82bc 100644 --- a/tests/test.c +++ b/tests/test.c @@ -711,7 +711,8 @@ void *GC_CALLBACK reverse_test_inner(void *data) check_ints(b,1,50); check_ints(a,1,49); for (i = 0; i < 60; i++) { -# if defined(GC_PTHREADS) || defined(GC_WIN32_THREADS) +# if (defined(GC_PTHREADS) || defined(GC_WIN32_THREADS)) \ + && (NTHREADS > 0) if (i % 10 == 0) fork_a_thread(); # endif /* This maintains the invariant that a always points to a list of */ @@ -803,12 +804,12 @@ void GC_CALLBACK finalizer(void * obj, void * client_data) size_t counter = 0; -# define MAX_FINALIZED (NTHREADS*4000) +# define MAX_FINALIZED ((NTHREADS+1)*4000) # if !defined(MACOS) GC_FAR GC_word live_indicators[MAX_FINALIZED] = {0}; # ifndef GC_LONG_REFS_NOT_NEEDED - GC_FAR void *live_long_refs[MAX_FINALIZED] = { NULL }; + GC_FAR void *live_long_refs[MAX_FINALIZED] = { NULL }; # endif #else /* Too big for THINK_C. have to allocate it dynamically. */ @@ -2150,10 +2151,12 @@ void * thr_run_one_test(void * arg GC_ATTR_UNUSED) int main(void) { - pthread_t th[NTHREADS]; +# if NTHREADS > 0 + pthread_t th[NTHREADS]; + int i; +# endif pthread_attr_t attr; int code; - int i; # ifdef GC_IRIX_THREADS /* Force a larger stack to be preallocated */ /* Since the initial can't always grow later. */ @@ -2206,19 +2209,23 @@ int main(void) GC_printf("Key creation failed %d\n", code); FAIL; } - for (i = 0; i < NTHREADS; ++i) { - if ((code = pthread_create(th+i, &attr, thr_run_one_test, 0)) != 0) { - GC_printf("Thread %d creation failed %d\n", i, code); - FAIL; +# if NTHREADS > 0 + for (i = 0; i < NTHREADS; ++i) { + if ((code = pthread_create(th+i, &attr, thr_run_one_test, 0)) != 0) { + GC_printf("Thread %d creation failed %d\n", i, code); + FAIL; + } } - } +# endif run_one_test(); - for (i = 0; i < NTHREADS; ++i) { - if ((code = pthread_join(th[i], 0)) != 0) { - GC_printf("Thread %d failed %d\n", i, code); - FAIL; +# if NTHREADS > 0 + for (i = 0; i < NTHREADS; ++i) { + if ((code = pthread_join(th[i], 0)) != 0) { + GC_printf("Thread %d failed %d\n", i, code); + FAIL; + } } - } +# endif check_heap_stats(); (void)fflush(stdout); (void)pthread_attr_destroy(&attr); diff --git a/tests/thread_leak_test.c b/tests/thread_leak_test.c index 8fedbd15..6cb7ab39 100644 --- a/tests/thread_leak_test.c +++ b/tests/thread_leak_test.c @@ -40,9 +40,12 @@ # endif } -#define NTHREADS 5 +#ifndef NTHREADS +# define NTHREADS 5 +#endif int main(void) { +# if NTHREADS > 0 int i; # ifdef GC_PTHREADS pthread_t t[NTHREADS]; @@ -51,11 +54,13 @@ int main(void) { DWORD thread_id; # endif int code; +# endif GC_set_find_leak(1); /* for new collect versions not compiled */ /* with -DFIND_LEAK. */ GC_INIT(); +# if NTHREADS > 0 for (i = 0; i < NTHREADS; ++i) { # ifdef GC_PTHREADS code = pthread_create(t + i, 0, test, 0); @@ -81,6 +86,7 @@ int main(void) { exit(2); } } +# endif CHECK_LEAKS(); CHECK_LEAKS();