diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2015-11-02 09:31:45 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2015-11-20 01:38:23 +0300 |
commit | 8ff3262b23ff70e7ce53bccb90e20cfd4d39e171 (patch) | |
tree | 8d97d2d748ffdcf7a414773daf6ee26ea7281193 /tests/test.c | |
parent | 9f48082eafc4d54ca33390a72924715b03d7c1dd (diff) | |
download | bdwgc-8ff3262b23ff70e7ce53bccb90e20cfd4d39e171.tar.gz |
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).
Diffstat (limited to 'tests/test.c')
-rw-r--r-- | tests/test.c | 29 |
1 files changed, 29 insertions, 0 deletions
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; |