diff options
Diffstat (limited to 'src/client/mac/tests')
-rw-r--r-- | src/client/mac/tests/crash_generation_server_test.cc | 71 |
1 files changed, 62 insertions, 9 deletions
diff --git a/src/client/mac/tests/crash_generation_server_test.cc b/src/client/mac/tests/crash_generation_server_test.cc index f71624df..ff8ff78d 100644 --- a/src/client/mac/tests/crash_generation_server_test.cc +++ b/src/client/mac/tests/crash_generation_server_test.cc @@ -84,12 +84,14 @@ public: AutoTempDir temp_dir; // Counter just to ensure that we don't hit the same port again static int i; + bool filter_callback_called; void SetUp() { sprintf(mach_port_name, - "com.google.breakpad.ServerTest.%d.%d", getpid(), - CrashGenerationServerTest::i++); + "com.google.breakpad.ServerTest.%d.%d", getpid(), + CrashGenerationServerTest::i++); child_pid = (pid_t)-1; + filter_callback_called = false; } }; int CrashGenerationServerTest::i = 0; @@ -97,12 +99,14 @@ int CrashGenerationServerTest::i = 0; // Test that starting and stopping a server works TEST_F(CrashGenerationServerTest, testStartStopServer) { CrashGenerationServer server(mach_port_name, - NULL, // dump callback - NULL, // dump context - NULL, // exit callback - NULL, // exit context - false, // generate dumps - ""); // dump path + NULL, // filter callback + NULL, // filter context + NULL, // dump callback + NULL, // dump context + NULL, // exit callback + NULL, // exit context + false, // generate dumps + ""); // dump path ASSERT_TRUE(server.Start()); ASSERT_TRUE(server.Stop()); } @@ -111,6 +115,8 @@ TEST_F(CrashGenerationServerTest, testStartStopServer) { // Test without actually dumping TEST_F(CrashGenerationServerTest, testRequestDumpNoDump) { CrashGenerationServer server(mach_port_name, + NULL, // filter callback + NULL, // filter context NULL, // dump callback NULL, // dump context NULL, // exit callback @@ -142,7 +148,7 @@ TEST_F(CrashGenerationServerTest, testRequestDumpNoDump) { } void dumpCallback(void *context, const ClientInfo &client_info, - const std::string &file_path) { + const std::string &file_path) { if (context) { CrashGenerationServerTest* self = reinterpret_cast<CrashGenerationServerTest*>(context); @@ -161,6 +167,8 @@ void *RequestDump(void *context) { // Test that actually writing a minidump works TEST_F(CrashGenerationServerTest, testRequestDump) { CrashGenerationServer server(mach_port_name, + NULL, // filter callback + NULL, // filter context dumpCallback, // dump callback this, // dump context NULL, // exit callback @@ -209,6 +217,8 @@ static void Crasher() { // the parent. TEST_F(CrashGenerationServerTest, testChildProcessCrash) { CrashGenerationServer server(mach_port_name, + NULL, // filter callback + NULL, // filter context dumpCallback, // dump callback this, // dump context NULL, // exit callback @@ -270,6 +280,8 @@ TEST_F(CrashGenerationServerTest, testChildProcessCrash) { // produces a valid minidump. TEST_F(CrashGenerationServerTest, testChildProcessCrashCrossArchitecture) { CrashGenerationServer server(mach_port_name, + NULL, // filter callback + NULL, // filter context dumpCallback, // dump callback this, // dump context NULL, // exit callback @@ -342,4 +354,45 @@ const u_int32_t kExpectedContext = } #endif +bool filter_callback(void* context) { + CrashGenerationServerTest* self = + reinterpret_cast<CrashGenerationServerTest*>(context); + self->filter_callback_called = true; + // veto dump generation + return false; +} + +// Test that a filter callback can veto minidump writing. +TEST_F(CrashGenerationServerTest, testFilter) { + CrashGenerationServer server(mach_port_name, + filter_callback, // filter callback + this, // filter context + dumpCallback, // dump callback + this, // dump context + NULL, // exit callback + NULL, // exit context + true, // generate dumps + temp_dir.path()); // dump path + ASSERT_TRUE(server.Start()); + + pid_t pid = fork(); + ASSERT_NE(-1, pid); + if (pid == 0) { + // Instantiate an OOP exception handler. + ExceptionHandler eh("", NULL, NULL, NULL, true, mach_port_name); + Crasher(); + // not reached + exit(0); + } + + int ret; + ASSERT_EQ(pid, waitpid(pid, &ret, 0)); + EXPECT_FALSE(WIFEXITED(ret)); + EXPECT_TRUE(server.Stop()); + + // check that no minidump was written + EXPECT_TRUE(last_dump_name.empty()); + EXPECT_TRUE(filter_callback_called); +} + } // namespace |