]> granicus.if.org Git - gc/commitdiff
Add test for thread suspend/resume API
authorIvan Maidanski <ivmai@mail.ru>
Mon, 2 Nov 2015 06:31:45 +0000 (09:31 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 19 Nov 2015 22:38:23 +0000 (01:38 +0300)
* 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).

tests/test.c

index a8604b843d375978fcfdbcf7ed5a4b5cdcfa5ba7..12b3f9073918697757c06080f38c07e3e23dc4f5 100644 (file)
@@ -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;