harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r467506 [1/2] - in /incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread: ./ utils/
Date Tue, 24 Oct 2006 22:05:58 GMT
Author: geirm
Date: Tue Oct 24 15:05:57 2006
New Revision: 467506

URL: http://svn.apache.org/viewvc?view=rev&rev=467506
Log:
HARMONY-1862

Fixes to c-unit tests

Pass on Ubuntu 6


Modified:
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_identify.c
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_interrupt.c
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_monitors.c
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_park.c
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_suspend.c
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_instrum.c
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_monitor_info.c
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_peak_count.c
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_raw_monitors.c
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_state.c
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_timing.c
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c?view=diff&rev=467506&r1=467505&r2=467506
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c Tue Oct 24 15:05:57 2006
@@ -31,23 +31,35 @@
 /*
  * Test jthread_attach()
  */
-void * APR_THREAD_FUNC run_for_test_jthread_attach(apr_thread_t *thread, void *args){
-    tested_thread_sturct_t * tts = current_thread_tts;
-    JNIEnv * jni_env = NULL;
+int HYTHREAD_PROC run_for_test_jthread_attach(void *args){
+    tested_thread_sturct_t * tts;
+    hythread_t native_thread;
+    JNIEnv * jni_env;
     IDATA status;
-    
-    //tts->jni_env = tts_jni_env;
-    status = jthread_attach(jni_env, tts->java_thread, JNI_FALSE);
-    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_ATTACHED : TT_PHASE_ERROR);
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
+
+    tts = (tested_thread_sturct_t *) args;
+    native_thread = hythread_self();
+    if (!native_thread) {
+        status = hythread_attach(&native_thread);
+        if (status != JNI_OK) {
+            tts->phase = TT_PHASE_ERROR;
+            return 0;
         }
     }
 
-    tts->phase = TT_PHASE_DEAD;
+    status = vm_attach(GLOBAL_VM, &jni_env);
+    if (status != JNI_OK) {
+        tts->phase = TT_PHASE_ERROR;
+        return 0;
+    }
+
+    status = jthread_attach(jni_env, tts->java_thread, JNI_FALSE);
+    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_ATTACHED : TT_PHASE_ERROR);
+    tested_thread_started(tts);
+    tested_thread_wait_for_stop_request(tts);
+    status = jthread_detach(tts->java_thread);
+    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
     return 0;
 }
 
@@ -63,6 +75,7 @@
         check_tested_thread_phase(tts, TT_PHASE_ATTACHED);
         check_tested_thread_structures(tts);
     }
+
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
     return TEST_PASSED;
@@ -72,27 +85,7 @@
  * Test jthread_detach()
  */
 int test_jthread_detach (void){
-    tested_thread_sturct_t * tts;
-    jthread *thread;
-    hythread_t hythread;
-
-    // Initialize tts structures and run all tested threads
-    tested_threads_run(default_run_for_test);
-    
-    // Make second attach to the same jthread.
-    reset_tested_thread_iterator(&tts);
-    while(next_tested_thread(&tts)){
-        check_tested_thread_phase(tts, TT_PHASE_RUNNING);
-        hythread = vm_jthread_get_tm_data(tts->java_thread);
-        thread = hythread_get_private_data(hythread);
-        tf_assert_same(jthread_detach(tts->java_thread), TM_ERROR_NONE);
-        tf_assert_null(vm_jthread_get_tm_data(tts->java_thread));
-        //tf_assert_null(hythread_get_private_data(hythread));
-    }
-
-    // Terminate all threads and clear tts structures
-    tested_threads_destroy();
-    return TEST_PASSED;
+    return test_jthread_attach();
 }
 
 /*
@@ -110,7 +103,7 @@
     while(next_tested_thread(&tts)){
         check_tested_thread_phase(tts, TT_PHASE_RUNNING);
         check_tested_thread_structures(tts);
-        tf_assert(tested_thread_is_running(tts));
+        tested_thread_wait_running(tts);
     }
     // Terminate all tested threads and clear tts structures
     tested_threads_destroy();
@@ -121,23 +114,15 @@
 /*
  * Test hythread_create_with_function(...)
  */
-void JNICALL jvmti_start_proc(jvmtiEnv *jvmti_env, JNIEnv *jni_env, void *arg){
+void JNICALL jvmti_start_proc(jvmtiEnv *jvmti_env, JNIEnv *jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t * ) args;
     
-    if (tts->jvmti_start_proc_arg != arg){
-        tts->phase = TT_PHASE_ERROR;
-        return;
-    }
     tts->phase = TT_PHASE_RUNNING;
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
+    tested_thread_started(tts);
+    tested_thread_wait_for_stop_request(tts);
     tts->phase = TT_PHASE_DEAD;
+    tested_thread_ended(tts);
 }
 
 int test_hythread_create_with_function(void) {
@@ -146,14 +131,14 @@
     void * args = &args;
 
     // Initialize tts structures and run all tested threads
-    tested_threads_run_with_jvmti_start_proc(jvmti_start_proc);
+    tested_threads_run(jvmti_start_proc);
     
     // Test that all threads are running and have associated structures valid
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
         check_tested_thread_phase(tts, TT_PHASE_RUNNING);
         check_tested_thread_structures(tts);
-        tf_assert(tested_thread_is_running(tts));
+        tested_thread_wait_running(tts);
     }
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
@@ -164,9 +149,9 @@
 /*
  * Test jthread_join()
  */
-void JNICALL run_for_test_jthread_join(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_join(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     tested_thread_sturct_t * prev_tts = tts; 
     IDATA status;
 
@@ -174,20 +159,17 @@
     if (prev_tts == NULL){
         // its the first tested thread
         tts->phase = TT_PHASE_RUNNING;
-
-        while(1){
-            tts->clicks++;
-            sleep_a_click();
-            if (tts->stop) {
-                tts->phase = TT_PHASE_DEAD;
-                break;
-            }
-        }
+        tested_thread_started(tts);
+        tested_thread_wait_for_stop_request(tts);
+        tts->phase = TT_PHASE_DEAD;
+        tested_thread_ended(tts);
     } else {
         // wait until previous thread ends 
         tts->phase = TT_PHASE_WAITING_ON_JOIN;
+        tested_thread_started(tts);
         status = jthread_join(prev_tts->java_thread);
         tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+        tested_thread_ended(tts);
     }
 }
 
@@ -210,11 +192,10 @@
     // make the first thread terminated and test that all threads are terminated
     reset_tested_thread_iterator(&tts);
     next_tested_thread(&tts);
-    tts->stop = 1;
-    check_tested_thread_phase(tts, TT_PHASE_DEAD);
-    jthread_sleep(20 * CLICK_TIME_MSEC * MAX_TESTED_THREAD_NUMBER, 0);
+    tested_thread_send_stop_request(tts);
+    tested_thread_wait_ended(tts);
     while(next_tested_thread(&tts)){
-        check_tested_thread_phase(tts, TT_PHASE_DEAD);
+        tested_thread_wait_ended(tts);
     }
 
     // Terminate all threads (not needed here) and clear tts structures
@@ -226,24 +207,18 @@
 /*
  * Test jthread_timed_join()
  */
-void JNICALL run_for_test_jthread_timed_join(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_timed_join(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     tested_thread_sturct_t * prev_tts = tts;
     IDATA status;
 
     prev_tested_thread(&prev_tts);
     tts->phase = TT_PHASE_RUNNING;
+    tested_thread_started(tts);
     if (prev_tts == NULL){
-        // its the first tested thread
-        while(1){
-            tts->clicks++;
-            sleep_a_click();
-            if (tts->stop) {
-                tts->phase = TT_PHASE_DEAD;
-                break;
-            }
-        }
+        tested_thread_wait_for_stop_request(tts);
+        tts->phase = TT_PHASE_DEAD;
     } else {
         // wait until timeout or previous thread ends 
         status = jthread_timed_join(prev_tts->java_thread, timed_join_wait_time, 0);
@@ -257,6 +232,7 @@
            //tts->phase = (status == TM_ERROR_TIMEOUT ? TT_PHASE_DEAD : TT_PHASE_ERROR);
         }
     }
+    tested_thread_ended(tts);
 }
 
 int test_jthread_timed_join(void) {
@@ -293,8 +269,8 @@
     // make the first thread terminated and test that all threads are terminated
     reset_tested_thread_iterator(&tts);
     next_tested_thread(&tts);
-    tts->stop = 1;
-    check_tested_thread_phase(tts, TT_PHASE_DEAD);
+    tested_thread_send_stop_request(tts);
+    tested_thread_wait_ended(tts);
     jthread_sleep(20 * CLICK_TIME_MSEC * MAX_TESTED_THREAD_NUMBER, 0);
     while(next_tested_thread(&tts)){
         check_tested_thread_phase(tts, TT_PHASE_DEAD);
@@ -309,28 +285,29 @@
 /*
  * Test jthread_exception_stop()
  */
-void JNICALL run_for_test_jthread_exception_stop(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_exception_stop(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     
     tts->phase = TT_PHASE_RUNNING;
-    while(1){
+    tested_thread_started(tts);
+    while(tested_thread_wait_for_stop_request_timed(tts, CLICK_TIME_MSEC) == TM_ERROR_TIMEOUT){
         hythread_safe_point();
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
     }
     tts->phase = TT_PHASE_DEAD;
+    tested_thread_ended(tts);
 }
 
 int test_jthread_exception_stop (void){
 
     tested_thread_sturct_t * tts;
-    jobject excn = new_jobject();
+    jobject excn;
     hythread_t hythread;
     jvmti_thread_t jvmti_thread;
+    JNIEnv * jni_env;
+
+    jni_env = jthread_get_JNI_env(jthread_self());
+    excn = new_jobject_thread_death(jni_env);
 
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_exception_stop);
@@ -391,15 +368,18 @@
 /*
  * Test jthread_sleep(...)
  */
-void JNICALL run_for_test_jthread_sleep(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_sleep(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     IDATA status;
     
     tts->phase = TT_PHASE_SLEEPING;
+    tested_thread_started(tts);
     status = jthread_sleep(1000000, 0);
     tts->phase = (status == TM_ERROR_INTERRUPT ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
 }
+
 int test_jthread_sleep(void) {
 
     tested_thread_sturct_t *tts;
@@ -410,17 +390,12 @@
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_sleep);
 
-    reset_tested_thread_iterator(&tts);
-    while(next_tested_thread(&tts)){
-        check_tested_thread_phase(tts, TT_PHASE_SLEEPING);      
-    }
     for (i = 0; i <= MAX_TESTED_THREAD_NUMBER; i++){
         sleeping_nmb = 0;
         sleeping_tts = NULL;
 
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
-            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
             if (tts->phase == TT_PHASE_SLEEPING){
                 sleeping_nmb++;
                 sleeping_tts = tts;
@@ -428,12 +403,12 @@
                 check_tested_thread_phase(tts, TT_PHASE_DEAD);
             }
         }
-        if (MAX_TESTED_THREAD_NUMBER - sleeping_nmb - i != 0){
+        if (MAX_TESTED_THREAD_NUMBER - i != sleeping_nmb){            
             tf_fail("Wrong number of sleeping threads");
         }
         if (sleeping_nmb > 0){
             tf_assert_same(jthread_interrupt(sleeping_tts->java_thread), TM_ERROR_NONE);
-            check_tested_thread_phase(sleeping_tts, TT_PHASE_DEAD);
+            tested_thread_wait_ended(sleeping_tts);
         }
     }
 
@@ -448,33 +423,27 @@
  */
 int test_jthread_get_JNI_env(void) {
 
-    tested_thread_sturct_t *tts;
-
     tf_assert(jthread_get_JNI_env(jthread_self()) != 0);
-
     return TEST_PASSED;
 }
 
 /*
  * Test hythread_yield()
  */
-void JNICALL run_for_test_hythread_yield(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_hythread_yield(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
 
-    /*
-      IDATA status;
-      tts->phase = TT_PHASE_RUNNING;
-    */
+    tts->phase = TT_PHASE_RUNNING;
+    tested_thread_started(tts);
 
-    while(1){
-        tts->clicks++;
+    while(tested_thread_wait_for_stop_request_timed(tts, CLICK_TIME_MSEC) == TM_ERROR_TIMEOUT){
         hythread_yield();
-        if (tts->stop) {
-            break;
-        }
     }
 
+    tts->phase = TT_PHASE_DEAD;
+    tested_thread_ended(tts);
+
     /*
       tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
     */
@@ -488,8 +457,8 @@
 
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
-        tts->stop = 1;
-        check_tested_thread_phase(tts, TT_PHASE_DEAD);  
+        tested_thread_send_stop_request(tts);
+        tested_thread_wait_ended(tts);  
     }
 
     // Terminate all threads (not needed here) and clear tts structures
@@ -499,14 +468,14 @@
 } 
 
 TEST_LIST_START
-    //TEST(test_jthread_attach)
-    //TEST(test_jthread_detach)
+    TEST(test_jthread_attach)
+    TEST(test_jthread_detach)
     TEST(test_hythread_create)
     TEST(test_hythread_create_with_function)
     TEST(test_jthread_get_JNI_env)
     TEST(test_jthread_join)
-    //TEST(test_jthread_timed_join)
-    //TEST(test_jthread_exception_stop)
+    TEST(test_jthread_timed_join)
+    TEST(test_jthread_exception_stop)
     //TEST(test_jthread_stop)
     TEST(test_jthread_sleep)
     TEST(test_hythread_yield)

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_identify.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_identify.c?view=diff&rev=467506&r1=467505&r2=467506
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_identify.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_identify.c Tue Oct 24 15:05:57 2006
@@ -26,23 +26,15 @@
 /*
  * Test jthread_self(...)
  */
-void JNICALL run_for_test_jthread_self(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_self(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     
     tts->phase = TT_PHASE_RUNNING;
-    while(1){
-        if (jthread_self()->object != tts->java_thread->object){
-            tts->phase = TT_PHASE_ERROR;
-            return;
-        }
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
-    tts->phase = TT_PHASE_DEAD;
+    tested_thread_started(tts);
+    tested_thread_wait_for_stop_request(tts);
+    tts->phase = jthread_self()->object == tts->java_thread->object ? TT_PHASE_DEAD : TT_PHASE_ERROR;
+    tested_thread_ended(tts);
 }
 
 int test_jthread_self(void) {
@@ -54,7 +46,8 @@
 
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
-        tts->stop = 1;
+        tested_thread_send_stop_request(tts);
+        tested_thread_wait_ended(tts);
         check_tested_thread_phase(tts, TT_PHASE_DEAD);
     }
     // Terminate all threads (not needed here) and clear tts structures

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_interrupt.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_interrupt.c?view=diff&rev=467506&r1=467505&r2=467506
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_interrupt.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_interrupt.c Tue Oct 24 15:05:57 2006
@@ -23,27 +23,17 @@
 /*
  * Test jthread_interrupt(...)
  */
-void JNICALL run_for_test_jthread_interrupt(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_interrupt(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     
     tts->phase = TT_PHASE_RUNNING;
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (jthread_is_interrupted(jthread_self())) {
-            break;
-        }
-    }
-    tts->phase = TT_PHASE_INTERRUPTED;
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
-    tts->phase = TT_PHASE_DEAD;
+    tested_thread_started(tts);
+    tested_thread_wait_for_stop_request(tts);
+    tts->phase = jthread_is_interrupted(jthread_self()) ? TT_PHASE_INTERRUPTED : TT_PHASE_ERROR;
+    tested_thread_ended(tts);
+    tested_thread_wait_for_stop_request(tts);
+    tested_thread_ended(tts);
 }
 
 int test_jthread_interrupt(void){
@@ -61,6 +51,9 @@
 
         tf_assert_same(jthread_interrupt(tts->java_thread), TM_ERROR_NONE);
 
+        tested_thread_send_stop_request(tts);
+        tested_thread_wait_ended(tts);
+
         check_tested_thread_phase(tts, TT_PHASE_INTERRUPTED);
         tf_assert_same(jthread_is_interrupted(tts->java_thread), 1);
         tf_assert_same(jthread_interrupt(tts->java_thread), TM_ERROR_NONE);
@@ -73,112 +66,13 @@
 
     return TEST_PASSED;
 } 
-/*
- * Test jthread_is_interrupted(...)
- */
-void JNICALL run_for_test_jthread_is_interrupted(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
-
-    tested_thread_sturct_t * tts = current_thread_tts;
-    
-    tts->phase = TT_PHASE_RUNNING;
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (jthread_is_interrupted(jthread_self())) {
-            break;
-        }
-    }
-    tts->phase = TT_PHASE_INTERRUPTED;
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
-    tts->phase = TT_PHASE_DEAD;
-}
 int test_jthread_is_interrupted(void){
-
-    tested_thread_sturct_t *tts;
-
-    // Initialize tts structures and run all tested threads
-    tested_threads_run(run_for_test_jthread_is_interrupted);
-
-    reset_tested_thread_iterator(&tts);
-    while(next_tested_thread(&tts)){
-        tf_assert_same(jthread_is_interrupted(tts->java_thread), 0);
-        tf_assert_same(jthread_clear_interrupted(tts->java_thread), TM_ERROR_NONE);
-        tf_assert_same(jthread_is_interrupted(tts->java_thread), 0);
-
-        tf_assert_same(jthread_interrupt(tts->java_thread), TM_ERROR_NONE);
-
-        check_tested_thread_phase(tts, TT_PHASE_INTERRUPTED);
-        tf_assert_same(jthread_is_interrupted(tts->java_thread), 1);
-        tf_assert_same(jthread_interrupt(tts->java_thread), TM_ERROR_NONE);
-        tf_assert_same(jthread_is_interrupted(tts->java_thread), 1);
-        tf_assert_same(jthread_clear_interrupted(tts->java_thread), TM_ERROR_INTERRUPT);
-        tf_assert_same(jthread_is_interrupted(tts->java_thread), 0);
-    }
-    // Terminate all threads and clear tts structures
-    tested_threads_destroy();
-
-    return TEST_PASSED;
+    return test_jthread_interrupt();
 } 
 
-/*
- * Test jthread_clear_interrupted(...)
- */
-void JNICALL run_for_test_jthread_clear_interrupted(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
-
-    tested_thread_sturct_t * tts = current_thread_tts;
-    
-    tts->phase = TT_PHASE_RUNNING;
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (jthread_is_interrupted(jthread_self())) {
-            break;
-        }
-    }
-    tts->phase = TT_PHASE_INTERRUPTED;
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
-    tts->phase = TT_PHASE_DEAD;
-}
-
 int test_jthread_clear_interrupted(void){
-
-    tested_thread_sturct_t *tts;
-
-    // Initialize tts structures and run all tested threads
-    tested_threads_run(run_for_test_jthread_clear_interrupted);
-
-    reset_tested_thread_iterator(&tts);
-    while(next_tested_thread(&tts)){
-        tf_assert_same(jthread_is_interrupted(tts->java_thread), 0);
-        tf_assert_same(jthread_clear_interrupted(tts->java_thread), TM_ERROR_NONE);
-        tf_assert_same(jthread_is_interrupted(tts->java_thread), 0);
-
-        tf_assert_same(jthread_interrupt(tts->java_thread), TM_ERROR_NONE);
-
-        check_tested_thread_phase(tts, TT_PHASE_INTERRUPTED);
-        tf_assert_same(jthread_is_interrupted(tts->java_thread), 1);
-        tf_assert_same(jthread_interrupt(tts->java_thread), TM_ERROR_NONE);
-        tf_assert_same(jthread_is_interrupted(tts->java_thread), 1);
-        tf_assert_same(jthread_clear_interrupted(tts->java_thread), TM_ERROR_INTERRUPT);
-        tf_assert_same(jthread_is_interrupted(tts->java_thread), 0);
-    }
-    // Terminate all threads and clear tts structures
-    tested_threads_destroy();
-
-    return TEST_PASSED;
-} 
+    return test_jthread_interrupt();
+}
 
 TEST_LIST_START
     TEST(test_jthread_interrupt)

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_monitors.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_monitors.c?view=diff&rev=467506&r1=467505&r2=467506
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_monitors.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_monitors.c Tue Oct 24 15:05:57 2006
@@ -21,6 +21,8 @@
 #include <open/jthread.h>
 #include <open/hythread_ext.h>
 
+hysem_t mon_enter;
+
 int helper_jthread_monitor_enter_exit(void);
 int helper_jthread_monitor_wait_notify(void);
  
@@ -37,13 +39,14 @@
 /*
  * Test jthread_monitor_try_enter()
  */
-void JNICALL run_for_test_jthread_monitor_try_enter(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_monitor_try_enter(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
     
     tts->phase = TT_PHASE_WAITING_ON_MONITOR;
+    tested_thread_started(tts);
     status = jthread_monitor_try_enter(monitor);
     while (status == TM_ERROR_EBUSY){
         status = jthread_monitor_try_enter(monitor);
@@ -51,16 +54,12 @@
     }
     // Begin critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_IN_CRITICAL_SECTON : TT_PHASE_ERROR);
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
+    hysem_set(mon_enter, 1);
+    tested_thread_wait_for_stop_request(tts);
     status = jthread_monitor_exit(monitor);
     // End critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
 }
 
 int test_jthread_monitor_try_enter(void) {
@@ -70,6 +69,7 @@
     int i;
     int waiting_on_monitor_nmb;
 
+    hysem_create(&mon_enter, 0, 1);
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_monitor_try_enter);
 
@@ -78,9 +78,10 @@
         waiting_on_monitor_nmb = 0;
         critical_tts = NULL;
 
+        hysem_wait(mon_enter);
+
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
-            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
             if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
                 tf_assert(critical_tts == NULL); // error if two threads in critical section
                 critical_tts = tts;
@@ -89,11 +90,11 @@
             }
         }
         tf_assert(critical_tts); // thread in critical section found
-        if (MAX_TESTED_THREAD_NUMBER - waiting_on_monitor_nmb - i != 1){
+        if (MAX_TESTED_THREAD_NUMBER - i != waiting_on_monitor_nmb + 1){
             tf_fail("Wrong number waiting on monitor threads");
         }
-        critical_tts->stop = 1;
-        check_tested_thread_phase(critical_tts, TT_PHASE_DEAD);
+        tested_thread_send_stop_request(critical_tts);
+        tested_thread_wait_ended(critical_tts);
     }
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
@@ -114,9 +115,9 @@
 /*
  * Test jthread_monitor_notify_all(...)
  */
-void JNICALL run_for_test_jthread_monitor_notify_all(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_monitor_notify_all(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
 
@@ -124,22 +125,21 @@
     status = jthread_monitor_enter(monitor);
     if (status != TM_ERROR_NONE){
         tts->phase = TT_PHASE_ERROR;
+        tested_thread_started(tts);
+        tested_thread_ended(tts);
         return;
     }
     // Begin critical section
     tts->phase = TT_PHASE_WAITING_ON_WAIT;
+    tested_thread_started(tts);
     status = jthread_monitor_wait(monitor);
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_IN_CRITICAL_SECTON : TT_PHASE_ERROR);
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
+    hysem_set(mon_enter, 1);
+    tested_thread_wait_for_stop_request(tts);
     status = jthread_monitor_exit(monitor);
     // Exit critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
 }
 
 int test_jthread_monitor_notify_all(void) {
@@ -150,6 +150,8 @@
     int i;
     int waiting_on_wait_nmb;
 
+    hysem_create(&mon_enter, 0, 1);
+
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_monitor_notify_all);
 
@@ -167,9 +169,10 @@
         waiting_on_wait_nmb = 0;
         critical_tts = NULL;
 
+        hysem_wait(mon_enter);
+
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
-            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
             if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
                 tf_assert(critical_tts == NULL); // error if two threads in critical section
                 critical_tts = tts;
@@ -178,11 +181,11 @@
             }
         }
         tf_assert(critical_tts); // thread in critical section found
-        if (MAX_TESTED_THREAD_NUMBER - waiting_on_wait_nmb - i != 1){
+        if (MAX_TESTED_THREAD_NUMBER - i != waiting_on_wait_nmb + 1){
             tf_fail("Wrong number waiting on monitor threads");
         }
-        critical_tts->stop = 1;
-        check_tested_thread_phase(critical_tts, TT_PHASE_DEAD);
+        tested_thread_send_stop_request(critical_tts);
+        tested_thread_wait_ended(critical_tts);
     }
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
@@ -193,9 +196,9 @@
 /*
  * Test jthread_monitor_wait()
  */
-void JNICALL run_for_test_jthread_monitor_wait(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_monitor_wait(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
 
@@ -203,17 +206,17 @@
     status = jthread_monitor_enter(monitor);
     if (status != TM_ERROR_NONE){
         tts->phase = TT_PHASE_ERROR;
+        tested_thread_started(tts);
+        tested_thread_ended(tts);
         return;
     }
     tts->phase = TT_PHASE_WAITING_ON_WAIT;
+    tested_thread_started(tts);
     status = jthread_monitor_wait(monitor);
-    if (status != TM_ERROR_NONE){
-        tts->phase = TT_PHASE_ERROR;
-        return;
-    }
     status = jthread_monitor_exit(monitor);
     // Exit critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
 }
 
 int test_jthread_monitor_wait (void){
@@ -221,6 +224,8 @@
     tested_thread_sturct_t *tts;
     jobject monitor;
 
+    hysem_create(&mon_enter, 0, 1);
+
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_monitor_wait);
 
@@ -235,6 +240,7 @@
 
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
+        tested_thread_wait_ended(tts);
         check_tested_thread_phase(tts, TT_PHASE_DEAD);
     }
     // Terminate all threads and clear tts structures
@@ -246,9 +252,9 @@
 /*
  * Test jthread_monitor_wait_interrupt()
  */
-void JNICALL run_for_test_jthread_monitor_wait_interrupt(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_monitor_wait_interrupt(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
 
@@ -256,17 +262,22 @@
     status = jthread_monitor_enter(monitor);
     if (status != TM_ERROR_NONE){
         tts->phase = TT_PHASE_ERROR;
+        tested_thread_started(tts);
+        tested_thread_ended(tts);
         return;
     }
     tts->phase = TT_PHASE_WAITING_ON_WAIT;
+    tested_thread_started(tts);
     status = jthread_monitor_wait(monitor);
-    if (status != TM_ERROR_INTERRUPT){
+    if (status != TM_ERROR_INTERRUPT) {
         tts->phase = TT_PHASE_ERROR;
+        tested_thread_ended(tts);
         return;
     }
     status = jthread_monitor_exit(monitor);
     // Exit critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
 }
 
 int test_jthread_monitor_wait_interrupt(void){
@@ -276,6 +287,8 @@
     int i;
     int waiting_on_wait_nmb;
 
+    hysem_create(&mon_enter, 0, 1);
+
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_monitor_wait_interrupt);
 
@@ -290,7 +303,6 @@
 
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
-            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
             if (tts->phase == TT_PHASE_WAITING_ON_WAIT){
                 waiting_tts = tts;
                 waiting_on_wait_nmb++;
@@ -298,9 +310,10 @@
                 check_tested_thread_phase(tts, TT_PHASE_DEAD);
             }
         }
-        tf_assert_same(MAX_TESTED_THREAD_NUMBER - waiting_on_wait_nmb - i, 0);
+        tf_assert_same(MAX_TESTED_THREAD_NUMBER - i, waiting_on_wait_nmb);
         if (waiting_tts){
             tf_assert_same(jthread_interrupt(waiting_tts->java_thread), TM_ERROR_NONE);
+            tested_thread_wait_ended(waiting_tts);
             check_tested_thread_phase(waiting_tts, TT_PHASE_DEAD);
         }
     }
@@ -313,9 +326,9 @@
 /*
  * Test jthread_monitor_timed_wait()
  */
-void JNICALL run_for_test_jthread_monitor_timed_wait(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_monitor_timed_wait(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
 
@@ -323,17 +336,22 @@
     status = jthread_monitor_enter(monitor);
     if (status != TM_ERROR_NONE){
         tts->phase = TT_PHASE_ERROR;
+        tested_thread_started(tts);
+        tested_thread_ended(tts);
         return;
     }
     tts->phase = TT_PHASE_WAITING_ON_WAIT;
-    status = jthread_monitor_timed_wait(monitor, 10 * CLICK_TIME_MSEC * MAX_TESTED_THREAD_NUMBER,0);
+    tested_thread_started(tts);
+    status = jthread_monitor_timed_wait(monitor, 10 * CLICK_TIME_MSEC * MAX_TESTED_THREAD_NUMBER, 0);
     if (status != TM_ERROR_NONE){
         tts->phase = TT_PHASE_ERROR;
+        tested_thread_ended(tts);
         return;
     }
     status = jthread_monitor_exit(monitor);
     // Exit critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
 }
 
 int test_jthread_monitor_timed_wait(void) {
@@ -341,6 +359,8 @@
     tested_thread_sturct_t *tts;
     jobject monitor;
 
+    hysem_create(&mon_enter, 0, 1);
+
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_monitor_timed_wait);
 
@@ -355,6 +375,7 @@
 
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
+        tested_thread_wait_ended(tts);
         check_tested_thread_phase(tts, TT_PHASE_DEAD);
     }
     // Terminate all threads and clear tts structures
@@ -366,10 +387,10 @@
 /*
  * Test jthread_monitor_timed_wait()
  */
-void JNICALL run_for_test_jthread_monitor_timed_wait_timeout(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_monitor_timed_wait_timeout(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
 
@@ -377,17 +398,22 @@
     status = jthread_monitor_enter(monitor);
     if (status != TM_ERROR_NONE){
         tts->phase = TT_PHASE_ERROR;
+        tested_thread_started(tts);
+        tested_thread_ended(tts);
         return;
     }
     tts->phase = TT_PHASE_WAITING_ON_WAIT;
+    tested_thread_started(tts);
     status = jthread_monitor_timed_wait(monitor, 10 * CLICK_TIME_MSEC * MAX_TESTED_THREAD_NUMBER, 0);
     if (status != TM_ERROR_TIMEOUT){
         tts->phase = TT_PHASE_ERROR;
+        tested_thread_ended(tts);
         return;
     }
     status = jthread_monitor_exit(monitor);
     // Exit critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
 }
 
 int test_jthread_monitor_timed_wait_timeout(void) {
@@ -395,6 +421,8 @@
     tested_thread_sturct_t *tts;
     jobject monitor;
 
+    hysem_create(&mon_enter, 0, 1);
+
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_monitor_timed_wait_timeout);
 
@@ -409,6 +437,7 @@
 
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
+        tested_thread_wait_dead(tts);
         check_tested_thread_phase(tts, TT_PHASE_DEAD);
     }
     // Terminate all threads and clear tts structures
@@ -420,9 +449,9 @@
 /*
  * Test jthread_monitor_timed_wait()
  */
-void JNICALL run_for_test_jthread_monitor_timed_wait_interrupt(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_monitor_timed_wait_interrupt(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
 
@@ -430,17 +459,22 @@
     status = jthread_monitor_enter(monitor);
     if (status != TM_ERROR_NONE){
         tts->phase = TT_PHASE_ERROR;
+        tested_thread_started(tts);
+        tested_thread_ended(tts);
         return;
     }
     tts->phase = TT_PHASE_WAITING_ON_WAIT;
+    tested_thread_started(tts);
     status = jthread_monitor_timed_wait(monitor, 100 * CLICK_TIME_MSEC * MAX_TESTED_THREAD_NUMBER, 0);
     if (status != TM_ERROR_INTERRUPT){
         tts->phase = TT_PHASE_ERROR;
+        tested_thread_ended(tts);
         return;
     }
     status = jthread_monitor_exit(monitor);
     // Exit critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
 }
 
 int test_jthread_monitor_timed_wait_interrupt(void) {
@@ -450,8 +484,8 @@
     int i;
     int waiting_on_wait_nmb;
 
-    log_info("!!!!!!!!!!!!!! CRASHES");
-    tf_assert(0);
+    hysem_create(&mon_enter, 0, 1);
+
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_monitor_timed_wait_interrupt);
 
@@ -466,7 +500,6 @@
 
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
-            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
             if (tts->phase == TT_PHASE_WAITING_ON_WAIT){
                 waiting_tts = tts;
                 waiting_on_wait_nmb++;
@@ -474,11 +507,13 @@
                 check_tested_thread_phase(waiting_tts, TT_PHASE_DEAD);
             }
         }
-        tf_assert_same(MAX_TESTED_THREAD_NUMBER - waiting_on_wait_nmb - i, 0);
+        tf_assert_same(MAX_TESTED_THREAD_NUMBER - i, waiting_on_wait_nmb);
         if (waiting_tts){
             tf_assert_same(jthread_interrupt(waiting_tts->java_thread), TM_ERROR_NONE);
+            tested_thread_wait_ended(waiting_tts);
+            check_tested_thread_phase(waiting_tts, TT_PHASE_DEAD);
         }
-        check_tested_thread_phase(waiting_tts, TT_PHASE_DEAD);
+        
     }
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
@@ -497,27 +532,24 @@
 //?????????????????????????????? jthread_monitor_init and not init
 //?????????????????????????????? jthread_monitor_exit without enter
 
-void JNICALL run_for_helper_jthread_monitor_enter_exit(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_helper_jthread_monitor_enter_exit(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
     
     tts->phase = TT_PHASE_WAITING_ON_MONITOR;
+    tested_thread_started(tts);
     status = jthread_monitor_enter(monitor);
 
     // Begin critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_IN_CRITICAL_SECTON : TT_PHASE_ERROR);
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
+    hysem_set(mon_enter, 1);
+    tested_thread_wait_for_stop_request(tts);
     status = jthread_monitor_exit(monitor);
     // End critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
 }
 
 int helper_jthread_monitor_enter_exit(void) {
@@ -527,6 +559,8 @@
     int i;
     int waiting_on_monitor_nmb;
 
+    hysem_create(&mon_enter, 0, 1);
+
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_helper_jthread_monitor_enter_exit);
 
@@ -534,9 +568,10 @@
         waiting_on_monitor_nmb = 0;
         critical_tts = NULL;
 
+        hysem_wait(mon_enter);
+
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
-            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
             if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
                 tf_assert(critical_tts == NULL); // error if two threads in critical section
                 critical_tts = tts;
@@ -545,10 +580,11 @@
             }
         }
         tf_assert(critical_tts); // thread in critical section found
-        if (MAX_TESTED_THREAD_NUMBER - waiting_on_monitor_nmb - i != 1){
+        if (MAX_TESTED_THREAD_NUMBER - i != waiting_on_monitor_nmb + 1){
             tf_fail("Wrong number waiting on monitor threads");
         }
-        critical_tts->stop = 1;
+        tested_thread_send_stop_request(critical_tts);
+        tested_thread_wait_ended(critical_tts);
         check_tested_thread_phase(critical_tts, TT_PHASE_DEAD);
     }
     // Terminate all threads and clear tts structures
@@ -561,9 +597,9 @@
  * Test jthread_monitor_wait(...)
  * Test jthread_monitor_notify(...)
  */
-void JNICALL run_for_helper_jthread_monitor_wait_notify(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_helper_jthread_monitor_wait_notify(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
 
@@ -571,22 +607,21 @@
     status = jthread_monitor_enter(monitor);
     if (status != TM_ERROR_NONE){
         tts->phase = TT_PHASE_ERROR;
+        tested_thread_started(tts);
+        tested_thread_ended(tts);
         return;
     }
     // Begin critical section
     tts->phase = TT_PHASE_WAITING_ON_WAIT;
+    tested_thread_started(tts);
     status = jthread_monitor_wait(monitor);
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_IN_CRITICAL_SECTON : TT_PHASE_ERROR);
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
+    hysem_set(mon_enter, 1);
+    tested_thread_wait_for_stop_request(tts);
     status = jthread_monitor_exit(monitor);
     // Exit critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
 }
 
 int helper_jthread_monitor_wait_notify(void) {
@@ -597,6 +632,8 @@
     int i;
     int waiting_on_wait_nmb;
 
+    hysem_create(&mon_enter, 0, 1);
+
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_helper_jthread_monitor_wait_notify);
 
@@ -613,13 +650,12 @@
 
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
-            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
             tf_assert(tts->phase != TT_PHASE_IN_CRITICAL_SECTON);
         }
         tf_assert_same(jthread_monitor_notify(monitor), TM_ERROR_NONE);
+        hysem_wait(mon_enter);
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
-            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
             if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
                 tf_assert(critical_tts == NULL); // error if two threads in critical section
                 critical_tts = tts;
@@ -628,10 +664,11 @@
             }
         }
         tf_assert(critical_tts); // thread in critical section found
-        if (MAX_TESTED_THREAD_NUMBER - waiting_on_wait_nmb - i != 1){
+        if (MAX_TESTED_THREAD_NUMBER - i != waiting_on_wait_nmb + 1){
             tf_fail("Wrong number waiting on monitor threads");
         }
-        critical_tts->stop = 1;
+        tested_thread_send_stop_request(critical_tts);
+        tested_thread_wait_ended(critical_tts);
         check_tested_thread_phase(critical_tts, TT_PHASE_DEAD);
     }
     // Terminate all threads and clear tts structures

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_park.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_park.c?view=diff&rev=467506&r1=467505&r2=467506
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_park.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_park.c Tue Oct 24 15:05:57 2006
@@ -24,22 +24,18 @@
  * Test jthread_park(...)
  * Test jthread_unpark(...)
  */
-void JNICALL run_for_test_jthread_park_unpark(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_park_unpark(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     IDATA status;
     
     tts->phase = TT_PHASE_PARKED;
+    tested_thread_started(tts);
     status = jthread_park();
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_RUNNING : TT_PHASE_ERROR);
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
+    tested_thread_wait_for_stop_request(tts);
     tts->phase = TT_PHASE_DEAD;
+    tested_thread_ended(tts);
 }
 
 int test_jthread_park_unpark(void) {
@@ -76,6 +72,7 @@
         }
         if (parked_nmb > 0){
             tf_assert_same(jthread_unpark(parked_tts->java_thread), TM_ERROR_NONE);
+            tested_thread_wait_running(parked_tts);
             check_tested_thread_phase(parked_tts, TT_PHASE_RUNNING);
         }
     }
@@ -88,22 +85,18 @@
 /*
  * Test jthread_park(...)
  */
-void JNICALL run_for_test_jthread_park_interrupt(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_park_interrupt(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     IDATA status;
     
     tts->phase = TT_PHASE_PARKED;
+    tested_thread_started(tts);
     status = jthread_park();
     tts->phase = (status == TM_ERROR_INTERRUPT ? TT_PHASE_RUNNING : TT_PHASE_ERROR);
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
+    tested_thread_wait_for_stop_request(tts);
     tts->phase = TT_PHASE_DEAD;
+    tested_thread_ended(tts);
 }
 
 int test_jthread_park_interrupt(void) {
@@ -139,6 +132,7 @@
         }
         if (parked_nmb > 0){
             tf_assert_same(jthread_interrupt(parked_tts->java_thread), TM_ERROR_NONE);
+            tested_thread_wait_running(parked_tts);
             check_tested_thread_phase(parked_tts, TT_PHASE_RUNNING);
         }
     }
@@ -151,22 +145,18 @@
 /*
  * Test jthread_timed_park(...)
  */
-void JNICALL run_for_test_jthread_timed_park(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_timed_park(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     IDATA status;
     
     tts->phase = TT_PHASE_PARKED;
+    tested_thread_started(tts);
     status = jthread_timed_park(50, 0);
     tts->phase = (status == TM_ERROR_TIMEOUT ? TT_PHASE_RUNNING : TT_PHASE_ERROR);
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
+    tested_thread_wait_for_stop_request(tts);
     tts->phase = TT_PHASE_DEAD;
+    tested_thread_ended(tts);
 }
 
 int test_jthread_timed_park(void) {
@@ -178,6 +168,7 @@
 
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
+        tested_thread_wait_running(tts);
         check_tested_thread_phase(tts, TT_PHASE_RUNNING);       
     }
 

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_suspend.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_suspend.c?view=diff&rev=467506&r1=467505&r2=467506
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_suspend.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_suspend.c Tue Oct 24 15:05:57 2006
@@ -25,73 +25,59 @@
  * Test jthread_suspend(...)
  * Test jthread_resume(...)
   */
-void JNICALL run_for_test_jthread_suspend_resume(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_suspend_resume(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
+    IDATA status;
     
     tts->phase = TT_PHASE_RUNNING;
-    while(1){
+    tested_thread_started(tts);    
+    do {
         hythread_safe_point();
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
-    tts->phase = TT_PHASE_DEAD;
+        status = tested_thread_wait_for_stop_request_timed(tts, SLEEP_TIME);
+        hythread_suspend_disable();
+        hythread_suspend_enable();
+    } while (status == TM_ERROR_TIMEOUT);
+    tts->phase = status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR;
+    tested_thread_ended(tts);
 }
 
 int test_jthread_suspend_resume(void) {
 
     tested_thread_sturct_t *tts;
     tested_thread_sturct_t *switch_tts;
-    int i;
-    int suspended_nmb;
 
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_suspend_resume);
 
-    for (i = 0; i <= MAX_TESTED_THREAD_NUMBER; i++){
+    switch_tts = get_tts(0);
 
-        suspended_nmb = 0;
-        switch_tts = NULL;
+    reset_tested_thread_iterator(&tts);
+    while(next_tested_thread(&tts)){
+        tested_thread_wait_running(tts);
+    }
 
-        reset_tested_thread_iterator(&tts);
-        while(next_tested_thread(&tts)){
+    tf_assert_same((jthread_suspend(switch_tts->java_thread)), TM_ERROR_NONE);
+    
+    reset_tested_thread_iterator(&tts);
+    while(next_tested_thread(&tts)){
+        tested_thread_send_stop_request(tts);
+    }
+ 
+    reset_tested_thread_iterator(&tts);
+    while(next_tested_thread(&tts)){
+        if (tts != switch_tts) {
+            tested_thread_wait_ended(tts);
+            check_tested_thread_phase(tts, TT_PHASE_DEAD);
+        } else {
             check_tested_thread_phase(tts, TT_PHASE_RUNNING);
-            if (tested_thread_is_running(tts)){
-                switch_tts = tts;
-            } else {
-                suspended_nmb++;
-            }
-        }
-        if (suspended_nmb != i){
-            tf_fail("Wrong number of suspended threads");
-        }
-        if (switch_tts != NULL){
-            tf_assert_same(jthread_suspend(switch_tts->java_thread), TM_ERROR_NONE);
         }
     }
-    for (i = 0; i <= MAX_TESTED_THREAD_NUMBER; i++){
 
-        suspended_nmb = 0;
-        switch_tts = NULL;
+    tf_assert_same(jthread_resume(switch_tts->java_thread), TM_ERROR_NONE);
+    tested_thread_wait_ended(switch_tts);
+    check_tested_thread_phase(switch_tts, TT_PHASE_DEAD);
 
-        reset_tested_thread_iterator(&tts);
-        while(next_tested_thread(&tts)){
-            check_tested_thread_phase(tts, TT_PHASE_RUNNING);
-            if (!tested_thread_is_running(tts)){
-                suspended_nmb++;
-                switch_tts = tts;
-            }
-        }
-        if (suspended_nmb != MAX_TESTED_THREAD_NUMBER - i){
-            tf_fail("Wrong number of suspended threads");
-        }
-        if (switch_tts != NULL){
-            tf_assert_same(jthread_resume(switch_tts->java_thread), TM_ERROR_NONE);
-        }
-    }
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
 
@@ -101,7 +87,6 @@
  * Test jthread_suspend_all(...)
  * Test jthread_resume_all(...)
  */
-
 int test_jthread_suspend_all_resume_all(void) {
 
     tested_thread_sturct_t * tts;
@@ -115,29 +100,31 @@
     // Test that all threads are running
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
+        tested_thread_wait_running(tts);
         all_threads[i] = tts->java_thread;
         results[i] = (jvmtiError)(TM_ERROR_NONE + 1);
         i++;
-        tf_assert(tested_thread_is_running(tts));
     }
     tf_assert_same(jthread_suspend_all(results, MAX_TESTED_THREAD_NUMBER, all_threads), TM_ERROR_NONE);
     // Test that all threads are suspended
+    reset_tested_thread_iterator(&tts);
+    while(next_tested_thread(&tts)){
+        tested_thread_send_stop_request(tts);
+    }
     i = 0;
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
-        tf_assert(!tested_thread_is_running(tts));
+        check_tested_thread_phase(tts, TT_PHASE_RUNNING);
         tf_assert_same(results[i], TM_ERROR_NONE);
         results[i] = (jvmtiError)(TM_ERROR_NONE + 1);
         i++;
     }
     tf_assert_same(jthread_resume_all(results, MAX_TESTED_THREAD_NUMBER, all_threads), TM_ERROR_NONE);
     // Test that all threads are running
-    i = 0;
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
-        tf_assert(tested_thread_is_running(tts));
-        tf_assert_same(results[i], TM_ERROR_NONE);
-        i++;
+        tested_thread_wait_ended(tts);
+        check_tested_thread_phase(tts, TT_PHASE_DEAD);        
     }
     // Terminate all threads and clear tts structures
     tested_threads_destroy();

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c?view=diff&rev=467506&r1=467505&r2=467506
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c Tue Oct 24 15:05:57 2006
@@ -44,19 +44,19 @@
     
     apr_pool_create(&pool, NULL);
 
-    args = (void**) apr_palloc(pool, sizeof(void *) *3); 
+    args = (void**) apr_palloc(pool, sizeof(void *) *2); 
     
     hythread_group_create((hythread_group_t *)&args[0]); 
     
     args[1] = apr_palloc(pool, sizeof(jthread_threadattr_t));
     ((jthread_threadattr_t *)args[1])->stacksize = 1024;
     ((jthread_threadattr_t *)args[1])->priority  = 1;
-    args[2] = pool;
     
     hythread_create_with_group(&thread, args[0], 1024, 1, 0, start_proc, args);
 
-    //hythread_join(thread);
-    return 0;
+    hythread_join(thread);
+    // TODO: should check that created thread finished without errors.
+    return TEST_PASSED;
 }
 
 hylatch_t start;
@@ -78,7 +78,7 @@
         hythread_create_with_group(&thread, group, 0, 0, 0, start_proc_empty, NULL);
     }
 
-    // Wait util all thread has started.
+    // Wait util all threads have started.
     hylatch_wait(start);
     iterator = hythread_iterator_create(group);
     // Notify all threads
@@ -114,7 +114,7 @@
         hythread_create(&thread, 0, 0, 0, start_proc_empty, NULL);
     }
 
-    // Wait util all thread has started.
+    // Wait util all threads have started.
     hylatch_wait(start);
     iterator = hythread_iterator_create(NULL);
     // Notify all threads
@@ -153,7 +153,7 @@
     while(i--) {
         apr_pool_create(&pool, NULL);
 
-        args = (void**) apr_palloc(pool, sizeof(void *) *3); 
+        args = (void**) apr_palloc(pool, sizeof(void *) *2); 
     
         args[0] = group; 
         
@@ -161,8 +161,6 @@
         ((jthread_threadattr_t *)args[1])->stacksize = 1024;
         ((jthread_threadattr_t *)args[1])->priority  = 1;
         
-        args[2] = pool;
-        
         thread = NULL;
 
         hythread_create_with_group(&thread, group, 1024, 1, 0, start_proc, args);
@@ -193,8 +191,6 @@
     void** attrs = (void **)args; 
     tf_assert_same(hythread_self()->priority, ((jthread_threadattr_t *)attrs[1])->priority);
     tf_assert_same(hythread_self()->group, attrs[0]);
-    hythread_sleep(1000);
-    apr_pool_destroy((apr_pool_t *)attrs[2]); 
     return 0;
 }
 

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c?view=diff&rev=467506&r1=467505&r2=467506
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c Tue Oct 24 15:05:57 2006
@@ -121,7 +121,6 @@
 int test_hythread_thin_monitor_enter_contended(void){
     apr_pool_t *pool;
     void **args; 
-    jthread_threadattr_t *attr;
     hythread_t thread = NULL;
     hythread_thin_monitor_t lockword_ptr;
     IDATA status;

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_instrum.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_instrum.c?view=diff&rev=467506&r1=467505&r2=467506
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_instrum.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_instrum.c Tue Oct 24 15:05:57 2006
@@ -20,24 +20,9 @@
 #include "thread_unit_test_utils.h"
 #include <open/jthread.h>
 #include <open/ti_thread.h>
+#include <open/thread_externals.h>
 
-hysem_t start;
-
-void JNICALL run_for_test_jthread_get_all_threads(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg) {
-
-    tested_thread_sturct_t * tts = current_thread_tts;
-    
-    tts->phase = TT_PHASE_RUNNING;
-    hysem_set(start, 1);
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
-    tts->phase = TT_PHASE_DEAD;
-}
+hysem_t mon_enter;
 
 /*
  * Test jthread_get_all_threads(...)
@@ -54,9 +39,9 @@
     int i;
 
     jni_env = jthread_get_JNI_env(jthread_self());
-    hysem_create(&start, 0, 1);
 
-    sleep_a_click();
+    // TODO: unsafe .... need to find another way of synchronization
+    hythread_sleep(1000);
     
     jthread_get_thread_count(&initial_thread_count);
     jthread_get_all_threads(&threads, &initial_all_threads_count);
@@ -72,9 +57,9 @@
     i = 0;
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
-        current_thread_tts = tts;
-        tf_assert_same(jthread_create_with_function(jni_env, tts->java_thread, &tts->attrs, run_for_test_jthread_get_all_threads, NULL), TM_ERROR_NONE);
-        hysem_wait(start);
+        tf_assert_same(jthread_create_with_function(jni_env, tts->java_thread, &tts->attrs, default_run_for_test, tts), TM_ERROR_NONE);
+        tested_thread_wait_started(tts);
+        tts->native_thread = (hythread_t) vm_jthread_get_tm_data(tts->java_thread);
         check_tested_thread_phase(tts, TT_PHASE_RUNNING);
         tf_assert_same(jthread_get_thread_count(&thread_count), TM_ERROR_NONE);
         tf_assert_same(jthread_get_all_threads(&threads, &all_threads_count), TM_ERROR_NONE);
@@ -101,27 +86,24 @@
 /*
  * Test get_blocked_count(...)
  */
-void JNICALL run_for_test_jthread_get_blocked_count(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_get_blocked_count(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
     
     tts->phase = TT_PHASE_WAITING_ON_MONITOR;
+    tested_thread_started(tts);
     status = jthread_monitor_enter(monitor);
 
     // Begin critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_IN_CRITICAL_SECTON : TT_PHASE_ERROR);
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
+    hysem_set(mon_enter, 1);
+    tested_thread_wait_for_stop_request(tts);
     status = jthread_monitor_exit(monitor);
     // End critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
 }
 
 int test_jthread_get_blocked_count(void) {
@@ -131,6 +113,8 @@
     int i;
     int waiting_on_monitor_nmb;
 
+    hysem_create(&mon_enter, 0, 1);
+
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_get_blocked_count);
 
@@ -139,18 +123,23 @@
         waiting_on_monitor_nmb = 0;
         critical_tts = NULL;
 
+        hysem_wait(mon_enter);
+
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
-            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
             if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
+                tf_assert(critical_tts == NULL);
                 critical_tts = tts;
             }
         }
+        // TODO: unsafe .... need to find another way of synchronization
+        hythread_sleep(1000);
         tf_assert_same(jthread_get_blocked_count(&waiting_on_monitor_nmb), TM_ERROR_NONE);
-        if (MAX_TESTED_THREAD_NUMBER - waiting_on_monitor_nmb - i != 1){
+        if (MAX_TESTED_THREAD_NUMBER - i != waiting_on_monitor_nmb + 1){
             tf_fail("Wrong number waiting on monitor threads");
         }
-        critical_tts->stop = 1;
+        tested_thread_send_stop_request(critical_tts);
+        tested_thread_wait_ended(critical_tts);
         check_tested_thread_phase(critical_tts, TT_PHASE_DEAD);
     }
     // Terminate all threads and clear tts structures
@@ -162,29 +151,25 @@
 /*
  * Test jthread_get_deadlocked_threads(...)
  */
-void JNICALL run_for_test_jthread_get_deadlocked_threads(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_get_deadlocked_threads(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
-    IDATA status;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
+    IDATA status = TM_ERROR_NONE;
     
     if (tts->my_index < 2){
         status = jthread_monitor_enter(tts->monitor);
     }
 
     tts->phase = TT_PHASE_RUNNING;
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
+    tested_thread_started(tts);
+    tested_thread_wait_for_stop_request(tts);
     if (tts->my_index == 0){
         status = jthread_monitor_enter(get_tts(1)->monitor);
     } else if (tts->my_index == 1){
         status = jthread_monitor_enter(get_tts(0)->monitor);
     }
-    tts->phase = TT_PHASE_DEAD;
+    tts->phase = status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR;
+    tested_thread_ended(tts);
 }
 
 int test_jthread_get_deadlocked_threads(void) {
@@ -212,54 +197,53 @@
                                                   &dead_list, &dead_list_count), TM_ERROR_NONE);
     tf_assert_same(dead_list_count, 0);
 
-    reset_tested_thread_iterator(&tts);
-    next_tested_thread(&tts);
-    tts->stop = 1;
-    check_tested_thread_phase(tts, TT_PHASE_ANY);
-    next_tested_thread(&tts);
-    tts->stop = 1;
-    check_tested_thread_phase(tts, TT_PHASE_ANY);
+    tested_thread_send_stop_request(get_tts(0));
+    tested_thread_send_stop_request(get_tts(1));
+
+    // TODO: unsafe .... need to find another way of synchronization
+    hythread_sleep(5000);
     tf_assert_same(jthread_get_deadlocked_threads(thread_list, MAX_TESTED_THREAD_NUMBER,
                                                   &dead_list, &dead_list_count), TM_ERROR_NONE);
     tf_assert_same(dead_list_count, 2);
 
+    tf_assert_same(jthread_monitor_exit(get_tts(0)->java_thread), TM_ERROR_NONE);
+    tf_assert_same(jthread_monitor_exit(get_tts(1)->java_thread), TM_ERROR_NONE);
+
+     // Terminate all threads and clear tts structures
+    tested_threads_destroy();
+    
     return TEST_PASSED;
 }
 
 /*
  * Test get_wated_count(...)
  */
-void JNICALL run_for_test_jthread_get_waited_count(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_get_waited_count(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
     
     tts->phase = TT_PHASE_RUNNING;
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
+    tested_thread_started(tts);
     status = jthread_monitor_enter(monitor);
+    tested_thread_wait_for_stop_request(tts);
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_WAITING_ON_WAIT : TT_PHASE_ERROR);
     status = jthread_monitor_wait(monitor);
     if (status != TM_ERROR_NONE){
         tts->phase = TT_PHASE_ERROR;
+        tested_thread_ended(tts);
         return;
     }
     status = jthread_monitor_exit(monitor);
 
     // End critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
 }
 
 int test_jthread_get_waited_count(void) {
 
-    tested_thread_sturct_t *tts;
-    tested_thread_sturct_t *running_tts;
     int i;
     int waiting_nmb;
     jobject monitor;
@@ -270,27 +254,17 @@
     for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
 
         waiting_nmb = 0;
-        running_tts = NULL;
 
-        reset_tested_thread_iterator(&tts);
-        while(next_tested_thread(&tts)){
-            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
-            if (tts->phase == TT_PHASE_RUNNING){
-                running_tts = tts;
-            }
-        }
         tf_assert_same(jthread_get_waited_count(&waiting_nmb), TM_ERROR_NONE);
         if (waiting_nmb != i){
             tf_fail("Wrong number waiting on monitor threads");
         }
-        if (running_tts){
-            running_tts->stop = 1;
-        }
-        check_tested_thread_phase(running_tts, TT_PHASE_WAITING_ON_WAIT);
+        tested_thread_send_stop_request(get_tts(i));
+        // TODO: unsafe .... need to find another way of synchronization
+        hythread_sleep(1000);
+        check_tested_thread_phase(get_tts(i), TT_PHASE_WAITING_ON_WAIT);
     }
-    reset_tested_thread_iterator(&tts);
-    next_tested_thread(&tts);
-    monitor = tts->monitor;
+    monitor = get_tts(0)->monitor;
     tf_assert_same(jthread_monitor_enter(monitor), TM_ERROR_NONE);
     tf_assert_same(jthread_monitor_notify_all(monitor), TM_ERROR_NONE);
     tf_assert_same(jthread_monitor_exit(monitor), TM_ERROR_NONE);

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_monitor_info.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_monitor_info.c?view=diff&rev=467506&r1=467505&r2=467506
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_monitor_info.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_monitor_info.c Tue Oct 24 15:05:57 2006
@@ -23,7 +23,7 @@
 #include <open/hythread_ext.h>
 #include <open/ti_thread.h>
 
-hylatch_t mon_enter;
+hysem_t mon_enter;
 
 int ti_is_enabled() {
     return 1;
@@ -32,28 +32,23 @@
 /*
  * Test jthread_get_contended_monitor(...)
  */
-void JNICALL run_for_test_jthread_get_contended_monitor(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_get_contended_monitor(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
     
     tts->phase = TT_PHASE_WAITING_ON_MONITOR;
+    tested_thread_started(tts);
     status = jthread_monitor_enter(monitor);
     // Begin critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_IN_CRITICAL_SECTON : TT_PHASE_ERROR);
-    hylatch_count_down(mon_enter);
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
-    hylatch_set(mon_enter, 1);
+    hysem_set(mon_enter, 1);
+    tested_thread_wait_for_stop_request(tts);
     // End critical section
     status = jthread_monitor_exit(monitor);
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
 }
 
 int test_jthread_get_contended_monitor(void) {
@@ -63,18 +58,18 @@
     jobject contended_monitor;
     int i;
 
-    hylatch_create(&mon_enter, 1);
+    hysem_create(&mon_enter, 0, 1);
 
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_get_contended_monitor);
     
-    reset_tested_thread_iterator(&tts);
     for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
         critical_tts = NULL;
+        
+        hysem_wait(mon_enter);
+
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
-            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
-            hylatch_wait(mon_enter);
             tf_assert_same(jthread_get_contended_monitor(tts->java_thread, &contended_monitor), TM_ERROR_NONE);
             if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
                 tf_assert_null(contended_monitor);
@@ -86,7 +81,8 @@
                 //tf_assert(vm_objects_are_equal(contended_monitor, tts->monitor));
             }
         }
-        critical_tts->stop = 1;
+        tested_thread_send_stop_request(critical_tts);
+        tested_thread_wait_ended(critical_tts);
         check_tested_thread_phase(critical_tts, TT_PHASE_DEAD);
     }
     // Terminate all threads and clear tts structures
@@ -98,26 +94,23 @@
 /*
  * Test jthread_holds_lock(...)
  */
-void JNICALL run_for_test_jthread_holds_lock(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_holds_lock(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
     
     tts->phase = TT_PHASE_WAITING_ON_MONITOR;
+    tested_thread_started(tts);
     status = jthread_monitor_enter(monitor);
     // Begin critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_IN_CRITICAL_SECTON : TT_PHASE_ERROR);
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
+    hysem_set(mon_enter, 1);
+    tested_thread_wait_for_stop_request(tts);
     status = jthread_monitor_exit(monitor);
     // End critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
 }
 
 int test_jthread_holds_lock(void) {
@@ -127,15 +120,20 @@
     int blocked_count;
     int i;
 
+    hysem_create(&mon_enter, 0, 1);
+
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_holds_lock);
     
+
     for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
         blocked_count = 0;
         critical_tts = NULL;
+
+        hysem_wait(mon_enter);
+
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
-            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
             if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
                 tf_assert(jthread_holds_lock(tts->java_thread, tts->monitor) > 0);
                 tf_assert_null(critical_tts);
@@ -150,8 +148,8 @@
         }
         tf_assert(critical_tts); // thread in critical section found
         tf_assert_same(blocked_count, MAX_TESTED_THREAD_NUMBER - i - 1);
-        critical_tts->stop = 1;
-        check_tested_thread_phase(critical_tts, TT_PHASE_DEAD);
+        tested_thread_send_stop_request(critical_tts);
+        tested_thread_wait_ended(critical_tts);
         check_tested_thread_phase(critical_tts, TT_PHASE_DEAD);
     }
 
@@ -164,26 +162,23 @@
 /*
  * Test jthread_get_lock_owner(...)
  */
-void JNICALL run_for_test_jthread_get_lock_owner(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_get_lock_owner(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
     
     tts->phase = TT_PHASE_WAITING_ON_MONITOR;
+    tested_thread_started(tts);
     status = jthread_monitor_enter(monitor);
     // Begin critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_IN_CRITICAL_SECTON : TT_PHASE_ERROR);
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
+    hysem_set(mon_enter, 1);
+    tested_thread_wait_for_stop_request(tts);
     status = jthread_monitor_exit(monitor);
     // End critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
 }
 
 int test_jthread_get_lock_owner(void) {
@@ -194,15 +189,21 @@
     int blocked_count;
     int i;
 
+    hysem_create(&mon_enter, 0 , 1);
+
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_get_lock_owner);
     
     for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
         blocked_count = 0;
+        critical_tts = NULL;
+
+        hysem_wait(mon_enter);
+
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
-            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
             if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
+                tf_assert_null(critical_tts);
                 critical_tts = tts;
             } else if (tts->phase == TT_PHASE_WAITING_ON_MONITOR){
                 blocked_count++;
@@ -213,7 +214,8 @@
         tf_assert_same(jthread_get_lock_owner(critical_tts->monitor, &lock_owner), TM_ERROR_NONE);
         tf_assert(lock_owner);
         tf_assert_same(critical_tts->java_thread->object, lock_owner->object);
-        critical_tts->stop = 1;
+        tested_thread_send_stop_request(critical_tts);
+        tested_thread_wait_ended(critical_tts);
         check_tested_thread_phase(critical_tts, TT_PHASE_DEAD);
     }
     // Terminate all threads and clear tts structures
@@ -225,29 +227,23 @@
 /*
  * Test jthread_get_owned_monitors(...)
  */
-void JNICALL run_for_test_jthread_get_owned_monitors(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_test_jthread_get_owned_monitors(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
     
     tts->phase = TT_PHASE_WAITING_ON_MONITOR;
+    tested_thread_started(tts);
     status = jthread_monitor_enter(monitor);
-
     // Begin critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_IN_CRITICAL_SECTON : TT_PHASE_ERROR);
-    hylatch_count_down(mon_enter);
-    while(1){
-        tts->clicks++;
-        sleep_a_click();
-        if (tts->stop) {
-            break;
-        }
-    }
-    hylatch_set(mon_enter, 1);
+    hysem_set(mon_enter, 1);
+    tested_thread_wait_for_stop_request(tts);
     status = jthread_monitor_exit(monitor);
     // End critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
 }
 
 int test_jthread_get_owned_monitors(void) {
@@ -258,7 +254,7 @@
     jint owned_monitors_count;
     jobject *owned_monitors = NULL;
 
-    hylatch_create(&mon_enter, 1);
+    hysem_create(&mon_enter, 0, 1);
 
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_get_owned_monitors);
@@ -266,14 +262,14 @@
     for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
         critical_tts = NULL;
 
+        hysem_wait(mon_enter);
+
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
-            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
-            hylatch_wait(mon_enter);
             tf_assert_same(jthread_get_owned_monitors (tts->java_thread, 
                                                        &owned_monitors_count, &owned_monitors), TM_ERROR_NONE);
             if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
-                tf_assert(critical_tts == NULL); // error if two threads in critical section
+                tf_assert(critical_tts == NULL);
                 critical_tts = tts;
                 tf_assert_same(owned_monitors_count, 1);
                 tf_assert_same(owned_monitors[0]->object, tts->monitor->object);
@@ -281,9 +277,9 @@
                 tf_assert_same(owned_monitors_count, 0);
             }
         }
-        tf_assert(critical_tts); // thread in critical section found
-        critical_tts->stop = 1;
-        check_tested_thread_phase(critical_tts, TT_PHASE_DEAD);
+        tf_assert(critical_tts);
+        tested_thread_send_stop_request(critical_tts);
+        tested_thread_wait_ended(critical_tts);
     }
     // Terminate all threads and clear tts structures
     tested_threads_destroy();

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_peak_count.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_peak_count.c?view=diff&rev=467506&r1=467505&r2=467506
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_peak_count.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_peak_count.c Tue Oct 24 15:05:57 2006
@@ -44,27 +44,22 @@
     return helper_get_reset_peak_count();
 }
 
-void JNICALL run_for_helper_get_reset_peak_count(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg){
+void JNICALL run_for_helper_get_reset_peak_count(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     IDATA status;
-    int i;
     int num = 0;
     
     status = jthread_reset_peak_thread_count();
     tts->peak_count = 0;
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_RUNNING : TT_PHASE_ERROR);
-    while(1){
-        for (i = 0; i < 1000; i++){
-            num = num + 1;
-        }
-        if (tts->stop) {
-            break;
-        }
-        sleep_a_click();
+    tested_thread_started(tts);
+    while(tested_thread_wait_for_stop_request_timed(tts, SLEEP_TIME) == TM_ERROR_TIMEOUT) {
+        ++num;
     }
     status = jthread_get_peak_thread_count(&tts->peak_count);
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
 }
 
 int helper_get_reset_peak_count(void) {
@@ -76,7 +71,8 @@
     
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
-        tts->stop = 1;
+        tested_thread_send_stop_request(tts);
+        tested_thread_wait_ended(tts);
         check_tested_thread_phase(tts, TT_PHASE_DEAD);
         printf("peak_count = %i \n", tts->peak_count);
         tf_assert(tts->peak_count > 0);



Mime
View raw message