From b32ecb917d39e148d34956c9a8ca7ef35dab41c2 Mon Sep 17 00:00:00 2001 From: Salikh Zakirov Date: Thu, 15 Mar 2007 20:00:18 +0300 Subject: [PATCH] Fix cunit tests to pass a valid stack size attribute APR thread creation function somehow didn't return error code when passed an invalid stack size attribute. However, pthread_create returns EINVAL if requested stack size is 1024. This patch fixes the test_native_basic test: 1) to request a sane stack size (1024000) 2) to check an error code returned by thread creation code to avoid test hangs --- vm/tests/kernel/java/lang/ThreadTest.java | 13 ++++++++++--- vm/tests/unit/thread/test_native_basic.c | 19 ++++++++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/vm/tests/kernel/java/lang/ThreadTest.java b/vm/tests/kernel/java/lang/ThreadTest.java index 08e0b73..bfa6b9c 100644 --- a/vm/tests/kernel/java/lang/ThreadTest.java +++ b/vm/tests/kernel/java/lang/ThreadTest.java @@ -527,7 +527,7 @@ public class ThreadTest extends TestCase { ThreadGroup tg = new ThreadGroup("newGroup"); String name = "t1"; Square s = new Square(25); - Thread t = new Thread(tg, s, name, 1); + Thread t = new Thread(tg, s, name, 0); t.start(); waitTime = waitDuration; StackTraceElement ste[] = t.getStackTrace(); @@ -549,7 +549,14 @@ public class ThreadTest extends TestCase { Square s = new Square(25); StackTraceElement ste[] = null; try { - Thread t = new Thread(tg, s, name, Long.MAX_VALUE); + Thread t; + try { + t = new Thread(tg, s, name, Long.MAX_VALUE); + } catch (OutOfMemoryError e) { + // fall back to default stack size if can't allocate + // Long.MAX_VALUE bytes for stack + t = new Thread(tg, s, name, 0); + } t.start(); waitTime = waitDuration; ste = t.getStackTrace(); @@ -1964,4 +1971,4 @@ public class ThreadTest extends TestCase { return; } } -} \ No newline at end of file +} diff --git a/vm/tests/unit/thread/test_native_basic.c b/vm/tests/unit/thread/test_native_basic.c index 0677cda..27be05b 100644 --- a/vm/tests/unit/thread/test_native_basic.c +++ b/vm/tests/unit/thread/test_native_basic.c @@ -41,6 +41,7 @@ int test_hythread_create(void){ apr_pool_t *pool; void **args; hythread_t thread = NULL; + int r; apr_pool_create(&pool, NULL); @@ -49,13 +50,14 @@ int test_hythread_create(void){ 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])->stacksize = 1024000; ((jthread_threadattr_t *)args[1])->priority = 1; - hythread_create_with_group(&thread, args[0], 1024, 1, 0, start_proc, args); + r = hythread_create_with_group(&thread, args[0], 1024000, 1, 0, start_proc, args); + tf_assert(r == 0 && "thread creation failed"); - hythread_join(thread); - // TODO: should check that created thread finished without errors. + r = hythread_join(thread); + tf_assert(r == 0 && "thread join failed"); return TEST_PASSED; } @@ -145,6 +147,7 @@ int test_hythread_create_many(void){ void **args; hythread_t thread = NULL; hythread_group_t group = NULL; + int r; char *buf; int i = 10; @@ -158,19 +161,21 @@ int test_hythread_create_many(void){ args[0] = group; args[1] = apr_palloc(pool, sizeof(jthread_threadattr_t)); - ((jthread_threadattr_t *)args[1])->stacksize = 1024; + ((jthread_threadattr_t *)args[1])->stacksize = 1024000; ((jthread_threadattr_t *)args[1])->priority = 1; thread = NULL; - hythread_create_with_group(&thread, group, 1024, 1, 0, start_proc, args); + r = hythread_create_with_group(&thread, group, 1024000, 1, 0, start_proc, args); + tf_assert(r == 0 && "thread creation failed"); buf = (char *)apr_pcalloc(pool, sizeof(char)*12); /* sprintf(buf, "Thread %d\0", i); hythread_set_name(thread, buf); */ - hythread_join(thread); + r = hythread_join(thread); + tf_assert(r == 0 && "thread join failed"); } //check thread structures: -- 1.5.0.33.g1b20