libabigail/tests/test-diff-dwarf.cc

247 lines
7.0 KiB
C++
Raw Normal View History

// -*- Mode: C++ -*-
//
// Copyright (C) 2013-2014 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
///
/// This program runs a diff between input dwarf files and compares
/// the resulting report with a reference report. If the resulting
/// report is different from the reference report, the test has
/// failed. Note that the comparison is done using the libabigail
/// library directly.
///
/// The set of input files and reference reports to consider should be
/// present in the source distribution.
#include <string>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include "abg-tools-utils.h"
#include "test-utils.h"
#include "abg-dwarf-reader.h"
#include "abg-comparison.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_elfv0_path;
const char* in_elfv1_path;
const char* in_report_path;
const char* out_report_path;
};// end struct InOutSpec
InOutSpec in_out_specs[] =
{
{
"data/test-diff-dwarf/test0-v0.o",
"data/test-diff-dwarf/test0-v1.o",
"data/test-diff-dwarf/test0-report.txt",
"output/test-diff-dwarf/test0-report.txt"
},
{
"data/test-diff-dwarf/test1-v0.o",
"data/test-diff-dwarf/test1-v1.o",
"data/test-diff-dwarf/test1-report.txt",
"output/test-diff-dwarf/test1-report.txt"
},
2014-04-01 10:38:51 +00:00
{
"data/test-diff-dwarf/test2-v0.o",
"data/test-diff-dwarf/test2-v1.o",
"data/test-diff-dwarf/test2-report.txt",
"output/test-diff-dwarf/test2-report.txt"
},
{
"data/test-diff-dwarf/test3-v0.o",
"data/test-diff-dwarf/test3-v1.o",
"data/test-diff-dwarf/test3-report.txt",
"output/test-diff-dwarf/test3-report.txt"
},
{
"data/test-diff-dwarf/test3-v0.o",
"data/test-diff-dwarf/test3-v1.o",
"data/test-diff-dwarf/test3-report.txt",
"output/test-diff-dwarf/test3-report.txt"
},
{
"data/test-diff-dwarf/test4-v0.o",
"data/test-diff-dwarf/test4-v1.o",
"data/test-diff-dwarf/test4-report.txt",
"output/test-diff-dwarf/test4-report.txt"
},
Represent a removed+added data member at a given offset as changed * include/abg-fwd.h (get_data_member_offset): Declare new overload for decl_base_sptr. * include/abg-comparison.h (unsigned_decl_base_sptr_map) (unsigned_changed_type_or_decl_map): New typedefs. * src/abg-ir.cc (get_data_member_offset): Define new overload for decl_base_sptr. * src/abg-comparison.cc (diff_kind::subtype_change_kind): New enumerator for a change about a type or sub-type of a member of a structure/enum. (report_mem_header): Handle the new enumerator above. (class_diff::priv::{deleted_dm_by_offset_, inserted_dm_by_offset_, changed_dm_}): New data members. (class_diff::priv::subtype_changed_dm_): Renamed class_diff::priv::changed_data_members_ into this. (class_diff::priv::subtype_changed_dm): Renamed class_diff::priv::data_member_has_changed into this. Adjust. (class_diff::count_filtered_subtype_changed_dm): Renamed count_filtered_data_members into this. Adjust. (class_diff::priv::count_filtered_changed_dm): New member function. (class_diff::lookup_tables_empty): Adjust. (class_diff::ensure_lookup_tables_populated): Adjust. Detect when a data member is deleted and added back to offset N, and be prepared to present that as a change of data member at offset N. (class_diff::report): Adjust. Report data members of a given offset that have changed. * tests/data/test-diff-dwarf/test6-report.txt: New reference report for new test input. * tests/data/test-diff-dwarf/test6-v0.cc: Source code for new test input binary. * tests/data/test-diff-dwarf/test6-v0.o: New test input binary. * tests/data/test-diff-dwarf/test6-v1.cc: Source code for new test input binary. * tests/data/test-diff-dwarf/test6-v1.o: New test input binary. * tests/test-diff-dwarf.cc: Adjust to include the new test inputs above. Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-04-11 14:52:00 +00:00
{
"data/test-diff-dwarf/test5-v0.o",
"data/test-diff-dwarf/test5-v1.o",
"data/test-diff-dwarf/test5-report.txt",
"output/test-diff-dwarf/test5-report.txt"
},
{
"data/test-diff-dwarf/test6-v0.o",
"data/test-diff-dwarf/test6-v1.o",
"data/test-diff-dwarf/test6-report.txt",
"output/test-diff-dwarf/test6-report.txt"
},
{
"data/test-diff-dwarf/test7-v0.o",
"data/test-diff-dwarf/test7-v1.o",
"data/test-diff-dwarf/test7-report.txt",
"output/test-diff-dwarf/test7-report.txt"
},
{
"data/test-diff-dwarf/test8-v0.o",
"data/test-diff-dwarf/test8-v1.o",
"data/test-diff-dwarf/test8-report.txt",
"output/test-diff-dwarf/test8-report.txt"
},
Support TLS variables * src/abg-ir.cc (elf_symbol::is_variable): Accept TLS objects as variables too. * src/abg-dwarf-reader.cc (eval_last_constant_dwarf_sub_expr) (die_location_address): Add an output parameter to say if the resulting constant value is a tls address or not. (lookup_public_variable_symbol_from_elf): Use the proper elf_symbol::is_variable() method, rather than trying to figure out the low levels of what a variable is here. Also, cleanup the condition. (read_context::load_symbol_maps): Consider symbols of type STT_TLS, when loading symbols for variables. Also, to avoir symbols that are for versions, filter out symbols of type STT_OBJECT and with a SHN_ABS section index. (read_context::get_variable_address): If the address is for a tls variable, do no try to adjust the address to arrange for things like prelink. As that doesn't seem to affect TLS variables. (dwarf_expr_eval_context::set_tls_addr): New data member. (dwarf_expr_eval_context::dwarf_expr_eval_context): Initialize it. (dwarf_expr_eval_context::set_tls_address): New accessors. (dwarf_expr_eval_context::op_manipulates_stack): Handle DW_OP_GNU_push_tls_address, a bit like DW_OP_form_tls_address, but then, its result is a constant. Set the dwarf_expr_eval_context::set_tls_addr flag when these two OPs are run. (die_member_offset): Adjust to the new signature of eval_last_constant_dwarf_sub_expr. * tests/data/test-diff-dwarf/libtest9-v0.so: New test input. * tests/data/test-diff-dwarf/libtest9-v1.so: Likewise. * tests/data/test-diff-dwarf/test9-report.txt: Likewise * tests/data/test-diff-dwarf/test9-v0.cc: Source code for the first input. * tests/data/test-diff-dwarf/test9-v1.cc: Source code for the second input. * tests/test-diff-dwarf.cc: Run this harness on the two new inputs above. * tests/Makefile.am: Add the new inputs to the source distribution. Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-08-19 09:08:36 +00:00
{
"data/test-diff-dwarf/libtest9-v0.so",
"data/test-diff-dwarf/libtest9-v1.so",
"data/test-diff-dwarf/test9-report.txt",
"output/test-diff-dwarf/test9-report.txt"
},
Support C and C++ array type. * include/abg-comparison.h (array_diff): Declare new class. (array_diff_sptr): Shared pointer to type array_diff. (compute_diff): Overload the function to take type array_diff_sptr as the first two arguments. * include/abg-fwd.h (array_type_def): Declare new class. (subrange_type): Likewise. (is_array_def): Declare new function. * include/abg-ir.h (array_type_def_sptr): Shared pointer to type array_type_def. (array_type_def): Declare new class. (ir_node_visitor::visit): Declare a new virtual function taking a pointer to type array_type_def as an argument. * src/abg-comparison.cc (compute_diff_for_types): Add try_to_diff for two instances of type array_type_def. (array_diff::priv): declare struct for holding private members of type array_diff. (array_diff::array_diff): Define constructor. (array_diff::{first,second}_array):Define new member functions. (array_diff::element_type_diff): Likewise. (array_diff::{length,report,traverse}): Likewise. (compute_diff): Define function overloaded in include/abg-comparison.h. * src/abg-dwarf-reader.cc (build_array_type): Define new function. Handle DW_TAG_array_type and DW_TAG_subrange type. (build_ir_node_from_die): Amend case DW_TAG_array_type with a call to build_array_type. * src/abg-hash.cc (array_type_def::hash): Declare new struct. (type_base::dynamic_hash::operator()): Attempt to dynamic_cast the argument to type array_type_def as well. (array_type_def::hash): Declare new struct. * src/abg-ir.cc (array_type_def::array_type_def): Define constructors. (array_type_def::priv): declare struct for holding private members of type array_type_def. (array_type_def::operator==(const decl_base&): Define new operator. (array_type_def::operator==(const type_base&): Likewise. (array_type_def::append_subrange{,s}): Define new functions. (array_type_def::{set,get}_size_in_bits): Likewise. (array_type_def::get_dimension_count): Likewise. (array_type_def::get_qualified_name): Likewise. (array_type_def::get_pretty_representation): Likewise. (array_type_def::get_subrange_representation): Likewise. (array_type_def::traverse): Likewise. (array_type_def::get_{element_type,location,subranges}): Likewise. (array_type_def::is_infinite): Likewise. (array_type_def::~array_type_def): Define destructor. (ir_node_visitor::visit): Define function, taking pointer to array_type_def as an argument. * src/abg-reader.cc (map_id_and_node): Check if node is an array. (is_array_def): Check if object is an array. (handle_element_node): Handle array_type_def as well. (build_subrange_type): Define new function. (build_array_type_def): Likewise. (build_type): Build type array_type_def as well. (build_type_composition): Likewise. (handle_array_type_def): Define new function. * src/abg-writer.cc: (write_decl): Output arrays as well. (write_member_type): Likewise. (write_type_composition): Likewise. (write_array_type_def): Define new function. * tests/data/test-diff-dwarf/test{10,11}-v{0,1}.{cc,o}: New test source files * tests/data/test-diff-dwarf/test{10,11}-report.txt: Likewise. * tests/data/test-diff-dwarf/test10-report.txt: New test input. * tests/data/test-read-dwarf/test7.cc: New test source file. * tests/data/test-read-dwarf/test7.so: New input binary to read. * tests/data/test-read-dwarf/test7.so.abi: New reference test to compare against. * tests/data/test-read-write/test25.xml: New test source file. * tests/test-diff-dwarf.cc: Adjust to launch the new test. * tests/test-read-dwarf.cc: Likewise. * tests/test-read-write.cc: Likewise. * test/Makefile.am: Add the new test inputs to the source distribution. Signed-off-by: Ondrej Oprala <ooprala@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-08-18 09:56:43 +00:00
{
"data/test-diff-dwarf/test10-v0.o",
"data/test-diff-dwarf/test10-v1.o",
"data/test-diff-dwarf/test10-report.txt",
"output/test-diff-dwarf/test10-report.txt"
},
{
"data/test-diff-dwarf/test11-v0.o",
"data/test-diff-dwarf/test11-v1.o",
"data/test-diff-dwarf/test11-report.txt",
"output/test-diff-dwarf/test11-report.txt"
},
{
"data/test-diff-dwarf/libtest12-v0.so",
"data/test-diff-dwarf/libtest12-v1.so",
"data/test-diff-dwarf/test12-report.txt",
"output/test-diff-dwarf/test12-report.txt"
},
{
"data/test-diff-dwarf/test13-v0.o",
"data/test-diff-dwarf/test13-v1.o",
"data/test-diff-dwarf/test13-report.txt",
"output/test-diff-dwarf/test13-report.txt"
},
Better support for inline related diffs * include/abg-comparison.h (diff_category::HARMLESS_SYMBOL_ALIAS_CHANGE_CATEORY): New enumerator. (diff_category::EVERYTHING_CATEGORY): Adjust. * include/abg-ir.h (elf_symbol::get_aliases_id_string) (elf_symbol::does_alias, elf_symbols_alias) (compute_aliases_for_elf_symbol): Declare new functions ... * src/abg-ir.cc (elf_symbol::get_aliases_id_string) (elf_symbol::does_alias, elf_symbols_alias) (compute_aliases_for_elf_symbol): ... and define them. (function_decl::operator==): Take in account elf symbol aliases. * src/abg-comp-filter.cc (function_name_changed_but_not_symbol): Define new static functions. (harmless_filter::visit): Categorize function name changes that n doesn't impact underlying elf symbols (or the fact that two symbols were aliases and are not anymore) as harmless. * src/abg-comparison.cc (function_decl_diff::report): Properly report function name changes, or symbol aliases changes for that matter. Also report inline-ness declaration changes. * src/abg-dwarf-reader.cc (die_is_declared_inline): New static function. (build_function_decl): Use the above. * tools/bidiff.cc (set_diff_context_from_opts): Add abigail::comparison::HARMLESS_SYMBOL_ALIAS_CHANGE_CATEORY into the harmless change camp. * tests/data/test-diff-dwarf/test14-inline-report.txt: New test input. * tests/data/test-diff-dwarf/test14-inline-v0.o: Likewise. * tests/data/test-diff-dwarf/test14-inline-v1.o: Likewise. * tests/data/test-diff-dwarf/test14-inline-v0.cc: Source code for test input. * tests/data/test-diff-dwarf/test14-inline-v1.cc: Source code for test input. * tests/test-diff-dwarf.cc: Run this test harness over the new input above. * tests/data/test-diff-filter/test20-inline-report-0.txt: Likewise. * tests/data/test-diff-filter/test20-inline-report-1.txt: Likewise. * tests/data/test-diff-filter/test20-inline-v0.o: New test input. * tests/data/test-diff-filter/test20-inline-v1.o: New test input. * tests/data/test-diff-filter/test20-inline-v0.cc: Source code for test input. * tests/data/test-diff-filter/test20-inline-v1.cc: Likewise. * tests/test-diff-filter.cc: Run this test harness over the new input above. Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-09-16 12:53:30 +00:00
{
"data/test-diff-dwarf/test14-inline-v0.o",
"data/test-diff-dwarf/test14-inline-v1.o",
"data/test-diff-dwarf/test14-inline-report.txt",
"output/test-diff-dwarf/test14-inline-report.txt"
},
Better support for enum diffs * include/abg-comparison.h (changed_enumerator_type): New typedef. (diff_category::{HARMLESS_ENUM_CHANGE_CATEGORY}): New enumerator. * src/abg-comp-filter.cc (has_type_size_change) (has_enumerator_insertion, has_enumerator_removal_or_change) (has_harmful_enum_change): New functions. (harmless_filter::visit): Categorize enumerator insertions that don't change the size of the type into HARMLESS_ENUM_CHANGE_CATEGORY. (harmful_filter::visit): Categorize enumerator removal or any enum change that changes the size of the type into SIZE_OR_OFFSET_CHANGE_CATEGORY. * src/abg-comparison.cc (enumerator_value_comp) (changed_enumerator_comp): New types. (sort_enumerators, sort_changed_enumerators): New static functions. (enum_diff::report): Sort enum related reports by the value of the enumerators. * src/abg-dwarf-reader.cc (build_enum_type): Name anonymous enums as __anonymous_enum__. * tools/bidiff.cc (set_diff_context_from_opts): Add abigail::comparison::HARMLESS_ENUM_CHANGE_CATEGORY into the harmless stuff camp. * tests/data/test-diff-dwarf/test15-enum-report.txt: New test input. * tests/data/test-diff-dwarf/test15-enum-v1.o: Likewise. * tests/data/test-diff-dwarf/test15-enum-v0.o: Likewise. * tests/data/test-diff-dwarf/test15-enum-v0.cc: Source code for test input. * tests/data/test-diff-dwarf/test15-enum-v1.cc: Likewise. * tests/data/test-diff-filter/test19-enum-report-0.txt: New test input. * tests/data/test-diff-filter/test19-enum-report-1.txt: Likewise. * tests/data/test-diff-filter/test19-enum-v0.o: Likewise. * tests/data/test-diff-filter/test19-enum-v1.o: Likewise. * tests/data/test-diff-filter/test19-enum-v0.cc: Source code for test input. * tests/data/test-diff-filter/test19-enum-v1.cc: Likewise. * tests/test-diff-dwarf.cc: Run this test harness on the new test inputs above. * tests/test-diff-filter.cc: Likewise. * tests/Makefile.am: Add the new files above to the source distribution. Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-09-16 11:40:35 +00:00
{
"data/test-diff-dwarf/test15-enum-v0.o",
"data/test-diff-dwarf/test15-enum-v1.o",
"data/test-diff-dwarf/test15-enum-report.txt",
"output/test-diff-dwarf/test15-enum-report.txt"
},
// This should be the last entry
{NULL, NULL, NULL, NULL}
};
int
main()
{
using abigail::tests::get_src_dir;
using abigail::tests::get_build_dir;
using abigail::tools::ensure_parent_dir_created;
using abigail::dwarf_reader::read_corpus_from_elf;
using abigail::comparison::compute_diff;
using abigail::comparison::corpus_diff_sptr;
bool is_ok = true;
string in_elfv0_path, in_elfv1_path,
ref_diff_report_path, out_diff_report_path;
abigail::corpus_sptr corp0, corp1;
for (InOutSpec* s = in_out_specs; s->in_elfv0_path; ++s)
{
in_elfv0_path = get_src_dir() + "/tests/" + s->in_elfv0_path;
in_elfv1_path = get_src_dir() + "/tests/" + s->in_elfv1_path;
out_diff_report_path = get_build_dir() + "/tests/" + s->out_report_path;
if (!ensure_parent_dir_created(out_diff_report_path))
{
cerr << "could not create parent directory for "
<< out_diff_report_path;
is_ok = false;
continue;
}
read_corpus_from_elf(in_elfv0_path,
/*debug_info_root_path=*/0,
corp0);
read_corpus_from_elf(in_elfv1_path,
/*debug_info_root_path=*/0,
corp1);
if (!corp0)
{
cerr << "failed to read " << in_elfv0_path << "\n";
is_ok = false;
continue;
}
if (!corp1)
{
cerr << "failed to read " << in_elfv1_path << "\n";
is_ok = false;
continue;
}
corp0->set_path(s->in_elfv0_path);
corp1->set_path(s->in_elfv1_path);
corpus_diff_sptr d = compute_diff(corp0, corp1);
if (!d)
{
cerr << "failed to compute diff\n";
is_ok = false;
continue;
}
ref_diff_report_path = get_src_dir() + "/tests/" + s->in_report_path;
out_diff_report_path = get_build_dir() + "/tests/" + s->out_report_path;
ofstream of(out_diff_report_path, std::ios_base::trunc);
if (!of.is_open())
{
cerr << "failed to read " << out_diff_report_path << "\n";
is_ok = false;
continue;
}
d->report(of);
of.close();
string cmd =
"diff -u " + ref_diff_report_path + " " + out_diff_report_path;
if (system(cmd.c_str()))
is_ok = false;
}
return !is_ok;
}