harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r607049 - in /harmony/enhanced/drlvm/trunk/vm/tests/unit/thread: test_native_basic.c test_native_fat_monitor.c test_native_suspend.c test_native_thin_monitor.c utils/thread_unit_test_utils.c utils/thread_unit_test_utils.h
Date Thu, 27 Dec 2007 12:21:06 GMT
Author: gshimansky
Date: Thu Dec 27 04:21:05 2007
New Revision: 607049

URL: http://svn.apache.org/viewvc?rev=607049&view=rev
Log:
Applied tests patch from HARMONY-5349
[drlvm][thread] Thread.join() refactoring


Modified:
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_fat_monitor.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_suspend.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c?rev=607049&r1=607048&r2=607049&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c Thu Dec 27 04:21:05
2007
@@ -17,48 +17,88 @@
 
 #include <stdio.h>
 #include "testframe.h"
+#include "thread_unit_test_utils.h"
 #include "thread_manager.h"
 
-int start_proc(void *);
-int start_proc_empty(void *);
+
+typedef struct proc_param {
+    hythread_group_t group;
+    UDATA stacksize;
+    jint priority;
+    hylatch_t start;
+    hylatch_t end;
+} proc_param;
+
+
+static int start_proc(void *args) {
+    proc_param *attrs = (proc_param *)args;
+    tf_assert_same(hythread_get_priority(hythread_self()), attrs->priority);
+    tf_assert_same(hythread_self()->group, attrs->group);
+    hylatch_count_down(attrs->end);
+    return 0;
+} // start_proc
+
+static int start_proc_empty(void *args) {
+    proc_param *attrs = (proc_param *)args;
+    hylatch_count_down(attrs->start);
+    hylatch_wait(attrs->end);
+    return 0;
+} // start_proc_empty
+
 
 int test_hythread_self_base(void) {
     hythread_t thread;
-    //check that this thread is attached(tm_init called)
-    ////
+
+    // check that this thread is attached to VM
     tf_assert(thread = hythread_self());
-   
-    return 0; 
-}
+
+    return 0;
+} // test_hythread_self_base
 
 /*
- * Test tm_create(..)
- */
-int test_hythread_create(void){
-    void **args; 
+* Test tm_create(..)
+*/
+int test_hythread_create(void) {
+    proc_param *args;
     hythread_t thread;
-    IDATA res;
-    
-    args = (void**)calloc(2, sizeof(void *));
-    
-    hythread_group_create((hythread_group_t *)&args[0]); 
-    
-    args[1] = calloc(1, sizeof(struct jthread_start_proc_data));
-    ((jthread_start_proc_data_t)args[1])->stacksize = 1024000;
-    ((jthread_start_proc_data_t)args[1])->priority  = 1;
-    
+    IDATA status;
+
+    args = (proc_param*)calloc(1, sizeof(proc_param));
+    tf_assert(args && "alloc proc_params failed");
+
+    status = hythread_group_create(&args->group);
+    tf_assert(status == TM_ERROR_NONE && "thread group creation failed");
+
+    status = hylatch_create(&args->end, 1);
+    tf_assert(status == TM_ERROR_NONE && "latch creation failed");
+
+    args->priority  = 1;
+
     thread = (hythread_t)calloc(1, hythread_get_struct_size());
     assert(thread);
-    res = hythread_create_ex(thread, args[0], 1024000, 1, NULL,
-        (hythread_entrypoint_t)start_proc, args);
-    tf_assert(res == TM_ERROR_NONE && "thread creation failed");
+    status = hythread_create_ex(thread, args->group, 1024000, 1, NULL,
+        (hythread_entrypoint_t)start_proc, (void*)args);
+    tf_assert(status == TM_ERROR_NONE && "thread creation failed");
+
+    // Wait util tested thread have finished.
+    status = hylatch_wait(args->end);
+    tf_assert(status == TM_ERROR_NONE && "thread finished failed");
+
+    status = hylatch_destroy(args->end);
+    tf_assert(status == TM_ERROR_NONE && "latch destroy failed");
+
+    hythread_sleep(SLEEP_TIME);
+    hythread_group_release(args->group);
+
+    free(args);
 
-    res = hythread_join(thread);
-    tf_assert(res == TM_ERROR_NONE && "thread join failed");
     return TEST_PASSED;
 }
 
-// Waits until count of running threads in specified group reaches 'count' or less
+/**
+* Waits until count of running threads in specified group
+* reaches 'count' or less
+*/
 static void wait_for_all_treads_are_terminated(hythread_group_t group, int count)
 {
     int max_tries = 1000; // Maximum count of iterations
@@ -70,8 +110,7 @@
 
         hythread_iterator_t iterator = hythread_iterator_create(group);
 
-        while(hythread_iterator_has_next(iterator))
-        {
+        while(hythread_iterator_has_next(iterator)) {
             thread = hythread_iterator_next(&iterator);
 
             if (!hythread_is_terminated(thread))
@@ -83,155 +122,202 @@
         if (n <= count)
             break;
 
-        hythread_sleep(1); // 1ms
+        hythread_yield();
     }
 
-    hythread_sleep(100);// 0.1s to let system threads finish their work
-}
-
-hylatch_t start;
-hylatch_t end;
+    // 0.1s to let system threads finish their work
+    hythread_sleep(100);
+} // wait_for_all_treads_are_terminated
 
 int test_hythread_iterator(void) {
-    hythread_group_t group = NULL;
+    int i;
+    const int n = 100;
+    IDATA status;
+    proc_param *args;
     hythread_t thread = NULL;
     hythread_iterator_t iterator;
-    const int n = 100;
-    int i;
 
-    hythread_group_create(&group);
-    hylatch_create(&start, n);
-    hylatch_create(&end, 1);
+    args = (proc_param*)calloc(1, sizeof(proc_param));
+    tf_assert(args && "alloc proc_params failed");
+
+    status = hythread_group_create(&args->group);
+    tf_assert(status == TM_ERROR_NONE && "create group failed");
+
+    status = hylatch_create(&args->start, n);
+    tf_assert(status == TM_ERROR_NONE && "latch creation failed");
+
+    status = hylatch_create(&args->end, 1);
+    tf_assert(status == TM_ERROR_NONE && "latch creation failed");
 
     for (i = 0; i < n; i++) {
-        IDATA status;
         thread = (hythread_t)calloc(1, hythread_get_struct_size());
         assert(thread);
-        status = hythread_create_ex(thread, group, 0, 0, NULL,
-            (hythread_entrypoint_t)start_proc_empty, NULL);
-        tf_assert_same(status, TM_ERROR_NONE);
+        status = hythread_create_ex(thread, args->group, 0, 0, NULL,
+            (hythread_entrypoint_t)start_proc_empty, (void*)args);
+        tf_assert(status == TM_ERROR_NONE && "test thread creation failed");
     }
 
     // Wait util all threads have started.
-    hylatch_wait(start);
-    iterator = hythread_iterator_create(group);
-    // Notify all threads
-    hylatch_count_down(end);
+    status = hylatch_wait(args->start);
+    tf_assert(status == TM_ERROR_NONE && "start waiting failed");
+
+    iterator = hythread_iterator_create(args->group);
+    tf_assert(iterator && "interator creation failed");
 
     printf ("iterator size: %d\n", (int)hythread_iterator_size(iterator));
-    tf_assert(hythread_iterator_size(iterator) == n);
+    tf_assert(hythread_iterator_size(iterator) == n && "iterator size");
+
     i = 0;
     while(hythread_iterator_has_next(iterator)) {
         i++;
         thread = hythread_iterator_next(&iterator);
-        tf_assert(hythread_is_alive(thread));
+        tf_assert(hythread_is_alive(thread) && "thread is not alive!");
     }
 
-    tf_assert(i == n);
+    tf_assert(i == n && "wrong number of tested threads");
 
-    hythread_iterator_release(&iterator);
+    status = hythread_iterator_release(&iterator);
+    tf_assert(status == TM_ERROR_NONE && "release iterator failed");
 
-    wait_for_all_treads_are_terminated(group, i - n);
+    // Notify all threads
+    status = hylatch_count_down(args->end);
+    tf_assert(status == TM_ERROR_NONE && "all threads notify failed");
 
-    return 0;
-}
+    wait_for_all_treads_are_terminated(args->group, i - n);
+
+    status = hylatch_destroy(args->start);
+    tf_assert(status == TM_ERROR_NONE && "start latch destroy failed");
+
+    status = hylatch_destroy(args->end);
+    tf_assert(status == TM_ERROR_NONE && "end latch destroy failed");
+
+    hythread_sleep(SLEEP_TIME);
+    hythread_group_release(args->group);
+
+    free(args);
+
+    return TEST_PASSED;
+} // test_hythread_iterator
 
 int test_hythread_iterator_default(void) {
+    int i;
+    const int n = 100;
+    IDATA status;
+    proc_param *args;
     hythread_t thread = NULL;
     hythread_iterator_t iterator;
-    const int n = 100;
-    int i;
 
-    hylatch_create(&start, n);
-    hylatch_create(&end, 1);
+    args = (proc_param*)calloc(1, sizeof(proc_param));
+    tf_assert(args && "alloc proc_params failed");
+
+    status = hylatch_create(&args->start, n);
+    tf_assert(status == TM_ERROR_NONE && "latch creation failed");
+
+    status = hylatch_create(&args->end, 1);
+    tf_assert(status == TM_ERROR_NONE && "latch creation failed");
 
     for (i = 0; i < n; i++) {
-        IDATA status;
         status = hythread_create(NULL, 0, 0, 0,
-            (hythread_entrypoint_t)start_proc_empty, NULL);
-        tf_assert_same(status, TM_ERROR_NONE);
+            (hythread_entrypoint_t)start_proc_empty, (void*)args);
+        tf_assert(status == TM_ERROR_NONE && "test thread creation failed");
     }
 
     // Wait util all threads have started.
-    hylatch_wait(start);
-    iterator = hythread_iterator_create(NULL);
-    // Notify all threads
-    hylatch_count_down(end);
+    status = hylatch_wait(args->start);
+    tf_assert(status == TM_ERROR_NONE && "start waiting failed");
+
+    iterator = hythread_iterator_create(args->group);
+    tf_assert(iterator && "interator creation failed");
+
+    printf ("default group iterator size: %d\n", (int)hythread_iterator_size(iterator));
+    tf_assert(hythread_iterator_size(iterator) >= n && "iterator size");
 
-    printf("default group iterator: %d\n", (int)hythread_iterator_size(iterator));
-    tf_assert(hythread_iterator_size(iterator) >= n);
     i = 0;
     while(hythread_iterator_has_next(iterator)) {
-        i++;
         thread = hythread_iterator_next(&iterator);
+        if (hythread_is_alive(thread)) {
+            i++;
+        }
     }
+    tf_assert(i >= n && "wrong number of tested threads");
 
-    tf_assert(i >= n);
+    status = hythread_iterator_release(&iterator);
+    tf_assert(status == TM_ERROR_NONE && "release iterator failed");
 
-    hythread_iterator_release(&iterator);
+    // Notify all threads
+    status = hylatch_count_down(args->end);
+    tf_assert(status == TM_ERROR_NONE && "all threads notify failed");
 
     wait_for_all_treads_are_terminated(NULL, i - n);
 
-    return 0;
-}
+    status = hylatch_destroy(args->start);
+    tf_assert(status == TM_ERROR_NONE && "start latch destroy failed");
 
+    status = hylatch_destroy(args->end);
+    tf_assert(status == TM_ERROR_NONE && "end latch destroy failed");
 
+    free(args);
+
+    return TEST_PASSED;
+} // test_hythread_iterator_default
 
 /*
- * Test tm_create(..)
- */
+* Test tm_create(..)
+*/
 int test_hythread_create_many(void){
-    void **args; 
-    hythread_t thread = NULL;
-    hythread_group_t group = NULL;
-    IDATA res;
-    int i = 10;
-    
-    hythread_group_create(&group);
-    while(i--) {
-        args = (void**)calloc(2, sizeof(void *));
-    
-        args[0] = group; 
-        
-        args[1] = calloc(1, sizeof(struct jthread_start_proc_data));
-        ((jthread_start_proc_data_t)args[1])->stacksize = 1024000;
-        ((jthread_start_proc_data_t)args[1])->priority  = 1;
-        
+    int i;
+    const int n = 10;
+    IDATA status;
+    proc_param *args;
+    hythread_t thread;
+
+    args = (proc_param*)calloc(1, sizeof(proc_param));
+    tf_assert(args && "alloc proc_params failed");
+
+    status = hythread_group_create(&args->group);
+    tf_assert(status == TM_ERROR_NONE && "create group failed");
+
+    status = hylatch_create(&args->start, n);
+    tf_assert(status == TM_ERROR_NONE && "latch creation failed");
+
+    status = hylatch_create(&args->end, 1);
+    tf_assert(status == TM_ERROR_NONE && "latch creation failed");
+
+    for (i = 0; i < n; i++) {
         thread = (hythread_t)calloc(1, hythread_get_struct_size());
         assert(thread);
-        res = hythread_create_ex(thread, group, 1024000, 1, NULL,
-            (hythread_entrypoint_t)start_proc, args);
-        tf_assert(res == TM_ERROR_NONE && "thread creation failed");
-        res = hythread_join(thread);
-        tf_assert(res == TM_ERROR_NONE && "thread join failed");
-    }
-
-    //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 == 0);
+        status = hythread_create_ex(thread, args->group, 0, 0, NULL,
+            (hythread_entrypoint_t)start_proc_empty, (void*)args);
+        tf_assert(status == TM_ERROR_NONE && "test thread creation failed");
+    }
 
-    return 0;
-}
+    // Wait util all threads have started.
+    status = hylatch_wait(args->start);
+    tf_assert(status == TM_ERROR_NONE && "start waiting failed");
 
-int start_proc(void *args) {
-    void** attrs = (void **)args; 
-    tf_assert_same(hythread_get_priority(hythread_self()), ((jthread_start_proc_data_t)attrs[1])->priority);
-    tf_assert_same(((HyThread_public*)hythread_self())->group, attrs[0]);
-    return 0;
-}
+    // huck to get group_count from hythread_group_t structure
+    i = hythread_iterator_size((hythread_iterator_t)thread);
+    tf_assert(i == n && "incorrect threads count");
 
-int start_proc_empty(void *args) {
-    hylatch_count_down(start);
-    hylatch_wait(end);
-    return 0;
-}
+    // Notify all threads
+    status = hylatch_count_down(args->end);
+    tf_assert(status == TM_ERROR_NONE && "all threads notify failed");
+
+    wait_for_all_treads_are_terminated(args->group, i - n);
+
+    status = hylatch_destroy(args->start);
+    tf_assert(status == TM_ERROR_NONE && "start latch destroy failed");
+
+    status = hylatch_destroy(args->end);
+    tf_assert(status == TM_ERROR_NONE && "end latch destroy failed");
+
+    hythread_sleep(SLEEP_TIME);
+    hythread_group_release(args->group);
+
+    free(args);
+
+    return TEST_PASSED;
+} // test_hythread_create_many
 
 TEST_LIST_START
     TEST(test_hythread_self_base)

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_fat_monitor.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_fat_monitor.c?rev=607049&r1=607048&r2=607049&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_fat_monitor.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_fat_monitor.c Thu Dec 27
04:21:05 2007
@@ -16,8 +16,9 @@
  */
 
 #include "thread_manager.h"
-#include "testframe.h"
 #include <open/hythread_ext.h>
+#include "testframe.h"
+#include "thread_unit_test_utils.h"
 
 #define NMB 5
 
@@ -73,14 +74,14 @@
         status = hythread_monitor_exit(monitor);
         tf_assert_same(status, TM_ERROR_NONE);
 
-        hythread_sleep(100);
+        hythread_sleep(SLEEP_TIME);
     }
     status = hythread_monitor_exit(monitor);
 
 
     // Send one signal per tested thread
     for (i = 0; i < NMB; i++){
-        jthread_sleep(100, 0);
+        hythread_sleep(SLEEP_TIME);
 
         status = hythread_monitor_enter(monitor);
         tf_assert_same(status, TM_ERROR_NONE);
@@ -92,8 +93,7 @@
         tf_assert_same(status, TM_ERROR_NONE);
     }
     for (i = 0; i < NMB; i++){
-        hythread_sleep(100);
-        hythread_join(threads[i]);
+        test_thread_join(threads[i], i);
     }
     return 0;
 }

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_suspend.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_suspend.c?rev=607049&r1=607048&r2=607049&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_suspend.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_suspend.c Thu Dec 27 04:21:05
2007
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <open/hythread_ext.h>
 #include "testframe.h"
+#include "thread_unit_test_utils.h"
 #include "thread_manager.h"
 
 int started_thread_count;
@@ -85,8 +86,7 @@
     // resume thread
     hythread_resume(thread);
 
-    status = hythread_join(thread);
-    tf_assert_same(status, TM_ERROR_NONE);
+    test_thread_join(thread, 1);
     
     tf_assert_same((IDATA)args[2], 1);
 
@@ -170,8 +170,7 @@
     log_info("resume all suspended threads");
 
     for(i = 0; i < THREAD_COUNT; i++) {
-        status = hythread_join(thread_list[i]);
-        tf_assert_same(status, TM_ERROR_NONE);
+        test_thread_join(thread_list[i], i);
         log_info("%d thread is terminated", i + 1);
     }
 

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c?rev=607049&r1=607048&r2=607049&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c Thu Dec 27
04:21:05 2007
@@ -16,8 +16,9 @@
  */
 
 #include <stdio.h>
-#include "testframe.h"
 #include <open/hythread_ext.h>
+#include "testframe.h"
+#include "thread_unit_test_utils.h"
 
 int start_proc(void *);
 /*
@@ -143,7 +144,7 @@
     status = hythread_thin_monitor_exit(&lockword_ptr);
     tf_assert_same(status, TM_ERROR_NONE);
     hythread_suspend_enable();
-    hythread_join(thread);
+    test_thread_join(thread, 1);
     
     tf_assert_same((IDATA)args[1], 1);
     hythread_suspend_disable();
@@ -162,7 +163,7 @@
     hythread_suspend_enable();
     tf_assert_same(status, TM_ERROR_NONE);
 
-    hythread_join(thread);
+    test_thread_join(thread, 1);
     
     tf_assert_same((IDATA)args[1], 1);
 

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c?rev=607049&r1=607048&r2=607049&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c Thu Dec
27 04:21:05 2007
@@ -393,14 +393,21 @@
 }
 
 void tested_thread_wait_dead(tested_thread_sturct_t *tts) {
-    int i;
-     
-    i = 0;
-    while (hythread_join_timed(tts->native_thread, MAX_TIME_TO_WAIT, 0) == TM_ERROR_TIMEOUT)
{
-        i++;
-        printf("Thread %i isn't dead after %i milliseconds", 
-            tts->my_index, (i * MAX_TIME_TO_WAIT));
-    }
+    test_thread_join(tts->native_thread, tts->my_index);
+}
+
+void test_thread_join(hythread_t native_thread, int index) {
+    int i = 0;
+    do {
+        hythread_sleep(SLEEP_TIME);
+        if(!hythread_is_alive(native_thread)) {
+            break;
+        }
+        if ((i % (MAX_TIME_TO_WAIT / SLEEP_TIME)) == 0) {
+            printf("Thread %i isn't dead after %i milliseconds",
+                index, (++i * SLEEP_TIME));
+        }
+    } while(1);
 }
 
 int compare_threads(jthread *threads, int thread_nmb, int compare_from_end) {

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h?rev=607049&r1=607048&r2=607049&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h Thu Dec
27 04:21:05 2007
@@ -113,6 +113,7 @@
 void tested_thread_wait_running(tested_thread_sturct_t *tts);
 void tested_thread_wait_ended(tested_thread_sturct_t *tts);
 void tested_thread_wait_dead(tested_thread_sturct_t *tts);
+void test_thread_join(hythread_t native_thread, int index);
 
 int compare_threads(jthread *threads, int thread_nmb, int compare_from_end);
 int compare_pointer_sets(void ** set_a, void ** set_b, int nmb);



Mime
View raw message