File: fallback_crash_handling_win_unittest.cc

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (85 lines) | stat: -rw-r--r-- 2,994 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/crash/content/app/fallback_crash_handling_win.h"

#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
#include "base/test/multiprocess_test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/multiprocess_func_list.h"
#include "third_party/crashpad/crashpad/client/crash_report_database.h"

namespace crash_reporter {

namespace {

const DWORD kExceptionCode = 0xCAFEBABE;

// This main function runs in two modes, first as a faux-crashpad handler,
// and then with --type=fallback-handler to handle the crash in the first
// instance.
MULTIPROCESS_TEST_MAIN(FallbackCrashHandlingWinRunHandler) {
  base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
  if (cmd_line->GetSwitchValueASCII("type") ==
      switches::kFallbackCrashHandler) {
    return RunAsFallbackCrashHandler(*cmd_line,
                                     "FallbackCrashHandlingWinRunHandler",
                                     "1.2.3.4", "FakeChannel");
  }

  CHECK(SetupFallbackCrashHandling(*cmd_line));

  // Provoke a crash with a well-defined exception code.
  // The process shouldn't terminate with this exception code.
  RaiseException(kExceptionCode, 0, 0, nullptr);

  // This process should never return from the exception.
  CHECK(false) << "Unexpected return from RaiseException";

  // Should never get here.
  return 0;
}

class FallbackCrashHandlingTest : public base::MultiProcessTest {
 public:
  void SetUp() override { ASSERT_TRUE(database_dir_.CreateUniqueTempDir()); }

 protected:
  base::ScopedTempDir database_dir_;
};

}  // namespace

TEST_F(FallbackCrashHandlingTest, SetupAndRunAsFallbackCrashHandler) {
  // Launch a subprocess to test the fallback handling implementation.
  base::CommandLine cmd_line = base::GetMultiProcessTestChildBaseCommandLine();
  cmd_line.AppendSwitchPath("database", database_dir_.GetPath());

  base::LaunchOptions options;
  options.start_hidden = true;
  base::Process test_child = base::SpawnMultiProcessTestChild(
      "FallbackCrashHandlingWinRunHandler", cmd_line, options);

  ASSERT_TRUE(test_child.IsValid());
  int exit_code = -1;
  ASSERT_TRUE(test_child.WaitForExit(&exit_code));
  ASSERT_EQ(kFallbackCrashTerminationCode, static_cast<uint32_t>(exit_code));

  // Validate that the database contains one valid crash dump.
  std::unique_ptr<crashpad::CrashReportDatabase> database =
      crashpad::CrashReportDatabase::InitializeWithoutCreating(
          database_dir_.GetPath());

  std::vector<crashpad::CrashReportDatabase::Report> reports;
  ASSERT_EQ(crashpad::CrashReportDatabase::kNoError,
            database->GetPendingReports(&reports));

  EXPECT_EQ(1U, reports.size());
}

}  // namespace crash_reporter