OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/test/sequenced_task_runner_test_template.h" | 5 #include "base/test/sequenced_task_runner_test_template.h" |
6 #include "base/test/task_runner_test_template.h" | 6 #include "base/test/task_runner_test_template.h" |
7 #include "base/threading/simple_thread.h" | 7 #include "base/threading/simple_thread.h" |
| 8 #include "cc/test/task_graph_runner_test_template.h" |
8 #include "content/renderer/raster_worker_pool.h" | 9 #include "content/renderer/raster_worker_pool.h" |
9 | 10 |
10 namespace base { | 11 namespace base { |
11 namespace { | 12 namespace { |
12 | 13 |
13 // Number of threads spawned in tests. | 14 // Number of threads spawned in tests. |
14 const int kNumThreads = 4; | 15 const int kNumThreads = 4; |
15 | 16 |
16 class RasterWorkerPoolTestDelegate { | 17 class RasterWorkerPoolTestDelegate { |
17 public: | 18 public: |
18 RasterWorkerPoolTestDelegate() | 19 RasterWorkerPoolTestDelegate() |
19 : raster_worker_pool_(new content::RasterWorkerPool()) {} | 20 : raster_worker_pool_(new content::RasterWorkerPool()) {} |
20 | 21 |
21 void StartTaskRunner() { | 22 void StartTaskRunner() { |
22 raster_worker_pool_->Start(kNumThreads, SimpleThread::Options()); | 23 raster_worker_pool_->Start(kNumThreads, SimpleThread::Options()); |
23 } | 24 } |
24 | 25 |
25 scoped_refptr<content::RasterWorkerPool> GetTaskRunner() { | 26 scoped_refptr<content::RasterWorkerPool> GetTaskRunner() { |
26 return raster_worker_pool_; | 27 return raster_worker_pool_; |
27 } | 28 } |
28 | 29 |
29 void StopTaskRunner() { | 30 void StopTaskRunner() { raster_worker_pool_->FlushForTesting(); } |
30 raster_worker_pool_->GetTaskGraphRunner()->FlushForTesting(); | |
31 } | |
32 | 31 |
33 ~RasterWorkerPoolTestDelegate() { raster_worker_pool_->Shutdown(); } | 32 ~RasterWorkerPoolTestDelegate() { raster_worker_pool_->Shutdown(); } |
34 | 33 |
35 private: | 34 private: |
36 scoped_refptr<content::RasterWorkerPool> raster_worker_pool_; | 35 scoped_refptr<content::RasterWorkerPool> raster_worker_pool_; |
37 }; | 36 }; |
38 | 37 |
39 INSTANTIATE_TYPED_TEST_CASE_P(RasterWorkerPool, | 38 INSTANTIATE_TYPED_TEST_CASE_P(RasterWorkerPool, |
40 TaskRunnerTest, | 39 TaskRunnerTest, |
41 RasterWorkerPoolTestDelegate); | 40 RasterWorkerPoolTestDelegate); |
42 | 41 |
43 class RasterWorkerPoolSequencedTestDelegate { | 42 class RasterWorkerPoolSequencedTestDelegate { |
44 public: | 43 public: |
45 RasterWorkerPoolSequencedTestDelegate() | 44 RasterWorkerPoolSequencedTestDelegate() |
46 : raster_worker_pool_(new content::RasterWorkerPool()) {} | 45 : raster_worker_pool_(new content::RasterWorkerPool()) {} |
47 | 46 |
48 void StartTaskRunner() { | 47 void StartTaskRunner() { |
49 raster_worker_pool_->Start(kNumThreads, SimpleThread::Options()); | 48 raster_worker_pool_->Start(kNumThreads, SimpleThread::Options()); |
50 } | 49 } |
51 | 50 |
52 scoped_refptr<base::SequencedTaskRunner> GetTaskRunner() { | 51 scoped_refptr<base::SequencedTaskRunner> GetTaskRunner() { |
53 return raster_worker_pool_->CreateSequencedTaskRunner(); | 52 return raster_worker_pool_->CreateSequencedTaskRunner(); |
54 } | 53 } |
55 | 54 |
56 void StopTaskRunner() { | 55 void StopTaskRunner() { raster_worker_pool_->FlushForTesting(); } |
57 raster_worker_pool_->GetTaskGraphRunner()->FlushForTesting(); | |
58 } | |
59 | 56 |
60 ~RasterWorkerPoolSequencedTestDelegate() { raster_worker_pool_->Shutdown(); } | 57 ~RasterWorkerPoolSequencedTestDelegate() { raster_worker_pool_->Shutdown(); } |
61 | 58 |
62 private: | 59 private: |
63 scoped_refptr<content::RasterWorkerPool> raster_worker_pool_; | 60 scoped_refptr<content::RasterWorkerPool> raster_worker_pool_; |
64 }; | 61 }; |
65 | 62 |
66 INSTANTIATE_TYPED_TEST_CASE_P(RasterWorkerPool, | 63 INSTANTIATE_TYPED_TEST_CASE_P(RasterWorkerPool, |
67 SequencedTaskRunnerTest, | 64 SequencedTaskRunnerTest, |
68 RasterWorkerPoolSequencedTestDelegate); | 65 RasterWorkerPoolSequencedTestDelegate); |
69 | 66 |
70 } // namespace | 67 } // namespace |
71 } // namespace base | 68 } // namespace base |
| 69 |
| 70 namespace cc { |
| 71 namespace { |
| 72 |
| 73 template <int NumThreads> |
| 74 class RasterWorkerPoolTaskGraphRunnerTestDelegate { |
| 75 public: |
| 76 RasterWorkerPoolTaskGraphRunnerTestDelegate() |
| 77 : raster_worker_pool_(new content::RasterWorkerPool()) {} |
| 78 |
| 79 void StartTaskGraphRunner() { |
| 80 raster_worker_pool_->Start(NumThreads, base::SimpleThread::Options()); |
| 81 } |
| 82 |
| 83 cc::TaskGraphRunner* GetTaskGraphRunner() { |
| 84 return raster_worker_pool_->GetTaskGraphRunner(); |
| 85 } |
| 86 |
| 87 void StopTaskGraphRunner() { raster_worker_pool_->FlushForTesting(); } |
| 88 |
| 89 ~RasterWorkerPoolTaskGraphRunnerTestDelegate() { |
| 90 raster_worker_pool_->Shutdown(); |
| 91 } |
| 92 |
| 93 private: |
| 94 scoped_refptr<content::RasterWorkerPool> raster_worker_pool_; |
| 95 }; |
| 96 |
| 97 // Multithreaded tests. |
| 98 INSTANTIATE_TYPED_TEST_CASE_P(RasterWorkerPool_1_Threads, |
| 99 TaskGraphRunnerTest, |
| 100 RasterWorkerPoolTaskGraphRunnerTestDelegate<1>); |
| 101 INSTANTIATE_TYPED_TEST_CASE_P(RasterWorkerPool_2_Threads, |
| 102 TaskGraphRunnerTest, |
| 103 RasterWorkerPoolTaskGraphRunnerTestDelegate<2>); |
| 104 INSTANTIATE_TYPED_TEST_CASE_P(RasterWorkerPool_3_Threads, |
| 105 TaskGraphRunnerTest, |
| 106 RasterWorkerPoolTaskGraphRunnerTestDelegate<3>); |
| 107 INSTANTIATE_TYPED_TEST_CASE_P(RasterWorkerPool_4_Threads, |
| 108 TaskGraphRunnerTest, |
| 109 RasterWorkerPoolTaskGraphRunnerTestDelegate<4>); |
| 110 INSTANTIATE_TYPED_TEST_CASE_P(RasterWorkerPool_5_Threads, |
| 111 TaskGraphRunnerTest, |
| 112 RasterWorkerPoolTaskGraphRunnerTestDelegate<5>); |
| 113 |
| 114 // Single threaded tests. |
| 115 INSTANTIATE_TYPED_TEST_CASE_P(RasterWorkerPool, |
| 116 SingleThreadTaskGraphRunnerTest, |
| 117 RasterWorkerPoolTaskGraphRunnerTestDelegate<1>); |
| 118 |
| 119 } // namespace |
| 120 } // namespace cc |
OLD | NEW |