harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r612140 [1/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
Date Tue, 15 Jan 2008 15:47:21 GMT
Author: gshimansky
Date: Tue Jan 15 07:47:20 2008
New Revision: 612140

URL: http://svn.apache.org/viewvc?rev=612140&view=rev
Log:
Applied patch from HARMONY-5350
[drlvm][test] cunit test improvement


Modified:
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_monitors.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_park.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_instrum.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_peak_count.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_raw_monitors.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_state.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_timing.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_monitors.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_monitors.c?rev=612140&r1=612139&r2=612140&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_monitors.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_monitors.c Tue Jan 15 07:47:20 2008
@@ -21,71 +21,76 @@
 #include <open/jthread.h>
 #include <open/hythread_ext.h>
 
-hysem_t mon_enter;
+static hysem_t mon_enter;
 
-int helper_jthread_monitor_enter_exit(void);
-int helper_jthread_monitor_wait_notify(void);
- 
-int test_jthread_monitor_init (void){
-
-    return helper_jthread_monitor_enter_exit();
-} 
-
-int test_jthread_monitor_enter (void){
-
-    return helper_jthread_monitor_enter_exit();
-} 
+/**
+ * Monitor TODO:
+ *
+ * - Init monitor and not init
+ * - jthread_monitor_exit() without jthread_monitor_enter()
+ */
 
-/*
+/**
  * Test jthread_monitor_try_enter()
  */
-void JNICALL run_for_test_jthread_monitor_try_enter(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
-
+void JNICALL run_for_test_jthread_monitor_try_enter(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args)
+{
     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);
+    // Begin critical section
     status = jthread_monitor_try_enter(monitor);
     while (status == TM_ERROR_EBUSY){
         status = jthread_monitor_try_enter(monitor);
         sleep_a_click();
     }
-    // Begin critical section
-    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_IN_CRITICAL_SECTON : 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_IN_CRITICAL_SECTON;
+    }
     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);
+    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_monitor_try_enter(void) {
+} // run_for_test_jthread_monitor_try_enter
 
+int test_jthread_monitor_try_enter(void)
+{
     tested_thread_sturct_t *tts;
     tested_thread_sturct_t *critical_tts;
     int i;
     int waiting_on_monitor_nmb;
 
-    hysem_create(&mon_enter, 0, 1);
+    tf_assert_same(hysem_create(&mon_enter, 0, 1), TM_ERROR_NONE);
+
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_monitor_try_enter);
 
-    for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
-
+    for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++) {
         waiting_on_monitor_nmb = 0;
         critical_tts = NULL;
 
-        hysem_wait(mon_enter);
+        tf_assert_same(hysem_wait(mon_enter), TM_ERROR_NONE);
 
         reset_tested_thread_iterator(&tts);
-        while(next_tested_thread(&tts)){
-            if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
-                tf_assert(critical_tts == NULL); // error if two threads in critical section
+        while(next_tested_thread(&tts)) {
+            if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON) {
+                // error if two threads in critical section
+                tf_assert(critical_tts == NULL);
                 critical_tts = tts;
-            } else if (tts->phase == TT_PHASE_WAITING_ON_MONITOR){
+            } else if (tts->phase == TT_PHASE_WAITING_ON_MONITOR) {
                 waiting_on_monitor_nmb++;
             }
         }
@@ -93,37 +98,33 @@
         if (MAX_TESTED_THREAD_NUMBER - i != waiting_on_monitor_nmb + 1){
             tf_fail("Wrong number waiting on monitor threads");
         }
+        log_info("Thread %d grabbed monitor", critical_tts->my_index);
         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
     tested_threads_destroy();
 
-    return TEST_PASSED;
-}
-
-int test_jthread_monitor_exit (void){
-
-    return helper_jthread_monitor_enter_exit();
-} 
+    tf_assert_same(hysem_destroy(mon_enter), TM_ERROR_NONE);
 
-int test_jthread_monitor_notify (void){
-
-    return helper_jthread_monitor_wait_notify();
-} 
+    return TEST_PASSED;
+} // test_jthread_monitor_try_enter
 
-/*
- * Test jthread_monitor_notify_all(...)
+/**
+ * Test jthread_monitor_notify_all()
+ * Test jthread_monitor_notify()
  */
-void JNICALL run_for_test_jthread_monitor_notify_all(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
-
+void JNICALL run_for_test_jthread_monitor_notify(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args)
+{
     tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
 
     tts->phase = TT_PHASE_WAITING_ON_MONITOR;
     status = jthread_monitor_enter(monitor);
-    if (status != TM_ERROR_NONE){
+    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_started(tts);
         tested_thread_ended(tts);
@@ -133,43 +134,65 @@
     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);
+    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_IN_CRITICAL_SECTON;
+    }
     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);
+    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);
-}
-
-int test_jthread_monitor_notify_all(void) {
+} // run_for_test_jthread_monitor_notify
 
-    tested_thread_sturct_t *tts;
-    tested_thread_sturct_t *critical_tts;
-    jobject monitor;
+int test_jthread_monitor_notify_all(void)
+{
     int i;
+    int count;
     int waiting_on_wait_nmb;
+    jobject monitor;
+    tested_thread_sturct_t *tts;
+    tested_thread_sturct_t *critical_tts;
 
-    hysem_create(&mon_enter, 0, 1);
+    tf_assert_same(hysem_create(&mon_enter, 0, 1), TM_ERROR_NONE);
 
     // Initialize tts structures and run all tested threads
-    tested_threads_run(run_for_test_jthread_monitor_notify_all);
+    tested_threads_run(run_for_test_jthread_monitor_notify);
+
+    monitor = get_tts(0)->monitor;
 
     reset_tested_thread_iterator(&tts);
-    while(next_tested_thread(&tts)){
-        monitor = tts->monitor; // the same for all tts
-        check_tested_thread_phase(tts, TT_PHASE_WAITING_ON_WAIT);       
+    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);
+        log_info("Thread %d is waiting.", tts->my_index);
     }
+
+    log_info("Notify all 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);
 
-    for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
-
+    for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++) {
         waiting_on_wait_nmb = 0;
         critical_tts = NULL;
 
-        hysem_wait(mon_enter);
+        tf_assert_same(hysem_wait(mon_enter), TM_ERROR_NONE);
 
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
@@ -184,20 +207,97 @@
         if (MAX_TESTED_THREAD_NUMBER - i != waiting_on_wait_nmb + 1){
             tf_fail("Wrong number waiting on monitor threads");
         }
+        log_info("Thread %d was notified", critical_tts->my_index);
         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
     tested_threads_destroy();
 
+    tf_assert_same(hysem_destroy(mon_enter), TM_ERROR_NONE);
+
     return TEST_PASSED;
-}
+} // test_jthread_monitor_notify_all
 
-/*
+int test_jthread_monitor_notify(void)
+{
+    int i;
+    int count;
+    int waiting_on_wait_nmb;
+    jobject monitor;
+    tested_thread_sturct_t *tts;
+    tested_thread_sturct_t *critical_tts;
+
+    tf_assert_same(hysem_create(&mon_enter, 0, 1), TM_ERROR_NONE);
+
+    // Initialize tts structures and run all tested threads
+    tested_threads_run(run_for_test_jthread_monitor_notify);
+
+    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);
+        log_info("Thread %d is waiting.", tts->my_index);
+    }
+
+    for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
+        waiting_on_wait_nmb = 0;
+        critical_tts = NULL;
+
+        reset_tested_thread_iterator(&tts);
+        while(next_tested_thread(&tts)){
+            tf_assert(tts->phase != TT_PHASE_IN_CRITICAL_SECTON);
+        }
+
+        log_info("Notify monitor");
+        tf_assert_same(jthread_monitor_enter(monitor), TM_ERROR_NONE);
+        tf_assert_same(jthread_monitor_notify(monitor), TM_ERROR_NONE);
+        tf_assert_same(jthread_monitor_exit(monitor), TM_ERROR_NONE);
+
+        tf_assert_same(hysem_wait(mon_enter), TM_ERROR_NONE);
+
+        reset_tested_thread_iterator(&tts);
+        while(next_tested_thread(&tts)) {
+            if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON) {
+                // error if two threads in critical section
+                tf_assert(critical_tts == NULL);
+                critical_tts = tts;
+            } else if (tts->phase == TT_PHASE_WAITING_ON_WAIT) {
+                waiting_on_wait_nmb++;
+            }
+        }
+        tf_assert(critical_tts); // thread in critical section found
+        if (MAX_TESTED_THREAD_NUMBER - i != waiting_on_wait_nmb + 1){
+            tf_fail("Wrong number waiting on monitor threads");
+        }
+        log_info("Thread %d was notified", critical_tts->my_index);
+        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
+    tested_threads_destroy();
+
+    tf_assert_same(hysem_destroy(mon_enter), TM_ERROR_NONE);
+
+    return TEST_PASSED;
+} // test_jthread_monitor_notify
+
+/**
  * Test jthread_monitor_wait()
  */
-void JNICALL run_for_test_jthread_monitor_wait(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
-
+void JNICALL run_for_test_jthread_monitor_wait(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args)
+{
     tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
@@ -205,6 +305,7 @@
     tts->phase = TT_PHASE_WAITING_ON_MONITOR;
     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_started(tts);
         tested_thread_ended(tts);
@@ -214,26 +315,41 @@
     tested_thread_started(tts);
     status = jthread_monitor_wait(monitor);
     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_monitor_wait (void){
+} // run_for_test_jthread_monitor_wait
 
+int test_jthread_monitor_wait(void)
+{
+    int count;
     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);
 
+    monitor = get_tts(0)->monitor;
+
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
-        monitor = tts->monitor; // the same for all tts
-        check_tested_thread_phase(tts, TT_PHASE_WAITING_ON_WAIT);       
+        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);
+        log_info("Thread %d is waiting.", tts->my_index);
     }
+
+    log_info("Notify all 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);
@@ -247,20 +363,21 @@
     tested_threads_destroy();
 
     return TEST_PASSED;
-} 
+}  // test_jthread_monitor_wait
 
 /*
  * Test jthread_monitor_wait_interrupt()
  */
-void JNICALL run_for_test_jthread_monitor_wait_interrupt(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
-
+void JNICALL run_for_test_jthread_monitor_wait_interrupt(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args)
+{
     tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
 
     tts->phase = TT_PHASE_WAITING_ON_MONITOR;
     status = jthread_monitor_enter(monitor);
-    if (status != TM_ERROR_NONE){
+    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_started(tts);
         tested_thread_ended(tts);
@@ -270,40 +387,55 @@
     tested_thread_started(tts);
     status = jthread_monitor_wait(monitor);
     if (status != TM_ERROR_INTERRUPT) {
+        log_info("Test status is %d, but expected %d", status, TM_ERROR_INTERRUPT);
         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_monitor_wait_interrupt
 
-int test_jthread_monitor_wait_interrupt(void){
-
-    tested_thread_sturct_t *tts;
-    tested_thread_sturct_t *waiting_tts;
+int test_jthread_monitor_wait_interrupt(void)
+{
     int i;
+    int count;
     int waiting_on_wait_nmb;
-
-    hysem_create(&mon_enter, 0, 1);
+    tested_thread_sturct_t *tts;
+    tested_thread_sturct_t *waiting_tts;
 
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_monitor_wait_interrupt);
 
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
-        check_tested_thread_phase(tts, TT_PHASE_WAITING_ON_WAIT);       
+        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);
+        log_info("Thread %d is waiting.", tts->my_index);
     }
-    for (i = 0; i < MAX_TESTED_THREAD_NUMBER + 1; i++){
 
+    for (i = 0; i < MAX_TESTED_THREAD_NUMBER + 1; i++) {
         waiting_on_wait_nmb = 0;
         waiting_tts = NULL;
 
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
-            if (tts->phase == TT_PHASE_WAITING_ON_WAIT){
+            if (tts->phase == TT_PHASE_WAITING_ON_WAIT) {
                 waiting_tts = tts;
                 waiting_on_wait_nmb++;
             } else {
@@ -311,7 +443,8 @@
             }
         }
         tf_assert_same(MAX_TESTED_THREAD_NUMBER - i, waiting_on_wait_nmb);
-        if (waiting_tts){
+        if (waiting_tts) {
+            log_info("Interrupt thread %d", waiting_tts->my_index);
             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);
@@ -321,20 +454,21 @@
     tested_threads_destroy();
 
     return TEST_PASSED;
-} 
+} // test_jthread_monitor_wait_interrupt
 
 /*
  * Test jthread_monitor_timed_wait()
  */
-void JNICALL run_for_test_jthread_monitor_timed_wait(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
-
+void JNICALL run_for_test_jthread_monitor_timed_wait(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args)
+{
     tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
 
     tts->phase = TT_PHASE_WAITING_ON_MONITOR;
     status = jthread_monitor_enter(monitor);
-    if (status != TM_ERROR_NONE){
+    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_started(tts);
         tested_thread_ended(tts);
@@ -344,31 +478,49 @@
     tested_thread_started(tts);
     status = jthread_monitor_timed_wait(monitor, 10 * CLICK_TIME_MSEC * MAX_TESTED_THREAD_NUMBER, 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);
-}
-
-int test_jthread_monitor_timed_wait(void) {
+} // run_for_test_jthread_monitor_timed_wait
 
+int test_jthread_monitor_timed_wait(void)
+{
+    int count;
     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);
 
+    monitor = get_tts(0)->monitor;
+
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
-        monitor = tts->monitor; // the same for all tts
-        check_tested_thread_phase(tts, TT_PHASE_WAITING_ON_WAIT);       
+        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);
+        log_info("Thread %d is waiting.", tts->my_index);
     }
+
+    log_info("Notify all 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);
@@ -382,21 +534,21 @@
     tested_threads_destroy();
 
     return TEST_PASSED;
-} 
+} // test_jthread_monitor_timed_wait
 
 /*
  * Test jthread_monitor_timed_wait()
  */
-void JNICALL run_for_test_jthread_monitor_timed_wait_timeout(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
-
-
+void JNICALL run_for_test_jthread_monitor_timed_wait_timeout(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args)
+{
     tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
 
     tts->phase = TT_PHASE_WAITING_ON_MONITOR;
     status = jthread_monitor_enter(monitor);
-    if (status != TM_ERROR_NONE){
+    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_started(tts);
         tested_thread_ended(tts);
@@ -410,54 +562,69 @@
         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);
-}
-
-int test_jthread_monitor_timed_wait_timeout(void) {
+} // run_for_test_jthread_monitor_timed_wait_timeout
 
+int test_jthread_monitor_timed_wait_timeout(void)
+{
+    int count;
     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);
 
+    monitor = get_tts(0)->monitor;
+
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
-        monitor = tts->monitor; // the same for all tts
-        check_tested_thread_phase(tts, TT_PHASE_WAITING_ON_WAIT);       
+        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);
+        log_info("Thread %d is waiting.", tts->my_index);
     }
 
     // Wait for all threads wait timeout
-    jthread_sleep(20 * CLICK_TIME_MSEC * MAX_TESTED_THREAD_NUMBER, 0);
+    hythread_sleep(20 * CLICK_TIME_MSEC * MAX_TESTED_THREAD_NUMBER);
 
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
-        tested_thread_wait_dead(tts);
+        //tested_thread_wait_dead(tts);
         check_tested_thread_phase(tts, TT_PHASE_DEAD);
     }
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
 
     return TEST_PASSED;
-} 
+} // test_jthread_monitor_timed_wait_timeout
 
 /*
  * Test jthread_monitor_timed_wait()
  */
-void JNICALL run_for_test_jthread_monitor_timed_wait_interrupt(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
-
+void JNICALL run_for_test_jthread_monitor_timed_wait_interrupt(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args)
+{
     tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
 
     tts->phase = TT_PHASE_WAITING_ON_MONITOR;
     status = jthread_monitor_enter(monitor);
-    if (status != TM_ERROR_NONE){
+    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_started(tts);
         tested_thread_ended(tts);
@@ -466,109 +633,126 @@
     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){
+    if (status != TM_ERROR_INTERRUPT) {
+        log_info("Test status is %d, but expected %d", status, TM_ERROR_INTERRUPT);
         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);
-}
-
-int test_jthread_monitor_timed_wait_interrupt(void) {
+} // run_for_test_jthread_monitor_timed_wait_interrupt
 
-    tested_thread_sturct_t *tts;
-    tested_thread_sturct_t *waiting_tts;
+int test_jthread_monitor_timed_wait_interrupt(void)
+{
     int i;
+    int count;
     int waiting_on_wait_nmb;
-
-    hysem_create(&mon_enter, 0, 1);
+    tested_thread_sturct_t *tts;
+    tested_thread_sturct_t *waiting_tts;
 
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_monitor_timed_wait_interrupt);
 
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
-        check_tested_thread_phase(tts, TT_PHASE_WAITING_ON_WAIT);       
+        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);
+        log_info("Thread %d is waiting.", tts->my_index);
     }
-    for (i = 0; i < MAX_TESTED_THREAD_NUMBER + 1; i++){
 
+    for (i = 0; i < MAX_TESTED_THREAD_NUMBER + 1; i++) {
         waiting_on_wait_nmb = 0;
         waiting_tts = NULL;
 
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
-            if (tts->phase == TT_PHASE_WAITING_ON_WAIT){
+            if (tts->phase == TT_PHASE_WAITING_ON_WAIT) {
                 waiting_tts = tts;
                 waiting_on_wait_nmb++;
             } else {
-                check_tested_thread_phase(waiting_tts, TT_PHASE_DEAD);
+                check_tested_thread_phase(tts, TT_PHASE_DEAD);
             }
         }
         tf_assert_same(MAX_TESTED_THREAD_NUMBER - i, waiting_on_wait_nmb);
-        if (waiting_tts){
+        if (waiting_tts) {
+            log_info("Interrupt thread %d", waiting_tts->my_index);
             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);
         }
-        
     }
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
 
     return TEST_PASSED;
-} 
-
-/*
- * ------------------------ HELPERS -----------------------
- */
+} // test_jthread_monitor_timed_wait_interrupt
 
-/*
- * Test jthread_monitor_enter(...)
- * Test jthread_monitor_exit(...)
+/**
+ * Test jthread_monitor_enter()
+ * Test jthread_monitor_exit()
  */
-//?????????????????????????????? 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 *args){
-
+void JNICALL run_for_test_jthread_monitor_enter_exit(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args)
+{
+    IDATA status;
     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);
+    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;
+    } else {
+        tts->phase = TT_PHASE_IN_CRITICAL_SECTON;
+    }
     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);
+    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_monitor_enter_exit
 
-int helper_jthread_monitor_enter_exit(void) {
-
-    tested_thread_sturct_t *tts;
-    tested_thread_sturct_t *critical_tts;
+int test_jthread_monitor_enter_exit(void)
+{
     int i;
     int waiting_on_monitor_nmb;
+    tested_thread_sturct_t *tts;
+    tested_thread_sturct_t *critical_tts;
 
-    hysem_create(&mon_enter, 0, 1);
+    tf_assert_same(hysem_create(&mon_enter, 0, 1), TM_ERROR_NONE);
 
     // Initialize tts structures and run all tested threads
-    tested_threads_run(run_for_helper_jthread_monitor_enter_exit);
+    tested_threads_run(run_for_test_jthread_monitor_enter_exit);
 
-    for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
+    for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++) {
         waiting_on_monitor_nmb = 0;
         critical_tts = NULL;
 
-        hysem_wait(mon_enter);
+        tf_assert_same(hysem_wait(mon_enter), TM_ERROR_NONE);
 
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
@@ -583,6 +767,7 @@
         if (MAX_TESTED_THREAD_NUMBER - i != waiting_on_monitor_nmb + 1){
             tf_fail("Wrong number waiting on monitor threads");
         }
+        log_info("Thread %d grabbed the monitor", critical_tts->my_index);
         tested_thread_send_stop_request(critical_tts);
         tested_thread_wait_ended(critical_tts);
         check_tested_thread_phase(critical_tts, TT_PHASE_DEAD);
@@ -590,103 +775,19 @@
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
 
-    return TEST_PASSED;
-}
-
-/*
- * Test jthread_monitor_wait(...)
- * Test jthread_monitor_notify(...)
- */
-void JNICALL run_for_helper_jthread_monitor_wait_notify(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
-
-    tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
-    jobject monitor = tts->monitor;
-    IDATA status;
-
-    tts->phase = TT_PHASE_WAITING_ON_MONITOR;
-    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);
-    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) {
-
-    tested_thread_sturct_t *tts;
-    tested_thread_sturct_t *critical_tts;
-    jobject monitor;
-    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);
-
-    reset_tested_thread_iterator(&tts);
-    while(next_tested_thread(&tts)){
-        monitor = tts->monitor; // the same for all tts
-        check_tested_thread_phase(tts, TT_PHASE_WAITING_ON_WAIT);       
-    }
-
-    for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
-
-        waiting_on_wait_nmb = 0;
-        critical_tts = NULL;
-
-        reset_tested_thread_iterator(&tts);
-        while(next_tested_thread(&tts)){
-            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)){
-            if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
-                tf_assert(critical_tts == NULL); // error if two threads in critical section
-                critical_tts = tts;
-            } else if (tts->phase == TT_PHASE_WAITING_ON_WAIT){
-                waiting_on_wait_nmb++;
-            }
-        }
-        tf_assert(critical_tts); // thread in critical section found
-        if (MAX_TESTED_THREAD_NUMBER - i != waiting_on_wait_nmb + 1){
-            tf_fail("Wrong number waiting on monitor threads");
-        }
-        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
-    tested_threads_destroy();
+    tf_assert_same(hysem_destroy(mon_enter), TM_ERROR_NONE);
 
     return TEST_PASSED;
-}
+} // test_jthread_monitor_enter_exit
 
 TEST_LIST_START
-    TEST(test_jthread_monitor_init)
-    TEST(test_jthread_monitor_enter)
+    TEST(test_jthread_monitor_enter_exit)
     TEST(test_jthread_monitor_try_enter)
-    TEST(test_jthread_monitor_exit)
-    //TEST(test_jthread_monitor_notify)
+    TEST(test_jthread_monitor_notify)
     TEST(test_jthread_monitor_notify_all)
     TEST(test_jthread_monitor_wait)
-    //TEST(test_jthread_monitor_wait_interrupt)
+    TEST(test_jthread_monitor_wait_interrupt)
     TEST(test_jthread_monitor_timed_wait)
     TEST(test_jthread_monitor_timed_wait_timeout)
-    //TEST(test_jthread_monitor_timed_wait_interrupt)
+    TEST(test_jthread_monitor_timed_wait_interrupt)
 TEST_LIST_END;

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_park.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_park.c?rev=612140&r1=612139&r2=612140&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_park.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_park.c Tue Jan 15 07:47:20 2008
@@ -32,7 +32,12 @@
     tts->phase = TT_PHASE_PARKED;
     tested_thread_started(tts);
     status = jthread_park();
-    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_RUNNING : 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_RUNNING;
+    }
     tested_thread_wait_for_stop_request(tts);
     tts->phase = TT_PHASE_DEAD;
     tested_thread_ended(tts);
@@ -93,7 +98,12 @@
     tts->phase = TT_PHASE_PARKED;
     tested_thread_started(tts);
     status = jthread_park();
-    tts->phase = (status == TM_ERROR_INTERRUPT ? TT_PHASE_RUNNING : TT_PHASE_ERROR);
+    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_RUNNING;
+    }
     tested_thread_wait_for_stop_request(tts);
     tts->phase = TT_PHASE_DEAD;
     tested_thread_ended(tts);
@@ -103,7 +113,7 @@
 
     tested_thread_sturct_t *tts;
     tested_thread_sturct_t *parked_tts;
-    int i;
+    int count;
     int parked_nmb;
 
     // Initialize tts structures and run all tested threads
@@ -111,9 +121,17 @@
 
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
+        count = 0;
+        while (!hythread_is_parked(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 PARKED");
+            }
+        }
         check_tested_thread_phase(tts, TT_PHASE_PARKED);
     }
-    for (i = 0; i <= MAX_TESTED_THREAD_NUMBER; i++){
+    for (count = 0; count <= MAX_TESTED_THREAD_NUMBER; count++){
 
         parked_nmb = 0;
         parked_tts = NULL;
@@ -127,7 +145,7 @@
                 tf_assert_same(tts->phase, TT_PHASE_RUNNING);
             }
         }
-        if (MAX_TESTED_THREAD_NUMBER - parked_nmb - i != 0){
+        if (MAX_TESTED_THREAD_NUMBER - parked_nmb - count != 0){
             tf_fail("Wrong number of parked threads");
         }
         if (parked_nmb > 0){
@@ -152,8 +170,13 @@
     
     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);
+    status = jthread_timed_park(SLEEP_TIME/2, 0);
+    if (status != TM_ERROR_TIMEOUT) {
+        log_info("Test status is %d, but expected %d", status, TM_ERROR_TIMEOUT);
+        tts->phase = TT_PHASE_ERROR;
+    } else {
+        tts->phase = TT_PHASE_RUNNING;
+    }
     tested_thread_wait_for_stop_request(tts);
     tts->phase = TT_PHASE_DEAD;
     tested_thread_ended(tts);

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_instrum.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_instrum.c?rev=612140&r1=612139&r2=612140&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_instrum.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_instrum.c Tue Jan 15 07:47:20 2008
@@ -21,27 +21,25 @@
 #include <open/jthread.h>
 #include <open/ti_thread.h>
 
-hysem_t mon_enter;
+static hysem_t mon_enter;
 
-/*
- * Test jthread_get_all_threads(...)
+/**
+ * Test jthread_get_all_threads()
+ * Test jthread_get_thread_count()
  */
-int test_jthread_get_all_threads(void) {
-
+int test_jthread_get_all_threads(void)
+{
     tested_thread_sturct_t *tts;
-    jint all_threads_count = 99;
-    jint thread_count = 99;
+    jint all_threads_count;
+    jint thread_count;
     jint initial_thread_count;
     jint initial_all_threads_count;
     jthread *threads = NULL;
     int i;
     JNIEnv * jni_env = jthread_get_JNI_env(jthread_self());
 
-    // 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);
+    tf_assert_same(jthread_get_thread_count(&initial_thread_count), TM_ERROR_NONE);
+    tf_assert_same(jthread_get_all_threads(&threads, &initial_all_threads_count), TM_ERROR_NONE);
 
     // Initialize tts structures
     tested_threads_init(TTS_INIT_COMMON_MONITOR);
@@ -51,6 +49,7 @@
     tf_assert_same(thread_count, initial_thread_count);
     tf_assert_same(all_threads_count, initial_all_threads_count);
     tf_assert_not_null(threads);
+
     i = 0;
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
@@ -72,25 +71,17 @@
     tested_threads_destroy();
 
     return TEST_PASSED;
-}
-
-/*
- * Test jthread_get_thread_count(...)
- */
-int test_jthread_get_thread_count(void) {
-
-    return test_jthread_get_all_threads();
-}
+} // test_jthread_get_all_threads
 
 /*
- * Test get_blocked_count(...)
+ * Test jthread_get_blocked_count()
  */
 void JNICALL run_for_test_jthread_get_blocked_count(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
     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);
@@ -103,16 +94,16 @@
     // 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) {
+} // run_for_test_jthread_get_blocked_count
 
+int test_jthread_get_blocked_count(void)
+{
     tested_thread_sturct_t *tts;
     tested_thread_sturct_t *critical_tts;
     int i;
     int waiting_on_monitor_nmb;
 
-    hysem_create(&mon_enter, 0, 1);
+    tf_assert_same(hysem_create(&mon_enter, 0, 1), TM_ERROR_NONE);
 
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_get_blocked_count);
@@ -120,11 +111,9 @@
     for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
         int cycles = MAX_TIME_TO_WAIT / CLICK_TIME_MSEC;
 
-        waiting_on_monitor_nmb = 0;
-        critical_tts = NULL;
-
-        hysem_wait(mon_enter);
+        tf_assert_same(hysem_wait(mon_enter), TM_ERROR_NONE);
 
+        critical_tts = NULL;
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
             if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
@@ -132,6 +121,8 @@
                 critical_tts = tts;
             }
         }
+
+        waiting_on_monitor_nmb = 0;
         while ((MAX_TESTED_THREAD_NUMBER - i > waiting_on_monitor_nmb + 1) && (cycles-- > 0)) {
             tf_assert_same(jthread_get_blocked_count(&waiting_on_monitor_nmb), TM_ERROR_NONE);
             sleep_a_click();
@@ -147,122 +138,172 @@
     tested_threads_destroy();
 
     return TEST_PASSED;
-}
+} // test_jthread_get_blocked_count
 
 /*
- * Test jthread_get_deadlocked_threads(...)
+ * Test jthread_get_deadlocked_threads()
  */
-void JNICALL run_for_test_jthread_get_deadlocked_threads(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
-
+void JNICALL run_for_test_jthread_get_deadlocked_threads(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args)
+{
     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_WAITING_ON_MONITOR;
+    status = jthread_monitor_enter(tts->monitor);
 
     tts->phase = TT_PHASE_RUNNING;
     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_WAITING_ON_MONITOR;
+    status = jthread_monitor_enter(
+        get_tts(MAX_TESTED_THREAD_NUMBER - (tts->my_index + 1))->monitor);
     tts->phase = status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR;
     tested_thread_ended(tts);
-}
-
-int test_jthread_get_deadlocked_threads(void) {
+} // run_for_test_jthread_get_deadlocked_threads
 
+int test_jthread_get_deadlocked_threads(void)
+{
     tested_thread_sturct_t * tts;
     jthread *thread_list;
     int dead_list_count;
     jthread *dead_list;
-    int i = 0;
-
-    thread_list =
-        (jthread*)calloc(MAX_TESTED_THREAD_NUMBER, sizeof(int));
+    int count;
 
     // Initialize tts structures and run all tested threads
     tested_threads_run_with_different_monitors(run_for_test_jthread_get_deadlocked_threads);
 
+    thread_list =
+        (jthread*)calloc(MAX_TESTED_THREAD_NUMBER, sizeof(jthread*));
+    tf_assert(thread_list && "failed to alloc memory");
+
     reset_tested_thread_iterator(&tts);
-    while(next_tested_thread(&tts)){
-        thread_list[i] = tts->java_thread;
-        i++;
+    while(next_tested_thread(&tts)) {
+        thread_list[tts->my_index] = tts->java_thread;
     }
     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, 0);
 
-    tested_thread_send_stop_request(get_tts(0));
-    tested_thread_send_stop_request(get_tts(1));
+    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)) {
+        count = 0;
+        if ((MAX_TESTED_THREAD_NUMBER % 2)
+            && (tts->my_index == MAX_TESTED_THREAD_NUMBER / 2))
+        {
+            while (hythread_is_alive(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");
+                }
+            }
+            log_info("Thread %d is dead", tts->my_index);
+            check_tested_thread_phase(tts, TT_PHASE_DEAD);
+            thread_list[tts->my_index] = jthread_self();
+        } else {
+            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 WAITING");
+                }
+            }
+            log_info("Thread %d is blocked on monitor", tts->my_index);
+            check_tested_thread_phase(tts, TT_PHASE_WAITING_ON_MONITOR);
+        }
+    }
 
-    // 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);
+        &dead_list, &dead_list_count), TM_ERROR_NONE);
+    log_info("Deadlocked thread numbre is %d", dead_list_count);
+    tf_assert_same(dead_list_count,
+        ((MAX_TESTED_THREAD_NUMBER % 2)
+        ? MAX_TESTED_THREAD_NUMBER - 1 : MAX_TESTED_THREAD_NUMBER));
 
-    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);
+    count = 0;
+    reset_tested_thread_iterator(&tts);
+    while(next_tested_thread(&tts)) {
+        if ((MAX_TESTED_THREAD_NUMBER % 2)
+            && (tts->my_index == MAX_TESTED_THREAD_NUMBER / 2))
+        {
+            continue;
+        } else {
+            tf_assert_same(dead_list[count++], tts->java_thread);
+            log_info("Thread %d is deadlocked", tts->my_index);
+            hythread_set_state(tts->native_thread, TM_THREAD_STATE_TERMINATED);
+            hythread_cancel(tts->native_thread);
+        }
+    }
 
      // Terminate all threads and clear tts structures
     tested_threads_destroy();
-    
+
     return TEST_PASSED;
-}
+} // test_jthread_get_deadlocked_threads
 
-/*
- * Test get_wated_count(...)
+/**
+ * Test jthread_get_waited_count()
  */
-void JNICALL run_for_test_jthread_get_waited_count(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
-
+void JNICALL run_for_test_jthread_get_waited_count(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args)
+{
     tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jobject monitor = tts->monitor;
     IDATA status;
-    
+
     tts->phase = TT_PHASE_RUNNING;
     tested_thread_started(tts);
+    // Enter critical section
     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);
+    // Wait on monitor
     status = jthread_monitor_wait(monitor);
     if (status != TM_ERROR_NONE){
         tts->phase = TT_PHASE_ERROR;
+        jthread_monitor_exit(monitor);
         tested_thread_ended(tts);
         return;
     }
+    // Exit critical section
     status = jthread_monitor_exit(monitor);
 
-    // End critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
     tested_thread_ended(tts);
-}
+} // run_for_test_jthread_get_waited_count
 
-int test_jthread_get_waited_count(void) {
-
-    int i;
+int test_jthread_get_waited_count(void)
+{
+    int count;
     int waiting_nmb;
     jobject monitor;
+    tested_thread_sturct_t * tts;
 
     // Initialize tts structures and run all tested threads
     tested_threads_run(run_for_test_jthread_get_waited_count);
 
-    for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
-
-        waiting_nmb = 0;
-
-        tf_assert_same(jthread_get_waited_count(&waiting_nmb), TM_ERROR_NONE);
-        if (waiting_nmb != i){
-            tf_fail("Wrong number waiting on monitor threads");
+    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");
+            }
         }
-        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);
+        check_tested_thread_phase(tts, TT_PHASE_WAITING_ON_WAIT);
+        log_info("Thread %d is waiting.", tts->my_index);
     }
+
+    tf_assert_same(jthread_get_waited_count(&waiting_nmb), TM_ERROR_NONE);
+    log_info("Waiting threads count is %d", waiting_nmb);
+    tf_assert_same(waiting_nmb, MAX_TESTED_THREAD_NUMBER);
+
+    log_info("Release all threads");
     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);
@@ -272,12 +313,11 @@
     tested_threads_destroy();
 
     return TEST_PASSED;
-}
+} // test_jthread_get_waited_count
 
 TEST_LIST_START
     TEST(test_jthread_get_all_threads)
-    TEST(test_jthread_get_thread_count)
     TEST(test_jthread_get_blocked_count)
-    //TEST(test_jthread_get_deadlocked_threads)
-    //TEST(test_jthread_get_waited_count)
+    TEST(test_jthread_get_deadlocked_threads)
+    TEST(test_jthread_get_waited_count)
 TEST_LIST_END;

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_peak_count.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_peak_count.c?rev=612140&r1=612139&r2=612140&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_peak_count.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_peak_count.c Tue Jan 15 07:47:20 2008
@@ -23,36 +23,19 @@
 #include <open/hythread_ext.h>
 #include <open/ti_thread.h>
 
-int helper_get_reset_peak_count(void);
-/*
- * Test jthread_reset_peak_thread_count(...)
+/**
+ * Test jthread_get_peak_thread_count()
+ * Test jthread_reset_peak_thread_count()
  */
-int test_jthread_reset_peak_thread_count(void) {
-
-    log_info("NO IMPLEMENTTATION TO TEST");
-    return TEST_FAILED;
-    return helper_get_reset_peak_count();
-}
-
-/*
- * Test jthread_get_peak_thread_count(...)
- */
-int test_jthread_get_peak_thread_count(void) {
-
-    log_info("NO IMPLEMENTTATION TO TEST");
-    return TEST_FAILED;
-    return helper_get_reset_peak_count();
-}
-
-void JNICALL run_for_helper_get_reset_peak_count(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
+void JNICALL run_for_test_get_reset_peak_count(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args)
+{
 
     tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     IDATA status;
     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);
+    tts->phase = TT_PHASE_RUNNING;
     tested_thread_started(tts);
     while(tested_thread_wait_for_stop_request_timed(tts, SLEEP_TIME) == TM_ERROR_TIMEOUT) {
         ++num;
@@ -60,31 +43,40 @@
     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) {
+} // run_for_test_get_reset_peak_count
 
+int test_get_get_reset_peak_count(void)
+{
+    jint peak_count;
     tested_thread_sturct_t *tts;
 
+    tf_assert_same(jthread_reset_peak_thread_count(), TM_ERROR_NONE);
+    tf_assert_same(jthread_get_peak_thread_count(&peak_count), TM_ERROR_NONE);
+    log_info("Initial peak_count = %d", peak_count);
+
     // Initialize tts structures and run all tested threads
-    tested_threads_run(run_for_helper_get_reset_peak_count);
-    
+    tested_threads_run(run_for_test_get_reset_peak_count);
+
     reset_tested_thread_iterator(&tts);
-    while(next_tested_thread(&tts)){
+    while(next_tested_thread(&tts)) {
+        while(tts->phase != TT_PHASE_RUNNING) {
+            hythread_sleep(SLEEP_TIME);
+        }
+        check_tested_thread_phase(tts, TT_PHASE_RUNNING);
         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);
+        log_info("Thread %d peak_count = %d", tts->my_index, tts->peak_count);
+        tf_assert(tts->peak_count > peak_count);
+        tf_assert_same(jthread_reset_peak_thread_count(), TM_ERROR_NONE);
     }
 
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
 
     return TEST_PASSED;
-}
+} // test_get_get_reset_peak_count
 
 TEST_LIST_START
-    //TEST(test_jthread_reset_peak_thread_count)
-    //TEST(test_jthread_get_peak_thread_count)
+    TEST(test_get_get_reset_peak_count)
 TEST_LIST_END;

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_raw_monitors.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_raw_monitors.c?rev=612140&r1=612139&r2=612140&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_raw_monitors.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_raw_monitors.c Tue Jan 15 07:47:20 2008
@@ -15,91 +15,51 @@
  *  limitations under the License.
  */
 
-
 #include <stdio.h>
 #include "testframe.h"
 #include "thread_unit_test_utils.h"
 #include <open/jthread.h>
 #include <open/ti_thread.h>
 
-int test_jthread_raw_monitor_destroy(void);
-int helper_jthread_raw_monitor_enter_exit(void);
-int helper_jthread_raw_monitor_try_enter(void);
-int helper_jthread_raw_wait_notify(void);
-int helper_jthread_raw_wait_notify_all(void);
+static hysem_t mon_enter;
 
-/*
- * Raw monitors 
+/**
+ * Raw monitor TODO:
+ *
+ * - Init raw monitor and not init
+ * - jthread_raw_monitor_exit() without jthread_raw_monitor_enter()
  */
 
-int test_jthread_raw_monitor_create(void) {
-
-    return test_jthread_raw_monitor_destroy();
-}
-
-int test_jthread_raw_monitor_destroy(void) {
-
+/**
+ * Test jthread_raw_monitor_create()
+ * Test jthread_raw_monitor_destroy()
+ */
+int test_jthread_raw_monitor_create_destroy(void)
+{
+    IDATA status;
     jrawMonitorID raw_monitor;
-    IDATA status; 
 
     status = jthread_raw_monitor_create(&raw_monitor);
-    if (status != TM_ERROR_NONE){
+    if (status != TM_ERROR_NONE) {
         return TEST_FAILED;
     }
     status = jthread_raw_monitor_destroy(raw_monitor);
-    if (status != TM_ERROR_NONE){
+    if (status != TM_ERROR_NONE) {
         return TEST_FAILED;
     }
     return TEST_PASSED;
-}
-
-int test_jthread_raw_monitor_enter(void) {
-
-    return helper_jthread_raw_monitor_enter_exit();
-}
-
-int test_jthread_raw_monitor_try_enter(void) {
-
-    return helper_jthread_raw_monitor_try_enter();
-}
-
-int test_jthread_raw_monitor_exit(void) {
-
-    return helper_jthread_raw_monitor_enter_exit();
-}
-
-int test_jthread_raw_notify(void) {
+} // test_jthread_raw_monitor_create_destroy
 
-    return helper_jthread_raw_wait_notify();
-}
-
-int test_jthread_raw_notify_all(void) {
-
-    return helper_jthread_raw_wait_notify_all();
-}
-
-int test_jthread_raw_wait(void) {
-
-    return helper_jthread_raw_wait_notify();
-}
-
-/*
- * ------------------------ HELPERS -----------------------
- */
-
-hysem_t mon_enter;
-/*
- * Test jthread_raw_monitor_enter(...)
- * Test jthread_raw_monitor_exit(...)
+/**
+ * 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 *args){
+void JNICALL run_for_test_jthread_raw_monitor_enter_exit(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
     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);
@@ -112,40 +72,40 @@
     // End critical section
     tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
     tested_thread_ended(tts);
-}
+} // run_for_test_jthread_raw_monitor_enter_exit
 
-int helper_jthread_raw_monitor_enter_exit(void) {
+int test_jthread_raw_monitor_enter_exit(void) {
 
     tested_thread_sturct_t *tts;
     tested_thread_sturct_t *critical_tts;
     int i;
     int waiting_on_monitor_nmb;
 
-    hysem_create(&mon_enter, 0, 1);
+    tf_assert_same(hysem_create(&mon_enter, 0, 1), TM_ERROR_NONE);
 
     // Initialize tts structures and run all tested threads
-    tested_threads_run(run_for_helper_jthread_raw_monitor_enter_exit);
-
-    for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
+    tested_threads_run(run_for_test_jthread_raw_monitor_enter_exit);
 
+    for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++) {
         waiting_on_monitor_nmb = 0;
         critical_tts = NULL;
 
-        hysem_wait(mon_enter);
+        tf_assert_same(hysem_wait(mon_enter), TM_ERROR_NONE);
 
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
-            if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
+            if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON) {
                 tf_assert(critical_tts == NULL); // error if two threads in critical section
                 critical_tts = tts;
-            } else if (tts->phase == TT_PHASE_WAITING_ON_MONITOR){
+            } else if (tts->phase == TT_PHASE_WAITING_ON_MONITOR) {
                 waiting_on_monitor_nmb++;
             }
         }
         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 - waiting_on_monitor_nmb - i != 1) {
             tf_fail("Wrong number waiting on monitor threads");
         }
+        log_info("Thread %d grabbed monitor", critical_tts->my_index);
         tested_thread_send_stop_request(critical_tts);
         tested_thread_wait_ended(critical_tts);
         check_tested_thread_phase(critical_tts, TT_PHASE_DEAD);
@@ -153,20 +113,22 @@
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
 
+    tf_assert_same(hysem_destroy(mon_enter), TM_ERROR_NONE);
+
     return TEST_PASSED;
-}
+} // test_jthread_raw_monitor_enter_exit
 
-/*
- * Test jthread_raw_wait(...)
- * Test jthread_raw_notify(...)
+/**
+ * Test jthread_raw_wait()
+ * Test jthread_raw_notify()
  */
-void JNICALL run_for_helper_jthread_raw_wait_notify(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
+void JNICALL run_for_test_jthread_raw_wait_notify(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
 
     tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args;
     jrawMonitorID monitor = tts->raw_monitor;
     IDATA status;
     int64 msec = 1000000;
-    
+
     status = jthread_raw_monitor_enter(monitor);
     if (status != TM_ERROR_NONE){
         tts->phase = TT_PHASE_ERROR;
@@ -184,28 +146,39 @@
     // 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) {
+} // run_for_test_jthread_raw_wait_notify
 
+int test_jthread_raw_notify(void)
+{
+    int i;
+    int count;
+    int waiting_on_wait_nmb;
     tested_thread_sturct_t *tts;
     tested_thread_sturct_t *critical_tts;
     jrawMonitorID monitor;
-    int i;
-    int waiting_on_wait_nmb;
 
-    hysem_create(&mon_enter, 0, 1);
+    tf_assert_same(hysem_create(&mon_enter, 0, 1), TM_ERROR_NONE);
 
     // Initialize tts structures and run all tested threads
-    tested_threads_run(run_for_helper_jthread_raw_wait_notify);
+    tested_threads_run(run_for_test_jthread_raw_wait_notify);
+
+    monitor = get_tts(0)->raw_monitor;
 
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
-        monitor = tts->raw_monitor; // the same for all tts
-        check_tested_thread_phase(tts, TT_PHASE_WAITING_ON_WAIT);       
+        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);
+        log_info("Thread %d is waiting.", tts->my_index);
     }
-    for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
 
+    for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++) {
         waiting_on_wait_nmb = 0;
         critical_tts = NULL;
 
@@ -213,8 +186,13 @@
         while(next_tested_thread(&tts)){
             tf_assert(tts->phase != TT_PHASE_IN_CRITICAL_SECTON);
         }
+        log_info("Notify tested threads");
+        tf_assert_same(jthread_raw_monitor_enter(monitor), TM_ERROR_NONE);
         tf_assert_same(jthread_raw_monitor_notify(monitor), TM_ERROR_NONE);
-        hysem_wait(mon_enter);
+        tf_assert_same(jthread_raw_monitor_exit(monitor), TM_ERROR_NONE);
+
+        tf_assert_same(hysem_wait(mon_enter), TM_ERROR_NONE);
+
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
             if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
@@ -228,6 +206,7 @@
         if (MAX_TESTED_THREAD_NUMBER - waiting_on_wait_nmb - i != 1){
             tf_fail("Wrong number waiting on monitor threads");
         }
+        log_info("Thread %d was notified", critical_tts->my_index);
         tested_thread_send_stop_request(critical_tts);
         tested_thread_wait_ended(critical_tts);
         check_tested_thread_phase(critical_tts, TT_PHASE_DEAD);
@@ -235,42 +214,56 @@
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
 
+    tf_assert_same(hysem_destroy(mon_enter), TM_ERROR_NONE);
+
     return TEST_PASSED;
-}
+} // test_jthread_raw_notify
 
-/*
- * Test jthread_raw_wait(...)
- * Test jthread_raw_notify_all(...)
+/**
+ * Test jthread_raw_wait()
+ * Test jthread_raw_notify_all()
  */
-
-int helper_jthread_raw_wait_notify_all(void) {
-
+int test_jthread_raw_notify_all(void)
+{
+    int i;
+    int count;
+    int waiting_on_wait_nmb;
     tested_thread_sturct_t *tts;
     tested_thread_sturct_t *critical_tts;
     jrawMonitorID monitor;
-    int i;
-    int waiting_on_wait_nmb;
 
-    hysem_create(&mon_enter, 0, 1);
+    tf_assert_same(hysem_create(&mon_enter, 0, 1), TM_ERROR_NONE);
 
     // Initialize tts structures and run all tested threads
-    tested_threads_run(run_for_helper_jthread_raw_wait_notify);
+    tested_threads_run(run_for_test_jthread_raw_wait_notify);
+
+    monitor = get_tts(0)->raw_monitor;
 
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
-        monitor = tts->raw_monitor;
-        check_tested_thread_phase(tts, TT_PHASE_WAITING_ON_WAIT);       
+        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);
+        log_info("Thread %d is waiting.", tts->my_index);
     }
+
+    log_info("Notify all tested threads");
     tf_assert_same(jthread_raw_monitor_enter(monitor), TM_ERROR_NONE);
     tf_assert_same(jthread_raw_monitor_notify_all(monitor), TM_ERROR_NONE);
-    tf_assert_same(jthread_raw_monitor_enter(monitor), TM_ERROR_NONE);
+    tf_assert_same(jthread_raw_monitor_exit(monitor), TM_ERROR_NONE);
 
     for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
 
         waiting_on_wait_nmb = 0;
         critical_tts = NULL;
 
-        hysem_wait(mon_enter);
+        tf_assert_same(hysem_wait(mon_enter), TM_ERROR_NONE);
 
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
@@ -285,6 +278,7 @@
         if (MAX_TESTED_THREAD_NUMBER - waiting_on_wait_nmb - i != 1){
             tf_fail("Wrong number waiting on monitor threads");
         }
+        log_info("Thread %d was notified", critical_tts->my_index);
         tested_thread_send_stop_request(critical_tts);
         tested_thread_wait_ended(critical_tts);
         check_tested_thread_phase(critical_tts, TT_PHASE_DEAD);
@@ -292,15 +286,17 @@
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
 
-    return TEST_PASSED;
-}
+    tf_assert_same(hysem_destroy(mon_enter), TM_ERROR_NONE);
 
-void JNICALL run_for_helper_jthread_raw_monitor_try_enter(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){
+    return TEST_PASSED;
+} // test_jthread_raw_notify_all
 
+void JNICALL run_for_test_jthread_raw_monitor_try_enter(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args)
+{
     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);
@@ -316,26 +312,26 @@
     // 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) {
+} // run_for_test_jthread_raw_monitor_try_enter
 
+int test_jthread_raw_monitor_try_enter(void)
+{
     tested_thread_sturct_t *tts;
     tested_thread_sturct_t *critical_tts;
     int i;
     int waiting_on_monitor_nmb;
 
-    hysem_create(&mon_enter, 0, 1);
+    tf_assert_same(hysem_create(&mon_enter, 0, 1), TM_ERROR_NONE);
 
     // Initialize tts structures and run all tested threads
-    tested_threads_run(run_for_helper_jthread_raw_monitor_try_enter);
+    tested_threads_run(run_for_test_jthread_raw_monitor_try_enter);
 
     for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
 
         waiting_on_monitor_nmb = 0;
         critical_tts = NULL;
 
-        hysem_wait(mon_enter);
+        tf_assert_same(hysem_wait(mon_enter), TM_ERROR_NONE);
 
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
@@ -350,6 +346,7 @@
         if (MAX_TESTED_THREAD_NUMBER - waiting_on_monitor_nmb - i != 1){
             tf_fail("Wrong number waiting on monitor threads");
         }
+        log_info("Thread %d grabbed monitor", critical_tts->my_index);
         tested_thread_send_stop_request(critical_tts);
         tested_thread_wait_ended(critical_tts);
         check_tested_thread_phase(critical_tts, TT_PHASE_DEAD);
@@ -357,16 +354,15 @@
     // Terminate all threads and clear tts structures
     tested_threads_destroy();
 
+    tf_assert_same(hysem_destroy(mon_enter), TM_ERROR_NONE);
+
     return TEST_PASSED;
-}
+} // test_jthread_raw_monitor_try_enter
 
 TEST_LIST_START
-    TEST(test_jthread_raw_monitor_create)
-    TEST(test_jthread_raw_monitor_destroy)
-    TEST(test_jthread_raw_monitor_enter)
+    TEST(test_jthread_raw_monitor_create_destroy)
+    TEST(test_jthread_raw_monitor_enter_exit)
     TEST(test_jthread_raw_monitor_try_enter)
-    TEST(test_jthread_raw_monitor_exit)
-    //TEST(test_jthread_raw_notify)
-    //TEST(test_jthread_raw_notify_all)
-    //TEST(test_jthread_raw_wait)
+    TEST(test_jthread_raw_notify)
+    TEST(test_jthread_raw_notify_all)
 TEST_LIST_END;



Mime
View raw message