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

Side by Side Diff: chromecast/crash/linux/synchronized_minidump_manager_unittest.cc

Issue 1254113004: [Chromecast] Consolidate duplicated crash test functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Fixed namespace footer comment Created 5 years, 4 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
« no previous file with comments | « chromecast/crash/linux/minidump_writer_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <fcntl.h> 5 #include <fcntl.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <sys/file.h> 7 #include <sys/file.h>
8 #include <sys/stat.h> // mkdir 8 #include <sys/stat.h> // mkdir
9 #include <sys/types.h> // 9 #include <sys/types.h> //
10 #include <stdio.h> // perror 10 #include <stdio.h> // perror
11 #include <time.h> 11 #include <time.h>
12 12
13 #include <fstream> 13 #include <fstream>
14 14
15 #include "base/base_paths.h" 15 #include "base/base_paths.h"
16 #include "base/bind.h" 16 #include "base/bind.h"
17 #include "base/files/file.h" 17 #include "base/files/file.h"
18 #include "base/files/file_util.h" 18 #include "base/files/file_util.h"
19 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
20 #include "base/memory/scoped_vector.h" 20 #include "base/memory/scoped_vector.h"
21 #include "base/process/launch.h" 21 #include "base/process/launch.h"
22 #include "base/test/scoped_path_override.h" 22 #include "base/test/scoped_path_override.h"
23 #include "base/threading/platform_thread.h" 23 #include "base/threading/platform_thread.h"
24 #include "base/threading/thread.h" 24 #include "base/threading/thread.h"
25 #include "chromecast/base/serializers.h" 25 #include "chromecast/crash/linux/crash_testing_utils.h"
26 #include "chromecast/crash/linux/dump_info.h" 26 #include "chromecast/crash/linux/dump_info.h"
27 #include "chromecast/crash/linux/synchronized_minidump_manager.h" 27 #include "chromecast/crash/linux/synchronized_minidump_manager.h"
28 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
29 29
30 namespace chromecast { 30 namespace chromecast {
31 namespace { 31 namespace {
32 32
33 const char kLockfileName[] = "lockfile"; 33 const char kLockfileName[] = "lockfile";
34 const char kMinidumpSubdir[] = "minidumps"; 34 const char kMinidumpSubdir[] = "minidumps";
35 const char kDumpsKey[] = "dumps";
36 35
37 // A trivial implementation of SynchronizedMinidumpManager, which does no work 36 // A trivial implementation of SynchronizedMinidumpManager, which does no work
38 // to the 37 // to the
39 // minidump and exposes its protected members for testing. 38 // minidump and exposes its protected members for testing.
40 class SynchronizedMinidumpManagerSimple : public SynchronizedMinidumpManager { 39 class SynchronizedMinidumpManagerSimple : public SynchronizedMinidumpManager {
41 public: 40 public:
42 SynchronizedMinidumpManagerSimple() 41 SynchronizedMinidumpManagerSimple()
43 : SynchronizedMinidumpManager(), 42 : SynchronizedMinidumpManager(),
44 work_done_(false), 43 work_done_(false),
45 add_entry_return_code_(-1), 44 add_entry_return_code_(-1),
(...skipping 20 matching lines...) Expand all
66 bool work_done() { return work_done_; } 65 bool work_done() { return work_done_; }
67 int add_entry_return_code() { return add_entry_return_code_; } 66 int add_entry_return_code() { return add_entry_return_code_; }
68 67
69 private: 68 private:
70 bool work_done_; 69 bool work_done_;
71 int add_entry_return_code_; 70 int add_entry_return_code_;
72 std::string lockfile_path_; 71 std::string lockfile_path_;
73 scoped_ptr<DumpInfo> dump_info_; 72 scoped_ptr<DumpInfo> dump_info_;
74 }; 73 };
75 74
76 bool FetchDumps(const std::string& lockfile_path,
77 ScopedVector<DumpInfo>* dumps) {
78 if (!dumps) {
79 return false;
80 }
81 dumps->clear();
82
83 base::FilePath path(lockfile_path);
84 scoped_ptr<base::Value> contents(DeserializeJsonFromFile(path));
85
86 base::DictionaryValue* dict;
87 base::ListValue* dump_list;
88 if (!contents || !contents->GetAsDictionary(&dict) ||
89 !dict->GetList(kDumpsKey, &dump_list) || !dump_list) {
90 return false;
91 }
92
93 for (base::Value* elem : *dump_list) {
94 scoped_ptr<DumpInfo> dump = make_scoped_ptr(new DumpInfo(elem));
95 if (!dump->valid()) {
96 return false;
97 }
98 dumps->push_back(dump.Pass());
99 }
100
101 return true;
102 }
103
104 bool CreateLockFile(const std::string& lockfile_path) {
105 scoped_ptr<base::DictionaryValue> output =
106 make_scoped_ptr(new base::DictionaryValue());
107 output->Set("dumps", make_scoped_ptr(new base::ListValue()));
108
109 base::FilePath path(lockfile_path);
110
111 const base::Value* val = output.get();
112 return SerializeJsonToFile(path, *val);
113 }
114
115 void DoWorkLockedTask(SynchronizedMinidumpManagerSimple* manager) { 75 void DoWorkLockedTask(SynchronizedMinidumpManagerSimple* manager) {
116 manager->DoWorkLocked(); 76 manager->DoWorkLocked();
117 } 77 }
118 78
119 class SleepySynchronizedMinidumpManagerSimple 79 class SleepySynchronizedMinidumpManagerSimple
120 : public SynchronizedMinidumpManagerSimple { 80 : public SynchronizedMinidumpManagerSimple {
121 public: 81 public:
122 SleepySynchronizedMinidumpManagerSimple(int sleep_duration_ms) 82 SleepySynchronizedMinidumpManagerSimple(int sleep_duration_ms)
123 : SynchronizedMinidumpManagerSimple(), 83 : SynchronizedMinidumpManagerSimple(),
124 sleep_duration_ms_(sleep_duration_ms) {} 84 sleep_duration_ms_(sleep_duration_ms) {}
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 EXPECT_EQ(0, manager.add_entry_return_code()); 374 EXPECT_EQ(0, manager.add_entry_return_code());
415 EXPECT_TRUE(manager.work_done()); 375 EXPECT_TRUE(manager.work_done());
416 376
417 // Test that both entries were logged. 377 // Test that both entries were logged.
418 ScopedVector<DumpInfo> dumps; 378 ScopedVector<DumpInfo> dumps;
419 ASSERT_TRUE(FetchDumps(lockfile_.value(), &dumps)); 379 ASSERT_TRUE(FetchDumps(lockfile_.value(), &dumps));
420 EXPECT_EQ(2u, dumps.size()); 380 EXPECT_EQ(2u, dumps.size());
421 } 381 }
422 382
423 } // namespace chromecast 383 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/crash/linux/minidump_writer_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698