From: Ivan Maidanski Date: Mon, 2 Nov 2015 06:31:45 +0000 (+0300) Subject: Add test for thread suspend/resume API X-Git-Tag: gc7_6_0~29^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8ff3262b23ff70e7ce53bccb90e20cfd4d39e171;p=gc Add test for thread suspend/resume API * tests/test.c (tiny_reverse_test): Call GC_gcollect (only if GC_ENABLE_SUSPEND_THREAD). * tests/test.c: Include "javaxfc.h" if GC_ENABLE_SUSPEND_THREAD (and GC_PTHREADS) to GC_suspend/resume_thread declared. * tests/test.c (fork_a_thread): Test GC_is_thread_suspended, GC_suspend_thread, GC_resume_thread (only if the functions defined). --- diff --git a/tests/test.c b/tests/test.c index a8604b84..12b3f907 100644 --- a/tests/test.c +++ b/tests/test.c @@ -506,10 +506,18 @@ void check_marks_int_list(sexpr x) check_ints(reverse(reverse(ints(1, TINY_REVERSE_UPPER_VALUE))), 1, TINY_REVERSE_UPPER_VALUE); } +# if defined(GC_ENABLE_SUSPEND_THREAD) + /* Force collection from a thread. */ + GC_gcollect(); +# endif return 0; } # if defined(GC_PTHREADS) +# if defined(GC_ENABLE_SUSPEND_THREAD) +# include "javaxfc.h" +# endif + void fork_a_thread(void) { pthread_t t; @@ -518,6 +526,27 @@ void check_marks_int_list(sexpr x) GC_printf("Small thread creation failed %d\n", code); FAIL; } +# if defined(GC_ENABLE_SUSPEND_THREAD) && !defined(GC_DARWIN_THREADS) \ + && !defined(GC_OPENBSD_UTHREADS) && !defined(GC_WIN32_THREADS) \ + && !defined(NACL) + if (GC_is_thread_suspended(t)) { + GC_printf("Running thread should be not suspended\n"); + FAIL; + } + /* Thread could be running or already terminated (but not joined). */ + GC_suspend_thread(t); + if (!GC_is_thread_suspended(t)) { + GC_printf("Thread expected to be suspended\n"); + FAIL; + } + GC_suspend_thread(t); /* should be no-op */ + GC_resume_thread(t); + if (GC_is_thread_suspended(t)) { + GC_printf("Resumed thread should be not suspended\n"); + FAIL; + } + GC_resume_thread(t); /* should be no-op */ +# endif if ((code = pthread_join(t, 0)) != 0) { GC_printf("Small thread join failed %d\n", code); FAIL;