OLD | NEW |
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 EXPECT_GE(1 * kNanosecondsPerSecond, ClockMonotonicNanoseconds() - start); | 74 EXPECT_GE(1 * kNanosecondsPerSecond, ClockMonotonicNanoseconds() - start); |
75 } | 75 } |
76 | 76 |
77 TEST(WorkerThread, StopBeforeDoWork) { | 77 TEST(WorkerThread, StopBeforeDoWork) { |
78 WorkDelegate delegate; | 78 WorkDelegate delegate; |
79 WorkerThread thread(1, &delegate); | 79 WorkerThread thread(1, &delegate); |
80 | 80 |
81 thread.Start(15); | 81 thread.Start(15); |
82 thread.Stop(); | 82 thread.Stop(); |
83 | 83 |
84 EXPECT_EQ(0, delegate.work_count()); | 84 EXPECT_EQ(delegate.work_count(), 0); |
85 } | 85 } |
86 | 86 |
87 TEST(WorkerThread, Restart) { | 87 TEST(WorkerThread, Restart) { |
88 WorkDelegate delegate; | 88 WorkDelegate delegate; |
89 WorkerThread thread(0.05, &delegate); | 89 WorkerThread thread(0.05, &delegate); |
90 | 90 |
91 delegate.SetDesiredWorkCount(1); | 91 delegate.SetDesiredWorkCount(1); |
92 thread.Start(0); | 92 thread.Start(0); |
93 EXPECT_TRUE(thread.is_running()); | 93 EXPECT_TRUE(thread.is_running()); |
94 | 94 |
(...skipping 12 matching lines...) Expand all Loading... |
107 WorkDelegate delegate; | 107 WorkDelegate delegate; |
108 WorkerThread thread(100, &delegate); | 108 WorkerThread thread(100, &delegate); |
109 | 109 |
110 uint64_t start = ClockMonotonicNanoseconds(); | 110 uint64_t start = ClockMonotonicNanoseconds(); |
111 | 111 |
112 delegate.SetDesiredWorkCount(1); | 112 delegate.SetDesiredWorkCount(1); |
113 thread.Start(0); | 113 thread.Start(0); |
114 EXPECT_TRUE(thread.is_running()); | 114 EXPECT_TRUE(thread.is_running()); |
115 | 115 |
116 delegate.WaitForWorkCount(); | 116 delegate.WaitForWorkCount(); |
117 EXPECT_EQ(1, delegate.work_count()); | 117 EXPECT_EQ(delegate.work_count(), 1); |
118 | 118 |
119 delegate.SetDesiredWorkCount(2); | 119 delegate.SetDesiredWorkCount(2); |
120 thread.DoWorkNow(); | 120 thread.DoWorkNow(); |
121 delegate.WaitForWorkCount(); | 121 delegate.WaitForWorkCount(); |
122 thread.Stop(); | 122 thread.Stop(); |
123 EXPECT_EQ(2, delegate.work_count()); | 123 EXPECT_EQ(delegate.work_count(), 2); |
124 | 124 |
125 EXPECT_GE(100 * kNanosecondsPerSecond, ClockMonotonicNanoseconds() - start); | 125 EXPECT_GE(100 * kNanosecondsPerSecond, ClockMonotonicNanoseconds() - start); |
126 } | 126 } |
127 | 127 |
128 TEST(WorkerThread, DoWorkNowAtStart) { | 128 TEST(WorkerThread, DoWorkNowAtStart) { |
129 WorkDelegate delegate; | 129 WorkDelegate delegate; |
130 WorkerThread thread(100, &delegate); | 130 WorkerThread thread(100, &delegate); |
131 | 131 |
132 uint64_t start = ClockMonotonicNanoseconds(); | 132 uint64_t start = ClockMonotonicNanoseconds(); |
133 | 133 |
134 delegate.SetDesiredWorkCount(1); | 134 delegate.SetDesiredWorkCount(1); |
135 thread.Start(100); | 135 thread.Start(100); |
136 EXPECT_TRUE(thread.is_running()); | 136 EXPECT_TRUE(thread.is_running()); |
137 | 137 |
138 thread.DoWorkNow(); | 138 thread.DoWorkNow(); |
139 delegate.WaitForWorkCount(); | 139 delegate.WaitForWorkCount(); |
140 EXPECT_EQ(1, delegate.work_count()); | 140 EXPECT_EQ(delegate.work_count(), 1); |
141 | 141 |
142 EXPECT_GE(100 * kNanosecondsPerSecond, ClockMonotonicNanoseconds() - start); | 142 EXPECT_GE(100 * kNanosecondsPerSecond, ClockMonotonicNanoseconds() - start); |
143 | 143 |
144 thread.Stop(); | 144 thread.Stop(); |
145 EXPECT_FALSE(thread.is_running()); | 145 EXPECT_FALSE(thread.is_running()); |
146 } | 146 } |
147 | 147 |
148 } // namespace | 148 } // namespace |
149 } // namespace test | 149 } // namespace test |
150 } // namespace crashpad | 150 } // namespace crashpad |
OLD | NEW |