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

Unified Diff: base/trace_event/blame_context_unittest.cc

Issue 1921973003: Proof of concept about BlameContext races on dtor. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/blame_context_unittest.cc
diff --git a/base/trace_event/blame_context_unittest.cc b/base/trace_event/blame_context_unittest.cc
index 7217d8fb1bb6e305621b0d475b72f1e2e63aa5b3..c139eb95c71855f873b0d0864f13c5be3331b7f1 100644
--- a/base/trace_event/blame_context_unittest.cc
+++ b/base/trace_event/blame_context_unittest.cc
@@ -4,6 +4,8 @@
#include "base/trace_event/blame_context.h"
+#include <unistd.h>
+
#include "base/json/json_writer.h"
#include "base/memory/ref_counted_memory.h"
#include "base/run_loop.h"
@@ -211,6 +213,42 @@ TEST_F(BlameContextTest, TakeSnapshot) {
EXPECT_EQ(kExpectedSnapshotJson, snapshot_json);
}
+class TestBlameContextWithSleep : public BlameContext {
+ public:
+ TestBlameContextWithSleep()
+ : BlameContext(kTestBlameContextCategory,
+ kTestBlameContextName,
+ kTestBlameContextType,
+ kTestBlameContextScope,
+ 0,
+ nullptr), destroyed_(false) {}
+
+ ~TestBlameContextWithSleep() override {
+ destroyed_ = true;
+ usleep(200000); //anything longer than the PostDelayedTask below.
+ }
+
+ protected:
+ void AsValueInto(trace_event::TracedValue* state) override {
+ CHECK(!destroyed_) << "KABOOM, calling the derived AsValueInto after its "
+ "dtor. Weird things will happen now.";
+ }
+
+ bool destroyed_;
+};
+
+TEST_F(BlameContextTest, DTOR) {
+ Thread thread("test thread");
+ thread.Start();
+ thread.task_runner()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&BlameContextTest::StartTracing, base::Unretained(this)),
+ TimeDelta::FromMicroseconds(100000));
+ std::unique_ptr<TestBlameContextWithSleep> derived(new TestBlameContextWithSleep());
+ derived->Initialize();
+ derived.reset();
+}
+
} // namepace
} // namespace trace_event
} // namespace base
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698