mirror of
git://sourceware.org/git/libabigail.git
synced 2025-02-20 15:56:57 +00:00
Add regression tests for dwarf reading
* tests/test-read-dwarf.cc: New dwarf reading regression test. * tests/data/test-read-dwarf/test0: New test input. * data/test-read-dwarf/test0: Likewise. * data/test-read-dwarf/test0.abi: Likewise. * data/test-read-dwarf/test0.cc: Likewise. * data/test-read-dwarf/test1: Likewise. * data/test-read-dwarf/test1.abi: Likewise. * data/test-read-dwarf/test1.cc: Likewise. * tests/Makefile.am: Build the new tests/test-read-dwarf.cc file. Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This commit is contained in:
parent
a2ea8852f8
commit
8f9b8e76a0
@ -3,6 +3,7 @@ h=$(abs_srcdir)
|
||||
TESTS= \
|
||||
runtestreadwrite \
|
||||
runtestwritereadarchive \
|
||||
runtestreaddwarf \
|
||||
runtestcorediff \
|
||||
runtestbidiff \
|
||||
runtestsvg \
|
||||
@ -29,6 +30,9 @@ runtestreadwrite_LDADD=libtestutils.la $(top_builddir)/src/libabigail.la
|
||||
runtestwritereadarchive_SOURCES=$(h)/test-write-read-archive.cc
|
||||
runtestwritereadarchive_LDADD= libtestutils.la $(top_builddir)/src/libabigail.la $(top_builddir)/tools/libtoolsutils.la
|
||||
|
||||
runtestreaddwarf_SOURCES=$(h)/test-read-dwarf.cc
|
||||
runtestreaddwarf_LDADD=libtestutils.la $(top_builddir)/src/libabigail.la
|
||||
|
||||
runtestcorediff_SOURCES=$(h)/test-core-diff.cc
|
||||
runtestcorediff_LDADD=libtestutils.la $(top_builddir)/src/libabigail.la
|
||||
|
||||
@ -98,7 +102,14 @@ data/test-bidiff/test-struct1-v1.cc.bi \
|
||||
data/test-bidiff/test-struct1-report.txt \
|
||||
data/test-bidiff/test-var0-v0.cc.bi \
|
||||
data/test-bidiff/test-var0-v1.cc.bi \
|
||||
data/test-bidiff/test-var0-report.txt
|
||||
data/test-bidiff/test-var0-report.txt \
|
||||
\
|
||||
data/test-read-dwarf/test0 \
|
||||
data/test-read-dwarf/test0.abi \
|
||||
data/test-read-dwarf/test0.cc \
|
||||
data/test-read-dwarf/test1 \
|
||||
data/test-read-dwarf/test1.abi \
|
||||
data/test-read-dwarf/test1.cc
|
||||
|
||||
clean-local: clean-local-check
|
||||
.PHONY: clean-local-check
|
||||
|
BIN
tests/data/test-read-dwarf/test0
Executable file
BIN
tests/data/test-read-dwarf/test0
Executable file
Binary file not shown.
43
tests/data/test-read-dwarf/test0.abi
Normal file
43
tests/data/test-read-dwarf/test0.abi
Normal file
@ -0,0 +1,43 @@
|
||||
<abi-corpus path='data/test-read-dwarf/test0'>
|
||||
<abi-instr version='1.0' address-size='64' path='test0.cc'>
|
||||
<type-decl name='long int' size-in-bits='64' alignment-in-bits='64' id='type-id-1'/>
|
||||
<type-decl name='char' size-in-bits='8' alignment-in-bits='8' id='type-id-2'/>
|
||||
<pointer-type-def type-id='type-id-2' size-in-bits='64' alignment-in-bits='64' id='type-id-3'/>
|
||||
<type-decl name='int' size-in-bits='32' alignment-in-bits='32' id='type-id-4'/>
|
||||
<reference-type-def kind='lvalue' type-id='type-id-4' size-in-bits='64' alignment-in-bits='64' id='type-id-5'/>
|
||||
<type-decl name='enum-E-underlying-type' size-in-bits='32' alignment-in-bits='32' id='type-id-6'/>
|
||||
<type-decl name='long long int' size-in-bits='64' alignment-in-bits='64' id='type-id-7'/>
|
||||
<namespace-decl name='ns0'>
|
||||
<function-decl name='foo' mangled-name='_ZN3ns03fooEPcl' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test0.cc' line='8' column='1' visibility='default' binding='global' size-in-bits='64' alignment-in-bits='64'>
|
||||
<parameter type-id='type-id-3'/>
|
||||
<parameter type-id='type-id-1'/>
|
||||
<return type-id='type-id-1'/>
|
||||
</function-decl>
|
||||
<function-decl name='bar' mangled-name='_ZN3ns03barEiz' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test0.cc' line='12' column='1' visibility='default' binding='global' size-in-bits='64' alignment-in-bits='64'>
|
||||
<parameter type-id='type-id-4'/>
|
||||
<parameter is-variadic='yes'/>
|
||||
</function-decl>
|
||||
<function-decl name='baz' mangled-name='_ZN3ns03bazERi' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test0.cc' line='16' column='1' visibility='default' binding='global' size-in-bits='64' alignment-in-bits='64'>
|
||||
<parameter type-id='type-id-5'/>
|
||||
</function-decl>
|
||||
<enum-decl name='E' id='type-id-8'>
|
||||
<underlying-type type-id='type-id-6'/>
|
||||
<enumerator name='e0' value='0'/>
|
||||
<enumerator name='e1' value='1'/>
|
||||
</enum-decl>
|
||||
<reference-type-def kind='lvalue' type-id='type-id-8' size-in-bits='64' alignment-in-bits='64' id='type-id-9'/>
|
||||
<function-decl name='bar2' mangled-name='_ZN3ns04bar2ERNS_1EE' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test0.cc' line='22' column='1' visibility='default' binding='global' size-in-bits='64' alignment-in-bits='64'>
|
||||
<parameter type-id='type-id-9'/>
|
||||
</function-decl>
|
||||
<typedef-decl name='long_long' type-id='type-id-7' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test0.cc' line='25' column='1' id='type-id-10'/>
|
||||
<function-decl name='baz2' mangled-name='_ZN3ns04baz2ERi' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test0.cc' line='28' column='1' visibility='default' binding='global' size-in-bits='64' alignment-in-bits='64'>
|
||||
<parameter type-id='type-id-5'/>
|
||||
<return type-id='type-id-10'/>
|
||||
</function-decl>
|
||||
</namespace-decl>
|
||||
<function-decl name='main' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test0.cc' line='45' column='1' visibility='default' binding='global' size-in-bits='64' alignment-in-bits='64'>
|
||||
<return type-id='type-id-4'/>
|
||||
</function-decl>
|
||||
<var-decl name='global' type-id='type-id-4' visibility='default' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test0.cc' line='3' column='1'/>
|
||||
</abi-instr>
|
||||
</abi-corpus>
|
48
tests/data/test-read-dwarf/test0.cc
Normal file
48
tests/data/test-read-dwarf/test0.cc
Normal file
@ -0,0 +1,48 @@
|
||||
// Random comment
|
||||
//
|
||||
int global = 1;
|
||||
|
||||
namespace ns0
|
||||
{
|
||||
long
|
||||
foo(char* c, const volatile long l)
|
||||
{return *c + l;}
|
||||
|
||||
void
|
||||
bar(const int c, ...)
|
||||
{}
|
||||
|
||||
void
|
||||
baz(int& c)
|
||||
{c = 0;}
|
||||
|
||||
enum E {e0, e1};
|
||||
|
||||
void
|
||||
bar2(E& e)
|
||||
{int c = e; ++c;}
|
||||
|
||||
typedef long long long_long;
|
||||
|
||||
long_long
|
||||
baz2(int& c)
|
||||
{c = 0; return c;}
|
||||
|
||||
typedef const volatile unsigned long long useless_long_long;
|
||||
|
||||
static useless_long_long
|
||||
this_should_not_be_seen_by_bidw()
|
||||
{
|
||||
int i = 0;
|
||||
bar(0);
|
||||
baz2(i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // end namespace ns0
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
return ns0::this_should_not_be_seen_by_bidw();
|
||||
}
|
BIN
tests/data/test-read-dwarf/test1
Executable file
BIN
tests/data/test-read-dwarf/test1
Executable file
Binary file not shown.
92
tests/data/test-read-dwarf/test1.abi
Normal file
92
tests/data/test-read-dwarf/test1.abi
Normal file
@ -0,0 +1,92 @@
|
||||
<abi-corpus path='data/test-read-dwarf/test1'>
|
||||
<abi-instr version='1.0' address-size='64' path='test1.cc'>
|
||||
<class-decl name='b0' visibility='default' is-declaration-only='yes' id='type-id-1'/>
|
||||
<type-decl name='long long int' size-in-bits='64' alignment-in-bits='64' id='type-id-2'/>
|
||||
<type-decl name='char' size-in-bits='8' alignment-in-bits='8' id='type-id-3'/>
|
||||
<pointer-type-def type-id='type-id-1' size-in-bits='64' alignment-in-bits='64' id='type-id-4'/>
|
||||
<class-decl name='b0' size-in-bits='128' visibility='default' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test1.cc' line='1' column='1' def-of-decl-id='type-id-1' id='type-id-5'>
|
||||
<data-member access='public' layout-offset-in-bits='0'>
|
||||
<var-decl name='m0' type-id='type-id-2' visibility='default' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test1.cc' line='3' column='1'/>
|
||||
</data-member>
|
||||
<data-member access='public' layout-offset-in-bits='64'>
|
||||
<var-decl name='m1' type-id='type-id-3' visibility='default' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test1.cc' line='4' column='1'/>
|
||||
</data-member>
|
||||
<member-function access='public' constructor='yes'>
|
||||
<function-decl name='b0' visibility='default' binding='global' size-in-bits='64' alignment-in-bits='64'>
|
||||
<parameter type-id='type-id-4' is-artificial='yes'/>
|
||||
</function-decl>
|
||||
</member-function>
|
||||
</class-decl>
|
||||
<class-decl name='b1' visibility='default' is-declaration-only='yes' id='type-id-6'/>
|
||||
<type-decl name='double' size-in-bits='64' alignment-in-bits='64' id='type-id-7'/>
|
||||
<pointer-type-def type-id='type-id-6' size-in-bits='64' alignment-in-bits='64' id='type-id-8'/>
|
||||
<class-decl name='b1' size-in-bits='128' visibility='default' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test1.cc' line='7' column='1' def-of-decl-id='type-id-6' id='type-id-9'>
|
||||
<data-member access='public' layout-offset-in-bits='0'>
|
||||
<var-decl name='m0' type-id='type-id-7' visibility='default' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test1.cc' line='9' column='1'/>
|
||||
</data-member>
|
||||
<data-member access='public' layout-offset-in-bits='64'>
|
||||
<var-decl name='m1' type-id='type-id-3' visibility='default' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test1.cc' line='10' column='1'/>
|
||||
</data-member>
|
||||
<member-function access='public' constructor='yes'>
|
||||
<function-decl name='b1' visibility='default' binding='global' size-in-bits='64' alignment-in-bits='64'>
|
||||
<parameter type-id='type-id-8' is-artificial='yes'/>
|
||||
</function-decl>
|
||||
</member-function>
|
||||
</class-decl>
|
||||
<class-decl name='s0' visibility='default' is-declaration-only='yes' id='type-id-10'/>
|
||||
<type-decl name='int' size-in-bits='32' alignment-in-bits='32' id='type-id-11'/>
|
||||
<type-decl name='unsigned char' size-in-bits='8' alignment-in-bits='8' id='type-id-12'/>
|
||||
<pointer-type-def type-id='type-id-10' size-in-bits='64' alignment-in-bits='64' id='type-id-13'/>
|
||||
<qualified-type-def type-id='type-id-10' const='yes' id='type-id-14'/>
|
||||
<reference-type-def kind='lvalue' type-id='type-id-14' size-in-bits='64' alignment-in-bits='64' id='type-id-15'/>
|
||||
<class-decl name='s0' size-in-bits='384' visibility='default' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test1.cc' line='13' column='1' def-of-decl-id='type-id-10' id='type-id-16'>
|
||||
<base-class access='public' layout-offset-in-bits='24' is-virtual='yes' type-id='type-id-5'/>
|
||||
<base-class access='public' layout-offset-in-bits='32' is-virtual='yes' type-id='type-id-9'/>
|
||||
<member-type access='public'>
|
||||
<typedef-decl name='integer' type-id='type-id-11' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test1.cc' line='15' column='1' id='type-id-17'/>
|
||||
</member-type>
|
||||
<member-type access='public'>
|
||||
<typedef-decl name='byte' type-id='type-id-12' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test1.cc' line='16' column='1' id='type-id-18'/>
|
||||
</member-type>
|
||||
<data-member access='public' layout-offset-in-bits='64'>
|
||||
<var-decl name='m0' type-id='type-id-17' visibility='default' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test1.cc' line='18' column='1'/>
|
||||
</data-member>
|
||||
<data-member access='public' layout-offset-in-bits='96'>
|
||||
<var-decl name='m1' type-id='type-id-18' visibility='default' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test1.cc' line='19' column='1'/>
|
||||
</data-member>
|
||||
<member-function access='public' constructor='yes'>
|
||||
<function-decl name='s0' visibility='default' binding='global' size-in-bits='64' alignment-in-bits='64'>
|
||||
<parameter type-id='type-id-13' is-artificial='yes'/>
|
||||
<parameter type-id='type-id-11' is-artificial='yes'/>
|
||||
<parameter type-id='type-id-15'/>
|
||||
</function-decl>
|
||||
</member-function>
|
||||
<member-function access='public' constructor='yes'>
|
||||
<function-decl name='s0' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test1.cc' line='21' column='1' visibility='default' binding='global' size-in-bits='64' alignment-in-bits='64'>
|
||||
<parameter type-id='type-id-13' is-artificial='yes'/>
|
||||
<parameter type-id='type-id-11' is-artificial='yes'/>
|
||||
</function-decl>
|
||||
</member-function>
|
||||
<member-function access='public' destructor='yes'>
|
||||
<function-decl name='~s0' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test1.cc' line='27' column='1' visibility='default' binding='global' size-in-bits='64' alignment-in-bits='64'>
|
||||
<parameter type-id='type-id-13' is-artificial='yes'/>
|
||||
<parameter type-id='type-id-11' is-artificial='yes'/>
|
||||
</function-decl>
|
||||
</member-function>
|
||||
<member-function access='public'>
|
||||
<function-decl name='mem_fun' mangled-name='_ZN2s07mem_funEv' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test1.cc' line='36' column='1' visibility='default' binding='global' size-in-bits='64' alignment-in-bits='64'>
|
||||
<parameter type-id='type-id-13' is-artificial='yes'/>
|
||||
<return type-id='type-id-17'/>
|
||||
</function-decl>
|
||||
</member-function>
|
||||
</class-decl>
|
||||
<reference-type-def kind='lvalue' type-id='type-id-16' size-in-bits='64' alignment-in-bits='64' id='type-id-19'/>
|
||||
<qualified-type-def type-id='type-id-19' const='yes' id='type-id-20'/>
|
||||
<function-decl name='foo' mangled-name='_Z3fooR2s0' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test1.cc' line='42' column='1' visibility='default' binding='global' size-in-bits='64' alignment-in-bits='64'>
|
||||
<parameter type-id='type-id-20' name='s' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test1.cc' line='42' column='1'/>
|
||||
</function-decl>
|
||||
<function-decl name='main' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test1.cc' line='48' column='1' visibility='default' binding='global' size-in-bits='64' alignment-in-bits='64'>
|
||||
<return type-id='type-id-11'/>
|
||||
</function-decl>
|
||||
</abi-instr>
|
||||
</abi-corpus>
|
52
tests/data/test-read-dwarf/test1.cc
Normal file
52
tests/data/test-read-dwarf/test1.cc
Normal file
@ -0,0 +1,52 @@
|
||||
struct b0
|
||||
{
|
||||
long long m0;
|
||||
char m1;
|
||||
};
|
||||
|
||||
struct b1
|
||||
{
|
||||
double m0;
|
||||
char m1;
|
||||
};
|
||||
|
||||
struct s0 : virtual b0, virtual b1
|
||||
{
|
||||
typedef int integer;
|
||||
typedef unsigned char byte;
|
||||
|
||||
integer m0;
|
||||
byte m1;
|
||||
|
||||
s0()
|
||||
: m0(0),
|
||||
m1(0)
|
||||
{
|
||||
}
|
||||
|
||||
~s0()
|
||||
{
|
||||
}
|
||||
|
||||
integer
|
||||
mem_fun();
|
||||
};
|
||||
|
||||
s0::integer
|
||||
s0::mem_fun()
|
||||
{
|
||||
return m0 + m1;
|
||||
}
|
||||
|
||||
void
|
||||
foo(s0& s)
|
||||
{
|
||||
s.mem_fun();
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
s0 s;
|
||||
foo(s);
|
||||
}
|
119
tests/test-read-dwarf.cc
Normal file
119
tests/test-read-dwarf.cc
Normal file
@ -0,0 +1,119 @@
|
||||
// -*- Mode: C++ -*-
|
||||
//
|
||||
// Copyright (C) 2013 Red Hat, Inc.
|
||||
//
|
||||
// This file is part of the GNU Application Binary Interface Generic
|
||||
// Analysis and Instrumentation Library (libabigail). This library is
|
||||
// free software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU Lesser General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option) any
|
||||
// later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Lesser Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; see the file COPYING-LGPLV3. If
|
||||
// not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// Author: Dodji Seketeli
|
||||
|
||||
/// @file read ELF binaries containing DWARF, save them in XML corpus
|
||||
/// files and diff the corpus files against reference XML corpus
|
||||
/// files.
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include "abg-ir.h"
|
||||
#include "abg-dwarf-reader.h"
|
||||
#include "abg-writer.h"
|
||||
#include "abg-tools-utils.h"
|
||||
#include "test-utils.h"
|
||||
|
||||
using std::string;
|
||||
using std::ofstream;
|
||||
using std::cerr;
|
||||
|
||||
/// This is an aggregate that specifies where a test shall get its
|
||||
/// input from, and where it shall write its ouput to.
|
||||
struct InOutSpec
|
||||
{
|
||||
const char* in_elf_path;
|
||||
const char* in_abi_path;
|
||||
const char* out_abi_path;
|
||||
};// end struct InOutSpec
|
||||
|
||||
|
||||
InOutSpec in_out_specs[] =
|
||||
{
|
||||
{
|
||||
"data/test-read-dwarf/test0",
|
||||
"data/test-read-dwarf/test0.abi",
|
||||
"output/test-read-dwarf/test0.abi"
|
||||
},
|
||||
{
|
||||
"data/test-read-dwarf/test1",
|
||||
"data/test-read-dwarf/test1.abi",
|
||||
"output/test-read-dwarf/test1.abi"
|
||||
},
|
||||
// This should be the last entry.
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
unsigned result = 1;
|
||||
|
||||
bool is_ok = true;
|
||||
string in_elf_path, in_abi_path, out_abi_path;
|
||||
abigail::corpus_sptr corp;
|
||||
|
||||
for (InOutSpec* s = in_out_specs; s->in_elf_path; ++s)
|
||||
{
|
||||
in_elf_path = abigail::tests::get_src_dir() + "/tests/" + s->in_elf_path;
|
||||
corp = abigail::dwarf_reader::read_corpus_from_elf(in_elf_path);
|
||||
if (!corp)
|
||||
{
|
||||
cerr << "failed to read " << in_elf_path << "\n";
|
||||
is_ok = false;
|
||||
continue;
|
||||
}
|
||||
corp->set_path(s->in_elf_path);
|
||||
|
||||
out_abi_path =
|
||||
abigail::tests::get_build_dir() + "/tests/" + s->out_abi_path;
|
||||
if (!abigail::tools::ensure_parent_dir_created(out_abi_path))
|
||||
{
|
||||
cerr << "Could not create parent director for " << out_abi_path;
|
||||
is_ok = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
ofstream of(out_abi_path.c_str(), std::ios_base::trunc);
|
||||
if (!of.is_open())
|
||||
{
|
||||
cerr << "failed to read " << out_abi_path << "\n";
|
||||
is_ok = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
bool r =
|
||||
abigail::xml_writer::write_corpus_to_native_xml(corp,
|
||||
/*indent=*/0,
|
||||
of);
|
||||
is_ok = (is_ok && r);
|
||||
of.close();
|
||||
|
||||
in_abi_path = abigail::tests::get_src_dir() + "/tests/" + s->in_abi_path;
|
||||
string cmd = "diff -u " + in_abi_path + " " + out_abi_path;
|
||||
if (system(cmd.c_str()))
|
||||
is_ok = false;
|
||||
}
|
||||
|
||||
return !is_ok;
|
||||
}
|
Loading…
Reference in New Issue
Block a user