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

Side by Side Diff: base/debug/activity_tracker_unittest.cc

Issue 2702413006: Enable storing last-dispatched exception per-thread. (Closed)
Patch Set: harden exception recording Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/activity_tracker.h" 5 #include "base/debug/activity_tracker.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 ASSERT_EQ(1U, snapshot.activity_stack.size()); 232 ASSERT_EQ(1U, snapshot.activity_stack.size());
233 EXPECT_EQ(Activity::ACT_TASK, snapshot.activity_stack[0].activity_type); 233 EXPECT_EQ(Activity::ACT_TASK, snapshot.activity_stack[0].activity_type);
234 } 234 }
235 235
236 ASSERT_TRUE(tracker->CreateSnapshot(&snapshot)); 236 ASSERT_TRUE(tracker->CreateSnapshot(&snapshot));
237 ASSERT_EQ(0U, snapshot.activity_stack_depth); 237 ASSERT_EQ(0U, snapshot.activity_stack_depth);
238 ASSERT_EQ(0U, snapshot.activity_stack.size()); 238 ASSERT_EQ(0U, snapshot.activity_stack.size());
239 ASSERT_EQ(2U, GetGlobalUserDataMemoryCacheUsed()); 239 ASSERT_EQ(2U, GetGlobalUserDataMemoryCacheUsed());
240 } 240 }
241 241
242 TEST_F(ActivityTrackerTest, ExceptionTest) {
243 GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3);
244 GlobalActivityTracker* global = GlobalActivityTracker::Get();
245
246 ThreadActivityTracker* tracker =
247 GlobalActivityTracker::Get()->GetOrCreateTrackerForCurrentThread();
248 ThreadActivityTracker::Snapshot snapshot;
249 ASSERT_EQ(0U, GetGlobalUserDataMemoryCacheUsed());
250
251 ASSERT_TRUE(tracker->CreateSnapshot(&snapshot));
252 ASSERT_EQ(0U, snapshot.last_exception.activity_type);
253
254 char origin;
255 ActivityUserData& data = global->RecordException(&origin);
256 data.SetString("foo", "bar");
257
258 ASSERT_TRUE(tracker->CreateSnapshot(&snapshot));
259 EXPECT_EQ(Activity::ACT_EXCEPTION, snapshot.last_exception.activity_type);
260 EXPECT_EQ(reinterpret_cast<uintptr_t>(&origin),
261 snapshot.last_exception.origin_address);
262
263 void* memory = global->allocator()->GetAsArray<char>(
264 snapshot.last_exception.user_data_ref,
265 GlobalActivityTracker::kTypeIdUserDataRecord,
266 PersistentMemoryAllocator::kSizeAny);
267 ASSERT_TRUE(memory);
268 ActivityUserData saved_data(
269 memory,
270 global->allocator()->GetAllocSize(snapshot.last_exception.user_data_ref));
271 EXPECT_EQ(data.id(), saved_data.id());
272 }
273
242 TEST_F(ActivityTrackerTest, CreateWithFileTest) { 274 TEST_F(ActivityTrackerTest, CreateWithFileTest) {
243 const char temp_name[] = "CreateWithFileTest"; 275 const char temp_name[] = "CreateWithFileTest";
244 ScopedTempDir temp_dir; 276 ScopedTempDir temp_dir;
245 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 277 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
246 FilePath temp_file = temp_dir.GetPath().AppendASCII(temp_name); 278 FilePath temp_file = temp_dir.GetPath().AppendASCII(temp_name);
247 const size_t temp_size = 64 << 10; // 64 KiB 279 const size_t temp_size = 64 << 10; // 64 KiB
248 280
249 // Create a global tracker on a new file. 281 // Create a global tracker on a new file.
250 ASSERT_FALSE(PathExists(temp_file)); 282 ASSERT_FALSE(PathExists(temp_file));
251 GlobalActivityTracker::CreateWithFile(temp_file, temp_size, 0, "foo", 3); 283 GlobalActivityTracker::CreateWithFile(temp_file, temp_size, 0, "foo", 3);
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 global->allocator()->ChangeType( 492 global->allocator()->ChangeType(
461 tracker_ref, GlobalActivityTracker::kTypeIdActivityTracker, 493 tracker_ref, GlobalActivityTracker::kTypeIdActivityTracker,
462 GlobalActivityTracker::kTypeIdActivityTrackerFree, false); 494 GlobalActivityTracker::kTypeIdActivityTrackerFree, false);
463 global->allocator()->ChangeType( 495 global->allocator()->ChangeType(
464 user_data_ref, GlobalActivityTracker::kTypeIdUserDataRecord, 496 user_data_ref, GlobalActivityTracker::kTypeIdUserDataRecord,
465 GlobalActivityTracker::kTypeIdUserDataRecordFree, false); 497 GlobalActivityTracker::kTypeIdUserDataRecordFree, false);
466 } 498 }
467 499
468 } // namespace debug 500 } // namespace debug
469 } // namespace base 501 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698