From: Ivan Maidanski Date: Fri, 6 Oct 2017 08:14:23 +0000 (+0300) Subject: Eliminate TSan warnings for print_proc variables assignment (gctest) X-Git-Tag: v8.0.0~563 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ad8ff65ac2167f4943c0db7aac34e754eb4360b8;p=gc Eliminate TSan warnings for print_proc variables assignment (gctest) Now GC_is_valid_displacement_print_proc and GC_is_visible_print_proc are set only once (before the first invocation of run_one_test). * tests/test.c [DBG_HDRS_ALL] (set_print_procs): New macro (defined to (void)0). * tests/test.c [!DBG_HDRS_ALL] (set_print_procs): New function (which sets GC_is_valid_displacement_print_proc and GC_is_visible_print_proc). * tests/test.c (fail_count, fail_proc1, TEST_FAIL_COUNT): Do not define if DBG_HDRS_ALL. * tests/test.c [!DBG_HDRS_ALL] (run_one_test): Do not set GC_is_valid_displacement_print_proc and GC_is_visible_print_proc. * tests/test.c (main): Call set_print_procs() before run_one_test(). * tests/test.c [PCR] (test): Likewise. --- diff --git a/tests/test.c b/tests/test.c index 2e8d7c24..3a728e0e 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1204,12 +1204,28 @@ void typed_test(void) GC_noop1((word)x); } -int fail_count = 0; +#ifdef DBG_HDRS_ALL +# define set_print_procs() (void)0 +#else + int fail_count = 0; -void GC_CALLBACK fail_proc1(void *x GC_ATTR_UNUSED) -{ + void GC_CALLBACK fail_proc1(void *x GC_ATTR_UNUSED) + { fail_count++; -} + } + + void set_print_procs(void) + { + GC_is_valid_displacement_print_proc = fail_proc1; + GC_is_visible_print_proc = fail_proc1; + } + +# ifdef THREADS +# define TEST_FAIL_COUNT(n) 1 +# else +# define TEST_FAIL_COUNT(n) (fail_count >= (n)) +# endif +#endif /* !DBG_HDRS_ALL */ static void uniq(void *p, ...) { va_list a; @@ -1230,12 +1246,6 @@ static void uniq(void *p, ...) { } } -#ifdef THREADS -# define TEST_FAIL_COUNT(n) 1 -#else -# define TEST_FAIL_COUNT(n) (fail_count >= (n)) -#endif - void * GC_CALLBACK inc_int_counter(void *pcounter) { ++(*(int *)pcounter); @@ -1291,8 +1301,6 @@ void run_one_test(void) GC_printf("GC_malloc_uncollectable(0) failed\n"); FAIL; } - GC_is_valid_displacement_print_proc = fail_proc1; - GC_is_visible_print_proc = fail_proc1; AO_fetch_and_add1(&collectable_count); x = GC_malloc(16); if (GC_base(GC_PTR_ADD(x, 13)) != x) { @@ -1796,6 +1804,7 @@ void GC_CALLBACK warn_proc(char *msg, GC_word p) # endif } # endif + set_print_procs(); run_one_test(); check_heap_stats(); # ifndef MSWINCE @@ -2087,6 +2096,7 @@ DWORD __stdcall thr_window(void * arg GC_ATTR_UNUSED) FAIL; CloseHandle(win_created_h); # endif + set_print_procs(); # if NTHREADS > 0 for (i = 0; i < NTHREADS; i++) { h[i] = GC_CreateThread(NULL, 0, thr_run_one_test, 0, 0, &thread_id); @@ -2139,6 +2149,7 @@ int test(void) n_tests = 0; /* GC_enable_incremental(); */ GC_set_warn_proc(warn_proc); + set_print_procs(); th1 = PCR_Th_Fork(run_one_test, 0); th2 = PCR_Th_Fork(run_one_test, 0); run_one_test(); @@ -2226,6 +2237,7 @@ int main(void) GC_printf("Key creation failed %d\n", code); FAIL; } + set_print_procs(); # if NTHREADS > 0 for (i = 0; i < NTHREADS; ++i) { if ((code = pthread_create(th+i, &attr, thr_run_one_test, 0)) != 0) {