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

Unified Diff: crash_collector_test.cc

Issue 3209003: Limit the number of crash reports to enqueue at once (Closed) Base URL: http://git.chromium.org/git/crash-reporter.git
Patch Set: Respond to reviews Created 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « crash_collector.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crash_collector_test.cc
diff --git a/crash_collector_test.cc b/crash_collector_test.cc
index 48b7fa03c677526d2ba0613b8c3e8629ab234f72..ed8fff7565fae308047c60904e923abce1b88899 100644
--- a/crash_collector_test.cc
+++ b/crash_collector_test.cc
@@ -5,6 +5,7 @@
#include <unistd.h>
#include "base/file_util.h"
+#include "base/string_util.h"
#include "crash-reporter/crash_collector.h"
#include "crash-reporter/system_logging_mock.h"
#include "gflags/gflags.h"
@@ -20,15 +21,25 @@ bool IsMetrics() {
}
class CrashCollectorTest : public ::testing::Test {
+ public:
void SetUp() {
collector_.Initialize(CountCrash,
IsMetrics,
&logging_);
+ test_dir_ = FilePath("test");
+ file_util::CreateDirectory(test_dir_);
}
+
+ void TearDown() {
+ file_util::Delete(test_dir_, true);
+ }
+
+ bool CheckHasCapacity();
+
protected:
SystemLoggingMock logging_;
CrashCollector collector_;
- pid_t pid_;
+ FilePath test_dir_;
};
TEST_F(CrashCollectorTest, Initialize) {
@@ -99,6 +110,49 @@ TEST_F(CrashCollectorTest, FormatDumpBasename) {
ASSERT_EQ("foo.20100523.135015.100", basename);
}
+bool CrashCollectorTest::CheckHasCapacity() {
+ static const char kFullMessage[] = "Crash directory test already full";
+ bool has_capacity = collector_.CheckHasCapacity(test_dir_);
+ bool has_message = (logging_.log().find(kFullMessage) != std::string::npos);
+ EXPECT_EQ(has_message, !has_capacity);
+ return has_capacity;
+}
+
+TEST_F(CrashCollectorTest, CheckHasCapacityOverNonCore) {
+ // Test up to kMaxCrashDirectorySize-1 non-core files can be added.
+ for (int i = 0; i < CrashCollector::kMaxCrashDirectorySize - 1; ++i) {
+ EXPECT_TRUE(CheckHasCapacity());
+ file_util::WriteFile(test_dir_.Append(StringPrintf("file%d", i)), "", 0);
+ }
+
+ // Test an additional kMaxCrashDirectorySize - 1 core files fit.
+ for (int i = 0; i < CrashCollector::kMaxCrashDirectorySize - 1; ++i) {
+ EXPECT_TRUE(CheckHasCapacity());
+ file_util::WriteFile(test_dir_.Append(StringPrintf("file%d.core", i)),
+ "", 0);
+ }
+
+ // Test an additional kMaxCrashDirectorySize non-core files don't fit.
+ for (int i = 0; i < CrashCollector::kMaxCrashDirectorySize; ++i) {
+ file_util::WriteFile(test_dir_.Append(StringPrintf("overage%d", i)), "", 0);
+ EXPECT_FALSE(CheckHasCapacity());
+ }
+}
+
+TEST_F(CrashCollectorTest, CheckHasCapacityOverCore) {
+ // Set up kMaxCrashDirectorySize - 1 core files.
+ for (int i = 0; i < CrashCollector::kMaxCrashDirectorySize - 1; ++i) {
+ file_util::WriteFile(test_dir_.Append(StringPrintf("file%d.core", i)),
+ "", 0);
+ }
+
+ EXPECT_TRUE(CheckHasCapacity());
+
+ // Test an additional core file does not fit.
+ file_util::WriteFile(test_dir_.Append("overage.core"), "", 0);
+ EXPECT_FALSE(CheckHasCapacity());
+}
+
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
« no previous file with comments | « crash_collector.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698