Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(541)

Unified Diff: runtime/bin/thread_pool_test.cc

Issue 9212043: Refactored thread pool (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« runtime/bin/thread_pool.cc ('K') | « runtime/bin/thread_pool.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/thread_pool_test.cc
diff --git a/runtime/bin/thread_pool_test.cc b/runtime/bin/thread_pool_test.cc
index a5712006008300443e00dcb0c413a9e45f4b48d9..df1bedb9f7aeb6aa674c9782d433a47049830038 100644
--- a/runtime/bin/thread_pool_test.cc
+++ b/runtime/bin/thread_pool_test.cc
@@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
#include "bin/thread_pool.h"
+#include "bin/thread.h"
#include "platform/assert.h"
#include "platform/globals.h"
#include "vm/unit_test.h"
@@ -13,3 +14,74 @@ UNIT_TEST_CASE(ThreadPoolStartStop) {
thread_pool.Start();
thread_pool.Shutdown();
}
+
+
+static dart::Monitor* monitor = NULL;
+static uint32_t task_count = 0;
+static uint32_t task_sum = 0;
+void TestTaskHandler(ThreadPool::Task args) {
Mads Ager (google) 2012/01/24 12:29:39 Blank line before the function?
Søren Gjesse 2012/01/24 13:04:35 Done.
+ MonitorLocker ml(monitor);
+ task_count++;
+ task_sum += reinterpret_cast<int>(args);
+}
+
+
+UNIT_TEST_CASE(ThreadPoolTest1) {
+ static const uint32_t kNumTestThreads = 10;
+ static const uint32_t kNumTestTasks = 1000;
+ static const uint32_t kNumLoops = 100;
+ monitor = new dart::Monitor();
+ ThreadPool thread_pool(&TestTaskHandler, kNumTestThreads);
+ uint32_t pool_start_count = 0;
+ while (pool_start_count++ < kNumLoops) {
+ task_count = 0;
+ task_sum = 0;
+ thread_pool.Start();
+ for (uint32_t i = 1; i <= kNumTestTasks; i++) {
+ bool result =
+ thread_pool.InsertTask(reinterpret_cast<ThreadPool::Task>(i));
+ EXPECT(result);
+ }
+ thread_pool.Shutdown(true);
+
+ EXPECT_EQ(kNumTestTasks, task_count);
+ EXPECT_EQ((1 + kNumTestTasks) * (kNumTestTasks / 2), task_sum);
+ }
+
+ delete monitor;
+ monitor = NULL;
+}
+
+
+UNIT_TEST_CASE(ThreadPoolTest2) {
+ static const uint32_t kNumTestThreads = 10;
+ static const uint32_t kNumTestTasks = 50000;
+ static const uint32_t kNumLoops = 100;
+ monitor = new dart::Monitor();
+ ThreadPool thread_pool(&TestTaskHandler, kNumTestThreads);
+ for (uint32_t i = 1; i <= kNumTestTasks; i++) {
+ bool result =
+ thread_pool.InsertTask(reinterpret_cast<ThreadPool::Task>(i));
+ EXPECT(result);
+ }
+
+ // Start and stop the thread pool without draining the queue a
+ // number of times.
+ uint32_t pool_start_count = 0;
+ while (pool_start_count++ < kNumLoops) {
+ printf("%d %d\n", task_count, task_sum);
+ thread_pool.Start();
+ dart::OS::Sleep(1);
+ thread_pool.Shutdown(false);
+ }
+ // Finally start and drain the queue to get all messages processed.
+ thread_pool.Start();
+ thread_pool.Shutdown(true);
+
+ // Check that all tasks where processed.
+ EXPECT_EQ(kNumTestTasks, task_count);
+ EXPECT_EQ((1 + kNumTestTasks) * (kNumTestTasks / 2), task_sum);
+
+ delete monitor;
+ monitor = NULL;
+}
« runtime/bin/thread_pool.cc ('K') | « runtime/bin/thread_pool.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698