Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d257ea1c authored by Daniel Erat's avatar Daniel Erat Committed by ChromeOS Commit Bot
Browse files

crash-reporter: Clean up testing code.

Link all of the crash reporter's tests into a single
crash_reporter_test executable instead of building separate
binaries that lead to a bunch of duplication.

BUG=none
TEST=tests pass
CQ-DEPEND=I7f6623dd0ae36395efac89bdcfae54926ea6c918

Change-Id: I18e2d929d6545e7d05e88232bdaec089ae620544
Reviewed-on: https://chromium-review.googlesource.com/243940


Reviewed-by: default avatarDan Erat <derat@chromium.org>
Commit-Queue: Dan Erat <derat@chromium.org>
Trybot-Ready: Dan Erat <derat@chromium.org>
Tested-by: default avatarDan Erat <derat@chromium.org>
parent 7e3b76d8
Loading
Loading
Loading
Loading
+12 −17
Original line number Diff line number Diff line
@@ -6,26 +6,25 @@

#include <stdio.h>

#include <dbus/dbus-glib-lowlevel.h>

#include <base/auto_reset.h>
#include <base/files/file_util.h>
#include <base/files/scoped_temp_dir.h>
#include <chromeos/syslog_logging.h>
#include <chromeos/test_helpers.h>
#include <gtest/gtest.h>

using base::FilePath;

static const char kCrashFormatGood[] = "value1:10:abcdefghijvalue2:5:12345";
static const char kCrashFormatEmbeddedNewline[] =
namespace {

const char kCrashFormatGood[] = "value1:10:abcdefghijvalue2:5:12345";
const char kCrashFormatEmbeddedNewline[] =
    "value1:10:abcd\r\nghijvalue2:5:12\n34";
static const char kCrashFormatBad1[] = "value1:10:abcdefghijvalue2:6=12345";
static const char kCrashFormatBad2[] = "value1:10:abcdefghijvalue2:512345";
static const char kCrashFormatBad3[] = "value1:10::abcdefghijvalue2:5=12345";
static const char kCrashFormatBad4[] = "value1:10:abcdefghijvalue2:4=12345";
const char kCrashFormatBad1[] = "value1:10:abcdefghijvalue2:6=12345";
const char kCrashFormatBad2[] = "value1:10:abcdefghijvalue2:512345";
const char kCrashFormatBad3[] = "value1:10::abcdefghijvalue2:5=12345";
const char kCrashFormatBad4[] = "value1:10:abcdefghijvalue2:4=12345";

static const char kCrashFormatWithFile[] =
const char kCrashFormatWithFile[] =
    "value1:10:abcdefghijvalue2:5:12345"
    "some_file\"; filename=\"foo.txt\":15:12345\n789\n12345"
    "value3:2:ok";
@@ -33,12 +32,14 @@ static const char kCrashFormatWithFile[] =
void CountCrash() {
}

static bool s_allow_crash = false;
bool s_allow_crash = false;

bool IsMetrics() {
  return s_allow_crash;
}

}  // namespace

class ChromeCollectorTest : public ::testing::Test {
 protected:
  void ExpectFileEquals(const char *golden,
@@ -139,9 +140,3 @@ TEST_F(ChromeCollectorTest, HandleCrash) {
  }
  ExpectFileEquals(ChromeCollector::kSuccessMagic, log_file);
}

int main(int argc, char **argv) {
  ::g_type_init();
  SetUpTests(&argc, argv, false);
  return RUN_ALL_TESTS();
}
+5 −42
Original line number Diff line number Diff line
@@ -95,58 +95,21 @@
    ['USE_test == 1', {
      'targets': [
        {
          'target_name': 'chrome_collector_test',
          'target_name': 'crash_reporter_test',
          'type': 'executable',
          'includes': ['../common-mk/common_test.gypi'],
          'dependencies': ['libcrash'],
          'sources': [
            'chrome_collector_test.cc',
          ]
        },
        {
          'target_name': 'crash_collector_test',
          'type': 'executable',
          'includes': ['../common-mk/common_test.gypi'],
          'dependencies': ['libcrash'],
          'sources': [
            'crash_collector_test.cc',
          ]
        },
        {
          'target_name': 'kernel_collector_test',
          'type': 'executable',
          'includes': ['../common-mk/common_test.gypi'],
          'dependencies': ['libcrash'],
          'sources': [
            'crash_collector_test.h',
            'kernel_collector_test.cc',
          ]
        },
        {
          'target_name': 'udev_collector_test',
          'type': 'executable',
          'includes': ['../common-mk/common_test.gypi'],
          'dependencies': ['libcrash'],
          'sources': [
            'kernel_collector_test.h',
            'testrunner.cc',
            'udev_collector_test.cc',
          ]
        },
        {
          'target_name': 'unclean_shutdown_collector_test',
          'type': 'executable',
          'includes': ['../common-mk/common_test.gypi'],
          'dependencies': ['libcrash'],
          'sources': [
            'unclean_shutdown_collector_test.cc',
          ]
        },
        {
          'target_name': 'user_collector_test',
          'type': 'executable',
          'includes': ['../common-mk/common_test.gypi'],
          'dependencies': ['libcrash'],
          'sources': [
            'user_collector_test.cc',
          ]
          ],
        },
      ],
    }],
+4 −8
Original line number Diff line number Diff line
@@ -6,14 +6,12 @@

#include <unistd.h>

#include <dbus/dbus-glib-lowlevel.h>
#include <glib.h>

#include <base/files/file_util.h>
#include <base/strings/string_util.h>
#include <base/strings/stringprintf.h>
#include <chromeos/syslog_logging.h>
#include <chromeos/test_helpers.h>
#include <gtest/gtest.h>

#include "crash-reporter/crash_collector.h"
@@ -23,6 +21,8 @@ using base::StringPrintf;
using chromeos::FindLog;
using ::testing::Return;

namespace {

void CountCrash() {
  ADD_FAILURE();
}
@@ -32,6 +32,8 @@ bool IsMetrics() {
  return false;
}

}  // namespace

class CrashCollectorTest : public ::testing::Test {
 public:
  void SetUp() {
@@ -343,9 +345,3 @@ TEST_F(CrashCollectorTest, GetLogContents) {
  EXPECT_TRUE(base::ReadFileToString(output_file, &contents));
  EXPECT_EQ("hello world\n", contents);
}

int main(int argc, char **argv) {
  ::g_type_init();
  SetUpTests(&argc, argv, false);
  return RUN_ALL_TESTS();
}
+7 −9
Original line number Diff line number Diff line
@@ -11,17 +11,18 @@
#include <base/strings/string_util.h>
#include <base/strings/stringprintf.h>
#include <chromeos/syslog_logging.h>
#include <chromeos/test_helpers.h>
#include <gtest/gtest.h>

static int s_crashes = 0;
static bool s_metrics = false;

using base::FilePath;
using base::StringPrintf;
using chromeos::FindLog;
using chromeos::GetLog;

namespace {

int s_crashes = 0;
bool s_metrics = false;

void CountCrash() {
  ++s_crashes;
}
@@ -30,6 +31,8 @@ bool IsMetrics() {
  return s_metrics;
}

}  // namespace

class KernelCollectorTest : public ::testing::Test {
 protected:
  void WriteStringToFile(const FilePath &file_path,
@@ -666,8 +669,3 @@ TEST_F(KernelCollectorTest, ComputeKernelStackSignatureX86) {

  ComputeKernelStackSignatureCommon();
}

int main(int argc, char **argv) {
  SetUpTests(&argc, argv, false);
  return RUN_ALL_TESTS();
}
+13 −0
Original line number Diff line number Diff line
// Copyright 2015 The Chromium OS 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 <chromeos/test_helpers.h>
#include <glib-object.h>
#include <gtest/gtest.h>

int main(int argc, char** argv) {
  ::g_type_init();
  SetUpTests(&argc, argv, true);
  return RUN_ALL_TESTS();
}
Loading