You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2006/08/23 18:49:21 UTC

svn commit: r434076 [4/18] - in /incubator/harmony/enhanced/drlvm/trunk: build/make/components/ build/make/components/vm/ build/make/targets/ build/patches/lnx/ build/patches/lnx/APR/ build/patches/lnx/APR/threadproc/ build/patches/lnx/APR/threadproc/u...

Added: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_monitors.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_monitors.c?rev=434076&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_monitors.c (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_monitors.c Wed Aug 23 09:48:41 2006
@@ -0,0 +1,654 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#include <stdio.h>
+#include "testframe.h"
+#include "thread_unit_test_utils.h"
+#include <open/jthread.h>
+#include <open/hythread_ext.h>
+
+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();
+} 
+
+/*
+ * Test jthread_monitor_try_enter()
+ */
+void run_for_test_jthread_monitor_try_enter(void){
+
+    tested_thread_sturct_t * tts = current_thread_tts;
+    jobject monitor = tts->monitor;
+    IDATA status;
+    
+    tts->phase = TT_PHASE_WAITING_ON_MONITOR;
+    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);
+    while(1){
+        tts->clicks++;
+        sleep_a_click();
+        if (tts->stop) {
+            break;
+        }
+    }
+    status = jthread_monitor_exit(monitor);
+    // End critical section
+    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+}
+
+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;
+
+    // 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++){
+
+        waiting_on_monitor_nmb = 0;
+        critical_tts = NULL;
+
+        reset_tested_thread_iterator(&tts);
+        while(next_tested_thread(&tts)){
+            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
+            if (tts->phase == TT_PHASE_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){
+                waiting_on_monitor_nmb++;
+            }
+        }
+        tf_assert(critical_tts); // thread in critical section found
+        if (MAX_TESTED_THREAD_NUMBER - waiting_on_monitor_nmb - i != 1){
+            tf_fail("Wrong number waiting on monitor threads");
+        }
+        critical_tts->stop = 1;
+        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();
+} 
+
+int test_jthread_monitor_notify (void){
+
+    return helper_jthread_monitor_wait_notify();
+} 
+
+/*
+ * Test jthread_monitor_notify_all(...)
+ */
+void run_for_test_jthread_monitor_notify_all(void){
+
+    tested_thread_sturct_t * tts = current_thread_tts;
+    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;
+        return;
+    }
+    // Begin critical section
+    tts->phase = TT_PHASE_WAITING_ON_WAIT;
+    status = jthread_monitor_wait(monitor);
+    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_IN_CRITICAL_SECTON : TT_PHASE_ERROR);
+    while(1){
+        tts->clicks++;
+        sleep_a_click();
+        if (tts->stop) {
+            break;
+        }
+    }
+    status = jthread_monitor_exit(monitor);
+    // Exit critical section
+    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+}
+
+int test_jthread_monitor_notify_all(void) {
+
+    tested_thread_sturct_t *tts;
+    tested_thread_sturct_t *critical_tts;
+    jobject monitor;
+    int i;
+    int waiting_on_wait_nmb;
+
+    // Initialize tts structures and run all tested threads
+    tested_threads_run(run_for_test_jthread_monitor_notify_all);
+
+    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);       
+    }
+    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++){
+
+        waiting_on_wait_nmb = 0;
+        critical_tts = NULL;
+
+        reset_tested_thread_iterator(&tts);
+        while(next_tested_thread(&tts)){
+            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
+            if (tts->phase == TT_PHASE_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 - waiting_on_wait_nmb - i != 1){
+            tf_fail("Wrong number waiting on monitor threads");
+        }
+        critical_tts->stop = 1;
+        check_tested_thread_phase(critical_tts, TT_PHASE_DEAD);
+    }
+    // Terminate all threads and clear tts structures
+    tested_threads_destroy();
+
+    return TEST_PASSED;
+}
+
+/*
+ * Test jthread_monitor_wait()
+ */
+void run_for_test_jthread_monitor_wait(void){
+
+    tested_thread_sturct_t * tts = current_thread_tts;
+    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;
+        return;
+    }
+    tts->phase = TT_PHASE_WAITING_ON_WAIT;
+    status = jthread_monitor_wait(monitor);
+    if (status != TM_ERROR_NONE){
+        tts->phase = TT_PHASE_ERROR;
+        return;
+    }
+    status = jthread_monitor_exit(monitor);
+    // Exit critical section
+    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+}
+
+int test_jthread_monitor_wait (void){
+
+    tested_thread_sturct_t *tts;
+    jobject monitor;
+
+    // Initialize tts structures and run all tested threads
+    tested_threads_run(run_for_test_jthread_monitor_wait);
+
+    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);       
+    }
+    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)){
+        check_tested_thread_phase(tts, TT_PHASE_DEAD);
+    }
+    // Terminate all threads and clear tts structures
+    tested_threads_destroy();
+
+    return TEST_PASSED;
+} 
+
+/*
+ * Test jthread_monitor_wait_interrupt()
+ */
+void run_for_test_jthread_monitor_wait_interrupt(void){
+
+    tested_thread_sturct_t * tts = current_thread_tts;
+    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;
+        return;
+    }
+    tts->phase = TT_PHASE_WAITING_ON_WAIT;
+    status = jthread_monitor_wait(monitor);
+    if (status != TM_ERROR_INTERRUPT){
+        tts->phase = TT_PHASE_ERROR;
+        return;
+    }
+    status = jthread_monitor_exit(monitor);
+    // Exit critical section
+    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+}
+
+int test_jthread_monitor_wait_interrupt(void){
+
+    tested_thread_sturct_t *tts;
+    tested_thread_sturct_t *waiting_tts;
+    int i;
+    int waiting_on_wait_nmb;
+
+    // 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);       
+    }
+    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)){
+            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
+            if (tts->phase == TT_PHASE_WAITING_ON_WAIT){
+                waiting_tts = tts;
+                waiting_on_wait_nmb++;
+            } else {
+                check_tested_thread_phase(tts, TT_PHASE_DEAD);
+            }
+        }
+        tf_assert_same(MAX_TESTED_THREAD_NUMBER - waiting_on_wait_nmb - i, 0);
+        if (waiting_tts){
+            tf_assert_same(jthread_interrupt(waiting_tts->java_thread), TM_ERROR_NONE);
+            check_tested_thread_phase(waiting_tts, TT_PHASE_DEAD);
+        }
+    }
+    // Terminate all threads and clear tts structures
+    tested_threads_destroy();
+
+    return TEST_PASSED;
+} 
+
+/*
+ * Test jthread_monitor_timed_wait()
+ */
+void run_for_test_jthread_monitor_timed_wait(void){
+
+    tested_thread_sturct_t * tts = current_thread_tts;
+    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;
+        return;
+    }
+    tts->phase = TT_PHASE_WAITING_ON_WAIT;
+    status = jthread_monitor_timed_wait(monitor, 10 * CLICK_TIME_MSEC * MAX_TESTED_THREAD_NUMBER,0);
+    if (status != TM_ERROR_NONE){
+        tts->phase = TT_PHASE_ERROR;
+        return;
+    }
+    status = jthread_monitor_exit(monitor);
+    // Exit critical section
+    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+}
+
+int test_jthread_monitor_timed_wait(void) {
+
+    tested_thread_sturct_t *tts;
+    jobject monitor;
+
+    // Initialize tts structures and run all tested threads
+    tested_threads_run(run_for_test_jthread_monitor_timed_wait);
+
+    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);       
+    }
+    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)){
+        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()
+ */
+void run_for_test_jthread_monitor_timed_wait_timeout(void){
+
+
+    tested_thread_sturct_t * tts = current_thread_tts;
+    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;
+        return;
+    }
+    tts->phase = TT_PHASE_WAITING_ON_WAIT;
+    status = jthread_monitor_timed_wait(monitor, 10 * CLICK_TIME_MSEC * MAX_TESTED_THREAD_NUMBER, 0);
+    if (status != TM_ERROR_TIMEOUT){
+        tts->phase = TT_PHASE_ERROR;
+        return;
+    }
+    status = jthread_monitor_exit(monitor);
+    // Exit critical section
+    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+}
+
+int test_jthread_monitor_timed_wait_timeout(void) {
+
+    tested_thread_sturct_t *tts;
+    jobject monitor;
+
+    // Initialize tts structures and run all tested threads
+    tested_threads_run(run_for_test_jthread_monitor_timed_wait_timeout);
+
+    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);       
+    }
+
+    // Wait for all threads wait timeout
+    jthread_sleep(20 * CLICK_TIME_MSEC * MAX_TESTED_THREAD_NUMBER, 0);
+
+    reset_tested_thread_iterator(&tts);
+    while(next_tested_thread(&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()
+ */
+void run_for_test_jthread_monitor_timed_wait_interrupt(void){
+
+    tested_thread_sturct_t * tts = current_thread_tts;
+    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;
+        return;
+    }
+    tts->phase = TT_PHASE_WAITING_ON_WAIT;
+    status = jthread_monitor_timed_wait(monitor, 100 * CLICK_TIME_MSEC * MAX_TESTED_THREAD_NUMBER, 0);
+    if (status != TM_ERROR_INTERRUPT){
+        tts->phase = TT_PHASE_ERROR;
+        return;
+    }
+    status = jthread_monitor_exit(monitor);
+    // Exit critical section
+    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+}
+
+int test_jthread_monitor_timed_wait_interrupt(void) {
+
+    tested_thread_sturct_t *tts;
+    tested_thread_sturct_t *waiting_tts;
+    int i;
+    int waiting_on_wait_nmb;
+
+    log_info("!!!!!!!!!!!!!! CRASHES");
+    tf_assert(0);
+    // 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);       
+    }
+    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)){
+            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
+            if (tts->phase == TT_PHASE_WAITING_ON_WAIT){
+                waiting_tts = tts;
+                waiting_on_wait_nmb++;
+            } else {
+                check_tested_thread_phase(waiting_tts, TT_PHASE_DEAD);
+            }
+        }
+        tf_assert_same(MAX_TESTED_THREAD_NUMBER - waiting_on_wait_nmb - i, 0);
+        if (waiting_tts){
+            tf_assert_same(jthread_interrupt(waiting_tts->java_thread), TM_ERROR_NONE);
+        }
+        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_enter(...)
+ * Test jthread_monitor_exit(...)
+ */
+//?????????????????????????????? jthread_monitor_init and not init
+//?????????????????????????????? jthread_monitor_exit without enter
+
+void run_for_helper_jthread_monitor_enter_exit(void){
+
+    tested_thread_sturct_t * tts = current_thread_tts;
+    jobject monitor = tts->monitor;
+    IDATA status;
+    
+    tts->phase = TT_PHASE_WAITING_ON_MONITOR;
+    status = jthread_monitor_enter(monitor);
+
+    // Begin critical section
+    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_IN_CRITICAL_SECTON : TT_PHASE_ERROR);
+    while(1){
+        tts->clicks++;
+        sleep_a_click();
+        if (tts->stop) {
+            break;
+        }
+    }
+    status = jthread_monitor_exit(monitor);
+    // End critical section
+    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+}
+
+int helper_jthread_monitor_enter_exit(void) {
+
+    tested_thread_sturct_t *tts;
+    tested_thread_sturct_t *critical_tts;
+    int i;
+    int waiting_on_monitor_nmb;
+
+    // Initialize tts structures and run all tested threads
+    tested_threads_run(run_for_helper_jthread_monitor_enter_exit);
+
+    for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
+        waiting_on_monitor_nmb = 0;
+        critical_tts = NULL;
+
+        reset_tested_thread_iterator(&tts);
+        while(next_tested_thread(&tts)){
+            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
+            if (tts->phase == TT_PHASE_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){
+                waiting_on_monitor_nmb++;
+            }
+        }
+        tf_assert(critical_tts); // thread in critical section found
+        if (MAX_TESTED_THREAD_NUMBER - waiting_on_monitor_nmb - i != 1){
+            tf_fail("Wrong number waiting on monitor threads");
+        }
+        critical_tts->stop = 1;
+        check_tested_thread_phase(critical_tts, TT_PHASE_DEAD);
+    }
+    // Terminate all threads and clear tts structures
+    tested_threads_destroy();
+
+    return TEST_PASSED;
+}
+
+/*
+ * Test jthread_monitor_wait(...)
+ * Test jthread_monitor_notify(...)
+ */
+void run_for_helper_jthread_monitor_wait_notify(void){
+
+    tested_thread_sturct_t * tts = current_thread_tts;
+    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;
+        return;
+    }
+    // Begin critical section
+    tts->phase = TT_PHASE_WAITING_ON_WAIT;
+    status = jthread_monitor_wait(monitor);
+    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_IN_CRITICAL_SECTON : TT_PHASE_ERROR);
+    while(1){
+        tts->clicks++;
+        sleep_a_click();
+        if (tts->stop) {
+            break;
+        }
+    }
+    status = jthread_monitor_exit(monitor);
+    // Exit critical section
+    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR);
+}
+
+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;
+
+    // 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)){
+            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
+            tf_assert(tts->phase != TT_PHASE_IN_CRITICAL_SECTON);
+        }
+        tf_assert_same(jthread_monitor_notify(monitor), TM_ERROR_NONE);
+        reset_tested_thread_iterator(&tts);
+        while(next_tested_thread(&tts)){
+            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
+            if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
+                tf_assert(critical_tts == NULL); // error if two threads in critical section
+                critical_tts = tts;
+            } 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 - waiting_on_wait_nmb - i != 1){
+            tf_fail("Wrong number waiting on monitor threads");
+        }
+        critical_tts->stop = 1;
+        check_tested_thread_phase(critical_tts, TT_PHASE_DEAD);
+    }
+    // Terminate all threads and clear tts structures
+    tested_threads_destroy();
+
+    return TEST_PASSED;
+}
+
+TEST_LIST_START
+    TEST(test_jthread_monitor_init)
+    TEST(test_jthread_monitor_enter)
+    TEST(test_jthread_monitor_try_enter)
+    TEST(test_jthread_monitor_exit)
+    //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_timed_wait)
+    TEST(test_jthread_monitor_timed_wait_timeout)
+    //TEST(test_jthread_monitor_timed_wait_interrupt)
+TEST_LIST_END;

Propchange: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_monitors.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_park.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_park.c?rev=434076&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_park.c (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_park.c Wed Aug 23 09:48:41 2006
@@ -0,0 +1,193 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#include <stdio.h>
+#include "testframe.h"
+#include "thread_unit_test_utils.h"
+#include <open/jthread.h>
+
+/*
+ * Test jthread_park(...)
+ * Test jthread_unpark(...)
+ */
+void run_for_test_jthread_park_unpark(void){
+
+    tested_thread_sturct_t * tts = current_thread_tts;
+    IDATA status;
+    
+    tts->phase = TT_PHASE_PARKED;
+    status = jthread_park();
+    tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_RUNNING : TT_PHASE_ERROR);
+    while(1){
+        tts->clicks++;
+        sleep_a_click();
+        if (tts->stop) {
+            break;
+        }
+    }
+    tts->phase = TT_PHASE_DEAD;
+}
+
+int test_jthread_park_unpark(void) {
+
+    tested_thread_sturct_t *tts;
+    tested_thread_sturct_t *parked_tts;
+    int i;
+    int parked_nmb;
+
+    // Initialize tts structures and run all tested threads
+    tested_threads_run(run_for_test_jthread_park_unpark);
+
+    reset_tested_thread_iterator(&tts);
+    while(next_tested_thread(&tts)){
+        check_tested_thread_phase(tts, TT_PHASE_PARKED);        
+    }
+    for (i = 0; i <= MAX_TESTED_THREAD_NUMBER; i++){
+
+        parked_nmb = 0;
+        parked_tts = NULL;
+
+        reset_tested_thread_iterator(&tts);
+        while(next_tested_thread(&tts)){
+            check_tested_thread_phase(tts, TT_PHASE_ANY); // to make thread running
+            if (tts->phase == TT_PHASE_PARKED){
+                parked_nmb++;
+                parked_tts = tts;
+            } else {
+                tf_assert_same(tts->phase, TT_PHASE_RUNNING);
+            }
+        }
+        if (MAX_TESTED_THREAD_NUMBER - parked_nmb - i != 0){
+            tf_fail("Wrong number of parked threads");
+        }
+        if (parked_nmb > 0){
+            tf_assert_same(jthread_unpark(parked_tts->java_thread), TM_ERROR_NONE);
+            check_tested_thread_phase(parked_tts, TT_PHASE_RUNNING);
+        }
+    }
+    // Terminate all threads and clear tts structures
+    tested_threads_destroy();
+
+    return TEST_PASSED;
+}
+
+/*
+ * Test jthread_park(...)
+ */
+void run_for_test_jthread_park_interrupt(void){
+
+    tested_thread_sturct_t * tts = current_thread_tts;
+    IDATA status;
+    
+    tts->phase = TT_PHASE_PARKED;
+    status = jthread_park();
+    tts->phase = (status == TM_ERROR_INTERRUPT ? TT_PHASE_RUNNING : TT_PHASE_ERROR);
+    while(1){
+        tts->clicks++;
+        sleep_a_click();
+        if (tts->stop) {
+            break;
+        }
+    }
+    tts->phase = TT_PHASE_DEAD;
+}
+
+int test_jthread_park_interrupt(void) {
+
+    tested_thread_sturct_t *tts;
+    tested_thread_sturct_t *parked_tts;
+    int i;
+    int parked_nmb;
+
+    // Initialize tts structures and run all tested threads
+    tested_threads_run(run_for_test_jthread_park_interrupt);
+
+    reset_tested_thread_iterator(&tts);
+    while(next_tested_thread(&tts)){
+        check_tested_thread_phase(tts, TT_PHASE_PARKED);
+    }
+    for (i = 0; i <= MAX_TESTED_THREAD_NUMBER; i++){
+
+        parked_nmb = 0;
+        parked_tts = NULL;
+
+        reset_tested_thread_iterator(&tts);
+        while(next_tested_thread(&tts)){
+            if (tts->phase == TT_PHASE_PARKED){
+                parked_nmb++;
+                parked_tts = tts;
+            } else {
+                tf_assert_same(tts->phase, TT_PHASE_RUNNING);
+            }
+        }
+        if (MAX_TESTED_THREAD_NUMBER - parked_nmb - i != 0){
+            tf_fail("Wrong number of parked threads");
+        }
+        if (parked_nmb > 0){
+            tf_assert_same(jthread_interrupt(parked_tts->java_thread), TM_ERROR_NONE);
+            check_tested_thread_phase(parked_tts, TT_PHASE_RUNNING);
+        }
+    }
+    // Terminate all threads (not needed here) and clear tts structures
+    tested_threads_destroy();
+
+    return TEST_PASSED;
+}
+
+/*
+ * Test jthread_timed_park(...)
+ */
+void run_for_test_jthread_timed_park(void){
+
+    tested_thread_sturct_t * tts = current_thread_tts;
+    IDATA status;
+    
+    tts->phase = TT_PHASE_PARKED;
+    status = jthread_timed_park(50, 0);
+    tts->phase = (status == TM_ERROR_TIMEOUT ? TT_PHASE_RUNNING : TT_PHASE_ERROR);
+    while(1){
+        tts->clicks++;
+        sleep_a_click();
+        if (tts->stop) {
+            break;
+        }
+    }
+    tts->phase = TT_PHASE_DEAD;
+}
+
+int test_jthread_timed_park(void) {
+
+    tested_thread_sturct_t *tts;
+
+    // Initialize tts structures and run all tested threads
+    tested_threads_run(run_for_test_jthread_timed_park);
+
+    reset_tested_thread_iterator(&tts);
+    while(next_tested_thread(&tts)){
+        check_tested_thread_phase(tts, TT_PHASE_RUNNING);       
+    }
+
+    // Terminate all threads (not needed here) and clear tts structures
+    tested_threads_destroy();
+
+    return TEST_PASSED;
+}
+
+TEST_LIST_START
+    TEST(test_jthread_park_unpark)
+    TEST(test_jthread_park_interrupt)
+    TEST(test_jthread_timed_park)
+TEST_LIST_END;

Propchange: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_park.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_ptr_conv.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_ptr_conv.c?rev=434076&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_ptr_conv.c (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_ptr_conv.c Wed Aug 23 09:48:41 2006
@@ -0,0 +1,74 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#include <stdio.h>
+#include "testframe.h"
+#include "thread_unit_test_utils.h"
+#include <open/jthread.h>
+#include <open/hythread_ext.h>
+#include "thread_private.h"
+
+
+/*
+ * Test jthread_get_java_thread(...)
+ */
+int test_jthread_get_java_thread(void) {
+
+    tested_thread_sturct_t *tts;
+    hythread_t native_thread;
+
+    // Initialize tts structures and run all tested threads
+    tested_threads_run(default_run_for_test);
+
+    reset_tested_thread_iterator(&tts);
+    while(next_tested_thread(&tts)){
+        native_thread = jthread_get_native_thread(tts->java_thread);
+        tf_assert_same(jthread_get_java_thread(native_thread)->object, tts->java_thread->object);
+    }
+
+    // Terminate all threads and clear tts structures
+    tested_threads_destroy();
+
+    return TEST_PASSED;
+}
+
+/*
+ * Test jthread_get_native_thread(...)
+ */
+int test_jthread_get_native_thread(void) {
+
+    tested_thread_sturct_t *tts;
+    hythread_t native_thread;
+
+    // Initialize tts structures and run all tested threads
+    tested_threads_run(default_run_for_test);
+
+    reset_tested_thread_iterator(&tts);
+    while(next_tested_thread(&tts)){
+        native_thread = jthread_get_native_thread(tts->java_thread);
+        tf_assert_same(jthread_get_java_thread(native_thread)->object, tts->java_thread->object);
+    }
+
+    // Terminate all threads and clear tts structures
+    tested_threads_destroy();
+
+    return TEST_PASSED;
+}
+
+TEST_LIST_START
+    TEST(test_jthread_get_java_thread)
+    TEST(test_jthread_get_native_thread)
+TEST_LIST_END;

Propchange: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_ptr_conv.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_suspend.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_suspend.c?rev=434076&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_suspend.c (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_suspend.c Wed Aug 23 09:48:41 2006
@@ -0,0 +1,151 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#include <stdio.h>
+#include "testframe.h"
+#include "thread_unit_test_utils.h"
+#include <open/jthread.h>
+#include <open/hythread_ext.h>
+
+/*
+ * Test jthread_suspend(...)
+ * Test jthread_resume(...)
+  */
+void run_for_test_jthread_suspend_resume(void){
+
+    tested_thread_sturct_t * tts = current_thread_tts;
+    jobject mon = tts->monitor;
+    IDATA status;
+    
+    tts->phase = TT_PHASE_RUNNING;
+    while(1){
+        hythread_safe_point();
+        tts->clicks++;
+        sleep_a_click();
+        if (tts->stop) {
+            break;
+        }
+    }
+    tts->phase = TT_PHASE_DEAD;
+}
+
+int test_jthread_suspend_resume(void) {
+
+    tested_thread_sturct_t *tts;
+    tested_thread_sturct_t *switch_tts;
+    int i;
+    int suspended_nmb;
+
+    // Initialize tts structures and run all tested threads
+    tested_threads_run(run_for_test_jthread_suspend_resume);
+
+    for (i = 0; i <= MAX_TESTED_THREAD_NUMBER; i++){
+
+        suspended_nmb = 0;
+        switch_tts = NULL;
+
+        reset_tested_thread_iterator(&tts);
+        while(next_tested_thread(&tts)){
+            check_tested_thread_phase(tts, TT_PHASE_RUNNING);
+            if (tested_thread_is_running(tts)){
+                switch_tts = tts;
+            } else {
+                suspended_nmb++;
+            }
+        }
+        if (suspended_nmb != i){
+            tf_fail("Wrong number of suspended threads");
+        }
+        if (switch_tts != NULL){
+            tf_assert_same(jthread_suspend(switch_tts->java_thread), TM_ERROR_NONE);
+        }
+    }
+    for (i = 0; i <= MAX_TESTED_THREAD_NUMBER; i++){
+
+        suspended_nmb = 0;
+        switch_tts = NULL;
+
+        reset_tested_thread_iterator(&tts);
+        while(next_tested_thread(&tts)){
+            check_tested_thread_phase(tts, TT_PHASE_RUNNING);
+            if (!tested_thread_is_running(tts)){
+                suspended_nmb++;
+                switch_tts = tts;
+            }
+        }
+        if (suspended_nmb != MAX_TESTED_THREAD_NUMBER - i){
+            tf_fail("Wrong number of suspended threads");
+        }
+        if (switch_tts != NULL){
+            tf_assert_same(jthread_resume(switch_tts->java_thread), TM_ERROR_NONE);
+        }
+    }
+    // Terminate all threads and clear tts structures
+    tested_threads_destroy();
+
+    return TEST_PASSED;
+}
+/*
+ * Test jthread_suspend_all(...)
+ * Test jthread_resume_all(...)
+ */
+
+int test_jthread_suspend_all_resume_all(void) {
+
+    tested_thread_sturct_t * tts;
+    jthread all_threads[MAX_TESTED_THREAD_NUMBER];
+    jvmtiError results[MAX_TESTED_THREAD_NUMBER];
+    int i = 0;
+
+    // Initialize tts structures and run all tested threads
+    tested_threads_run(run_for_test_jthread_suspend_resume);
+
+    // Test that all threads are running
+    reset_tested_thread_iterator(&tts);
+    while(next_tested_thread(&tts)){
+        all_threads[i] = tts->java_thread;
+        results[i] = (jvmtiError)(TM_ERROR_NONE + 1);
+        i++;
+        tf_assert(tested_thread_is_running(tts));
+    }
+    tf_assert_same(jthread_suspend_all(results, MAX_TESTED_THREAD_NUMBER, all_threads), TM_ERROR_NONE);
+    // Test that all threads are suspended
+    i = 0;
+    reset_tested_thread_iterator(&tts);
+    while(next_tested_thread(&tts)){
+        tf_assert(!tested_thread_is_running(tts));
+        tf_assert_same(results[i], TM_ERROR_NONE);
+        results[i] = (jvmtiError)(TM_ERROR_NONE + 1);
+        i++;
+    }
+    tf_assert_same(jthread_resume_all(results, MAX_TESTED_THREAD_NUMBER, all_threads), TM_ERROR_NONE);
+    // Test that all threads are running
+    i = 0;
+    reset_tested_thread_iterator(&tts);
+    while(next_tested_thread(&tts)){
+        tf_assert(tested_thread_is_running(tts));
+        tf_assert_same(results[i], TM_ERROR_NONE);
+        i++;
+    }
+    // Terminate all threads and clear tts structures
+    tested_threads_destroy();
+    return TEST_PASSED;
+}
+
+TEST_LIST_START
+    TEST(test_jthread_suspend_resume)
+    TEST(test_jthread_suspend_all_resume_all)
+TEST_LIST_END;

Propchange: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_suspend.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c?rev=434076&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c Wed Aug 23 09:48:41 2006
@@ -0,0 +1,201 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#include <stdio.h>
+#include "thread_private.h"
+#include <apr_pools.h>
+#include "testframe.h"
+#include "jthread.h"
+#include <open/hythread_ext.h>
+
+int start_proc(void *);
+int start_proc_empty(void *);
+
+int test_hythread_self_base(void) {
+    hythread_t thread;
+    //check that this thread is attached(tm_init called)
+    ////
+    tf_assert(thread = hythread_self());
+   
+    return 0; 
+}
+
+/*
+ * Test tm_create(..)
+ */
+int test_hythread_create(void){
+    apr_pool_t *pool;
+    void **args; 
+    hythread_t thread = NULL;
+    
+    apr_pool_create(&pool, NULL);
+
+    args = (void**) apr_palloc(pool, sizeof(void *) *3); 
+    
+    hythread_group_create((hythread_group_t *)&args[0]); 
+    
+    args[1] = apr_palloc(pool, sizeof(jthread_threadattr_t));
+    ((jthread_threadattr_t *)args[1])->stacksize = 1024;
+    ((jthread_threadattr_t *)args[1])->priority  = 1;
+    args[2] = pool;
+    
+    hythread_create_with_group(&thread, args[0], 1024, 1, 0, start_proc, args);
+
+    //hythread_join(thread);
+    return 0;
+}
+
+int test_hythread_iterator(void) {
+    hythread_group_t group = NULL;
+    hythread_t thread = NULL;
+    hythread_iterator_t iterator;
+    int i = 100;
+
+    hythread_group_create(&group);
+
+    while(i--) {
+        thread = NULL;
+        hythread_create_with_group(&thread, group, 0, 0, 0, start_proc_empty, NULL);
+    }
+
+    iterator = hythread_iterator_create(group);
+    i++;
+    printf ("iterator size: %d\n", hythread_iterator_size(iterator));
+    tf_assert(hythread_iterator_size(iterator) == 100);
+    while(hythread_iterator_has_next(iterator)) {
+        i++;
+        thread = hythread_iterator_next(&iterator);
+        hythread_join(thread);
+    }
+
+    tf_assert(i == 100);
+    
+    hythread_iterator_release(&iterator);
+    
+    return 0;
+}
+
+int test_hythread_iterator_default(void) {
+    hythread_t thread = NULL;
+    hythread_iterator_t iterator;
+    int i = 100;
+
+    while(i--) {
+        thread = NULL;
+        hythread_create(&thread, 0, 0, 0, start_proc_empty, NULL);
+    }
+
+    iterator = hythread_iterator_create(NULL);
+    i++;
+    printf("default group iterator: %d\n", hythread_iterator_size(iterator));
+    tf_assert(hythread_iterator_size(iterator) == (100 + 1/*current thread*/));
+    
+    while(hythread_iterator_has_next(iterator)) {
+        i++;
+        thread = hythread_iterator_next(&iterator);
+    }
+
+    tf_assert(i == 101);
+    
+    hythread_iterator_release(&iterator);
+    
+    return 0;
+}
+
+
+
+/*
+ * Test tm_create(..)
+ */
+int test_hythread_create_many(void){
+    apr_pool_t *pool;
+    void **args; 
+    hythread_t thread = NULL;
+    hythread_group_t group = NULL;
+    
+    char *buf;
+    int i = 10;
+    
+    hythread_group_create(&group);
+    while(i--) {
+        apr_pool_create(&pool, NULL);
+
+        args = (void**) apr_palloc(pool, sizeof(void *) *3); 
+    
+        args[0] = group; 
+        
+        args[1] = apr_palloc(pool, sizeof(jthread_threadattr_t));
+        ((jthread_threadattr_t *)args[1])->stacksize = 1024;
+        ((jthread_threadattr_t *)args[1])->priority  = 1;
+        
+        args[2] = pool;
+        
+        thread = NULL;
+
+        hythread_create_with_group(&thread, group, 1024, 1, 0, start_proc, args);
+        buf = (char *)apr_pcalloc(pool, sizeof(char)*12);
+
+        /*
+          sprintf(buf, "Thread %d\0", i);
+          hythread_set_name(thread, buf);
+        */
+        //hythread_join(thread);
+    }
+
+    //check thread structures:
+    //1. thread get group
+    //2. check that group contains 10 threads
+    //NOTE: native structures should not be freed untill tm_thread_destroy method
+    ////
+    
+    //1.group
+    ////
+    tf_assert(group);
+    tf_assert(group->threads_count == 10);
+    thread = group->thread_list->next;
+    
+    i=10;
+    while(thread != group->thread_list && i>0) {
+        i--;
+        thread = thread->next;
+    } 
+    
+    tf_assert(!i);
+
+    return 0;
+}
+
+int start_proc(void *args) {
+    void** attrs = (void **)args; 
+    tf_assert_same(hythread_self()->priority, ((jthread_threadattr_t *)attrs[1])->priority);
+    tf_assert_same(hythread_self()->group, attrs[0]);
+    hythread_sleep(1000);
+    apr_pool_destroy((apr_pool_t *)attrs[2]); 
+    return 0;
+}
+
+int start_proc_empty(void *args) {
+    hythread_sleep(1000);
+    return 0;
+}
+
+TEST_LIST_START
+    TEST(test_hythread_self_base)
+    TEST(test_hythread_create)
+    TEST(test_hythread_create_many)
+    TEST(test_hythread_iterator)
+    TEST(test_hythread_iterator_default)
+TEST_LIST_END;

Propchange: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_fat_monitor.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_fat_monitor.c?rev=434076&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_fat_monitor.c (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_fat_monitor.c Wed Aug 23 09:48:41 2006
@@ -0,0 +1,174 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#include "thread_private.h"
+#include "testframe.h"
+#include "open/jthread.h"
+#include <open/hythread_ext.h>
+
+#define NMB 5
+
+hythread_monitor_t monitor;
+apr_thread_mutex_t *mutex;
+apr_thread_cond_t  *condvar;
+int waiting_count;
+
+int run_for_test_wait_signal(void *args) {
+
+    IDATA status;
+
+    status = hythread_monitor_enter(monitor);
+    tf_assert_same(status, TM_ERROR_NONE);
+    
+    waiting_count++;
+
+    status = hythread_monitor_wait(monitor);
+    tf_assert_same(status, TM_ERROR_NONE);
+
+    waiting_count--;
+
+    status = hythread_monitor_exit(monitor);
+    tf_assert_same(status, TM_ERROR_NONE);
+
+    return TEST_PASSED;
+}
+
+int test_wait_signal(void){
+
+    IDATA status;
+    hythread_t threads[NMB];
+    int i;
+
+    //log_error("BUG IN APR");
+    //tf_assert(0);
+    status = hythread_monitor_init(&monitor, 0);
+   status = hythread_monitor_exit(monitor);
+    tf_assert_same(status, TM_ERROR_NONE);
+    waiting_count = 0;
+
+    for (i = 0; i < NMB; i++){
+        threads[i] = NULL;
+        hythread_create(&threads[i], 0, 0, 0, run_for_test_wait_signal, NULL);
+    }
+
+    // Wait till all tested threads call wait() 
+    while (1){
+        status = hythread_monitor_enter(monitor);
+        tf_assert_same(status, TM_ERROR_NONE);
+
+        if (waiting_count == NMB) break;
+
+        status = hythread_monitor_exit(monitor);
+        tf_assert_same(status, TM_ERROR_NONE);
+
+        jthread_sleep(100, 0);
+    }
+    status = hythread_monitor_exit(monitor);
+
+
+    // Send one signal per tested thread
+    for (i = 0; i < NMB; i++){
+        jthread_sleep(100, 0);
+
+        status = hythread_monitor_enter(monitor);
+        tf_assert_same(status, TM_ERROR_NONE);
+            
+        //hythread_monitor_notify_all(monitor);
+        hythread_monitor_notify(monitor);
+
+        status = hythread_monitor_exit(monitor);
+        tf_assert_same(status, TM_ERROR_NONE);
+    }
+    for (i = 0; i < NMB; i++){
+        jthread_sleep(100, 0);
+        hythread_join(threads[i]);
+    }
+    return 0;
+}
+
+void * APR_THREAD_FUNC run_for_test_apr_wait_signal(apr_thread_t *thread, void *args) {
+
+    apr_status_t status;
+
+    status = apr_thread_mutex_lock(mutex);
+    waiting_count ++;
+
+    status = apr_thread_cond_wait(condvar, mutex);
+
+    waiting_count --;
+    status = apr_thread_mutex_unlock(mutex);
+
+    printf("------ waiting_count = %i\n", waiting_count);
+
+    return NULL;
+}
+
+int test_apr_wait_signal(void){
+
+    apr_thread_t *threads[NMB];
+    apr_threadattr_t *apr_attrs = NULL;
+    apr_status_t status;
+    apr_pool_t *pool;
+    int i;
+    int all_are_waiting;
+
+    log_error("BUG IN APR");
+    tf_assert(0);
+    waiting_count = 0;
+    status = apr_pool_create(&pool, NULL);
+    status = apr_thread_mutex_create(&mutex, TM_MUTEX_NESTED, pool);
+    status = apr_thread_cond_create(&condvar, pool);
+
+    for (i = 0; i < NMB; i++){
+        threads[i] = NULL;
+        // Create APR thread
+        status = apr_thread_create(
+                                   &threads[i],// new thread OS handle 
+                                   apr_attrs,
+                                   run_for_test_apr_wait_signal, // start proc
+                                   NULL,                         //start proc arg 
+                                   pool
+                                   ); 
+    }
+    all_are_waiting = 0;
+    while (!all_are_waiting){
+        status = apr_thread_mutex_lock(mutex);
+        if (waiting_count == NMB) all_are_waiting = 1;
+        status = apr_thread_mutex_unlock(mutex);
+        jthread_sleep(100, 0);
+    }
+    for (i = 0; i < NMB; i++){
+        jthread_sleep(100, 0);
+        status = apr_thread_mutex_lock(mutex);
+        apr_thread_cond_signal(condvar);
+        status = apr_thread_mutex_unlock(mutex);
+    }
+
+    //status = apr_thread_mutex_lock(mutex);
+    //apr_thread_cond_broadcast(condvar);
+    //status = apr_thread_mutex_unlock(mutex);
+
+    for (i = 0; i < NMB; i++){
+        jthread_sleep(100, 0);
+        apr_thread_join(&status, threads[i]);
+    }
+    return 0;
+}
+
+TEST_LIST_START
+    TEST(test_wait_signal)
+    //TEST(test_apr_wait_signal)
+TEST_LIST_END;

Propchange: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_fat_monitor.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_suspend.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_suspend.c?rev=434076&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_suspend.c (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_suspend.c Wed Aug 23 09:48:41 2006
@@ -0,0 +1,139 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#include <stdio.h>
+#include "thread_private.h"
+#include <apr_pools.h>
+#include <apr_atomic.h>
+#include "testframe.h"
+#include <open/hythread_ext.h>
+#include "open/jthread.h"
+
+int start_proc(void *);
+
+int start_proc(void *args);
+int test_hythread_thread_suspend(void){
+    apr_pool_t *pool;
+    void **args; 
+    hythread_t thread = NULL;
+    hythread_thin_monitor_t lockword_ptr;
+    IDATA status;
+    int i;
+    apr_pool_create(&pool, NULL);
+
+    args = (void**) apr_palloc(pool, sizeof(void *) *3); 
+    
+    status = hythread_thin_monitor_create(&lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+
+    args[0] = &lockword_ptr;
+    args[1] = 0;
+    hythread_create(&thread, 0, 0, 0, start_proc, args);
+    hythread_sleep(500); 
+    hythread_suspend_other(thread);
+    hythread_suspend_disable();
+    status = hythread_thin_monitor_enter(&lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+    status = hythread_thin_monitor_notify_all(&lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+    status = hythread_thin_monitor_exit(&lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+    hythread_suspend_enable();
+    tf_assert_same(status, TM_ERROR_NONE);
+
+
+    for(i = 0; i < 100000; i++) {
+        tf_assert_same(args[1], 0);
+    }
+    
+    hythread_resume(thread);
+    
+    hythread_join(thread);
+    
+    tf_assert_same((int)args[1], 1);
+
+    return 0;
+}
+
+
+int test_hythread_thread_suspend_all(void){
+    apr_pool_t *pool;
+    void **args; 
+    hythread_t thread = NULL;
+    hythread_thin_monitor_t *lockword_ptr;
+    IDATA status;
+    int i;
+    apr_pool_create(&pool, NULL);
+
+    args = (void**) apr_palloc(pool, sizeof(void *) *3); 
+    lockword_ptr = (hythread_thin_monitor_t *) apr_palloc(pool, sizeof(hythread_thin_monitor_t)); 
+    status = hythread_thin_monitor_create(lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+
+    args[0] = lockword_ptr;
+    args[1] = 0;
+    for(i = 0; i < 10; i++) {
+        thread = NULL;
+        hythread_create(&thread, 0, 0, 0, start_proc, args);
+    } 
+    hythread_sleep(500); 
+    hythread_suspend_all(NULL, hythread_self()->group);
+    hythread_suspend_disable();
+    status = hythread_thin_monitor_enter(lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+    status = hythread_thin_monitor_notify_all(lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+    status = hythread_thin_monitor_exit(lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+    hythread_suspend_enable();
+    tf_assert_same(status, TM_ERROR_NONE);
+
+
+    for(i = 0; i < 100000; i++) {
+        tf_assert_same(args[1], 0);
+    }
+    
+    hythread_resume_all(hythread_self()->group);
+    
+    hythread_join(thread);
+    
+    tf_assert_same((int)args[1], 1);
+
+    return 0;
+}
+
+int start_proc(void *args) {
+    hythread_thin_monitor_t *lockword_ptr = (hythread_thin_monitor_t*)((void**)args)[0];
+    int *ret =  (int*)args+1;
+    IDATA status;
+        
+    //wait to start
+       hythread_suspend_disable();
+    status = hythread_thin_monitor_enter(lockword_ptr);
+    hythread_thin_monitor_wait(lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+    status = hythread_thin_monitor_exit(lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+    *ret =1;
+    hythread_suspend_enable();
+
+    return 0;
+}
+
+TEST_LIST_START
+    TEST(test_hythread_thread_suspend)
+    TEST(test_hythread_thread_suspend_all)
+TEST_LIST_END;

Propchange: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_suspend.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c?rev=434076&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c Wed Aug 23 09:48:41 2006
@@ -0,0 +1,200 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#include <stdio.h>
+#include "thread_private.h"
+#include <apr_pools.h>
+#include <apr_atomic.h>
+#include "testframe.h"
+#include "jthread.h"
+#include <open/hythread_ext.h>
+
+int start_proc(void *);
+/*
+ * Test hythread_thin_monitor_try_enter
+ */
+int test_hythread_thin_monitor_try_enter(void){
+    IDATA status;
+    hythread_thin_monitor_t lockword_ptr;
+    status = hythread_thin_monitor_create(&lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+    hythread_suspend_disable();
+    status = hythread_thin_monitor_try_enter(&lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+
+    status = hythread_thin_monitor_exit(&lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+    hythread_suspend_enable();
+    return 0;
+}
+
+/*
+ * Test hythread_thin_monitor_enter
+ */
+int test_hythread_thin_monitor_enter(void){
+    IDATA status;
+    hythread_thin_monitor_t lockword_ptr;
+    status = hythread_thin_monitor_create(&lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+    hythread_suspend_disable();
+    status = hythread_thin_monitor_enter(&lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+
+    status = hythread_thin_monitor_exit(&lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+    hythread_suspend_enable();
+    return 0;
+}
+
+/*
+ * Test hythread_thin_monitor timed wait timeout
+ */
+int test_hythread_thin_monitor_wait_timed(void){
+    IDATA status;
+    hythread_thin_monitor_t lockword_ptr;
+    status = hythread_thin_monitor_create(&lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+    hythread_suspend_disable();
+
+    status = hythread_thin_monitor_enter(&lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+
+    status = hythread_thin_monitor_wait_timed(&lockword_ptr, 1000,100);
+    tf_assert_same(status, TM_ERROR_TIMEOUT);
+    hythread_suspend_enable();
+
+    return 0;
+}
+
+/*
+ * Test hythread_thin_monitor timed wait returns TM_ERROR_ILLEGAL_STATE
+ */
+int test_hythread_thin_monitor_wait_timed_illegal(void){
+    IDATA status;
+    hythread_thin_monitor_t lockword_ptr;
+    status = hythread_thin_monitor_create(&lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+
+    status = hythread_thin_monitor_wait_timed(&lockword_ptr, 1000,100);
+    tf_assert_same(status, TM_ERROR_ILLEGAL_STATE);
+
+    return 0;
+}
+/*
+ * Test hythread_thin_monitor fat unlock
+ */
+int test_hythread_thin_monitor_fat_unlock(void){
+    IDATA status;
+    hythread_thin_monitor_t lockword_ptr;
+    status = hythread_thin_monitor_create(&lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+    hythread_suspend_disable();
+
+    status = hythread_thin_monitor_enter(&lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+
+    status = hythread_thin_monitor_wait_timed(&lockword_ptr, 1000,100);
+    printf("status: %d\n", status);
+    tf_assert_same(status, TM_ERROR_TIMEOUT);
+
+    status = hythread_thin_monitor_exit(&lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+    hythread_suspend_enable();
+    return 0;
+}
+
+int start_proc(void *args);
+int test_hythread_thin_monitor_enter_contended(void){
+    apr_pool_t *pool;
+    void **args; 
+    jthread_threadattr_t *attr;
+    hythread_t thread = NULL;
+    hythread_thin_monitor_t lockword_ptr;
+    IDATA status;
+    int i;
+    apr_pool_create(&pool, NULL);
+
+    args = (void**) apr_palloc(pool, sizeof(void *) *3); 
+    
+    status = hythread_thin_monitor_create(&lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+    hythread_suspend_disable();
+
+    status = hythread_thin_monitor_enter(&lockword_ptr);
+    hythread_suspend_enable();
+    tf_assert_same(status, TM_ERROR_NONE);
+
+    args[0] = &lockword_ptr;
+    args[1] = 0;
+    status = hythread_create(&thread, 0, 0, 0, start_proc, args);
+    tf_assert_same(status, TM_ERROR_NONE);
+    for(i = 0; i < 100000; i++) {
+        tf_assert_same(args[1], 0);
+    }
+    hythread_suspend_disable();
+    status = hythread_thin_monitor_exit(&lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+    hythread_suspend_enable();
+    hythread_join(thread);
+    
+    tf_assert_same((int)args[1], 1);
+    hythread_suspend_disable();
+    status = hythread_thin_monitor_enter(&lockword_ptr);
+    tf_assert_same(status, TM_ERROR_NONE);
+    args[1] = 0;
+    thread = NULL;
+    hythread_suspend_enable();    
+    status = hythread_create(&thread, 0, 0, 0, start_proc, args);
+    tf_assert_same(status, TM_ERROR_NONE);
+    for(i = 0; i < 100000; i++) {
+        tf_assert_same(args[1], 0);
+    }
+    hythread_suspend_disable();    
+    status = hythread_thin_monitor_exit(&lockword_ptr);
+    hythread_suspend_enable();
+    tf_assert_same(status, TM_ERROR_NONE);
+
+    hythread_join(thread);
+    
+    tf_assert_same((int)args[1], 1);
+
+    return 0;
+}
+
+int start_proc(void *args) {
+    hythread_thin_monitor_t *lockword_ptr = (hythread_thin_monitor_t*)((void**)args)[0];
+    int *ret =  (int*)args+1;
+    IDATA status;
+    hythread_suspend_disable();    
+    status = hythread_thin_monitor_enter(lockword_ptr);
+    hythread_suspend_enable();
+    tf_assert_same(status, TM_ERROR_NONE);
+    *ret =1;
+    hythread_suspend_disable();
+    status = hythread_thin_monitor_exit(lockword_ptr);
+    hythread_suspend_enable();
+    tf_assert_same(status, TM_ERROR_NONE);
+    return 0;
+}
+
+TEST_LIST_START
+    TEST(test_hythread_thin_monitor_enter)
+    TEST(test_hythread_thin_monitor_try_enter)
+    TEST(test_hythread_thin_monitor_wait_timed_illegal)
+    TEST(test_hythread_thin_monitor_wait_timed)
+    TEST(test_hythread_thin_monitor_fat_unlock)
+    TEST(test_hythread_thin_monitor_enter_contended)
+TEST_LIST_END;

Propchange: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_performance.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_performance.h?rev=434076&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_performance.h (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_performance.h Wed Aug 23 09:48:41 2006
@@ -0,0 +1,76 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Alexander Shipilov
+ * @version $Revision$
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include "testframe.h"
+#include "thread_unit_test_utils.h"
+#include "apr_time.h"
+#include "apr_pools.h"
+#include "apr_thread_cond.h"
+#include "apr_thread_proc.h"
+#include "apr_thread_mutex.h"
+#include "thread_private.h"
+
+/* 
+ * Number of iterations for each test
+ * PERF_FIDELITY ~ measurement_fidelity ~ 1/running_time
+ * Make sure that PERF_FIDELITY * ITERATIONS don't exceed threads limit
+ */
+int const PERF_FIDELITY = 10;
+
+/*
+ * Coefficient shows how much TMH performance could be worse than APR
+ */
+float const PERF_COEFFICIENT = 3;
+
+/*
+ * Locks for waiting
+ */
+hymutex_t tm_mutex_lock = NULL;
+hycond_t tm_condition_lock = NULL;
+apr_thread_mutex_t* apr_mutex_lock = NULL;
+apr_thread_cond_t* apr_condition_lock = NULL;
+
+/*
+* Locks for concurrent mutex tests
+*/
+hymutex_t tm_concurrent_mutex_lock = NULL;
+apr_thread_mutex_t* apr_concurrent_mutex_lock = NULL;
+
+/*
+* Data variable and iterations constant for concurrent mutex tests
+*/
+int concurrent_mutex_data = 1;
+int const concurrent_mutex_iterations = 1000;
+int const concurrent_mutex_iterations_few_threads = 150000;
+
+int check_result(int difference, int otherdiff) {
+    log_info("TMN result is: %i", difference/concurrent_mutex_iterations);
+    log_info("APR result is: %i", otherdiff/concurrent_mutex_iterations);
+    if (difference > (otherdiff * PERF_COEFFICIENT)) {
+        if (!(difference == 0 || otherdiff == 0)) {
+            return TEST_FAILED;
+        }
+    }
+    return TEST_PASSED;
+}

Propchange: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_performance.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_performance_basic.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_performance_basic.c?rev=434076&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_performance_basic.c (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_performance_basic.c Wed Aug 23 09:48:41 2006
@@ -0,0 +1,583 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Alexander Shipilov
+ * @version $Revision: 1.1.2.3 $
+ */
+
+#include "test_performance.h"
+
+int proc_empty(void *args) {
+    return 0;
+}
+
+void* APR_THREAD_FUNC proc_apr_empty(apr_thread_t *thread, void *args) {
+    return 0;
+}
+
+int proc_waiting(void *args) {
+    hymutex_lock(tm_mutex_lock);
+    hycond_wait(tm_condition_lock, tm_mutex_lock);
+    hymutex_unlock(tm_mutex_lock);
+    return 0;
+}
+
+void* APR_THREAD_FUNC proc_apr_waiting(apr_thread_t *thread, void *args) {
+    apr_thread_mutex_lock(apr_mutex_lock);
+    apr_thread_cond_wait(apr_condition_lock, apr_mutex_lock);
+    apr_thread_mutex_unlock(apr_mutex_lock);
+    return 0;
+}
+
+/*
+ * Test hythread_self()
+ */
+int test_hythread_self(void){
+
+    apr_time_t start, end;
+
+    long difference = 0, aprdiff = 0;
+
+    int i, j;
+    long ITERATIONS = 1500000;
+
+    hythread_t tm_native_thread;
+
+    apr_status_t statapr;
+
+    /* APR test */
+    tested_threads_run(default_run_for_test);
+    for (j = 0; j < PERF_FIDELITY; j++) {
+        start = apr_time_now();
+        for (i = 0; i < ITERATIONS; i++) {
+            statapr = apr_threadkey_private_get((void **)(&tm_native_thread), TM_THREAD_KEY);
+            assert(!statapr);
+        }
+        end = apr_time_now();
+        aprdiff = aprdiff + (end - start);
+    }
+    aprdiff = aprdiff / PERF_FIDELITY;
+    tested_threads_destroy();
+
+    /* Thread manager test */
+    tested_threads_run(default_run_for_test);
+    for (j = 0; j < PERF_FIDELITY; j++) {
+        start = apr_time_now();
+        for (i = 0; i < ITERATIONS; i++) {
+            tm_native_thread = hythread_self();
+        }
+        end = apr_time_now();
+        difference = difference + (end - start);
+    }
+    difference = difference / PERF_FIDELITY;
+    tested_threads_destroy();
+
+    return check_result(difference, aprdiff);
+}
+
+/*
+ * Test test_hymutex_create_destroy()
+ */
+int test_hymutex_create_destroy(void) {
+
+    apr_time_t start, end;
+    long difference = 0, aprdiff = 0;
+
+    int i, j;
+    long ITERATIONS = 15000;
+
+    apr_pool_t *pool;
+
+    IDATA stat;
+    apr_status_t statapr;
+
+    /* APR test */
+    tested_threads_run(default_run_for_test);
+    for (j = 0; j < PERF_FIDELITY; j++) {
+        start = apr_time_now();
+        for (i = 0; i < ITERATIONS; i++) {
+            statapr = apr_pool_create(&pool, NULL);
+            assert(!statapr);
+            statapr = apr_thread_mutex_create(&apr_mutex_lock, APR_THREAD_MUTEX_DEFAULT, pool);
+            assert(!statapr);
+            statapr = apr_thread_mutex_destroy(apr_mutex_lock);
+            assert(!statapr);
+            apr_pool_destroy(pool);
+        }
+        end = apr_time_now();
+        aprdiff = aprdiff + (end - start);
+    }
+    apr_mutex_lock = NULL;
+    aprdiff = aprdiff / PERF_FIDELITY;
+    tested_threads_destroy();
+
+    /* Thread manager test */
+    tested_threads_run(default_run_for_test);
+    for (j = 0; j < PERF_FIDELITY; j++) {
+        start = apr_time_now();
+        for (i = 0; i < ITERATIONS; i++) {
+            stat = hymutex_create(&tm_mutex_lock, APR_THREAD_MUTEX_DEFAULT);
+            assert(!stat);
+            stat = hymutex_destroy(tm_mutex_lock);
+            assert(!stat);
+        }
+        end = apr_time_now();
+        difference = difference + (end - start);
+    }
+    tm_mutex_lock = NULL;
+    difference = difference / PERF_FIDELITY;
+    tested_threads_destroy();
+
+    return check_result(difference, aprdiff);
+}
+
+/*
+ * Test test_hymutex_lock_unlock()
+ */
+int test_hymutex_lock_unlock(void) {
+
+    apr_time_t start, end;
+    long difference = 0, aprdiff = 0;
+
+    int i, j;
+    long ITERATIONS = 150000;
+
+    apr_pool_t *pool;
+
+    IDATA stat;
+    apr_status_t statapr;
+
+    /* APR test */
+    tested_threads_run(default_run_for_test);
+    statapr = apr_pool_create(&pool, NULL);
+    assert(!statapr);
+    statapr = apr_thread_mutex_create(&apr_mutex_lock, APR_THREAD_MUTEX_DEFAULT, pool);
+    assert(!statapr);
+    for (j = 0; j < PERF_FIDELITY; j++) {
+        start = apr_time_now();
+        for (i = 0; i < ITERATIONS; i++) {
+            statapr = apr_thread_mutex_lock(apr_mutex_lock);
+            assert(!statapr);
+            statapr = apr_thread_mutex_unlock(apr_mutex_lock);                      
+            assert(!statapr);
+        }
+        end = apr_time_now();
+        aprdiff = aprdiff + (end - start);
+    }
+    statapr = apr_thread_mutex_destroy(apr_mutex_lock);
+    assert(!statapr);
+    apr_pool_destroy(pool);
+    aprdiff = aprdiff / PERF_FIDELITY;
+    tested_threads_destroy();
+
+    /* Thread manager test */
+    tested_threads_run(default_run_for_test);
+    stat = hymutex_create(&tm_mutex_lock, APR_THREAD_MUTEX_DEFAULT);
+    assert(!stat);
+    for (j = 0; j < PERF_FIDELITY; j++) {
+        start = apr_time_now();
+        for (i = 0; i < ITERATIONS; i++) {
+            stat = hymutex_lock(tm_mutex_lock);
+            assert(!stat);
+            stat = hymutex_unlock(tm_mutex_lock);
+            assert(!stat);
+        }
+        end = apr_time_now();
+        difference = difference + (end - start);
+    }
+    stat = hymutex_destroy(tm_mutex_lock);
+    assert(!stat);
+    difference = difference / PERF_FIDELITY;
+    tested_threads_destroy();
+
+    return check_result(difference, aprdiff);
+}
+
+/*
+ * Test test_hymutex_trylock_unlock()
+ */
+int test_hymutex_trylock_unlock(void) {
+
+    apr_time_t start, end;
+    long difference = 0, aprdiff = 0;
+
+    int i, j;
+    long ITERATIONS = 150000;
+
+    apr_pool_t *pool;
+
+    IDATA stat;
+    apr_status_t statapr;
+
+    /* APR test */
+    tested_threads_run(default_run_for_test);
+    statapr = apr_pool_create(&pool, NULL);
+    assert(!statapr);
+    statapr = apr_thread_mutex_create(&apr_mutex_lock, APR_THREAD_MUTEX_DEFAULT, pool);
+    assert(!statapr);
+    for (j = 0; j < PERF_FIDELITY; j++) {
+        start = apr_time_now();
+        for (i = 0; i < ITERATIONS; i++) {
+            statapr = apr_thread_mutex_trylock(apr_mutex_lock);
+            assert(!statapr);
+            statapr = apr_thread_mutex_unlock(apr_mutex_lock);                      
+            assert(!statapr);
+        }
+        end = apr_time_now();
+        aprdiff = aprdiff + (end - start);
+    }
+    statapr = apr_thread_mutex_destroy(apr_mutex_lock);
+    assert(!statapr);
+    apr_pool_destroy(pool);
+    aprdiff = aprdiff / PERF_FIDELITY;
+    tested_threads_destroy();
+
+    /* Thread manager test */
+    tested_threads_run(default_run_for_test);
+    stat = hymutex_create(&tm_mutex_lock, APR_THREAD_MUTEX_DEFAULT);
+    assert(!stat);
+    for (j = 0; j < PERF_FIDELITY; j++) {
+        start = apr_time_now();
+        for (i = 0; i < ITERATIONS; i++) {
+            stat = hymutex_trylock(tm_mutex_lock);
+            assert(!stat);
+            stat = hymutex_unlock(tm_mutex_lock);
+            assert(!stat);
+        }
+        end = apr_time_now();
+        difference = difference + (end - start);
+    }
+    stat = hymutex_destroy(tm_mutex_lock);
+    assert(!stat);
+    difference = difference / PERF_FIDELITY;
+    tested_threads_destroy();
+
+    return check_result(difference, aprdiff);
+}
+
+/*
+ * Test test_hythread_create()
+ */
+int test_hythread_create(void) {
+
+    apr_time_t start, end;
+    long difference = 0, aprdiff = 0;
+
+    int i, j;
+    long ITERATIONS = 300;
+
+    int OTHER_FIDELITY;
+    int const MAX_THREADS = 1000;
+
+    hythread_t thread = NULL;
+    void *args = NULL;
+    apr_thread_t *apr_thread = NULL;
+    apr_threadattr_t *apr_attrs = NULL;
+    apr_pool_t *pool;
+
+    IDATA stat;
+    apr_status_t statapr;
+
+    if ((ITERATIONS * PERF_FIDELITY) > MAX_THREADS) {
+        OTHER_FIDELITY = (MAX_THREADS / ITERATIONS);
+    } else {
+        OTHER_FIDELITY = PERF_FIDELITY;
+    }
+
+    /* APR test */
+    tested_threads_run(default_run_for_test);
+    for (j = 0; j < OTHER_FIDELITY; j++) {
+        start = apr_time_now();
+        for (i = 0; i < ITERATIONS; i++) {
+            statapr = apr_pool_create(&pool, NULL);
+            assert(!statapr);
+            statapr = apr_thread_create(&apr_thread, apr_attrs, proc_apr_empty, args, pool);
+            apr_thread_join(&statapr, apr_thread);
+            assert(!statapr);
+            assert(!statapr);
+            apr_pool_destroy(pool);
+        }
+        end = apr_time_now();
+        aprdiff = aprdiff + (end - start);
+    }
+    aprdiff = aprdiff / OTHER_FIDELITY;
+    tested_threads_destroy();
+
+    /* Thread manager test */
+    tested_threads_run(default_run_for_test);
+    for (j = 0; j < OTHER_FIDELITY; j++) {
+        start = apr_time_now();
+        for (i = 0; i < ITERATIONS; i++) {
+            thread = NULL;
+            stat = hythread_create(&thread, 0, 0, 0, proc_empty, args);
+            assert(!stat);
+            stat = hythread_join(thread);
+            assert(!stat);
+        }
+        end = apr_time_now();
+        difference = difference + (end - start);
+    }
+    difference = difference / OTHER_FIDELITY;
+    tested_threads_destroy();
+
+    return check_result(difference, aprdiff);
+}
+
+/*
+* Test test_hythread_thread_suspend_enable_disable()
+*/
+int test_hythread_thread_suspend_enable_disable(void) {
+
+    apr_time_t start, end;
+    long difference = 0, aprdiff = 0;
+
+    int i, j;
+    long ITERATIONS = 1500000;
+
+    apr_status_t statapr;
+
+    hythread_t tm_native_thread;
+
+    /* APR test */
+    tested_threads_run(default_run_for_test);
+    for (j = 0; j < PERF_FIDELITY; j++) {
+        start = apr_time_now();
+        for (i = 0; i < ITERATIONS; i++) {
+            statapr = apr_threadkey_private_get((void **)(&tm_native_thread), TM_THREAD_KEY);
+            assert(!statapr);
+            statapr = apr_threadkey_private_set((void *)(tm_native_thread), TM_THREAD_KEY);
+            assert(!statapr);
+        }
+        end = apr_time_now();
+        aprdiff = aprdiff + (end - start);
+    }
+    aprdiff = aprdiff / PERF_FIDELITY;
+    tested_threads_destroy();
+
+    /* Thread manager test */
+    tested_threads_run(default_run_for_test);
+    for (j = 0; j < PERF_FIDELITY; j++) {
+        start = apr_time_now();
+        for (i = 0; i < ITERATIONS; i++) {
+            hythread_suspend_disable();
+            hythread_suspend_enable();
+        }
+        end = apr_time_now();
+        difference = difference + (end - start);
+    }
+    difference = difference / PERF_FIDELITY;
+    tested_threads_destroy();
+
+    return check_result(difference, aprdiff);
+}
+
+/*
+* Test test_hythread_set_private_data()
+*/
+int test_hythread_set_private_data(void) {
+
+    apr_time_t start, end;
+    long difference = 0, aprdiff = 0;
+
+    int i, j;
+    long ITERATIONS = 1000000;
+
+    hythread_t thread = NULL;
+    void *args = NULL;
+    void *data = NULL;
+    apr_thread_t *apr_thread = NULL;
+    apr_threadattr_t *apr_attrs = NULL;
+
+    apr_pool_t *pool;
+    apr_pool_t *locks_pool;
+
+    IDATA stat;
+    apr_status_t statapr;
+
+    /* APR test */
+    tested_threads_run(default_run_for_test);
+    // Create pools, locks and thread
+    statapr = apr_pool_create(&pool, NULL);
+    assert(!statapr);
+    statapr = apr_pool_create(&locks_pool, NULL);
+    assert(!statapr);
+    statapr = apr_thread_cond_create(&apr_condition_lock, locks_pool);
+    assert(!statapr);
+    statapr = apr_thread_mutex_create(&apr_mutex_lock, APR_THREAD_MUTEX_DEFAULT, locks_pool);
+    assert(!statapr);
+    statapr = apr_thread_create(&apr_thread, apr_attrs, proc_apr_waiting, args, pool);
+    assert(!statapr);
+    for (j = 0; j < PERF_FIDELITY; j++) {
+        start = apr_time_now();
+        for (i = 0; i < ITERATIONS; i++) {
+            stat = apr_thread_data_set(data, "DATA", 0, apr_thread);
+            assert(!stat);
+        }
+        end = apr_time_now();
+        aprdiff = aprdiff + (end - start);
+    }
+    statapr = apr_thread_cond_signal(apr_condition_lock);
+    assert(!statapr);
+    apr_thread_join(&statapr, apr_thread);
+    assert(!statapr);
+    statapr = apr_thread_mutex_destroy(apr_mutex_lock);
+    assert(!statapr);
+    statapr = apr_thread_cond_destroy(apr_condition_lock);
+    assert(!statapr);
+    apr_pool_destroy(locks_pool);
+    apr_pool_destroy(pool);
+    aprdiff = aprdiff / PERF_FIDELITY;
+    tested_threads_destroy();
+
+    /* Thread manager test */
+    tested_threads_run(default_run_for_test);
+    // Create locks and thread
+    stat = hycond_create(&tm_condition_lock);
+    assert(!stat);
+    stat = hymutex_create(&tm_mutex_lock, APR_THREAD_MUTEX_DEFAULT);
+    assert(!stat);
+    stat = hythread_create(&thread, 0, 0, 0, proc_waiting, args);
+    assert(!stat);
+    for (j = 0; j < PERF_FIDELITY; j++) {
+        start = apr_time_now();
+        for (i = 0; i < ITERATIONS; i++) {
+            stat = hythread_set_private_data(thread, data);
+            assert(!stat);
+        }
+        end = apr_time_now();
+        difference = difference + (end - start);
+    }
+    stat = hycond_notify(tm_condition_lock);
+    assert(!stat);
+    stat = hythread_join(thread);
+    assert(!stat);
+    stat = hymutex_destroy(tm_mutex_lock);
+    assert(!stat);
+    stat = hycond_destroy(tm_condition_lock);
+    assert(!stat);
+    difference = difference / PERF_FIDELITY;
+    tested_threads_destroy();
+
+    return check_result(difference, aprdiff);
+}
+
+/*
+* Test test_hythread_get_private_data()
+*/
+int test_hythread_get_private_data(void) {
+
+    apr_time_t start, end;
+    long difference = 0, aprdiff = 0;
+
+    int i, j;
+    long ITERATIONS = 1000000;
+
+    hythread_t thread = NULL;
+    void *args = NULL;
+    void *data = NULL;
+    apr_thread_t *apr_thread = NULL;
+    apr_threadattr_t *apr_attrs = NULL;
+
+    apr_pool_t *pool;
+    apr_pool_t *locks_pool;
+
+    IDATA stat;
+    apr_status_t statapr;
+
+    /* APR test */
+    tested_threads_run(default_run_for_test);
+    // Create pools, locks and thread
+    statapr = apr_pool_create(&pool, NULL);
+    assert(!statapr);
+    statapr = apr_pool_create(&locks_pool, NULL);
+    assert(!statapr);
+    statapr = apr_thread_cond_create(&apr_condition_lock, locks_pool);
+    assert(!statapr);
+    statapr = apr_thread_mutex_create(&apr_mutex_lock, APR_THREAD_MUTEX_DEFAULT, locks_pool);
+    assert(!statapr);
+    statapr = apr_thread_create(&apr_thread, apr_attrs, proc_apr_waiting, args, pool);
+    assert(!statapr);
+    // Set private data
+    stat = apr_thread_data_set(data, "DATA", 0, apr_thread);
+    assert(!stat);
+    for (j = 0; j < PERF_FIDELITY; j++) {
+        start = apr_time_now();
+        for (i = 0; i < ITERATIONS; i++) {
+            stat = apr_thread_data_get(&data, "DATA", apr_thread);
+            assert(!stat);
+        }
+        end = apr_time_now();
+        aprdiff = aprdiff + (end - start);
+    }
+    statapr = apr_thread_cond_signal(apr_condition_lock);
+    assert(!statapr);
+    apr_thread_join(&statapr, apr_thread);
+    assert(!statapr);
+    statapr = apr_thread_mutex_destroy(apr_mutex_lock);
+    assert(!statapr);
+    statapr = apr_thread_cond_destroy(apr_condition_lock);
+    assert(!statapr);
+    apr_pool_destroy(locks_pool);
+    apr_pool_destroy(pool);
+    aprdiff = aprdiff / PERF_FIDELITY;
+    tested_threads_destroy();
+
+    /* Thread manager test */
+    tested_threads_run(default_run_for_test);
+    // Create locks and thread
+    stat = hycond_create(&tm_condition_lock);
+    assert(!stat);
+    stat = hymutex_create(&tm_mutex_lock, APR_THREAD_MUTEX_DEFAULT);
+    assert(!stat);
+    stat = hythread_create(&thread, 0, 0, 0, proc_waiting, args);
+    assert(!stat);
+    // Set private data
+    stat = hythread_set_private_data(thread, data);
+    assert(!stat);
+    for (j = 0; j < PERF_FIDELITY; j++) {
+        start = apr_time_now();
+        for (i = 0; i < ITERATIONS; i++) {
+            data = hythread_get_private_data(thread);
+            assert(!stat);
+        }
+        end = apr_time_now();
+        difference = difference + (end - start);
+    }
+    stat = hycond_notify(tm_condition_lock);
+    assert(!stat);
+    stat = hythread_join(thread);
+    assert(!stat);
+    stat = hymutex_destroy(tm_mutex_lock);
+    assert(!stat);
+    stat = hycond_destroy(tm_condition_lock);
+    assert(!stat);
+    difference = difference / PERF_FIDELITY;
+    tested_threads_destroy();
+
+    return check_result(difference, aprdiff);
+}
+
+TEST_LIST_START
+    TEST(test_hythread_self)
+    TEST(test_hymutex_create_destroy)
+    TEST(test_hymutex_lock_unlock)
+    TEST(test_hymutex_trylock_unlock)
+    TEST(test_hythread_create)
+    TEST(test_hythread_thread_suspend_enable_disable)
+    TEST(test_hythread_set_private_data)
+    TEST(test_hythread_get_private_data)
+TEST_LIST_END;

Propchange: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_performance_basic.c
------------------------------------------------------------------------------
    svn:eol-style = native