You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by gs...@apache.org on 2008/01/15 16:47:21 UTC

svn commit: r612140 [2/2] - in /harmony/enhanced/drlvm/trunk/vm/tests/unit/thread: test_java_monitors.c test_java_park.c test_ti_instrum.c test_ti_peak_count.c test_ti_raw_monitors.c test_ti_state.c test_ti_timing.c utils/thread_unit_test_utils.c

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_state.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_state.c?rev=612140&r1=612139&r2=612140&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_state.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_state.c Tue Jan 15 07:47:20 2008
@@ -24,15 +24,15 @@
 #include <open/ti_thread.h>
 
 /*
- * Test jthread_get_jvmti_state(...)
+ * Test test_jthread_get_jvmti_state_1
  *
- *  called function          tested state
+ *  called function                     tested state
  *
- *                           Not Alive, New (state == 0)
- *  hythread_create()             ALIVE | RUNNABLE
- *  jthread_interrupt()          ALIVE | RUNNABLE | INTERRUPTED
- *  jthread_clear_interrupted()  ALIVE | RUNNABLE
- *                           DEAD
+ *  tested_threads_init()               NEW   (state == 0)
+ *  hythread_create()                   ALIVE | RUNNABLE
+ *  jthread_interrupt()                 ALIVE | RUNNABLE | INTERRUPTED
+ *  jthread_clear_interrupted()         ALIVE | RUNNABLE
+ *  tested_thread_send_stop_request()   TERMINATED
  */
 void JNICALL run_for_test_jthread_get_jvmti_state_1(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
@@ -41,18 +41,18 @@
     tts->phase = TT_PHASE_RUNNING;
     tested_thread_started(tts);
     while(tested_thread_wait_for_stop_request_timed(tts, SLEEP_TIME) == TM_ERROR_TIMEOUT){
-        hythread_safe_point();
         hythread_yield();
     }
     tts->phase = TT_PHASE_DEAD;
     tested_thread_ended(tts);
-}
+} // run_for_test_jthread_get_jvmti_state_1
 
 int test_jthread_get_jvmti_state_1(void) {
 
     tested_thread_sturct_t *tts;
     int state;
     int ref_state;
+    int count;
 
     // Initialize tts structures and run all tested threads
     tested_threads_init(TTS_INIT_COMMON_MONITOR);
@@ -60,10 +60,8 @@
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
         tf_assert_same(jthread_get_jvmti_state(tts->java_thread, &state), TM_ERROR_NONE);
-        ref_state = 0;
-        if(tts->my_index == 0){
-            printf("state = %08x (%08x)\n", state, ref_state);
-        }
+        ref_state = 0;   // it's a new thread
+        log_info("thread %d state = %08x (%08x) - NEW", tts->my_index, state, ref_state);
         tf_assert_same(state, ref_state);
     }
 
@@ -74,46 +72,53 @@
     while(next_tested_thread(&tts)){
         tested_thread_wait_running(tts);
         tf_assert_same(jthread_get_jvmti_state(tts->java_thread, &state), TM_ERROR_NONE);
-        ref_state = 0x5;
-        if(tts->my_index == 0){
-            printf("state = %08x (%08x)\n", state, ref_state);
-        }
-        //tf_assert_same(state, ref_state);
+        ref_state = JVMTI_THREAD_STATE_RUNNABLE | JVMTI_THREAD_STATE_ALIVE;
+        log_info("thread %d state = %08x (%08x) - ALIVE|RUNNABLE", tts->my_index, state, ref_state);
+        tf_assert((state & ref_state) != 0 && "thread is not RUNNABLE or ALIVE");
 
         tf_assert_same(jthread_interrupt(tts->java_thread), TM_ERROR_NONE);
         tf_assert_same(jthread_get_jvmti_state(tts->java_thread, &state), TM_ERROR_NONE);
-        ref_state = 0x200005;
-        if(tts->my_index == 0){
-            printf("state = %08x (%08x)\n", state, ref_state);
-        }
-        //tf_assert_same(state, ref_state);
+        ref_state |= JVMTI_THREAD_STATE_INTERRUPTED;
+        log_info("thread %d state = %08x (%08x) - ALIVE|RUNNABLE|INTERRUPTED", tts->my_index, state, ref_state);
+        tf_assert_same(state, ref_state);
 
         tf_assert_same(jthread_clear_interrupted(tts->java_thread), TM_ERROR_INTERRUPT);
         tf_assert_same(jthread_get_jvmti_state(tts->java_thread, &state), TM_ERROR_NONE);
-        ref_state = 0x5;
-        if(tts->my_index == 0){
-            printf("state = %08x (%08x)\n", state, ref_state);
-        }
-        //tf_assert_same(state, ref_state);
+        ref_state &= ~JVMTI_THREAD_STATE_INTERRUPTED;
+        log_info("thread %d state = %08x (%08x) - ALIVE|RUNNABLE", tts->my_index, state, ref_state);
+        tf_assert((state & ref_state) != 0 && "thread is not RUNNABLE or ALIVE");
 
         tested_thread_send_stop_request(tts);
         tested_thread_wait_ended(tts);
         check_tested_thread_phase(tts, TT_PHASE_DEAD);
-        tf_assert_same(jthread_get_jvmti_state(tts->java_thread, &state), TM_ERROR_NONE);
-        ref_state = 0x2;
-        if(tts->my_index == 0){
-            printf("state = %08x (%08x)\n", state, ref_state);
+        count = 0;
+        while (hythread_is_alive(tts->native_thread)) {
+            // waiting when the thread goes to terminate state
+            hythread_sleep(SLEEP_TIME);
+            if (tts->phase == TT_PHASE_ERROR || ++count > (MAX_TIME_TO_WAIT/SLEEP_TIME)) {
+                tf_fail("thread failed to change state on TERMINATED");
+            }
         }
-        //tf_assert_same(state, ref_state);
+        tf_assert_same(jthread_get_jvmti_state(tts->java_thread, &state), TM_ERROR_NONE);
+        ref_state = JVMTI_THREAD_STATE_TERMINATED;
+        log_info("thread %d state = %08x (%08x) - TERMINATED", tts->my_index, state, ref_state);
+        tf_assert_same(state, ref_state);
     }
 
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
 
     return TEST_PASSED;
-}
-/*
- * Test jthread_get_jvmti_state(...)
+} // test_jthread_get_jvmti_state_1
+
+/**
+ * Test test_jthread_get_jvmti_state_2
+ *
+ *  called function                     tested state
+ *
+ *  jthread_monitor_enter()             ALIVE | BLOCKED
+ *  jthread_monitor_wait()              ALIVE | WAITING | OBJECT_WAIT | INDEFINITELY
+ *  jthread_monitor_notify_all()        ALIVE | RUNNABLE
  */
 void JNICALL run_for_test_jthread_get_jvmti_state_2(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
@@ -125,6 +130,7 @@
     tested_thread_started(tts);
     status = jthread_monitor_enter(monitor);
     if (status != TM_ERROR_NONE){
+        log_info("Test status is %d, but expected %d", status, TM_ERROR_NONE);
         tts->phase = TT_PHASE_ERROR;
         tested_thread_ended(tts);
         return;
@@ -133,36 +139,39 @@
     tts->phase = TT_PHASE_WAITING_ON_WAIT;
     status = jthread_monitor_wait(monitor);
     if (status != TM_ERROR_NONE){
+        log_info("Test status is %d, but expected %d", status, TM_ERROR_NONE);
         tts->phase = TT_PHASE_ERROR;
+        jthread_monitor_exit(monitor);
         return;
     }
-    status = jthread_monitor_exit(monitor);
+    tts->phase = TT_PHASE_RUNNING;
     // Exit critical section
-    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_RUNNING : TT_PHASE_ERROR);
+    status = jthread_monitor_exit(monitor);
+    if (status != TM_ERROR_NONE) {
+        log_info("Test status is %d, but expected %d", status, TM_ERROR_NONE);
+        tts->phase = TT_PHASE_ERROR;
+    }
     while(tested_thread_wait_for_stop_request_timed(tts, SLEEP_TIME) == TM_ERROR_TIMEOUT){
-        hythread_safe_point();
         hythread_yield();
     }
     tts->phase = TT_PHASE_DEAD;
     tested_thread_ended(tts);
-}
-
-int test_jthread_get_jvmti_state_2(void) {
+} // run_for_test_jthread_get_jvmti_state_2
 
+int test_jthread_get_jvmti_state_2(void)
+{
     tested_thread_sturct_t *tts;
     jobject monitor;
-    IDATA status;
     int state;
     int ref_state;
+    int count;
 
     // Initialize tts structures and run all tested threads
     tested_threads_init(TTS_INIT_COMMON_MONITOR);
 
     // Lock monitor
-    reset_tested_thread_iterator(&tts);
-    next_tested_thread(&tts);
-    monitor = tts->monitor;
-    status = jthread_monitor_enter(monitor);
+    monitor = get_tts(0)->monitor;
+    tf_assert_same(jthread_monitor_enter(monitor), TM_ERROR_NONE);
 
     // Run all tested threads
     tested_threads_run_common(run_for_test_jthread_get_jvmti_state_2);
@@ -170,64 +179,80 @@
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
         check_tested_thread_phase(tts, TT_PHASE_WAITING_ON_MONITOR);
-        tf_assert_same(jthread_get_jvmti_state(tts->java_thread, &state), TM_ERROR_NONE);
-        ref_state = 0x401;
-        if(tts->my_index == 0){
-            printf("state = %08x (%08x)\n", state, ref_state);
+        count = 0;
+        while (!hythread_is_blocked_on_monitor_enter(tts->native_thread)) {
+            // wait until the state is changed
+            hythread_sleep(SLEEP_TIME);
+            if (tts->phase == TT_PHASE_ERROR || ++count > (MAX_TIME_TO_WAIT/SLEEP_TIME)) {
+                tf_fail("thread failed to change state on BLOCKED_ON_MONITOR_ENTER");
+            }
         }
-        //tf_assert_same(state, ref_state);
-    }
-    // Release monitor
-    status = jthread_monitor_exit(monitor);
-
-    reset_tested_thread_iterator(&tts);
-    while(next_tested_thread(&tts)){
-        check_tested_thread_phase(tts, TT_PHASE_WAITING_ON_WAIT);
         tf_assert_same(jthread_get_jvmti_state(tts->java_thread, &state), TM_ERROR_NONE);
-        ref_state = 0x191;
-        if(tts->my_index == 0){
-            printf("state = %08x (%08x)\n", state, ref_state);
-        }
-        //tf_assert_same(state, ref_state);
+        ref_state = JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
+        log_info("thread %d state = %08x (%08x) - ALIVE|BLOCKED", tts->my_index, state, ref_state);
+        tf_assert_same(state, ref_state);
     }
 
-    // Lock monitor
-    status = jthread_monitor_enter(monitor);
-    status = jthread_monitor_notify_all(monitor);
+    // Release monitor
+    tf_assert_same(jthread_monitor_exit(monitor), TM_ERROR_NONE);
 
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
+        count = 0;
+        while (!hythread_is_waiting(tts->native_thread)) {
+            // wait until the state is changed
+            hythread_sleep(SLEEP_TIME);
+            if (tts->phase == TT_PHASE_ERROR || ++count > (MAX_TIME_TO_WAIT/SLEEP_TIME)) {
+                tf_fail("thread failed to change state on WAITING");
+            }
+        }
         check_tested_thread_phase(tts, TT_PHASE_WAITING_ON_WAIT);
         tf_assert_same(jthread_get_jvmti_state(tts->java_thread, &state), TM_ERROR_NONE);
-        ref_state = 0x401;
-        if(tts->my_index == 0){
-            printf("state = %08x (%08x)\n", state, ref_state);
-        }
-        //tf_assert_same(state, ref_state);
+        ref_state = JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_WAITING_INDEFINITELY
+            | JVMTI_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_IN_OBJECT_WAIT;
+        log_info("thread %d state = %08x (%08x) - ALIVE|WAITING|OBJECT_WAIT|INDEFINITELY",
+            tts->my_index, state, ref_state);
+        tf_assert_same(state, ref_state);
     }
 
-    // Release monitor
-    status = jthread_monitor_exit(monitor);
+    // Notify tested threads
+    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);
 
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
+        count = 0;
+        while (!hythread_is_runnable(tts->native_thread)) {
+            // wait until the state is changed
+            hythread_sleep(SLEEP_TIME);
+            if (tts->phase == TT_PHASE_ERROR || ++count > (MAX_TIME_TO_WAIT/SLEEP_TIME)) {
+                tf_fail("thread failed to change state on RUNNABLE");
+            }
+        }
+        tf_assert_same(jthread_monitor_enter(monitor), TM_ERROR_NONE);
+        tf_assert_same(jthread_monitor_exit(monitor), TM_ERROR_NONE);
         check_tested_thread_phase(tts, TT_PHASE_RUNNING);
         tf_assert_same(jthread_get_jvmti_state(tts->java_thread, &state), TM_ERROR_NONE);
-        ref_state = 0x5;
-        if(tts->my_index == 0){
-            printf("state = %08x (%08x)\n", state, ref_state);
-        }
-        //tf_assert_same(state, ref_state);
+        ref_state = JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_RUNNABLE;
+        log_info("thread %d state = %08x (%08x) - ALIVE|RUNNABLE",
+            tts->my_index, state, ref_state);
+        tf_assert_same(state, ref_state);
     }
 
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
 
     return TEST_PASSED;
-}
+} // test_jthread_get_jvmti_state_2
 
 /*
- * Test jthread_get_jvmti_state(...)
+ * Test test_jthread_get_jvmti_state_3
+ *
+ *  called function                     tested state
+ *
+ *  jthread_monitor_wait(m, n)          ALIVE | WAITING | OBJECT_WAIT | WITH_TIMEOUT
+ *  tested_thread_ended()               TERMINATED
  */
 void JNICALL run_for_test_jthread_get_jvmti_state_3(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
@@ -237,58 +262,103 @@
 
     tts->phase = TT_PHASE_WAITING_ON_MONITOR;
     tested_thread_started(tts);
+
+    // Begin critical section
     status = jthread_monitor_enter(monitor);
     if (status != TM_ERROR_NONE){
+        log_info("Test status is %d, but expected %d", status, TM_ERROR_NONE);
         tts->phase = TT_PHASE_ERROR;
         tested_thread_ended(tts);
         return;
     }
-    // Begin critical section
     tts->phase = TT_PHASE_WAITING_ON_WAIT;
-    status = jthread_monitor_timed_wait(monitor, 1000000, 100);
-    if (status != TM_ERROR_INTERRUPT){
+    status = jthread_monitor_timed_wait(monitor, MAX_TIME_TO_WAIT, 0);
+    if (status != TM_ERROR_NONE) {
+        log_info("Test status is %d, but expected %d", status, TM_ERROR_NONE);
         tts->phase = TT_PHASE_ERROR;
+        jthread_monitor_exit(monitor);
         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);
+    status = jthread_monitor_exit(monitor);
+    if (status != TM_ERROR_NONE) {
+        log_info("Test status is %d, but expected %d", status, TM_ERROR_NONE);
+        tts->phase = TT_PHASE_ERROR;
+    } else {
+        tts->phase = TT_PHASE_DEAD;
+    }
     tested_thread_ended(tts);
-}
+} // run_for_test_jthread_get_jvmti_state_3
 
 int test_jthread_get_jvmti_state_3(void) {
 
     tested_thread_sturct_t *tts;
     int state;
     int ref_state;
+    int count;
+    jobject monitor;
 
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_get_jvmti_state_3);
 
+    monitor = get_tts(0)->monitor;
+
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
+        count = 0;
+        while (!hythread_is_waiting(tts->native_thread)) {
+            // wait until the state is changed
+            hythread_sleep(SLEEP_TIME);
+            if (tts->phase == TT_PHASE_ERROR || ++count > (MAX_TIME_TO_WAIT/SLEEP_TIME)) {
+                tf_fail("thread failed to change state on WAITING");
+            }
+        }
         check_tested_thread_phase(tts, TT_PHASE_WAITING_ON_WAIT);
         tf_assert_same(jthread_get_jvmti_state(tts->java_thread, &state), TM_ERROR_NONE);
-        ref_state = 0x1a1;
-        printf("state = %08x (%08x)\n", state, ref_state);
-        //tf_assert_same(state, ref_state);
-        tf_assert_same(jthread_interrupt(tts->java_thread), TM_ERROR_NONE);
+        ref_state = JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT
+            | JVMTI_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_IN_OBJECT_WAIT;
+        log_info("thread %d state = %08x (%08x) - ALIVE|WAITING|OBJECT_WAIT|TIMEOUT",
+            tts->my_index, state, ref_state);
+        tf_assert_same(state, ref_state);
+    }
+
+    // Notify tested threads
+    log_info("Notify tested threads to end");
+    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);
+
+    ref_state = JVMTI_THREAD_STATE_TERMINATED;
+    reset_tested_thread_iterator(&tts);
+    while(next_tested_thread(&tts)){
+        while (hythread_is_alive(tts->native_thread)) {
+            // waiting when the thread goes to terminate state
+            hythread_sleep(SLEEP_TIME);
+            if (tts->phase == TT_PHASE_ERROR || ++count > (MAX_TIME_TO_WAIT/SLEEP_TIME)) {
+                log_info("Test thread phase: %d", tts->phase);
+                tf_fail("thread failed to change state on TERMINATED");
+            }
+        }
         check_tested_thread_phase(tts, TT_PHASE_DEAD);
         tf_assert_same(jthread_get_jvmti_state(tts->java_thread, &state), TM_ERROR_NONE);
-        ref_state = 0x2;
-        printf("state = %08x (%08x)\n", state, ref_state);
-        //tf_assert_same(state, ref_state);
+        log_info("thread %d state = %08x (%08x) - TERMINATED",
+            tts->my_index, state, ref_state);
+        tf_assert_same(state, ref_state);
     }
 
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
 
     return TEST_PASSED;
-}
+} // test_jthread_get_jvmti_state_3
 
-/*
- * Test jthread_get_jvmti_state(...)
+/**
+ * Test test_jthread_get_jvmti_state_4
+ *
+ * 1. Run threads
+ * 2. Wait 20 times more then 1 thread does
+ * 3. Expected TERMINATED state for all threads
  */
 void JNICALL run_for_test_jthread_get_jvmti_state_4(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
@@ -300,6 +370,7 @@
     tested_thread_started(tts);
     status = jthread_monitor_enter(monitor);
     if (status != TM_ERROR_NONE){
+        log_info("Test status is %d, but expected %d", status, TM_ERROR_NONE);
         tts->phase = TT_PHASE_ERROR;
         tested_thread_ended(tts);
         return;
@@ -308,21 +379,28 @@
     tts->phase = TT_PHASE_WAITING_ON_WAIT;
     status = jthread_monitor_timed_wait(monitor, CLICK_TIME_MSEC, 0);
     if (status != TM_ERROR_TIMEOUT){
+        log_info("Test status is %d, but expected %d", 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);
+    if (status != TM_ERROR_NONE) {
+        log_info("Test status is %d, but expected %d", status, TM_ERROR_NONE);
+        tts->phase = TT_PHASE_ERROR;
+    } else {
+        tts->phase = TT_PHASE_DEAD;
+    }
     tested_thread_ended(tts);
-}
-
-int test_jthread_get_jvmti_state_4(void) {
+} // run_for_test_jthread_get_jvmti_state_4
 
+int test_jthread_get_jvmti_state_4(void)
+{
     tested_thread_sturct_t *tts;
     int state;
     int ref_state;
+    int count;
 
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_get_jvmti_state_4);
@@ -333,20 +411,39 @@
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
         check_tested_thread_phase(tts, TT_PHASE_DEAD);
+    }
+
+    ref_state = JVMTI_THREAD_STATE_TERMINATED;
+    reset_tested_thread_iterator(&tts);
+    while(next_tested_thread(&tts)){
+        count = 0;
+        while (hythread_is_alive(tts->native_thread)) {
+            // waiting when the thread goes to terminate state
+            hythread_sleep(SLEEP_TIME);
+            if (tts->phase == TT_PHASE_ERROR || ++count > (MAX_TIME_TO_WAIT/SLEEP_TIME)) {
+                log_info("Test thread phase: %d", tts->phase);
+                tf_fail("thread failed to change state on TERMINATED");
+            }
+        }
         tf_assert_same(jthread_get_jvmti_state(tts->java_thread, &state), TM_ERROR_NONE);
-        ref_state = 0x2;
-        printf("state = %08x (%08x)\n", state, ref_state);
-        //tf_assert_same(state, ref_state);
+        log_info("thread %d state = %08x (%08x) - TERMINATED",
+            tts->my_index, state, ref_state);
+        tf_assert_same(state, ref_state);
     }
 
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
 
     return TEST_PASSED;
-}
+} // test_jthread_get_jvmti_state_4
 
-/*
- * Test jthread_get_jvmti_state(...)
+/**
+ * Test test_jthread_get_jvmti_state_5
+ *
+ * 1. Run threads
+ * 2. Check sleeping state
+ * 3. Interrupt sleep
+ * 4. Check TERMINATE state
  */
 void JNICALL run_for_test_jthread_get_jvmti_state_5(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
@@ -355,43 +452,76 @@
 
     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);
+    status = jthread_sleep(MAX_TIME_TO_WAIT, 0);
+    if (status != TM_ERROR_INTERRUPT) {
+        log_info("Test status is %d, but expected %d", status, TM_ERROR_INTERRUPT);
+        tts->phase = TT_PHASE_ERROR;
+    } else {
+        tts->phase = TT_PHASE_DEAD;
+    }
     tested_thread_ended(tts);
-}
-
-int test_jthread_get_jvmti_state_5(void) {
+} // run_for_test_jthread_get_jvmti_state_5
 
+int test_jthread_get_jvmti_state_5(void)
+{
     tested_thread_sturct_t *tts;
     int state;
     int ref_state;
+    int count;
 
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_get_jvmti_state_5);
 
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
+        count = 0;
+        while (!hythread_is_waiting(tts->native_thread)) {
+            // wait until the state is changed
+            hythread_sleep(SLEEP_TIME);
+            if (tts->phase == TT_PHASE_ERROR || ++count > (MAX_TIME_TO_WAIT/SLEEP_TIME)) {
+                tf_fail("thread failed to change state on WAITING");
+            }
+        }
         check_tested_thread_phase(tts, TT_PHASE_SLEEPING);
         tf_assert_same(jthread_get_jvmti_state(tts->java_thread, &state), TM_ERROR_NONE);
-        ref_state = 0;
-        printf("state = %08x (%08x)\n", state, ref_state);
-        //tf_assert_same(state, ref_state);
+        ref_state = JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT
+            | JVMTI_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_SLEEPING;
+        log_info("thread %d state = %08x (%08x) - ALIVE|WAITING|SLEEPING|TIMEOUT",
+            tts->my_index, state, ref_state);
+        tf_assert_same(state, ref_state);
         tf_assert_same(jthread_interrupt(tts->java_thread), TM_ERROR_NONE);
+    }
+
+    ref_state = JVMTI_THREAD_STATE_TERMINATED;
+    reset_tested_thread_iterator(&tts);
+    while(next_tested_thread(&tts)){
+        count = 0;
+        while (hythread_is_alive(tts->native_thread)) {
+            // waiting when the thread goes to terminate state
+            hythread_sleep(SLEEP_TIME);
+            if (tts->phase == TT_PHASE_ERROR || ++count > (MAX_TIME_TO_WAIT/SLEEP_TIME)) {
+                log_info("Test thread phase: %d", tts->phase);
+                tf_fail("thread failed to change state on TERMINATED");
+            }
+        }
         check_tested_thread_phase(tts, TT_PHASE_DEAD);
         tf_assert_same(jthread_get_jvmti_state(tts->java_thread, &state), TM_ERROR_NONE);
-        ref_state = 0;
-        printf("state = %08x (%08x)\n", state, ref_state);
-        //tf_assert_same(state, ref_state);
+        log_info("thread %d state = %08x (%08x) - TERMINATED",
+            tts->my_index, state, ref_state);
+        tf_assert_same(state, ref_state);
     }
-
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
 
     return TEST_PASSED;
-}
+} // test_jthread_get_jvmti_state_5
 
-/*
- * Test jthread_get_jvmti_state(...)
+/**
+ * Test test_jthread_get_jvmti_state_6
+ *
+ * 1. Run threads
+ * 2. Wait 20 times more then 1 thread does
+ * 3. Expected TERMINATED state for all threads
  */
 void JNICALL run_for_test_jthread_get_jvmti_state_6(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
@@ -401,15 +531,21 @@
     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);
+    if (status != TM_ERROR_NONE) {
+        log_info("Test status is %d, but expected %d", status, TM_ERROR_NONE);
+        tts->phase = TT_PHASE_ERROR;
+    } else {
+        tts->phase = TT_PHASE_DEAD;
+    }
     tested_thread_ended(tts);
-}
-
-int test_jthread_get_jvmti_state_6(void) {
+} // run_for_test_jthread_get_jvmti_state_6
 
-    tested_thread_sturct_t *tts;
+int test_jthread_get_jvmti_state_6(void)
+{
+    int count;
     int state;
     int ref_state;
+    tested_thread_sturct_t *tts;
 
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_get_jvmti_state_6);
@@ -417,26 +553,35 @@
     // Wait for all threads wait timeout
     jthread_sleep(20 * CLICK_TIME_MSEC * MAX_TESTED_THREAD_NUMBER, 0);
 
+    ref_state = JVMTI_THREAD_STATE_TERMINATED;
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
         check_tested_thread_phase(tts, TT_PHASE_DEAD);
+        count = 0;
+        while (hythread_is_alive(tts->native_thread)) {
+            // waiting when the thread goes to terminate state
+            hythread_sleep(SLEEP_TIME);
+            if (tts->phase == TT_PHASE_ERROR || ++count > (MAX_TIME_TO_WAIT/SLEEP_TIME)) {
+                tf_fail("thread failed to change state on TERMINATED");
+            }
+        }
         tf_assert_same(jthread_get_jvmti_state(tts->java_thread, &state), TM_ERROR_NONE);
-        ref_state = 0x2;
-        printf("state = %08x (%08x)\n", state, ref_state);
-        //tf_assert_same(state, ref_state);
+        log_info("thread %d state = %08x (%08x) - TERMINATED",
+            tts->my_index, state, ref_state);
+        tf_assert_same(state, ref_state);
     }
 
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
 
     return TEST_PASSED;
-}
+} // test_jthread_get_jvmti_state_6
 
 TEST_LIST_START
-    //TEST(test_jthread_get_jvmti_state_1)
-    //TEST(test_jthread_get_jvmti_state_2)
-    //TEST(test_jthread_get_jvmti_state_3)
-    //TEST(test_jthread_get_jvmti_state_4)
-    //TEST(test_jthread_get_jvmti_state_5)
+    TEST(test_jthread_get_jvmti_state_1)
+    TEST(test_jthread_get_jvmti_state_2)
+    TEST(test_jthread_get_jvmti_state_3)
+    TEST(test_jthread_get_jvmti_state_4)
+    TEST(test_jthread_get_jvmti_state_5)
     TEST(test_jthread_get_jvmti_state_6)
 TEST_LIST_END;

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_timing.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_timing.c?rev=612140&r1=612139&r2=612140&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_timing.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_timing.c Tue Jan 15 07:47:20 2008
@@ -23,115 +23,110 @@
 #include <open/hythread_ext.h>
 #include <open/ti_thread.h>
 
-int helper_hythread_cpu_timing(void);
-
-/*
- * CPU timing
- */
-
-int test_jthread_get_thread_cpu_time(void) {
-
-    log_info("NO IMPLEMENTTATION TO TEST");
-    return TEST_FAILED;
-    return helper_hythread_cpu_timing();
-}
-
-int test_jthread_get_thread_user_cpu_time(void) {
-
-    log_info("NO IMPLEMENTTATION TO TEST");
-    return TEST_FAILED;
-    return helper_hythread_cpu_timing();
-}
-
-int test_jthread_get_thread_blocked_time(void) {
-
-    log_info("NO IMPLEMENTTATION TO TEST");
-    return TEST_FAILED;
-    return helper_hythread_cpu_timing();
-}
-
-int test_jthread_get_thread_waited_time(void) {
-
-    log_info("NO IMPLEMENTTATION TO TEST");
-    return TEST_FAILED;
-    return helper_hythread_cpu_timing();
-}
-
-int test_jthread_get_thread_cpu_timer_info(void) {
-
-    log_info("NO IMPLEMENTTATION TO TEST");
-    return TEST_FAILED;
-    return helper_hythread_cpu_timing();
-}
-
-void JNICALL run_for_helper_hythread_cpu_timing(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
-
+void JNICALL run_for_helper_get_timing(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args)
+{
     tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     int num = 0;
-    
+    jobject monitor = tts->monitor;
+    IDATA status;
+
     tts->phase = TT_PHASE_RUNNING;
     tested_thread_started(tts);
-    while(tested_thread_wait_for_stop_request_timed(tts, SLEEP_TIME) == TM_ERROR_TIMEOUT) {
+    while(tested_thread_wait_for_stop_request_timed(tts, 1) == TM_ERROR_TIMEOUT) {
+        status = jthread_monitor_enter(monitor);
+        if (status != TM_ERROR_NONE){
+            tts->phase = TT_PHASE_ERROR;
+            tested_thread_ended(tts);
+            return;
+        }
+        status = jthread_monitor_timed_wait(monitor, 0, 100);
+        if (status != TM_ERROR_TIMEOUT) {
+            tts->phase = TT_PHASE_ERROR;
+            jthread_monitor_exit(monitor);
+            break;
+        }
+        status = jthread_monitor_exit(monitor);
+        if (status != TM_ERROR_NONE) {
+            tts->phase = TT_PHASE_ERROR;
+            break;
+        }
         ++num;
+        hythread_yield();
     }
+    log_info("Thread %d cycle times: %d", tts->my_index, num);
     tts->phase = TT_PHASE_DEAD;
     tested_thread_ended(tts);
-}
-
-int helper_hythread_cpu_timing(void) {
+} // run_for_helper_get_timing
 
+int test_jthread_get_timing(void)
+{
     tested_thread_sturct_t *tts;
     jlong cpu_time;
     jlong user_cpu_time;
     jlong blocked_time;
     jlong waited_time;
-    jvmtiTimerInfo timer_info;
-
-    log_info("NO IMPLEMENTATION TO TEST");
-    return TEST_FAILED;
 
     // Initialize tts structures and run all tested threads
-    tested_threads_run(run_for_helper_hythread_cpu_timing);
+    tested_threads_run(run_for_helper_get_timing);
+
+    hythread_sleep(MAX_TIME_TO_WAIT/20);
     
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
-        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);
         tf_assert_same(jthread_get_thread_user_cpu_time(tts->java_thread, &user_cpu_time), TM_ERROR_NONE);
         tf_assert_same(jthread_get_thread_blocked_time(tts->java_thread, &blocked_time), TM_ERROR_NONE);
         tf_assert_same(jthread_get_thread_waited_time(tts->java_thread, &waited_time), TM_ERROR_NONE);
-        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);
-        printf("blocked_time = %i \n", blocked_time);
-        printf("waited_time = %i \n", waited_time);
-        printf("cpu_time = %i \n", cpu_time);
-
-        printf("jvmtiTimerInfo :\n");
-        printf("max_value = %i \n", timer_info.max_value);
-        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);
-        */
+
+        log_info("Thread %d:", tts->my_index);
+        if (cpu_time/1000000) {
+            log_info("cpu_time = %.1f s", (float)cpu_time/1000000);
+        } else if(cpu_time/1000) {
+            log_info("cpu_time = %.1f ms", (float)cpu_time/1000);
+        } else {
+            log_info("cpu_time = %d ns", cpu_time);
+        }
+
+        if (user_cpu_time/1000000) {
+            log_info("user_cpu_time = %.1f s", (float)user_cpu_time/1000000);
+        } else if(user_cpu_time/1000) {
+            log_info("user_cpu_time = %.1f ms", (float)user_cpu_time/1000);
+        } else {
+            log_info("user_cpu_time = %d ns", user_cpu_time);
+        }
+
+        if (blocked_time/1000000) {
+            log_info("blocked_time = %.1f s", (float)blocked_time/1000000);
+        } else if (blocked_time/1000) {
+            log_info("blocked_time = %.1f ms", (float)blocked_time/1000);
+        } else {
+            log_info("blocked_time = %d ns", blocked_time);
+        }
+
+        if (waited_time/1000000) {
+            log_info("waited_time = %.1f s\n", (float)waited_time/1000000);
+        } else if (waited_time/1000) {
+            log_info("waited_time = %.1f ms\n", (float)waited_time/1000);
+        } else {
+            log_info("waited_time = %d ns\n", waited_time);
+        }
+    }
+
+    reset_tested_thread_iterator(&tts);
+    while(next_tested_thread(&tts)) {
+        tested_thread_send_stop_request(tts);
+        tested_thread_wait_ended(tts);
+        check_tested_thread_phase(tts, TT_PHASE_DEAD);
     }
 
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
 
     return TEST_PASSED;
-}
+} // test_jthread_get_timing
 
 TEST_LIST_START
-    //TEST(test_jthread_get_thread_cpu_time)
-    //TEST(test_jthread_get_thread_user_cpu_time)
-    //TEST(test_jthread_get_thread_waited_time)
-    //TEST(test_jthread_get_thread_blocked_time)
-    //TEST(test_jthread_get_thread_cpu_timer_info)
+    TEST(test_jthread_get_timing)
 TEST_LIST_END;

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c?rev=612140&r1=612139&r2=612140&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c Tue Jan 15 07:47:20 2008
@@ -350,7 +350,8 @@
     tf_assert(tts->phase != TT_PHASE_ERROR);
     if (phase == TT_PHASE_ANY) {
         tf_assert(tts->phase != TT_PHASE_NONE);
-    } else {
+    } else if (tts->phase != phase) {
+        log_info("Expected phase %d, but got %d", phase, tts->phase);
         tf_assert_same(tts->phase, phase);
     }
     return TEST_PASSED;
@@ -386,7 +387,7 @@
     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", 
+        log_info("Thread %i hasn't ended for %i milliseconds",
             tts->my_index, (i * MAX_TIME_TO_WAIT));
     }
     hysem_post(tts->ended);
@@ -403,7 +404,7 @@
         if(!hythread_is_alive(native_thread)) {
             break;
         }
-        if ((i % (MAX_TIME_TO_WAIT / SLEEP_TIME)) == 0) {
+        if (!i && (i % (MAX_TIME_TO_WAIT / SLEEP_TIME)) == 0) {
             printf("Thread %i isn't dead after %i milliseconds",
                 index, (++i * SLEEP_TIME));
         }