OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chromecast/crash/linux/synchronized_minidump_manager.h" | 5 #include "chromecast/crash/linux/synchronized_minidump_manager.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <stdio.h> // perror | 9 #include <stdio.h> // perror |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
11 #include <sys/file.h> | 11 #include <sys/file.h> |
12 #include <sys/stat.h> // mkdir | 12 #include <sys/stat.h> // mkdir |
13 #include <sys/types.h> | 13 #include <sys/types.h> |
14 #include <time.h> | 14 #include <time.h> |
| 15 |
15 #include <fstream> | 16 #include <fstream> |
| 17 #include <memory> |
16 #include <utility> | 18 #include <utility> |
17 | 19 |
18 #include "base/base_paths.h" | 20 #include "base/base_paths.h" |
19 #include "base/bind.h" | 21 #include "base/bind.h" |
20 #include "base/files/file.h" | 22 #include "base/files/file.h" |
21 #include "base/files/file_util.h" | 23 #include "base/files/file_util.h" |
22 #include "base/files/scoped_temp_dir.h" | 24 #include "base/files/scoped_temp_dir.h" |
23 #include "base/memory/scoped_ptr.h" | 25 #include "base/memory/ptr_util.h" |
24 #include "base/memory/scoped_vector.h" | 26 #include "base/memory/scoped_vector.h" |
25 #include "base/process/launch.h" | 27 #include "base/process/launch.h" |
26 #include "base/test/scoped_path_override.h" | 28 #include "base/test/scoped_path_override.h" |
27 #include "base/threading/platform_thread.h" | 29 #include "base/threading/platform_thread.h" |
28 #include "base/threading/thread.h" | 30 #include "base/threading/thread.h" |
29 #include "chromecast/base/scoped_temp_file.h" | 31 #include "chromecast/base/scoped_temp_file.h" |
30 #include "chromecast/crash/linux/crash_testing_utils.h" | 32 #include "chromecast/crash/linux/crash_testing_utils.h" |
31 #include "chromecast/crash/linux/dump_info.h" | 33 #include "chromecast/crash/linux/dump_info.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
33 | 35 |
34 namespace chromecast { | 36 namespace chromecast { |
35 namespace { | 37 namespace { |
36 | 38 |
37 const char kLockfileName[] = "lockfile"; | 39 const char kLockfileName[] = "lockfile"; |
38 const char kMetadataName[] = "metadata"; | 40 const char kMetadataName[] = "metadata"; |
39 const char kMinidumpSubdir[] = "minidumps"; | 41 const char kMinidumpSubdir[] = "minidumps"; |
40 | 42 |
41 // A trivial implementation of SynchronizedMinidumpManager, which does no work | 43 // A trivial implementation of SynchronizedMinidumpManager, which does no work |
42 // to the minidump and exposes its protected members for testing. This simply | 44 // to the minidump and exposes its protected members for testing. This simply |
43 // adds an entry to the lockfile. | 45 // adds an entry to the lockfile. |
44 class SynchronizedMinidumpManagerSimple : public SynchronizedMinidumpManager { | 46 class SynchronizedMinidumpManagerSimple : public SynchronizedMinidumpManager { |
45 public: | 47 public: |
46 SynchronizedMinidumpManagerSimple() | 48 SynchronizedMinidumpManagerSimple() |
47 : SynchronizedMinidumpManager(), | 49 : SynchronizedMinidumpManager(), |
48 work_done_(false), | 50 work_done_(false), |
49 add_entry_return_code_(-1), | 51 add_entry_return_code_(-1), |
50 lockfile_path_(dump_path_.Append(kLockfileName).value()) {} | 52 lockfile_path_(dump_path_.Append(kLockfileName).value()) {} |
51 ~SynchronizedMinidumpManagerSimple() override {} | 53 ~SynchronizedMinidumpManagerSimple() override {} |
52 | 54 |
53 void SetDumpInfoToWrite(scoped_ptr<DumpInfo> dump_info) { | 55 void SetDumpInfoToWrite(std::unique_ptr<DumpInfo> dump_info) { |
54 dump_info_ = std::move(dump_info); | 56 dump_info_ = std::move(dump_info); |
55 } | 57 } |
56 | 58 |
57 int DoWorkLocked() { return AcquireLockAndDoWork(); } | 59 int DoWorkLocked() { return AcquireLockAndDoWork(); } |
58 | 60 |
59 // SynchronizedMinidumpManager implementation: | 61 // SynchronizedMinidumpManager implementation: |
60 int DoWork() override { | 62 int DoWork() override { |
61 if (dump_info_) | 63 if (dump_info_) |
62 add_entry_return_code_ = AddEntryToLockFile(*dump_info_); | 64 add_entry_return_code_ = AddEntryToLockFile(*dump_info_); |
63 work_done_ = true; | 65 work_done_ = true; |
64 return 0; | 66 return 0; |
65 } | 67 } |
66 | 68 |
67 // Accessors for testing. | 69 // Accessors for testing. |
68 bool HasDumps() { return SynchronizedMinidumpManager::HasDumps(); } | 70 bool HasDumps() { return SynchronizedMinidumpManager::HasDumps(); } |
69 const std::string& dump_path() { return dump_path_.value(); } | 71 const std::string& dump_path() { return dump_path_.value(); } |
70 const std::string& lockfile_path() { return lockfile_path_; } | 72 const std::string& lockfile_path() { return lockfile_path_; } |
71 bool work_done() { return work_done_; } | 73 bool work_done() { return work_done_; } |
72 int add_entry_return_code() { return add_entry_return_code_; } | 74 int add_entry_return_code() { return add_entry_return_code_; } |
73 | 75 |
74 private: | 76 private: |
75 bool work_done_; | 77 bool work_done_; |
76 int add_entry_return_code_; | 78 int add_entry_return_code_; |
77 std::string lockfile_path_; | 79 std::string lockfile_path_; |
78 scoped_ptr<DumpInfo> dump_info_; | 80 std::unique_ptr<DumpInfo> dump_info_; |
79 }; | 81 }; |
80 | 82 |
81 void DoWorkLockedTask(SynchronizedMinidumpManagerSimple* manager) { | 83 void DoWorkLockedTask(SynchronizedMinidumpManagerSimple* manager) { |
82 manager->DoWorkLocked(); | 84 manager->DoWorkLocked(); |
83 } | 85 } |
84 | 86 |
85 // Simple SynchronizedMinidumpManager consumer. Checks if a dump can be uploaded | 87 // Simple SynchronizedMinidumpManager consumer. Checks if a dump can be uploaded |
86 // then removes it from the lockfile. | 88 // then removes it from the lockfile. |
87 class FakeSynchronizedMinidumpUploader : public SynchronizedMinidumpManager { | 89 class FakeSynchronizedMinidumpUploader : public SynchronizedMinidumpManager { |
88 public: | 90 public: |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 ASSERT_TRUE(lockfile.IsValid()); | 161 ASSERT_TRUE(lockfile.IsValid()); |
160 } | 162 } |
161 | 163 |
162 protected: | 164 protected: |
163 base::FilePath minidump_dir_; // Path the the minidump directory. | 165 base::FilePath minidump_dir_; // Path the the minidump directory. |
164 base::FilePath lockfile_; // Path to the lockfile in |minidump_dir_|. | 166 base::FilePath lockfile_; // Path to the lockfile in |minidump_dir_|. |
165 base::FilePath metadata_; // Path to the metadata in |minidump_dir_|. | 167 base::FilePath metadata_; // Path to the metadata in |minidump_dir_|. |
166 | 168 |
167 private: | 169 private: |
168 base::ScopedTempDir fake_home_dir_; | 170 base::ScopedTempDir fake_home_dir_; |
169 scoped_ptr<base::ScopedPathOverride> path_override_; | 171 std::unique_ptr<base::ScopedPathOverride> path_override_; |
170 }; | 172 }; |
171 | 173 |
172 // Have |producer| generate |num_dumps| while checking there are no errors. | 174 // Have |producer| generate |num_dumps| while checking there are no errors. |
173 void produce_dumps(SynchronizedMinidumpManagerSimple& producer, int num_dumps) { | 175 void produce_dumps(SynchronizedMinidumpManagerSimple& producer, int num_dumps) { |
174 for (int i = 0; i < num_dumps; ++i) { | 176 for (int i = 0; i < num_dumps; ++i) { |
175 ASSERT_EQ(0, producer.DoWorkLocked()); | 177 ASSERT_EQ(0, producer.DoWorkLocked()); |
176 ASSERT_EQ(0, producer.add_entry_return_code()); | 178 ASSERT_EQ(0, producer.add_entry_return_code()); |
177 } | 179 } |
178 } | 180 } |
179 | 181 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 ASSERT_TRUE(base::PathExists(lockfile_)); | 237 ASSERT_TRUE(base::PathExists(lockfile_)); |
236 } | 238 } |
237 | 239 |
238 TEST_F(SynchronizedMinidumpManagerTest, | 240 TEST_F(SynchronizedMinidumpManagerTest, |
239 AddEntryToLockFile_FailsWithInvalidEntry) { | 241 AddEntryToLockFile_FailsWithInvalidEntry) { |
240 // Create invalid dump info value | 242 // Create invalid dump info value |
241 base::DictionaryValue val; | 243 base::DictionaryValue val; |
242 | 244 |
243 // Test that the manager tried to log the entry and failed. | 245 // Test that the manager tried to log the entry and failed. |
244 SynchronizedMinidumpManagerSimple manager; | 246 SynchronizedMinidumpManagerSimple manager; |
245 manager.SetDumpInfoToWrite(make_scoped_ptr(new DumpInfo(&val))); | 247 manager.SetDumpInfoToWrite(base::WrapUnique(new DumpInfo(&val))); |
246 ASSERT_EQ(0, manager.DoWorkLocked()); | 248 ASSERT_EQ(0, manager.DoWorkLocked()); |
247 ASSERT_EQ(-1, manager.add_entry_return_code()); | 249 ASSERT_EQ(-1, manager.add_entry_return_code()); |
248 | 250 |
249 // Verify the lockfile is untouched. | 251 // Verify the lockfile is untouched. |
250 ScopedVector<DumpInfo> dumps; | 252 ScopedVector<DumpInfo> dumps; |
251 ASSERT_TRUE(FetchDumps(lockfile_.value(), &dumps)); | 253 ASSERT_TRUE(FetchDumps(lockfile_.value(), &dumps)); |
252 ASSERT_EQ(0u, dumps.size()); | 254 ASSERT_EQ(0u, dumps.size()); |
253 } | 255 } |
254 | 256 |
255 TEST_F(SynchronizedMinidumpManagerTest, | 257 TEST_F(SynchronizedMinidumpManagerTest, |
256 AddEntryToLockFile_SucceedsWithValidEntries) { | 258 AddEntryToLockFile_SucceedsWithValidEntries) { |
257 // Sample parameters. | 259 // Sample parameters. |
258 time_t now = time(0); | 260 time_t now = time(0); |
259 MinidumpParams params; | 261 MinidumpParams params; |
260 params.process_name = "process"; | 262 params.process_name = "process"; |
261 | 263 |
262 // Write the first entry. | 264 // Write the first entry. |
263 SynchronizedMinidumpManagerSimple manager; | 265 SynchronizedMinidumpManagerSimple manager; |
264 manager.SetDumpInfoToWrite( | 266 manager.SetDumpInfoToWrite( |
265 make_scoped_ptr(new DumpInfo("dump1", "log1", now, params))); | 267 base::WrapUnique(new DumpInfo("dump1", "log1", now, params))); |
266 ASSERT_EQ(0, manager.DoWorkLocked()); | 268 ASSERT_EQ(0, manager.DoWorkLocked()); |
267 ASSERT_EQ(0, manager.add_entry_return_code()); | 269 ASSERT_EQ(0, manager.add_entry_return_code()); |
268 | 270 |
269 // Test that the manager was successful in logging the entry. | 271 // Test that the manager was successful in logging the entry. |
270 ScopedVector<DumpInfo> dumps; | 272 ScopedVector<DumpInfo> dumps; |
271 ASSERT_TRUE(FetchDumps(lockfile_.value(), &dumps)); | 273 ASSERT_TRUE(FetchDumps(lockfile_.value(), &dumps)); |
272 ASSERT_EQ(1u, dumps.size()); | 274 ASSERT_EQ(1u, dumps.size()); |
273 | 275 |
274 // Write the second entry. | 276 // Write the second entry. |
275 manager.SetDumpInfoToWrite( | 277 manager.SetDumpInfoToWrite( |
276 make_scoped_ptr(new DumpInfo("dump2", "log2", now, params))); | 278 base::WrapUnique(new DumpInfo("dump2", "log2", now, params))); |
277 ASSERT_EQ(0, manager.DoWorkLocked()); | 279 ASSERT_EQ(0, manager.DoWorkLocked()); |
278 ASSERT_EQ(0, manager.add_entry_return_code()); | 280 ASSERT_EQ(0, manager.add_entry_return_code()); |
279 | 281 |
280 // Test that the second entry is also valid. | 282 // Test that the second entry is also valid. |
281 ASSERT_TRUE(FetchDumps(lockfile_.value(), &dumps)); | 283 ASSERT_TRUE(FetchDumps(lockfile_.value(), &dumps)); |
282 ASSERT_EQ(2u, dumps.size()); | 284 ASSERT_EQ(2u, dumps.size()); |
283 } | 285 } |
284 | 286 |
285 TEST_F(SynchronizedMinidumpManagerTest, | 287 TEST_F(SynchronizedMinidumpManagerTest, |
286 AcquireLockFile_FailsWhenNonBlockingAndFileLocked) { | 288 AcquireLockFile_FailsWhenNonBlockingAndFileLocked) { |
(...skipping 22 matching lines...) Expand all Loading... |
309 time_t now = time(0); | 311 time_t now = time(0); |
310 MinidumpParams params; | 312 MinidumpParams params; |
311 params.process_name = "process"; | 313 params.process_name = "process"; |
312 | 314 |
313 // Create a manager that grabs the lock then sleeps. Post a DoWork task to | 315 // Create a manager that grabs the lock then sleeps. Post a DoWork task to |
314 // another thread. |sleepy_manager| will grab the lock and hold it for | 316 // another thread. |sleepy_manager| will grab the lock and hold it for |
315 // |sleep_time_ms|. It will then write a dump and release the lock. | 317 // |sleep_time_ms|. It will then write a dump and release the lock. |
316 const int sleep_time_ms = 100; | 318 const int sleep_time_ms = 100; |
317 SleepySynchronizedMinidumpManagerSimple sleepy_manager(sleep_time_ms); | 319 SleepySynchronizedMinidumpManagerSimple sleepy_manager(sleep_time_ms); |
318 sleepy_manager.SetDumpInfoToWrite( | 320 sleepy_manager.SetDumpInfoToWrite( |
319 make_scoped_ptr(new DumpInfo("dump", "log", now, params))); | 321 base::WrapUnique(new DumpInfo("dump", "log", now, params))); |
320 base::Thread sleepy_thread("sleepy"); | 322 base::Thread sleepy_thread("sleepy"); |
321 sleepy_thread.Start(); | 323 sleepy_thread.Start(); |
322 sleepy_thread.task_runner()->PostTask( | 324 sleepy_thread.task_runner()->PostTask( |
323 FROM_HERE, | 325 FROM_HERE, |
324 base::Bind(&DoWorkLockedTask, base::Unretained(&sleepy_manager))); | 326 base::Bind(&DoWorkLockedTask, base::Unretained(&sleepy_manager))); |
325 | 327 |
326 // Meanwhile, this thread should wait brielfy to allow the other thread to | 328 // Meanwhile, this thread should wait brielfy to allow the other thread to |
327 // grab the lock. | 329 // grab the lock. |
328 const int concurrency_delay = 50; | 330 const int concurrency_delay = 50; |
329 base::PlatformThread::Sleep( | 331 base::PlatformThread::Sleep( |
330 base::TimeDelta::FromMilliseconds(concurrency_delay)); | 332 base::TimeDelta::FromMilliseconds(concurrency_delay)); |
331 | 333 |
332 // |sleepy_manager| has the lock by now, but has not released it. Attempt to | 334 // |sleepy_manager| has the lock by now, but has not released it. Attempt to |
333 // grab it. DoWorkLocked() should block until |manager| has a chance to write | 335 // grab it. DoWorkLocked() should block until |manager| has a chance to write |
334 // the dump. | 336 // the dump. |
335 SynchronizedMinidumpManagerSimple manager; | 337 SynchronizedMinidumpManagerSimple manager; |
336 manager.SetDumpInfoToWrite( | 338 manager.SetDumpInfoToWrite( |
337 make_scoped_ptr(new DumpInfo("dump", "log", now, params))); | 339 base::WrapUnique(new DumpInfo("dump", "log", now, params))); |
338 manager.set_non_blocking(false); | 340 manager.set_non_blocking(false); |
339 | 341 |
340 EXPECT_EQ(0, manager.DoWorkLocked()); | 342 EXPECT_EQ(0, manager.DoWorkLocked()); |
341 EXPECT_EQ(0, manager.add_entry_return_code()); | 343 EXPECT_EQ(0, manager.add_entry_return_code()); |
342 EXPECT_TRUE(manager.work_done()); | 344 EXPECT_TRUE(manager.work_done()); |
343 | 345 |
344 // Check that the other manager was also successful. | 346 // Check that the other manager was also successful. |
345 EXPECT_EQ(0, sleepy_manager.add_entry_return_code()); | 347 EXPECT_EQ(0, sleepy_manager.add_entry_return_code()); |
346 EXPECT_TRUE(sleepy_manager.work_done()); | 348 EXPECT_TRUE(sleepy_manager.work_done()); |
347 | 349 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 params.process_name = "process"; | 396 params.process_name = "process"; |
395 | 397 |
396 // Fork the process. | 398 // Fork the process. |
397 pid_t pid = base::ForkWithFlags(0u, nullptr, nullptr); | 399 pid_t pid = base::ForkWithFlags(0u, nullptr, nullptr); |
398 if (pid != 0) { | 400 if (pid != 0) { |
399 // The child process should instantiate a manager which immediately grabs | 401 // The child process should instantiate a manager which immediately grabs |
400 // the lock, and falls aleep for some period of time, then writes a dump, | 402 // the lock, and falls aleep for some period of time, then writes a dump, |
401 // and finally releases the lock. | 403 // and finally releases the lock. |
402 SleepySynchronizedMinidumpManagerSimple sleepy_manager(100); | 404 SleepySynchronizedMinidumpManagerSimple sleepy_manager(100); |
403 sleepy_manager.SetDumpInfoToWrite( | 405 sleepy_manager.SetDumpInfoToWrite( |
404 make_scoped_ptr(new DumpInfo("dump", "log", now, params))); | 406 base::WrapUnique(new DumpInfo("dump", "log", now, params))); |
405 ASSERT_EQ(0, sleepy_manager.DoWorkLocked()); | 407 ASSERT_EQ(0, sleepy_manager.DoWorkLocked()); |
406 ASSERT_TRUE(sleepy_manager.work_done()); | 408 ASSERT_TRUE(sleepy_manager.work_done()); |
407 return; | 409 return; |
408 } | 410 } |
409 | 411 |
410 // Meanwhile, this process should wait brielfy to allow the other thread to | 412 // Meanwhile, this process should wait brielfy to allow the other thread to |
411 // grab the lock. | 413 // grab the lock. |
412 const int concurrency_delay = 50; | 414 const int concurrency_delay = 50; |
413 base::PlatformThread::Sleep( | 415 base::PlatformThread::Sleep( |
414 base::TimeDelta::FromMilliseconds(concurrency_delay)); | 416 base::TimeDelta::FromMilliseconds(concurrency_delay)); |
415 | 417 |
416 // |sleepy_manager| has the lock by now, but has not released it. Attempt to | 418 // |sleepy_manager| has the lock by now, but has not released it. Attempt to |
417 // grab it. DoWorkLocked() should block until |manager| has a chance to write | 419 // grab it. DoWorkLocked() should block until |manager| has a chance to write |
418 // the dump. | 420 // the dump. |
419 SynchronizedMinidumpManagerSimple manager; | 421 SynchronizedMinidumpManagerSimple manager; |
420 manager.SetDumpInfoToWrite( | 422 manager.SetDumpInfoToWrite( |
421 make_scoped_ptr(new DumpInfo("dump", "log", now, params))); | 423 base::WrapUnique(new DumpInfo("dump", "log", now, params))); |
422 manager.set_non_blocking(false); | 424 manager.set_non_blocking(false); |
423 | 425 |
424 EXPECT_EQ(0, manager.DoWorkLocked()); | 426 EXPECT_EQ(0, manager.DoWorkLocked()); |
425 EXPECT_EQ(0, manager.add_entry_return_code()); | 427 EXPECT_EQ(0, manager.add_entry_return_code()); |
426 EXPECT_TRUE(manager.work_done()); | 428 EXPECT_TRUE(manager.work_done()); |
427 | 429 |
428 // Test that both entries were logged. | 430 // Test that both entries were logged. |
429 ScopedVector<DumpInfo> dumps; | 431 ScopedVector<DumpInfo> dumps; |
430 ASSERT_TRUE(FetchDumps(lockfile_.value(), &dumps)); | 432 ASSERT_TRUE(FetchDumps(lockfile_.value(), &dumps)); |
431 EXPECT_EQ(2u, dumps.size()); | 433 EXPECT_EQ(2u, dumps.size()); |
432 } | 434 } |
433 | 435 |
434 TEST_F(SynchronizedMinidumpManagerTest, | 436 TEST_F(SynchronizedMinidumpManagerTest, |
435 Upload_SucceedsWhenDumpLimitsNotExceeded) { | 437 Upload_SucceedsWhenDumpLimitsNotExceeded) { |
436 // Sample parameters. | 438 // Sample parameters. |
437 time_t now = time(0); | 439 time_t now = time(0); |
438 MinidumpParams params; | 440 MinidumpParams params; |
439 params.process_name = "process"; | 441 params.process_name = "process"; |
440 | 442 |
441 FakeSynchronizedMinidumpUploader uploader; | 443 FakeSynchronizedMinidumpUploader uploader; |
442 SynchronizedMinidumpManagerSimple producer; | 444 SynchronizedMinidumpManagerSimple producer; |
443 producer.SetDumpInfoToWrite( | 445 producer.SetDumpInfoToWrite( |
444 make_scoped_ptr(new DumpInfo("dump1", "log1", now, params))); | 446 base::WrapUnique(new DumpInfo("dump1", "log1", now, params))); |
445 | 447 |
446 const int max_dumps = SynchronizedMinidumpManager::kRatelimitPeriodMaxDumps; | 448 const int max_dumps = SynchronizedMinidumpManager::kRatelimitPeriodMaxDumps; |
447 produce_dumps(producer, max_dumps); | 449 produce_dumps(producer, max_dumps); |
448 consume_dumps(uploader, max_dumps); | 450 consume_dumps(uploader, max_dumps); |
449 } | 451 } |
450 | 452 |
451 TEST_F(SynchronizedMinidumpManagerTest, Upload_FailsWhenTooManyRecentDumps) { | 453 TEST_F(SynchronizedMinidumpManagerTest, Upload_FailsWhenTooManyRecentDumps) { |
452 // Sample parameters. | 454 // Sample parameters. |
453 time_t now = time(0); | 455 time_t now = time(0); |
454 MinidumpParams params; | 456 MinidumpParams params; |
455 params.process_name = "process"; | 457 params.process_name = "process"; |
456 | 458 |
457 FakeSynchronizedMinidumpUploader uploader; | 459 FakeSynchronizedMinidumpUploader uploader; |
458 SynchronizedMinidumpManagerSimple producer; | 460 SynchronizedMinidumpManagerSimple producer; |
459 producer.SetDumpInfoToWrite( | 461 producer.SetDumpInfoToWrite( |
460 make_scoped_ptr(new DumpInfo("dump1", "log1", now, params))); | 462 base::WrapUnique(new DumpInfo("dump1", "log1", now, params))); |
461 | 463 |
462 const int max_dumps = SynchronizedMinidumpManager::kRatelimitPeriodMaxDumps; | 464 const int max_dumps = SynchronizedMinidumpManager::kRatelimitPeriodMaxDumps; |
463 produce_dumps(producer, max_dumps + 1); | 465 produce_dumps(producer, max_dumps + 1); |
464 consume_dumps(uploader, max_dumps); | 466 consume_dumps(uploader, max_dumps); |
465 | 467 |
466 // Should fail with too many dumps | 468 // Should fail with too many dumps |
467 ASSERT_EQ(0, uploader.DoWorkLocked()); | 469 ASSERT_EQ(0, uploader.DoWorkLocked()); |
468 ASSERT_FALSE(uploader.can_upload_return_val()); | 470 ASSERT_FALSE(uploader.can_upload_return_val()); |
469 } | 471 } |
470 | 472 |
471 TEST_F(SynchronizedMinidumpManagerTest, UploadSucceedsAfterRateLimitPeriodEnd) { | 473 TEST_F(SynchronizedMinidumpManagerTest, UploadSucceedsAfterRateLimitPeriodEnd) { |
472 // Sample parameters. | 474 // Sample parameters. |
473 time_t now = time(0); | 475 time_t now = time(0); |
474 MinidumpParams params; | 476 MinidumpParams params; |
475 params.process_name = "process"; | 477 params.process_name = "process"; |
476 | 478 |
477 FakeSynchronizedMinidumpUploader uploader; | 479 FakeSynchronizedMinidumpUploader uploader; |
478 SynchronizedMinidumpManagerSimple producer; | 480 SynchronizedMinidumpManagerSimple producer; |
479 producer.SetDumpInfoToWrite( | 481 producer.SetDumpInfoToWrite( |
480 make_scoped_ptr(new DumpInfo("dump1", "log1", now, params))); | 482 base::WrapUnique(new DumpInfo("dump1", "log1", now, params))); |
481 | 483 |
482 const int iters = 3; | 484 const int iters = 3; |
483 const int max_dumps = SynchronizedMinidumpManager::kRatelimitPeriodMaxDumps; | 485 const int max_dumps = SynchronizedMinidumpManager::kRatelimitPeriodMaxDumps; |
484 | 486 |
485 for (int i = 0; i < iters; ++i) { | 487 for (int i = 0; i < iters; ++i) { |
486 produce_dumps(producer, max_dumps + 1); | 488 produce_dumps(producer, max_dumps + 1); |
487 consume_dumps(uploader, max_dumps); | 489 consume_dumps(uploader, max_dumps); |
488 | 490 |
489 // Should fail with too many dumps | 491 // Should fail with too many dumps |
490 ASSERT_EQ(0, uploader.DoWorkLocked()); | 492 ASSERT_EQ(0, uploader.DoWorkLocked()); |
(...skipping 23 matching lines...) Expand all Loading... |
514 TEST_F(SynchronizedMinidumpManagerTest, HasDumpsWithDumps) { | 516 TEST_F(SynchronizedMinidumpManagerTest, HasDumpsWithDumps) { |
515 // Sample parameters. | 517 // Sample parameters. |
516 time_t now = time(0); | 518 time_t now = time(0); |
517 MinidumpParams params; | 519 MinidumpParams params; |
518 params.process_name = "process"; | 520 params.process_name = "process"; |
519 | 521 |
520 SynchronizedMinidumpManagerSimple producer; | 522 SynchronizedMinidumpManagerSimple producer; |
521 FakeSynchronizedMinidumpUploader uploader; | 523 FakeSynchronizedMinidumpUploader uploader; |
522 | 524 |
523 producer.SetDumpInfoToWrite( | 525 producer.SetDumpInfoToWrite( |
524 make_scoped_ptr(new DumpInfo("dump1", "log1", now, params))); | 526 base::WrapUnique(new DumpInfo("dump1", "log1", now, params))); |
525 | 527 |
526 const int kNumDumps = 3; | 528 const int kNumDumps = 3; |
527 for (int i = 0; i < kNumDumps; ++i) { | 529 for (int i = 0; i < kNumDumps; ++i) { |
528 produce_dumps(producer, 1); | 530 produce_dumps(producer, 1); |
529 ASSERT_TRUE(uploader.HasDumps()); | 531 ASSERT_TRUE(uploader.HasDumps()); |
530 } | 532 } |
531 | 533 |
532 for (int i = 0; i < kNumDumps; ++i) { | 534 for (int i = 0; i < kNumDumps; ++i) { |
533 ASSERT_TRUE(uploader.HasDumps()); | 535 ASSERT_TRUE(uploader.HasDumps()); |
534 consume_dumps(uploader, 1); | 536 consume_dumps(uploader, 1); |
(...skipping 10 matching lines...) Expand all Loading... |
545 const base::FilePath path = | 547 const base::FilePath path = |
546 base::FilePath(manager.dump_path()).Append("hello123"); | 548 base::FilePath(manager.dump_path()).Append("hello123"); |
547 const char kFileContents[] = "foobar"; | 549 const char kFileContents[] = "foobar"; |
548 ASSERT_EQ(static_cast<int>(sizeof(kFileContents)), | 550 ASSERT_EQ(static_cast<int>(sizeof(kFileContents)), |
549 WriteFile(path, kFileContents, sizeof(kFileContents))); | 551 WriteFile(path, kFileContents, sizeof(kFileContents))); |
550 | 552 |
551 ASSERT_TRUE(manager.HasDumps()); | 553 ASSERT_TRUE(manager.HasDumps()); |
552 } | 554 } |
553 | 555 |
554 } // namespace chromecast | 556 } // namespace chromecast |
OLD | NEW |