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

Unified Diff: base/debug/trace_event_synthetic_delay_unittest.cc

Issue 392933002: Fix data race with synthetic delay initialization (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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
« no previous file with comments | « base/debug/trace_event_synthetic_delay.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/debug/trace_event_synthetic_delay_unittest.cc
diff --git a/base/debug/trace_event_synthetic_delay_unittest.cc b/base/debug/trace_event_synthetic_delay_unittest.cc
index 7833e7bbcdeb89d47bc2bb404e280cf962f48260..5b9c20d2fa428f07e0d3c432a2f8f87976558981 100644
--- a/base/debug/trace_event_synthetic_delay_unittest.cc
+++ b/base/debug/trace_event_synthetic_delay_unittest.cc
@@ -4,6 +4,7 @@
#include "base/debug/trace_event_synthetic_delay.h"
+#include "base/threading/simple_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
@@ -14,6 +15,7 @@ const int kTargetDurationMs = 100;
// Allow some leeway in timings to make it possible to run these tests with a
// wall clock time source too.
const int kShortDurationMs = 10;
+const char kThreadedDelayName[] = "test.ThreadedDelay";
} // namespace
@@ -152,5 +154,34 @@ TEST_F(TraceEventSyntheticDelayTest, BeginParallel) {
EXPECT_LT((Now() - start_time).InMilliseconds(), kShortDurationMs);
}
+class ThreadWithSyntheticDelay : public SimpleThread {
+ public:
+ ThreadWithSyntheticDelay()
+ : SimpleThread("delay_test", SimpleThread::Options()) {}
+
+ virtual void Run() OVERRIDE {
+ TRACE_EVENT_SYNTHETIC_DELAY(kThreadedDelayName);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ThreadWithSyntheticDelay);
+};
+
+TEST_F(TraceEventSyntheticDelayTest, ThreadedSetup) {
+ // This test is designed to exercise various multithreaded scenarios with
+ // 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
+ // problems.
+ ThreadWithSyntheticDelay threads[2];
+
+ for (size_t i = 0; i < arraysize(threads); ++i)
+ threads[i].Start();
Alexander Potapenko 2014/07/15 14:30:15 I think there should be two-space indentation here
+ TraceEventSyntheticDelay* delay =
+ TraceEventSyntheticDelay::Lookup(kThreadedDelayName);
+ delay->SetTargetDuration(
+ base::TimeDelta::FromMilliseconds(kShortDurationMs));
+ for (size_t i = 0; i < arraysize(threads); ++i)
+ threads[i].Join();
+}
+
} // namespace debug
} // namespace base
« no previous file with comments | « base/debug/trace_event_synthetic_delay.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698