OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/debug/trace_event_synthetic_delay.h" | 5 #include "base/debug/trace_event_synthetic_delay.h" |
6 | 6 |
7 #include "base/threading/simple_thread.h" | |
7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
8 | 9 |
9 namespace base { | 10 namespace base { |
10 namespace debug { | 11 namespace debug { |
11 namespace { | 12 namespace { |
12 | 13 |
13 const int kTargetDurationMs = 100; | 14 const int kTargetDurationMs = 100; |
14 // Allow some leeway in timings to make it possible to run these tests with a | 15 // Allow some leeway in timings to make it possible to run these tests with a |
15 // wall clock time source too. | 16 // wall clock time source too. |
16 const int kShortDurationMs = 10; | 17 const int kShortDurationMs = 10; |
18 const char kThreadedDelayName[] = "test.ThreadedDelay"; | |
17 | 19 |
18 } // namespace | 20 } // namespace |
19 | 21 |
20 class TraceEventSyntheticDelayTest : public testing::Test, | 22 class TraceEventSyntheticDelayTest : public testing::Test, |
21 public TraceEventSyntheticDelayClock { | 23 public TraceEventSyntheticDelayClock { |
22 public: | 24 public: |
23 TraceEventSyntheticDelayTest() {} | 25 TraceEventSyntheticDelayTest() {} |
24 virtual ~TraceEventSyntheticDelayTest() { | 26 virtual ~TraceEventSyntheticDelayTest() { |
25 ResetTraceEventSyntheticDelays(); | 27 ResetTraceEventSyntheticDelays(); |
26 } | 28 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 EXPECT_FALSE(end_times[1].is_null()); | 147 EXPECT_FALSE(end_times[1].is_null()); |
146 | 148 |
147 delay->EndParallel(end_times[0]); | 149 delay->EndParallel(end_times[0]); |
148 EXPECT_GE((Now() - start_time).InMilliseconds(), kTargetDurationMs); | 150 EXPECT_GE((Now() - start_time).InMilliseconds(), kTargetDurationMs); |
149 | 151 |
150 start_time = Now(); | 152 start_time = Now(); |
151 delay->EndParallel(end_times[1]); | 153 delay->EndParallel(end_times[1]); |
152 EXPECT_LT((Now() - start_time).InMilliseconds(), kShortDurationMs); | 154 EXPECT_LT((Now() - start_time).InMilliseconds(), kShortDurationMs); |
153 } | 155 } |
154 | 156 |
157 class ThreadWithSyntheticDelay : public SimpleThread { | |
158 public: | |
159 ThreadWithSyntheticDelay() | |
160 : SimpleThread("delay_test", SimpleThread::Options()) {} | |
161 | |
162 virtual void Run() OVERRIDE { | |
163 TRACE_EVENT_SYNTHETIC_DELAY(kThreadedDelayName); | |
164 } | |
165 | |
166 private: | |
167 DISALLOW_COPY_AND_ASSIGN(ThreadWithSyntheticDelay); | |
168 }; | |
169 | |
170 TEST_F(TraceEventSyntheticDelayTest, ThreadedSetup) { | |
171 // This test is designed to exercise various multithreaded scenarios with | |
172 // synthetic delays so that dynamic analyzers like TSAN can spot any | |
Alexander Potapenko
2014/07/15 14:30:15
That's 'TSan', not 'TSAN' :)
Have you actually tr
| |
173 // problems. | |
174 ThreadWithSyntheticDelay threads[2]; | |
175 | |
176 for (size_t i = 0; i < arraysize(threads); ++i) | |
177 threads[i].Start(); | |
Alexander Potapenko
2014/07/15 14:30:15
I think there should be two-space indentation here
| |
178 TraceEventSyntheticDelay* delay = | |
179 TraceEventSyntheticDelay::Lookup(kThreadedDelayName); | |
180 delay->SetTargetDuration( | |
181 base::TimeDelta::FromMilliseconds(kShortDurationMs)); | |
182 for (size_t i = 0; i < arraysize(threads); ++i) | |
183 threads[i].Join(); | |
184 } | |
185 | |
155 } // namespace debug | 186 } // namespace debug |
156 } // namespace base | 187 } // namespace base |
OLD | NEW |