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

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

Issue 1154383006: Adding crash utilities to chromecast/crash. (Closed) Base URL: https://eureka-internal.googlesource.com/chromium/src@master
Patch Set: Linux-specific utils moved to linux/ Created 5 years, 6 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
(Empty)
1
2 #include "base/base_paths.h"
3 #include "base/files/file_path.h"
4 #include "base/files/file_util.h"
5 #include "base/memory/scoped_ptr.h"
6 #include "base/test/scoped_path_override.h"
7 #include "chromecast/crash/linux/minidump_generator.h"
8 #include "chromecast/crash/linux/minidump_writer.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace chromecast {
12 namespace {
13
14 const char kLockfileName[] = "lockfile";
15 const char kMinidumpSubdir[] = "minidumps";
16
17 class FakeMinidumpGenerator : public MinidumpGenerator {
18 public:
19 FakeMinidumpGenerator() {}
20 ~FakeMinidumpGenerator() override {}
21
22 // MinidumpGenerator implementation:
23 bool Generate(const std::string& minidump_path) override { return true; }
24 };
25
26 } // namespace
27
28 // TODO(slan): Add more test coverage here.
29
30 TEST(MinidumpWriterTest, CanWriteDumpOnlyWhenMaxDumpsNotExceeded) {
31 // Set up a temporary directory which will be used as our fake home dir.
32 base::FilePath fake_home_dir;
33 ASSERT_TRUE(base::CreateNewTempDirectory("", &fake_home_dir));
34 base::ScopedPathOverride home(base::DIR_HOME, fake_home_dir);
35 base::FilePath minidump_dir = fake_home_dir.Append(kMinidumpSubdir);
36 base::FilePath lockfile_path = minidump_dir.Append(kLockfileName);
37
38 // Create the minidump directory and lockfile.
39 ASSERT_TRUE(base::CreateDirectory(minidump_dir));
40 base::File lockfile(lockfile_path,
41 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
42 ASSERT_TRUE(lockfile.IsValid());
43
44 // Create the writer. Initialize it for our use.
45 FakeMinidumpGenerator generator;
46 MinidumpWriter writer(&generator, minidump_dir.value(), MinidumpParams());
47 writer.SetMaxDumpsForTest(2);
48 writer.SetMaxRecentDumpsForTest(10);
49
50 // Should be able to write dump with empty file.
51 ASSERT_TRUE(writer.CanWriteDumpForTest());
52
53 // Add an entry to the lockfile. Should still be able to write dump.
54 DumpInfo info("p|2015-01-01 01:02:03|/dump/path||");
55 ASSERT_TRUE(info.valid());
56 base::AppendToFile(lockfile_path, info.entry().c_str(), info.entry().size());
57 ASSERT_TRUE(writer.CanWriteDumpForTest());
58
59 // Cannot write dump if next dump would exceed maximum.
60 DumpInfo info2("p|2015-01-01 01:02:04|/dump/path||");
61 ASSERT_TRUE(info2.valid());
62 base::AppendToFile(
63 lockfile_path, info2.entry().c_str(), info2.entry().size());
64 ASSERT_FALSE(writer.CanWriteDumpForTest());
65
66 // Cannot write dump if next dump would exceed maximum.
67 DumpInfo info3("p|2015-01-01 01:02:05|/dump/path||");
68 ASSERT_TRUE(info3.valid());
69 base::AppendToFile(
70 lockfile_path, info3.entry().c_str(), info3.entry().size());
71 ASSERT_FALSE(writer.CanWriteDumpForTest());
72 }
73
74 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698