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

Unified Diff: base/debug/trace_event_unittest.cc

Issue 8470001: TraceEvent fixes for thread name changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix mac - can't pass NULL to PlatformName::SetName Created 9 years, 1 month 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.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_unittest.cc
diff --git a/base/debug/trace_event_unittest.cc b/base/debug/trace_event_unittest.cc
index c30c77329294d0be3c1897203cf1d6b977ad6571..fc248e11c3526c32d04d3219b8ebba6fea65a456 100644
--- a/base/debug/trace_event_unittest.cc
+++ b/base/debug/trace_event_unittest.cc
@@ -10,9 +10,11 @@
#include "base/json/json_writer.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/singleton.h"
#include "base/process_util.h"
#include "base/stringprintf.h"
#include "base/synchronization/waitable_event.h"
+#include "base/threading/platform_thread.h"
#include "base/threading/thread.h"
#include "base/values.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -52,6 +54,14 @@ class TraceEventTestFixture : public testing::Test {
json_output_.json_output.clear();
}
+ virtual void SetUp() {
+ old_thread_name_ = PlatformThread::GetName();
+ }
+ virtual void TearDown() {
+ PlatformThread::SetName(old_thread_name_ ? old_thread_name_ : "");
+ }
+
+ const char* old_thread_name_;
ListValue trace_parsed_;
base::debug::TraceResultBuffer trace_buffer_;
base::debug::TraceResultBuffer::SimpleOutput json_output_;
@@ -778,7 +788,7 @@ TEST_F(TraceEventTestFixture, ThreadNames) {
FindTraceEntries(trace_parsed_, "thread_name");
for (int i = 0; i < static_cast<int>(items.size()); i++) {
item = items[i];
- EXPECT_TRUE(item);
+ ASSERT_TRUE(item);
EXPECT_TRUE(item->GetInteger("tid", &tmp_int));
// See if this thread name is one of the threads we just created
@@ -796,6 +806,44 @@ TEST_F(TraceEventTestFixture, ThreadNames) {
}
}
+TEST_F(TraceEventTestFixture, ThreadNameChanges) {
+ ManualTestSetUp();
+
+ TraceLog::GetInstance()->SetEnabled(true);
+
+ PlatformThread::SetName("");
+ TRACE_EVENT_INSTANT0("drink", "water");
+
+ PlatformThread::SetName("cafe");
+ TRACE_EVENT_INSTANT0("drink", "coffee");
+
+ PlatformThread::SetName("shop");
+ // No event here, so won't appear in combined name.
+
+ PlatformThread::SetName("pub");
+ TRACE_EVENT_INSTANT0("drink", "beer");
+ TRACE_EVENT_INSTANT0("drink", "wine");
+
+ PlatformThread::SetName(" bar");
+ TRACE_EVENT_INSTANT0("drink", "whisky");
+
+ TraceLog::GetInstance()->SetEnabled(false);
+
+ std::vector<DictionaryValue*> items =
+ FindTraceEntries(trace_parsed_, "thread_name");
+ EXPECT_EQ(1u, items.size());
+ ASSERT_GT(items.size(), 0u);
+ DictionaryValue* item = items[0];
+ ASSERT_TRUE(item);
+ int tid;
+ EXPECT_TRUE(item->GetInteger("tid", &tid));
+ EXPECT_EQ(PlatformThread::CurrentId(), static_cast<PlatformThreadId>(tid));
+
+ std::string expected_name = "cafe,pub, bar";
+ std::string tmp;
+ EXPECT_TRUE(item->GetString("args.name", &tmp));
+ EXPECT_EQ(expected_name, tmp);
+}
// Test trace calls made after tracing singleton shut down.
//
« no previous file with comments | « base/debug/trace_event.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698