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