From b6b4451142d871d6b9d9162e465dff5d4511cef9 Mon Sep 17 00:00:00 2001 From: "ted.mielczarek" Date: Fri, 20 Jul 2012 12:24:25 +0000 Subject: =?UTF-8?q?Add=20a=20filter=20callback=20to=20CrashGenerationServe?= =?UTF-8?q?r=20on=20mac=20A=3DRafael=20=C3=81vila=20de=20Esp=C3=ADndola=20?= =?UTF-8?q?=20R=3Dted=20at=20https://bugzilla.mozi?= =?UTF-8?q?lla.org/show=5Fbug.cgi=3Fid=3D732173?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@990 4c0a9323-5329-0410-9bdc-e9ce6186880e --- .../mac/tests/crash_generation_server_test.cc | 71 +++++++++++++++++++--- 1 file changed, 62 insertions(+), 9 deletions(-) (limited to 'src/client/mac/tests') 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(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(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 -- cgit v1.2.1