harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r467506 [2/2] - in /incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread: ./ utils/
Date Tue, 24 Oct 2006 22:05:58 GMT
Modified: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_raw_monitors.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_raw_monitors.c?view=diff&rev=467506&r1=467505&r2=467506
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_raw_monitors.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_raw_monitors.c Tue
Oct 24 15:05:57 2006
@@ -87,33 +87,31 @@
  * ------------------------ HELPERS -----------------------
  */
 
+hysem_t mon_enter;
 /*
  * Test jthread_raw_monitor_enter(...)
  * Test jthread_raw_monitor_exit(...)
  */
 //?????????????????????????????? jthread_raw_monitor_init and not init
 //?????????????????????????????? jthread_raw_monitor_exit without enter
-void JNICALL run_for_helper_jthread_raw_monitor_enter_exit(jvmtiEnv * jvmti_env, JNIEnv *
jni_env, void *arg){
+void JNICALL run_for_helper_jthread_raw_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;
     jrawMonitorID monitor = tts->raw_monitor;
     IDATA status;
     
     tts->phase = TT_PHASE_WAITING_ON_MONITOR;
+    tested_thread_started(tts);
     status = jthread_raw_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_raw_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_raw_monitor_enter_exit(void) {
@@ -123,6 +121,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_raw_monitor_enter_exit);
 
@@ -131,9 +131,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;
@@ -145,7 +146,8 @@
         if (MAX_TESTED_THREAD_NUMBER - waiting_on_monitor_nmb - i != 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
@@ -158,9 +160,9 @@
  * Test jthread_raw_wait(...)
  * Test jthread_raw_notify(...)
  */
-void JNICALL run_for_helper_jthread_raw_wait_notify(jvmtiEnv * jvmti_env, JNIEnv * jni_env,
void *arg){
+void JNICALL run_for_helper_jthread_raw_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;
     jrawMonitorID monitor = tts->raw_monitor;
     IDATA status;
     int64 msec = 1000000;
@@ -168,22 +170,20 @@
     status = jthread_raw_monitor_enter(monitor);
     if (status != TM_ERROR_NONE){
         tts->phase = TT_PHASE_ERROR;
+        tested_thread_ended(tts);
         return;
     }
     // Begin critical section
     tts->phase = TT_PHASE_WAITING_ON_WAIT;
+    tested_thread_started(tts);
     status = jthread_raw_monitor_wait(monitor, msec);
     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_raw_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_raw_wait_notify(void) {
@@ -191,10 +191,11 @@
     tested_thread_sturct_t *tts;
     tested_thread_sturct_t *critical_tts;
     jrawMonitorID monitor;
-    int64 msec = 1000000;
     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_raw_wait_notify);
 
@@ -210,13 +211,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_raw_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;
@@ -228,7 +228,8 @@
         if (MAX_TESTED_THREAD_NUMBER - waiting_on_wait_nmb - i != 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
@@ -241,34 +242,6 @@
  * Test jthread_raw_wait(...)
  * Test jthread_raw_notify_all(...)
  */
-void JNICALL run_for_helper_jthread_raw_wait_notify_all(jvmtiEnv * jvmti_env, JNIEnv * jni_env,
void *arg){
-
-    tested_thread_sturct_t * tts = current_thread_tts;
-    jrawMonitorID monitor = tts->raw_monitor;
-    int64 msec = 1000000;
-    IDATA status;
-
-    tts->phase = TT_PHASE_WAITING_ON_MONITOR;
-    status = jthread_raw_monitor_enter(monitor);
-    if (status != TM_ERROR_NONE){
-        tts->phase = TT_PHASE_ERROR;
-        return;
-    }
-    // Begin critical section
-    tts->phase = TT_PHASE_WAITING_ON_WAIT;
-    status = jthread_raw_monitor_wait(monitor, msec);
-    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;
-        }
-    }
-    status = jthread_raw_monitor_exit(monitor);
-    // Exit critical section
-    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
-}
 
 int helper_jthread_raw_wait_notify_all(void) {
 
@@ -278,8 +251,10 @@
     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_raw_wait_notify_all);
+    tested_threads_run(run_for_helper_jthread_raw_wait_notify);
 
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
@@ -295,9 +270,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;
@@ -309,7 +285,8 @@
         if (MAX_TESTED_THREAD_NUMBER - waiting_on_wait_nmb - i != 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
@@ -318,13 +295,14 @@
     return TEST_PASSED;
 }
 
-void JNICALL run_for_helper_jthread_raw_monitor_try_enter(jvmtiEnv * jvmti_env, JNIEnv *
jni_env, void *arg){
+void JNICALL run_for_helper_jthread_raw_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;
     jrawMonitorID monitor = tts->raw_monitor;
     IDATA status;
     
     tts->phase = TT_PHASE_WAITING_ON_MONITOR;
+    tested_thread_started(tts);
     status = jthread_raw_monitor_try_enter(monitor);
     while (status == TM_ERROR_EBUSY){
         status = jthread_raw_monitor_try_enter(monitor);
@@ -332,16 +310,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_raw_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_raw_monitor_try_enter(void) {
@@ -351,6 +325,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_raw_monitor_try_enter);
 
@@ -359,9 +335,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;
@@ -373,7 +350,8 @@
         if (MAX_TESTED_THREAD_NUMBER - waiting_on_monitor_nmb - i != 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_ti_state.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_state.c?view=diff&rev=467506&r1=467505&r2=467506
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_state.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_state.c Tue Oct 24
15:05:57 2006
@@ -34,20 +34,18 @@
  *  jthread_clear_interrupted()  ALIVE | RUNNABLE
  *                           DEAD
  */
-void JNICALL run_for_test_jthread_get_state_1(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void
*arg){
+void JNICALL run_for_test_jthread_get_state_1(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, SLEEP_TIME) == TM_ERROR_TIMEOUT){
         hythread_safe_point();
-        tts->clicks++;
         hythread_yield();
-        if (tts->stop) {
-            break;
-        }
     }
     tts->phase = TT_PHASE_DEAD;
+    tested_thread_ended(tts);
 }
 
 int test_jthread_get_state_1(void) {
@@ -74,7 +72,7 @@
 
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
-        check_tested_thread_phase(tts, TT_PHASE_RUNNING);
+        tested_thread_wait_running(tts);
         tf_assert_same(jthread_get_state(tts->java_thread, &state), TM_ERROR_NONE);
         ref_state = 0x5;
         if(tts->my_index == 0){
@@ -98,7 +96,8 @@
         }
         //tf_assert_same(state, ref_state);
 
-        tts->stop = 1;
+        tested_thread_send_stop_request(tts);
+        tested_thread_wait_ended(tts);
         check_tested_thread_phase(tts, TT_PHASE_DEAD);
         tf_assert_same(jthread_get_state(tts->java_thread, &state), TM_ERROR_NONE);
         ref_state = 0x2;
@@ -116,16 +115,18 @@
 /*
  * Test jthread_get_state(...)
  */
-void JNICALL run_for_test_jthread_get_state_2(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void
*arg){
+void JNICALL run_for_test_jthread_get_state_2(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);
     if (status != TM_ERROR_NONE){
         tts->phase = TT_PHASE_ERROR;
+        tested_thread_ended(tts);
         return;
     }
     // Begin critical section
@@ -138,15 +139,12 @@
     status = jthread_monitor_exit(monitor);
     // Exit critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_RUNNING : TT_PHASE_ERROR);
-    while(1){
+    while(tested_thread_wait_for_stop_request_timed(tts, SLEEP_TIME) == TM_ERROR_TIMEOUT){
         hythread_safe_point();
-        tts->clicks++;
         hythread_yield();
-        if (tts->stop) {
-            break;
-        }
     }
     tts->phase = TT_PHASE_DEAD;
+    tested_thread_ended(tts);
 }
 
 int test_jthread_get_state_2(void) {
@@ -231,16 +229,18 @@
 /*
  * Test jthread_get_state(...)
  */
-void JNICALL run_for_test_jthread_get_state_3(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void
*arg){
+void JNICALL run_for_test_jthread_get_state_3(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);
     if (status != TM_ERROR_NONE){
         tts->phase = TT_PHASE_ERROR;
+        tested_thread_ended(tts);
         return;
     }
     // Begin critical section
@@ -248,11 +248,13 @@
     status = jthread_monitor_timed_wait(monitor, 1000000, 100);
     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_get_state_3(void) {
@@ -288,16 +290,18 @@
 /*
  * Test jthread_get_state(...)
  */
-void JNICALL run_for_test_jthread_get_state_4(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void
*arg){
+void JNICALL run_for_test_jthread_get_state_4(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);
     if (status != TM_ERROR_NONE){
         tts->phase = TT_PHASE_ERROR;
+        tested_thread_ended(tts);
         return;
     }
     // Begin critical section
@@ -305,11 +309,13 @@
     status = jthread_monitor_timed_wait(monitor, CLICK_TIME_MSEC, 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_get_state_4(void) {
@@ -342,14 +348,16 @@
 /*
  * Test jthread_get_state(...)
  */
-void JNICALL run_for_test_jthread_get_state_5(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void
*arg){
+void JNICALL run_for_test_jthread_get_state_5(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 = hythread_sleep(1000000);
     tts->phase = (status == TM_ERROR_INTERRUPT ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
 }
 
 int test_jthread_get_state_5(void) {
@@ -385,14 +393,16 @@
 /*
  * Test jthread_get_state(...)
  */
-void JNICALL run_for_test_jthread_get_state_6(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void
*arg){
+void JNICALL run_for_test_jthread_get_state_6(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 = hythread_sleep(CLICK_TIME_MSEC);
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+    tested_thread_ended(tts);
 }
 
 int test_jthread_get_state_6(void) {

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_timing.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_timing.c?view=diff&rev=467506&r1=467505&r2=467506
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_timing.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_timing.c Tue Oct 24
15:05:57 2006
@@ -64,23 +64,18 @@
     return helper_hythread_cpu_timing();
 }
 
-void JNICALL run_for_helper_hythread_cpu_timing(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void
*arg){
+void JNICALL run_for_helper_hythread_cpu_timing(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void
*args){
 
-    tested_thread_sturct_t * tts = current_thread_tts;
-    int i;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     int num = 0;
     
     tts->phase = TT_PHASE_RUNNING;
-    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;
     }
     tts->phase = TT_PHASE_DEAD;
+    tested_thread_ended(tts);
 }
 
 int helper_hythread_cpu_timing(void) {
@@ -100,7 +95,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);
 
         tf_assert_same(jthread_get_thread_cpu_time(tts->java_thread, &cpu_time), TM_ERROR_NONE);
@@ -110,6 +106,7 @@
         tf_assert_same(jthread_get_thread_cpu_timer_info(&timer_info), TM_ERROR_NONE);
         
         tf_assert(user_cpu_time > 0);
+        /*
         printf("=================================================== %08x\n", cpu_time);
         printf("cpu_time = %i \n", cpu_time);
         printf("user_cpu_time = %i \n", user_cpu_time);
@@ -122,6 +119,7 @@
         printf("may_skip_forward = %i \n", timer_info.may_skip_forward);
         printf("may_skip_backward = %i \n", timer_info.may_skip_backward);
         printf("kind = %i \n", timer_info.kind);
+        */
     }
 
     // Terminate all threads and clear tts structures

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c?view=diff&rev=467506&r1=467505&r2=467506
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c
(original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c
Tue Oct 24 15:05:57 2006
@@ -23,6 +23,7 @@
 #include <open/hythread.h>
 #include <open/hythread_ext.h>
 #include <open/ti_thread.h>
+#include <open/thread_externals.h>
 #include "apr_time.h"
 
 
@@ -30,10 +31,10 @@
  * Utilities for thread manager unit tests 
  */
 
-tested_thread_sturct_t * current_thread_tts;
 tested_thread_sturct_t dummy_tts_struct;
 tested_thread_sturct_t * dummy_tts = &dummy_tts_struct;
 tested_thread_sturct_t tested_threads[MAX_TESTED_THREAD_NUMBER];
+JavaVM * GLOBAL_VM = NULL;
 
 apr_pool_t *pool = NULL;
 
@@ -41,7 +42,7 @@
     apr_sleep(CLICK_TIME_MSEC * 1000);
 }
 
-jthread new_jthread_jobject(JNIEnv * jni_env) {
+jthread new_jobject_thread(JNIEnv * jni_env) {
     const char * name = "<init>";
     const char * sig = "()V";
     jmethodID constructor = NULL;
@@ -52,6 +53,17 @@
     return (*jni_env)->NewObject(jni_env, thread_class, constructor);
 }
 
+jobject new_jobject_thread_death(JNIEnv * jni_env) {
+    const char * name = "<init>";
+    const char * sig = "()V";
+    jmethodID constructor = NULL;
+    jclass thread_death_class;
+    
+    thread_death_class = (*jni_env)->FindClass(jni_env, "java/lang/ThreadDeath");
+    constructor = (*jni_env)->GetMethodID(jni_env, thread_death_class, name, sig);
+    return (*jni_env)->NewObject(jni_env, thread_death_class, constructor);
+}
+
 jthread new_jobject(){
 
     apr_status_t status;
@@ -78,7 +90,6 @@
 
 void test_java_thread_setup(int argc, char *argv[]) {
     JavaVMInitArgs args;
-    JavaVM * java_vm;
     JNIEnv * jni_env;
     int i;
 
@@ -93,8 +104,9 @@
 
     log_debug("test_java_thread_init()");
 
+    hythread_sleep(1000);
     apr_initialize();
-    JNI_CreateJavaVM(&java_vm, &jni_env, &args);
+    JNI_CreateJavaVM(&GLOBAL_VM, &jni_env, &args);
 }
 
 void test_java_thread_teardown(void) {
@@ -140,14 +152,15 @@
     for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
         tts = &tested_threads[i];
         tts->my_index = i;
-        //tf_assert_null(tts->java_thread);
-        tts->java_thread = new_jthread_jobject(jni_env);
-        //tf_assert_null(tts->jni_env);
+        tts->java_thread = new_jobject_thread(jni_env);
+        tts->native_thread = NULL;
         //tts->attrs.priority = 5;
         tts->jvmti_start_proc_arg = &tts->jvmti_start_proc_arg;
-        tts->clicks = 0;
+        hysem_create(&tts->started, 0, 1);
+        hysem_create(&tts->running, 0, 1);
+        hysem_create(&tts->stop_request, 0, 1);
+        hysem_create(&tts->ended, 0, 1);
         tts->phase = TT_PHASE_NONE;
-        tts->stop = 0;
         if (mode == TTS_INIT_DIFFERENT_MONITORS){
             monitor = new_jobject();
             status = jthread_monitor_init(monitor);
@@ -230,10 +243,9 @@
 
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
-        current_thread_tts = tts;
-        tf_assert_same_v(jthread_create_with_function(jni_env, tts->java_thread, &tts->attrs,
run_method_param, NULL), TM_ERROR_NONE);
-        check_tested_thread_phase(tts, TT_PHASE_ANY);
-        check_tested_thread_structures(tts);
+        tf_assert_same_v(jthread_create_with_function(jni_env, tts->java_thread, &tts->attrs,
run_method_param, tts), TM_ERROR_NONE);
+        tested_thread_wait_started(tts);
+        tts->native_thread = (hythread_t) vm_jthread_get_tm_data(tts->java_thread);
     }
 }
 
@@ -249,85 +261,88 @@
     tested_threads_run_common(run_method_param);
 }
 
-void tested_threads_run_with_jvmti_start_proc(jvmtiStartFunction jvmti_start_proc){
+void tested_os_threads_run(hythread_entrypoint_t run_method_param){
+
     tested_thread_sturct_t *tts;
-    JNIEnv * jni_env;
+    IDATA status;
 
-    jni_env = jthread_get_JNI_env(jthread_self());
-    
     tested_threads_init(TTS_INIT_COMMON_MONITOR);
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
-        current_thread_tts = tts;
-        tf_assert_same_v(jthread_create_with_function(jni_env, tts->java_thread, &tts->attrs,
-                                                      jvmti_start_proc, tts->jvmti_start_proc_arg),
TM_ERROR_NONE);
-        check_tested_thread_phase(tts, TT_PHASE_ANY);
+        // Create thread
+        status = hythread_create(&tts->native_thread,  // new thread OS handle 
+                                 0, 5, 0,
+                                 run_method_param, // start proc
+                                 tts); 
+        tf_assert_v(status == TM_ERROR_NONE);
+        tested_thread_wait_started(tts);
     }
 }
 
-void tested_os_threads_run(apr_thread_start_t run_method_param){
+void tested_thread_started(tested_thread_sturct_t * tts) {
+    hysem_set(tts->started, 1);
+}
+
+void tested_thread_ended(tested_thread_sturct_t * tts) {
+    hysem_set(tts->ended, 1);
+}
 
-    tested_thread_sturct_t *tts;
-    apr_thread_t *apr_thread;
-    apr_threadattr_t *apr_attrs = NULL;
-    apr_status_t status;
-    apr_pool_t *pool;
+void tested_thread_send_stop_request(tested_thread_sturct_t * tts) {
+    hysem_set(tts->stop_request, 1);    
+}
 
-    status = apr_pool_create(&pool, NULL);
-    tf_assert_v(status == APR_SUCCESS);
-    tested_threads_init(TTS_INIT_COMMON_MONITOR);
-    reset_tested_thread_iterator(&tts);
-    while(next_tested_thread(&tts)){
-        current_thread_tts = tts;
-        apr_thread = NULL;
-        // Create APR thread
-        status = apr_thread_create(
-                                   &apr_thread,      // new thread OS handle 
-                                   apr_attrs,
-                                   run_method_param, // start proc
-                                   NULL,             // start proc arg 
-                                   pool
-                                   ); 
-        tf_assert_v(status == APR_SUCCESS);
-        check_tested_thread_phase(tts, TT_PHASE_ANY);
-    }
+void tested_thread_wait_for_stop_request(tested_thread_sturct_t * tts) {
+    IDATA status;
+    do {
+        hysem_set(tts->running, 1);
+        status = hysem_wait_timed(tts->stop_request, SLEEP_TIME, 0);
+    } while (status == TM_ERROR_TIMEOUT);
+}
+
+IDATA tested_thread_wait_for_stop_request_timed(tested_thread_sturct_t * tts, I_64 sleep_time)
{
+    hysem_set(tts->running, 1);
+    return hysem_wait_timed(tts->stop_request, sleep_time, 0);
 }
 
-int tested_threads_stop(){
+int tested_threads_stop() {
 
     tested_thread_sturct_t *tts;
     
     reset_tested_thread_iterator(&tts);
-    while(next_tested_thread(&tts)){
-        if (check_tested_thread_phase(tts, TT_PHASE_DEAD) != TEST_PASSED){
-            tts->stop = 1;
-            check_tested_thread_phase(tts, TT_PHASE_DEAD);
-            //Sleep(1000);
-        }
+    while (next_tested_thread(&tts)) {
+        tested_thread_send_stop_request(tts);
+    }
+    while (next_tested_thread(&tts)) {
+        tested_thread_wait_ended(tts);
     }
     return TEST_PASSED;
 }
 
-int tested_threads_destroy(){
+int tested_threads_destroy() {
 
     tested_thread_sturct_t *tts;
     
     reset_tested_thread_iterator(&tts);
-    while(next_tested_thread(&tts)){
-        tts->stop = 1;
-        check_tested_thread_phase(tts, TT_PHASE_DEAD);
+    while (next_tested_thread(&tts)) {
+        tested_thread_send_stop_request(tts);
+    }
+    reset_tested_thread_iterator(&tts);
+    while (next_tested_thread(&tts)) {
+        tested_thread_wait_dead(tts);
     }
+
     return TEST_PASSED;
 }
 
-int check_tested_thread_structures(tested_thread_sturct_t *tts){
+
+int check_structure(tested_thread_sturct_t *tts){
 
     jthread java_thread = tts->java_thread;
     jvmti_thread_t jvmti_thread;
     hythread_t hythread;
 
-    hythread = vm_jthread_get_tm_data(java_thread);
-    tf_assert(hythread);
+    hythread = (hythread_t) vm_jthread_get_tm_data(java_thread);
+    tf_assert_same(hythread, tts->native_thread);
     jvmti_thread = hythread_get_private_data(hythread);
     tf_assert(jvmti_thread);
     /*
@@ -339,41 +354,65 @@
     //if(jvmti_thread->stop_exception != stop_exception){
     //      return TEST_FAILED; ????????????????????????????????????????????
     //}
-
     return TEST_PASSED;
 }
 
-int check_tested_thread_phase(tested_thread_sturct_t *tts, int phase){
+int check_phase(tested_thread_sturct_t *tts, int phase) {
+    
+    tf_assert(tts->phase != TT_PHASE_ERROR);
+    if (phase == TT_PHASE_ANY) {
+        tf_assert(tts->phase != TT_PHASE_NONE);
+    } else {
+        tf_assert_same(tts->phase, phase);
+    }
+    return TEST_PASSED;
+}
 
+void tested_thread_wait_started(tested_thread_sturct_t *tts) {
     int i;
-    for (i = 0; i < MAX_CLICKS_TO_WAIT; i++){
-        sleep_a_click(); // must be here to give tested thread to change phase
-
-        tf_assert(tts->phase != TT_PHASE_ERROR);
-        if (phase == tts->phase){
-            return 0;
-        } 
-        if (phase == TT_PHASE_ANY && tts->phase != TT_PHASE_NONE){
-            return 0;
-        }
+     
+    i = 0;
+    while (hysem_wait_timed(tts->started, MAX_TIME_TO_WAIT, 0) == TM_ERROR_TIMEOUT) {
+        i++;
+        printf("Thread %i hasn't started for %i milliseconds", 
+            tts->my_index, (i * MAX_TIME_TO_WAIT));
     }
 
-    //    tf_assert_same(phase, tts->phase);
-    return 0;
+    hysem_post(tts->started);
 }
 
-int tested_thread_is_running(tested_thread_sturct_t *tts){
+void tested_thread_wait_running(tested_thread_sturct_t *tts) {
+    int i;
+     
+    i = 0;
+    while (hysem_wait_timed(tts->running, MAX_TIME_TO_WAIT, 0) == TM_ERROR_TIMEOUT) {
+        i++;
+        printf("Thread %i isn't running after %i milliseconds", 
+            tts->my_index, (i * MAX_TIME_TO_WAIT));
+    }    
+}
 
-    int clicks = tts->clicks;
+void tested_thread_wait_ended(tested_thread_sturct_t *tts) {
     int i;
+     
+    i = 0;
+    while (hysem_wait_timed(tts->ended, MAX_TIME_TO_WAIT, 0) == TM_ERROR_TIMEOUT) {
+        i++;
+        printf("Thread %i hasn't ended for %i milliseconds", 
+            tts->my_index, (i * MAX_TIME_TO_WAIT));
+    }
+    hysem_post(tts->ended);
+}
 
-    for (i = 0; i < MAX_CLICKS_TO_WAIT; i++){
-        sleep_a_click();
-        if (clicks != tts->clicks){
-            return 1;
-        }
+void tested_thread_wait_dead(tested_thread_sturct_t *tts) {
+    int i;
+     
+    i = 0;
+    while (hythread_join_timed(tts->native_thread, MAX_TIME_TO_WAIT, 0) == TM_ERROR_TIMEOUT)
{
+        i++;
+        printf("Thread %i isn't dead after %i milliseconds", 
+            tts->my_index, (i * MAX_TIME_TO_WAIT));
     }
-    return 0;
 }
 
 int compare_threads(jthread *threads, int thread_nmb, int compare_from_end) {
@@ -433,16 +472,12 @@
 
 void JNICALL default_run_for_test(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg) {
 
-    tested_thread_sturct_t * tts = current_thread_tts;
+    tested_thread_sturct_t * tts = (tested_thread_sturct_t *)arg;
     
     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);
 }
 

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h?view=diff&rev=467506&r1=467505&r2=467506
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h
(original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h
Tue Oct 24 15:05:57 2006
@@ -44,10 +44,12 @@
 #define TTS_INIT_DIFFERENT_MONITORS 1
 
 #define MAX_TESTED_THREAD_NUMBER 5
-#define MAX_CLICKS_TO_WAIT 30
-#define CLICK_TIME_MSEC 10
+#define MAX_TIME_TO_WAIT 1000
 #define MAX_OWNED_MONITORS_NMB 2
-#define SLEEP_MSEC 10
+#define SLEEP_TIME 100
+#define CLICK_TIME_MSEC 10
+
+extern JavaVM * GLOBAL_VM;
 
 typedef struct _jjobject{
     void *data;
@@ -63,20 +65,20 @@
 typedef struct {
     int my_index;
     jthread java_thread;
+    hythread_t native_thread;
     jobject monitor;
     jrawMonitorID raw_monitor;
     void * jvmti_start_proc_arg;
-    int clicks;
+    hysem_t started;
+    hysem_t running;
+    hysem_t stop_request;
+    hysem_t ended;
     int phase;
-    int stop;
     jint peak_count;
     jthread_threadattr_t attrs;
     jclass excn;
-}tested_thread_sturct_t;
+} tested_thread_sturct_t;
 
-extern tested_thread_sturct_t *current_thread_tts;
-extern tested_thread_sturct_t *dummy_tts;
-void jni_init();
 void sleep_a_click(void);
 void test_java_thread_setup(int argc, char *argv[]);
 void test_java_thread_teardown(void);
@@ -85,20 +87,38 @@
 void tested_threads_run_common(jvmtiStartFunction run_method_param);
 void tested_threads_run_with_different_monitors(jvmtiStartFunction run_method_param);
 void tested_threads_run_with_jvmti_start_proc(jvmtiStartFunction jvmti_start_proc);
-void tested_os_threads_run(apr_thread_start_t run_method_param);
+void tested_os_threads_run(hythread_entrypoint_t run_method_param);
+
 int tested_threads_destroy();
 int tested_threads_stop();
+
 tested_thread_sturct_t *get_tts(int tts_index);
 int next_tested_thread(tested_thread_sturct_t **tts);
 int prev_tested_thread(tested_thread_sturct_t **tts);
 void reset_tested_thread_iterator(tested_thread_sturct_t ** tts);
-int check_tested_thread_structures(tested_thread_sturct_t *tts);
-int check_tested_thread_phase(tested_thread_sturct_t *tts, int phase);
-int tested_thread_is_running(tested_thread_sturct_t *tts);
+
+#define check_tested_thread_phase(tts, phase) if (check_phase(tts, phase) != TEST_PASSED)
return TEST_FAILED;
+#define check_tested_thread_structures(tts) if (check_structure(tts) != TEST_PASSED) return
TEST_FAILED;
+int check_structure(tested_thread_sturct_t *tts);
+int check_phase(tested_thread_sturct_t *tts, int phase);
+
+void tested_thread_started(tested_thread_sturct_t * tts);
+void tested_thread_ended(tested_thread_sturct_t * tts);
+void tested_thread_send_stop_request(tested_thread_sturct_t * tts);
+void tested_thread_wait_for_stop_request(tested_thread_sturct_t * tts);
+IDATA tested_thread_wait_for_stop_request_timed(tested_thread_sturct_t * tts, I_64 sleep_time);
+
+void tested_thread_wait_started(tested_thread_sturct_t *tts);
+void tested_thread_wait_running(tested_thread_sturct_t *tts);
+void tested_thread_wait_ended(tested_thread_sturct_t *tts);
+void tested_thread_wait_dead(tested_thread_sturct_t *tts);
+
 int compare_threads(jthread *threads, int thread_nmb, int compare_from_end);
 int compare_pointer_sets(void ** set_a, void ** set_b, int nmb);
 int check_exception(jobject excn);
-jobject new_jobject();
-void delete_jobject(jobject obj);
 void set_phase(tested_thread_sturct_t *tts, int phase);
 void JNICALL default_run_for_test(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *arg);
+jthread new_jobject_thread(JNIEnv * jni_env);
+jobject new_jobject_thread_death(JNIEnv * jni_env);
+jthread new_jobject();
+void delete_jobject(jobject obj);



Mime
View raw message