Issue 49003: Breakpad Linux Dumper: Add unit tests for STABS dumper.

Previous patches added unit tests for the STABS parser and the
Breakpad symbol file writer; this adds unit tests for the "dumper"
class that sits between them, receiving data from the parser and
handing it to the writer.  So now the whole pathway has coverage.

a=jimblandy, r=nealsid


git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@467 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
jimblandy 2009-12-23 21:50:01 +00:00
parent 52cb2c6f42
commit c823931376
2 changed files with 193 additions and 0 deletions

View file

@ -0,0 +1,175 @@
// Copyright (c) 2009, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// dump_stabs_unittest.cc: Unit tests for DumpStabsHandler.
#include <vector>
#include "breakpad_googletest_includes.h"
#include "common/linux/dump_stabs.h"
using google_breakpad::DumpStabsHandler;
using google_breakpad::Module;
using std::vector;
TEST(DumpStabsHandler, SimpleCU) {
Module m("name", "os", "arch", "id");
DumpStabsHandler h(&m);
// Feed in a simple compilation unit that defines a function with
// one line.
EXPECT_TRUE(h.StartCompilationUnit("compilation-unit", 0x9f4d1271e50db93bLL,
"build-directory"));
EXPECT_TRUE(h.StartFunction("function", 0xfde4abbed390c394LL));
EXPECT_TRUE(h.Line(0xfde4abbed390c394LL, "source-file-name", 174823314));
EXPECT_TRUE(h.EndFunction(0xfde4abbed390c3a4LL));
EXPECT_TRUE(h.EndCompilationUnit(0xfee4abbed390c3a4LL));
h.Finalize();
// Now check to see what has been added to the Module.
Module::File *file = m.FindExistingFile("source-file-name");
ASSERT_TRUE(file != NULL);
vector<Module::Function *> functions;
m.GetFunctions(&functions, functions.end());
ASSERT_EQ((size_t) 1, functions.size());
Module::Function *function = functions[0];
EXPECT_STREQ("function", function->name_.c_str());
EXPECT_EQ(0xfde4abbed390c394LL, function->address_);
EXPECT_EQ(0x10U, function->size_);
EXPECT_EQ(0U, function->parameter_size_);
ASSERT_EQ((size_t) 1, function->lines_.size());
Module::Line *line = &function->lines_[0];
EXPECT_EQ(0xfde4abbed390c394LL, line->address_);
EXPECT_EQ(0x10U, line->size_); // derived from EndFunction
EXPECT_TRUE(line->file_ == file);
EXPECT_EQ(174823314, line->number_);
}
TEST(InferSizes, LineSize) {
Module m("name", "os", "arch", "id");
DumpStabsHandler h(&m);
// Feed in a simple compilation unit that defines a function with
// one line.
EXPECT_TRUE(h.StartCompilationUnit("compilation-unit", 0xb4513962eff94e92LL,
"build-directory"));
EXPECT_TRUE(h.StartFunction("function", 0xb4513962eff94e92LL));
EXPECT_TRUE(h.Line(0xb4513962eff94e92LL, "source-file-name-1", 77396614));
EXPECT_TRUE(h.Line(0xb4513963eff94e92LL, "source-file-name-2", 87660088));
EXPECT_TRUE(h.EndFunction(0)); // unknown function end address
EXPECT_TRUE(h.EndCompilationUnit(0)); // unknown CU end address
EXPECT_TRUE(h.StartCompilationUnit("compilation-unit-2", 0xb4523963eff94e92LL,
"build-directory-2")); // next boundary
EXPECT_TRUE(h.EndCompilationUnit(0));
h.Finalize();
// Now check to see what has been added to the Module.
Module::File *file1 = m.FindExistingFile("source-file-name-1");
ASSERT_TRUE(file1 != NULL);
Module::File *file2 = m.FindExistingFile("source-file-name-2");
ASSERT_TRUE(file2 != NULL);
vector<Module::Function *> functions;
m.GetFunctions(&functions, functions.end());
ASSERT_EQ((size_t) 1, functions.size());
Module::Function *function = functions[0];
EXPECT_STREQ("function", function->name_.c_str());
EXPECT_EQ(0xb4513962eff94e92LL, function->address_);
EXPECT_EQ(0x1000100000000ULL, function->size_); // inferred from CU end
EXPECT_EQ(0U, function->parameter_size_);
ASSERT_EQ((size_t) 2, function->lines_.size());
Module::Line *line1 = &function->lines_[0];
EXPECT_EQ(0xb4513962eff94e92LL, line1->address_);
EXPECT_EQ(0x100000000ULL, line1->size_); // derived from EndFunction
EXPECT_TRUE(line1->file_ == file1);
EXPECT_EQ(77396614, line1->number_);
Module::Line *line2 = &function->lines_[1];
EXPECT_EQ(0xb4513963eff94e92LL, line2->address_);
EXPECT_EQ(0x1000000000000ULL, line2->size_); // derived from EndFunction
EXPECT_TRUE(line2->file_ == file2);
EXPECT_EQ(87660088, line2->number_);
}
TEST(FunctionNames, Mangled) {
Module m("name", "os", "arch", "id");
DumpStabsHandler h(&m);
// Compilation unit with one function, mangled name.
EXPECT_TRUE(h.StartCompilationUnit("compilation-unit", 0xf2cfda63cef7f46cLL,
"build-directory"));
EXPECT_TRUE(h.StartFunction("_ZNSt6vectorIySaIyEE9push_backERKy",
0xf2cfda63cef7f46dLL));
EXPECT_TRUE(h.EndFunction(0));
EXPECT_TRUE(h.EndCompilationUnit(0));
h.Finalize();
// Now check to see what has been added to the Module.
Module::File *file = m.FindExistingFile("compilation-unit");
ASSERT_TRUE(file != NULL);
vector<Module::Function *> functions;
m.GetFunctions(&functions, functions.end());
ASSERT_EQ(1U, functions.size());
Module::Function *function = functions[0];
// This is GCC-specific, but we shouldn't be seeing STABS data anywhere
// but Linux.
EXPECT_STREQ("std::vector<unsigned long long, "
"std::allocator<unsigned long long> >::"
"push_back(unsigned long long const&)",
function->name_.c_str());
EXPECT_EQ(0xf2cfda63cef7f46dLL, function->address_);
EXPECT_LT(0U, function->size_); // should have used dummy size
EXPECT_EQ(0U, function->parameter_size_);
ASSERT_EQ(0U, function->lines_.size());
}
// TODO --- if we actually cared about STABS. Even without these we've
// got full coverage of non-failure source lines in dump_stabs.cc.
// Line size from next line
// Line size from function end
// Line size from next function start
// line size from cu end
// line size from next cu start
// fallback size is something plausible
// function size from function end
// function size from next function start
// function size from cu end
// function size from next cu start
// fallback size is something plausible
// omitting functions outside the compilation unit's address range
// zero-line, one-line, many-line functions

View file

@ -77,6 +77,7 @@ dump_syms.o: dump_syms.cc
VPATH += $(SRC)/common/linux
dump_stabs.o: dump_stabs.cc
COVERAGE_SOURCES += dump_stabs.cc
dump_symbols.o: dump_symbols.cc
file_id.o: file_id.cc
module.o: module.cc
@ -150,6 +151,23 @@ clean::
rm -f module_unittest
### Unit tests for google_breakpad::DumpStabsHandler.
check: check-dump_stabs_unittest
check-dump_stabs_unittest: dump_stabs_unittest
dump_stabs_unittest: \
gtest-all.o \
gtest_main.o \
dump_stabs.o \
dump_stabs_unittest.o \
module.o \
$(empty)
CPP_EXECUTABLES += dump_stabs_unittest
dump_stabs_unittest.o: dump_stabs_unittest.cc
dump_stabs_unittest.o: override CPPFLAGS += $(GTEST_CPPFLAGS) $(GMOCK_CPPFLAGS)
clean::
rm -f dump_stabs_unittest
### Generic compilation rules.
# Link C++ executables using the C++ compiler; see CPP_EXECUTABLES above.