OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Test of classes in the tracked_objects.h classes. | 5 // Test of classes in the tracked_objects.h classes. |
6 | 6 |
7 #include "base/tracked_objects.h" | 7 #include "base/tracked_objects.h" |
8 | 8 |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 | 11 |
12 #include "base/memory/scoped_ptr.h" | 12 #include <memory> |
| 13 |
13 #include "base/process/process_handle.h" | 14 #include "base/process/process_handle.h" |
14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
15 #include "base/tracking_info.h" | 16 #include "base/tracking_info.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 const int kLineNumber = 1776; | 19 const int kLineNumber = 1776; |
19 const char kFile[] = "FixedUnitTestFileName"; | 20 const char kFile[] = "FixedUnitTestFileName"; |
20 const char kWorkerThreadName[] = "WorkerThread-1"; | 21 const char kWorkerThreadName[] = "WorkerThread-1"; |
21 const char kMainThreadName[] = "SomeMainThreadName"; | 22 const char kMainThreadName[] = "SomeMainThreadName"; |
22 const char kStillAlive[] = "Still_Alive"; | 23 const char kStillAlive[] = "Still_Alive"; |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 process_data_phase.tasks[0].death_data.run_duration_sample); | 233 process_data_phase.tasks[0].death_data.run_duration_sample); |
233 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_sum); | 234 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_sum); |
234 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_max); | 235 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_max); |
235 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_sample); | 236 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_sample); |
236 EXPECT_EQ(kWorkerThreadName, process_data_phase.tasks[0].death_thread_name); | 237 EXPECT_EQ(kWorkerThreadName, process_data_phase.tasks[0].death_thread_name); |
237 } | 238 } |
238 | 239 |
239 TEST_F(TrackedObjectsTest, DeathDataTestRecordDeath) { | 240 TEST_F(TrackedObjectsTest, DeathDataTestRecordDeath) { |
240 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE); | 241 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE); |
241 | 242 |
242 scoped_ptr<DeathData> data(new DeathData()); | 243 std::unique_ptr<DeathData> data(new DeathData()); |
243 ASSERT_NE(data, nullptr); | 244 ASSERT_NE(data, nullptr); |
244 EXPECT_EQ(data->run_duration_sum(), 0); | 245 EXPECT_EQ(data->run_duration_sum(), 0); |
245 EXPECT_EQ(data->run_duration_max(), 0); | 246 EXPECT_EQ(data->run_duration_max(), 0); |
246 EXPECT_EQ(data->run_duration_sample(), 0); | 247 EXPECT_EQ(data->run_duration_sample(), 0); |
247 EXPECT_EQ(data->queue_duration_sum(), 0); | 248 EXPECT_EQ(data->queue_duration_sum(), 0); |
248 EXPECT_EQ(data->queue_duration_max(), 0); | 249 EXPECT_EQ(data->queue_duration_max(), 0); |
249 EXPECT_EQ(data->queue_duration_sample(), 0); | 250 EXPECT_EQ(data->queue_duration_sample(), 0); |
250 EXPECT_EQ(data->count(), 0); | 251 EXPECT_EQ(data->count(), 0); |
251 EXPECT_EQ(nullptr, data->last_phase_snapshot()); | 252 EXPECT_EQ(nullptr, data->last_phase_snapshot()); |
252 | 253 |
(...skipping 18 matching lines...) Expand all Loading... |
271 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms); | 272 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms); |
272 EXPECT_EQ(data->queue_duration_max(), queue_ms); | 273 EXPECT_EQ(data->queue_duration_max(), queue_ms); |
273 EXPECT_EQ(data->queue_duration_sample(), queue_ms); | 274 EXPECT_EQ(data->queue_duration_sample(), queue_ms); |
274 EXPECT_EQ(data->count(), 2); | 275 EXPECT_EQ(data->count(), 2); |
275 EXPECT_EQ(nullptr, data->last_phase_snapshot()); | 276 EXPECT_EQ(nullptr, data->last_phase_snapshot()); |
276 } | 277 } |
277 | 278 |
278 TEST_F(TrackedObjectsTest, DeathDataTest2Phases) { | 279 TEST_F(TrackedObjectsTest, DeathDataTest2Phases) { |
279 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE); | 280 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE); |
280 | 281 |
281 scoped_ptr<DeathData> data(new DeathData()); | 282 std::unique_ptr<DeathData> data(new DeathData()); |
282 ASSERT_NE(data, nullptr); | 283 ASSERT_NE(data, nullptr); |
283 | 284 |
284 int32_t run_ms = 42; | 285 int32_t run_ms = 42; |
285 int32_t queue_ms = 8; | 286 int32_t queue_ms = 8; |
286 | 287 |
287 const int kUnrandomInt = 0; // Fake random int that ensure we sample data. | 288 const int kUnrandomInt = 0; // Fake random int that ensure we sample data. |
288 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); | 289 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); |
289 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); | 290 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); |
290 | 291 |
291 data->OnProfilingPhaseCompleted(123); | 292 data->OnProfilingPhaseCompleted(123); |
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_max); | 1178 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_max); |
1178 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sample); | 1179 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sample); |
1179 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sum); | 1180 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sum); |
1180 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_max); | 1181 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_max); |
1181 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sample); | 1182 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sample); |
1182 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].death_thread_name); | 1183 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].death_thread_name); |
1183 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 1184 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
1184 } | 1185 } |
1185 | 1186 |
1186 } // namespace tracked_objects | 1187 } // namespace tracked_objects |
OLD | NEW |