libabigail/tests/test-symtab.cc

279 lines
9.7 KiB
C++
Raw Normal View History

Re-license the project to Apache v2 With LLVM Exception Thanks to the previous work done, changing the license is just a matter of changing the SPDX identifer from "LGPL-3.0-or-later" to "Apache-2.0 WITH LLVM-exception". Note that for the abigail.m4, tests/test-dot.cc and tests/test-svg.cc the change was from "GPL-3.0-or-later WITH GCC-exception-3.1" to "Apache-2.0 WITH LLVM-exception". include/abg-cxx-compat.h was changed from "LGPL-2.0-or-later" to "Apache-2.0 WITH LLVM-exception". Source code of programs (as opposed to source code of the library) where generally licensed under GPL-3.0-or-later; they are also now licensed "Apache-2.0 WITH LLVM-exception". This is what this patch does. * abigail.m4: Change the SPDX identifier from "GPL-3.0-or-later WITH GCC-exception-3.1" to "Apache-2.0 WITH LLVM-exception" * include/abg-cxx-compat.h: Change the SPDX identifier from "LGPL-2.0-or-later" to "Apache-2.0 WITH LLVM-exception". * .clang-format: Change the SPDX identifier from "LGPL-3.0-or-later" to "Apache-2.0 WITH LLVM-exception". * Makefile.am: Likewise. * bash-completion/Makefile.am: Likewise. * bash-completion/abicompat: Likewise. * bash-completion/abidiff: Likewise. * bash-completion/abidw: Likewise. * bash-completion/abilint: Likewise. * bash-completion/abinilint: Likewise. * bash-completion/abipkgdiff: Likewise. * bash-completion/abisym: Likewise. * bash-completion/fedabipkgdiff: Likewise. * configure.ac: Likewise. * default.abignore: Likewise. * doc/Makefile.am: Likewise. * doc/api/libabigail.doxy: Likewise. * doc/manuals/Makefile.am: Likewise. * doc/website/libabigail-website.doxy: Likewise. * include/Makefile.am: Likewise. * include/abg-comp-filter.h: Likewise. * include/abg-comparison.h: Likewise. * include/abg-config.h: Likewise. * include/abg-corpus.h: Likewise. * include/abg-diff-utils.h: Likewise. * include/abg-dwarf-reader.h: Likewise. * include/abg-fwd.h: Likewise. * include/abg-hash.h: Likewise. * include/abg-ini.h: Likewise. * include/abg-interned-str.h: Likewise. * include/abg-ir.h: Likewise. * include/abg-libxml-utils.h: Likewise. * include/abg-libzip-utils.h: Likewise. * include/abg-reader.h: Likewise. * include/abg-regex.h: Likewise. * include/abg-reporter.h: Likewise. * include/abg-sptr-utils.h: Likewise. * include/abg-suppression.h: Likewise. * include/abg-tools-utils.h: Likewise. * include/abg-traverse.h: Likewise. * include/abg-version.h.in: Likewise. * include/abg-viz-common.h: Likewise. * include/abg-viz-dot.h: Likewise. * include/abg-viz-svg.h: Likewise. * include/abg-workers.h: Likewise. * include/abg-writer.h: Likewise. * scripts/dot_to_png.sh: Likewise. * scripts/dot_to_svg.sh: Likewise. * scripts/make-verbose.sh: Likewise. * scripts/svg_to_plain_svg.sh: Likewise. * scripts/svg_to_png_and_pdf.sh: Likewise. * src/Makefile.am: Likewise. * src/abg-comp-filter.cc: Likewise. * src/abg-comparison-priv.h: Likewise. * src/abg-comparison.cc: Likewise. * src/abg-config.cc: Likewise. * src/abg-corpus-priv.h: Likewise. * src/abg-corpus.cc: Likewise. * src/abg-default-reporter.cc: Likewise. * src/abg-diff-utils.cc: Likewise. * src/abg-dwarf-reader.cc: Likewise. * src/abg-elf-helpers.cc: Likewise. * src/abg-elf-helpers.h: Likewise. * src/abg-hash.cc: Likewise. * src/abg-ini.cc: Likewise. * src/abg-internal.h: Likewise. * src/abg-ir-priv.h: Likewise. * src/abg-ir.cc: Likewise. * src/abg-leaf-reporter.cc: Likewise. * src/abg-libxml-utils.cc: Likewise. * src/abg-libzip-utils.cc: Likewise. * src/abg-reader.cc: Likewise. * src/abg-regex.cc: Likewise. * src/abg-reporter-priv.cc: Likewise. * src/abg-reporter-priv.h: Likewise. * src/abg-suppression-priv.h: Likewise. * src/abg-suppression.cc: Likewise. * src/abg-tools-utils.cc: Likewise. * src/abg-traverse.cc: Likewise. * src/abg-viz-common.cc: Likewise. * src/abg-viz-dot.cc: Likewise. * src/abg-viz-svg.cc: Likewise. * src/abg-workers.cc: Likewise. * src/abg-writer.cc: Likewise. * tests/Makefile.am: Likewise. * tests/data/Makefile.am: Likewise. * tests/lib/catch.cc: Likewise. * tests/mockfedabipkgdiff.in: Likewise. * tests/print-diff-tree.cc: Likewise. * tests/runtestcanonicalizetypes.sh.in: Likewise. * tests/runtestdefaultsupprs.py.in: Likewise. * tests/runtestdefaultsupprspy3.sh.in: Likewise. * tests/runtestfedabipkgdiff.py.in: Likewise. * tests/runtestfedabipkgdiffpy3.sh.in: Likewise. * tests/test-abicompat.cc: Likewise. * tests/test-abidiff-exit.cc: Likewise. * tests/test-abidiff.cc: Likewise. * tests/test-alt-dwarf-file.cc: Likewise. * tests/test-annotate.cc: Likewise. * tests/test-core-diff.cc: Likewise. * tests/test-cxx-compat.cc: Likewise. * tests/test-diff-dwarf-abixml.cc: Likewise. * tests/test-diff-dwarf.cc: Likewise. * tests/test-diff-filter.cc: Likewise. * tests/test-diff-pkg.cc: Likewise. * tests/test-diff-suppr.cc: Likewise. * tests/test-diff2.cc: Likewise. * tests/test-dot.cc: Change the SPDX identifier from "GPL-3.0-or-later WITH GCC-exception-3.1" to "Apache-2.0 WITH LLVM-exception" * tests/test-elf-helpers.cc: Change the SPDX identifier from "LGPL-3.0-or-later" to "Apache-2.0 WITH LLVM-exception" * tests/test-ini.cc: Likewise. * tests/test-ir-walker.cc: Likewise. * tests/test-kmi-whitelist.cc: Likewise. * tests/test-lookup-syms.cc: Likewise. * tests/test-read-dwarf.cc: Likewise. * tests/test-read-write.cc: Likewise. * tests/test-svg.cc: Change the SPDX identifier from "GPL-3.0-or-later WITH GCC-exception-3.1" to "Apache-2.0 WITH LLVM-exception". * tests/test-symtab.cc: Change the SPDX identifier from "LGPL-3.0-or-later" to "Apache-2.0 WITH LLVM-exception" * tests/test-tools-utils.cc: Likewise. * tests/test-types-stability.cc: Likewise. * tests/test-utils.cc: Likewise. * tests/test-utils.h: Likewise. * tests/test-write-read-archive.cc: Likewise. * tests/update-test-output.py: Likewise. * tools/Makefile.am: Likewise. * tools/abiar.cc: Likewise. * tools/abicompat.cc: Likewise. * tools/abidiff.cc: Likewise. * tools/abidw.cc: Likewise. * tools/abilint.cc: Likewise. * tools/abipkgdiff.cc: Likewise. * tools/abisym.cc: Likewise. * tools/binilint.cc: Likewise. * tools/fedabipkgdiff: Likewise. * tools/kmidiff.cc: Likewise. * update-copyright.sh: Likewise. Signed-off-by: Benjamin De Kosnik <bkoz@gnu.org> Signed-off-by: Ben Woodard <woodard@redhat.com> Signed-off-by: Chenxiong Qi <cqi@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Giuliano Procida <gprocida@google.com> Signed-off-by: Jan Engelhardt <jengelh@inai.de> Signed-off-by: Jessica Yu <jeyu@kernel.org> Signed-off-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Mark Wielaard <mark@klomp.org> Signed-off-by: Matthias Klose <doko@ubuntu.com> Signed-off-by: Matthias Maennich <maennich@google.com> Signed-off-by: Ondrej Oprala <ondrej.oprala@gmail.com> Signed-off-by: Roland McGrath <roland@hack.frob.com> Signed-off-by: Sinny Kumari <ksinny@gmail.com> Signed-off-by: Slava Barinov <v.barinov@samsung.com>
2020-05-29 14:26:04 +00:00
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
tests: Add symtab test suite Add (Catch based) test suite to test symbol table reading through the result persisted in abigail::corpus. The test cases are created through simple C source files targeting the desired properties (having an undefined/export function or both). The Makefile that comes with them recreates the test cases from the sources. This covers reading sorted_(undefined_)var|fun_symbols as well as the corresponding symbols maps accessible through the accessors of abigail::corpus. * tests/Makefile.am: add new test runtestsymtab * tests/data/Makefile.am: add new test data for runtestsymtab * tests/data/test-symtab/Makefile: Add this to build the binaries below from their source code. * tests/data/test-symtab/basic/empty.c: New test case source. * tests/data/test-symtab/basic/link_against_me.c: Likewise. * tests/data/test-symtab/basic/no_debug_info.c: Likewise. * tests/data/test-symtab/basic/one_function_one_variable.c: Likewise. * tests/data/test-symtab/basic/one_function_one_variable_undefined.c: Likewise. * tests/data/test-symtab/basic/single_function.c: Likewise. * tests/data/test-symtab/basic/single_undefined_function.c: Likewise. * tests/data/test-symtab/basic/single_undefined_variable.c: Likewise. * tests/data/test-symtab/basic/single_variable.c: Likewise. * tests/data/test-symtab/basic/empty.so: New test data, built from the Makefile above. * tests/data/test-symtab/basic/link_against_me.so: Likewise. * tests/data/test-symtab/basic/no_debug_info.so: Likewise. * tests/data/test-symtab/basic/one_function_one_variable.so: Likewise. * tests/data/test-symtab/basic/one_function_one_variable_undefined.so: Likewise. * tests/data/test-symtab/basic/single_function.so: Likewise. * tests/data/test-symtab/basic/single_undefined_function.so: Likewise. * tests/data/test-symtab/basic/single_undefined_variable.so: Likewise. * tests/data/test-symtab/basic/single_variable.so: Likewise. * tests/test-symtab.cc: New test driver. Signed-off-by: Matthias Maennich <maennich@google.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-18 11:50:13 +00:00
// -*- Mode: C++ -*-
//
// Copyright (C) 2020 Google, Inc.
//
// Author: Matthias Maennich
/// @file
///
/// This program tests symtab invariants through abg-corpus.
#include <iostream>
#include <limits>
#include <vector>
#include "abg-corpus.h"
#include "abg-dwarf-reader.h"
#include "abg-ir.h"
#include "lib/catch.hpp"
#include "test-utils.h"
using namespace abigail;
using dwarf_reader::create_read_context;
using dwarf_reader::read_context_sptr;
using dwarf_reader::read_corpus_from_elf;
using ir::environment;
using ir::environment_sptr;
static const std::string test_data_dir =
std::string(abigail::tests::get_src_dir()) + "/tests/data/test-symtab/";
dwarf_reader::status
read_corpus(const std::string path, corpus_sptr& result)
{
const std::string& absolute_path = test_data_dir + path;
environment_sptr env(new environment);
const std::vector<char**> debug_info_root_paths;
tests: Add kernel symtab test suite Add (Catch based) test suite to test kernel symbol table (ksymtab) reading through the result persisted in abigail::corpus. The test cases are created through simple kernel module C source files targeting the desired properties ((gpl) exported / local functions / variables). The kernel binaries are built without debug information to keep them reasonably small and reproducible. That is just enough sufficient to analyze ksymtabs. The Makefile that comes with them recreates the test cases from the sources, given a kernel source tree with the appropriate version, e.g. make KDIR=/path/to/4.14 This covers ksymtab reading and ensuring we detect the kernel binary correctly. The kernel versions are selected based on features introduced into the Linux kernel that affect the ksymtab representation. - Linux v4.14 - reasonably old kernel to start with (actually v4.14.180) - Linux v4.19 - first version having position relative relocations (PREL) in ksymtab entries on some platforms (actually v4.19.123) - Linux v5.4 - first version having symbol namespaces (actually v5.4.41) - Linux v5.6 - latest released stable kernel as of writing (actually v5.6.13) * tests/data/Makefile.am: add new test data for runtestsymtab * tests/data/test-symtab/kernel-4.14/Makefile: New test case makefile. * tests/data/test-symtab/kernel-4.14/empty.c: Likewise. * tests/data/test-symtab/kernel-4.14/one_of_each.c: Likewise. * tests/data/test-symtab/kernel-4.14/single_function.c: Likewise. * tests/data/test-symtab/kernel-4.14/single_function_gpl.c: Likewise. * tests/data/test-symtab/kernel-4.14/single_variable.c: Likewise. * tests/data/test-symtab/kernel-4.14/single_variable_gpl.c: Likewise. * tests/data/test-symtab/kernel-4.14/empty.ko: New test data. * tests/data/test-symtab/kernel-4.14/one_of_each.ko: Likewise. * tests/data/test-symtab/kernel-4.14/single_function.ko: Likewise. * tests/data/test-symtab/kernel-4.14/single_function_gpl.ko: Likewise. * tests/data/test-symtab/kernel-4.14/single_variable.ko: Likewise. * tests/data/test-symtab/kernel-4.14/single_variable_gpl.ko: Likewise. * tests/data/test-symtab/kernel-4.19/Makefile: New test case makefile. * tests/data/test-symtab/kernel-4.19/empty.c: Likewise. * tests/data/test-symtab/kernel-4.19/one_of_each.c: Likewise. * tests/data/test-symtab/kernel-4.19/single_function.c: Likewise. * tests/data/test-symtab/kernel-4.19/single_function_gpl.c: Likewise. * tests/data/test-symtab/kernel-4.19/single_variable.c: Likewise. * tests/data/test-symtab/kernel-4.19/single_variable_gpl.c: Likewise. * tests/data/test-symtab/kernel-4.19/empty.ko: New test data. * tests/data/test-symtab/kernel-4.19/one_of_each.ko: Likewise. * tests/data/test-symtab/kernel-4.19/single_function.ko: Likewise. * tests/data/test-symtab/kernel-4.19/single_function_gpl.ko: Likewise. * tests/data/test-symtab/kernel-4.19/single_variable.ko: Likewise. * tests/data/test-symtab/kernel-4.19/single_variable_gpl.ko: Likewise. * tests/data/test-symtab/kernel-5.4/Makefile: New test case makefile. * tests/data/test-symtab/kernel-5.4/empty.c: Likewise. * tests/data/test-symtab/kernel-5.4/one_of_each.c: Likewise. * tests/data/test-symtab/kernel-5.4/single_function.c: Likewise. * tests/data/test-symtab/kernel-5.4/single_function_gpl.c: Likewise. * tests/data/test-symtab/kernel-5.4/single_variable.c: Likewise. * tests/data/test-symtab/kernel-5.4/single_variable_gpl.c: Likewise. * tests/data/test-symtab/kernel-5.4/empty.ko: New test data. * tests/data/test-symtab/kernel-5.4/one_of_each.ko: Likewise. * tests/data/test-symtab/kernel-5.4/single_function.ko: Likewise. * tests/data/test-symtab/kernel-5.4/single_function_gpl.ko: Likewise. * tests/data/test-symtab/kernel-5.4/single_variable.ko: Likewise. * tests/data/test-symtab/kernel-5.4/single_variable_gpl.ko: Likewise. * tests/data/test-symtab/kernel-5.6/Makefile: New test case makefile. * tests/data/test-symtab/kernel-5.6/empty.c: Likewise. * tests/data/test-symtab/kernel-5.6/one_of_each.c: Likewise. * tests/data/test-symtab/kernel-5.6/single_function.c: Likewise. * tests/data/test-symtab/kernel-5.6/single_function_gpl.c: Likewise. * tests/data/test-symtab/kernel-5.6/single_variable.c: Likewise. * tests/data/test-symtab/kernel-5.6/single_variable_gpl.c: Likewise. * tests/data/test-symtab/kernel-5.6/empty.ko: New test data. * tests/data/test-symtab/kernel-5.6/one_of_each.ko: Likewise. * tests/data/test-symtab/kernel-5.6/single_function.ko: Likewise. * tests/data/test-symtab/kernel-5.6/single_function_gpl.ko: Likewise. * tests/data/test-symtab/kernel-5.6/single_variable.ko: Likewise. * tests/data/test-symtab/kernel-5.6/single_variable_gpl.ko: Likewise. * tests/data/test-symtab/kernel/Makefile: New test case source file. * tests/data/test-symtab/kernel/empty.c: Likewise. * tests/data/test-symtab/kernel/one_of_each.c: Likewise. * tests/data/test-symtab/kernel/single_function.c: Likewise. * tests/data/test-symtab/kernel/single_function_gpl.c: Likewise. * tests/data/test-symtab/kernel/single_variable.c: Likewise. * tests/data/test-symtab/kernel/single_variable_gpl.c: Likewise. * tests/test-symtab.cc: New test case to test kernel symtabs. Signed-off-by: Matthias Maennich <maennich@google.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-18 11:50:14 +00:00
read_context_sptr ctxt = create_read_context(
absolute_path, debug_info_root_paths, env.get(),
/* load_all_type = */ true, /* linux_kernel_mode = */ true);
tests: Add symtab test suite Add (Catch based) test suite to test symbol table reading through the result persisted in abigail::corpus. The test cases are created through simple C source files targeting the desired properties (having an undefined/export function or both). The Makefile that comes with them recreates the test cases from the sources. This covers reading sorted_(undefined_)var|fun_symbols as well as the corresponding symbols maps accessible through the accessors of abigail::corpus. * tests/Makefile.am: add new test runtestsymtab * tests/data/Makefile.am: add new test data for runtestsymtab * tests/data/test-symtab/Makefile: Add this to build the binaries below from their source code. * tests/data/test-symtab/basic/empty.c: New test case source. * tests/data/test-symtab/basic/link_against_me.c: Likewise. * tests/data/test-symtab/basic/no_debug_info.c: Likewise. * tests/data/test-symtab/basic/one_function_one_variable.c: Likewise. * tests/data/test-symtab/basic/one_function_one_variable_undefined.c: Likewise. * tests/data/test-symtab/basic/single_function.c: Likewise. * tests/data/test-symtab/basic/single_undefined_function.c: Likewise. * tests/data/test-symtab/basic/single_undefined_variable.c: Likewise. * tests/data/test-symtab/basic/single_variable.c: Likewise. * tests/data/test-symtab/basic/empty.so: New test data, built from the Makefile above. * tests/data/test-symtab/basic/link_against_me.so: Likewise. * tests/data/test-symtab/basic/no_debug_info.so: Likewise. * tests/data/test-symtab/basic/one_function_one_variable.so: Likewise. * tests/data/test-symtab/basic/one_function_one_variable_undefined.so: Likewise. * tests/data/test-symtab/basic/single_function.so: Likewise. * tests/data/test-symtab/basic/single_undefined_function.so: Likewise. * tests/data/test-symtab/basic/single_undefined_variable.so: Likewise. * tests/data/test-symtab/basic/single_variable.so: Likewise. * tests/test-symtab.cc: New test driver. Signed-off-by: Matthias Maennich <maennich@google.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-18 11:50:13 +00:00
dwarf_reader::status status = dwarf_reader::STATUS_UNKNOWN;
result = read_corpus_from_elf(*ctxt, status);
REQUIRE(status != dwarf_reader::STATUS_UNKNOWN);
return status;
}
TEST_CASE("Symtab::Empty", "[symtab, basic]")
{
const std::string binary = "basic/empty.so";
corpus_sptr corpus_ptr;
const dwarf_reader::status status = read_corpus(binary, corpus_ptr);
REQUIRE(corpus_ptr);
REQUIRE((status & dwarf_reader::STATUS_OK));
// TODO: Those two assertions are currently not met. Empty symtabs are
// currently treated like the error case.
// REQUIRE((status & dwarf_reader::STATUS_OK));
// REQUIRE((status & dwarf_reader::STATUS_NO_SYMBOLS_FOUND));
}
TEST_CASE("Symtab::NoDebugInfo", "[symtab, basic]")
{
const std::string binary = "basic/no_debug_info.so";
corpus_sptr corpus_ptr;
const dwarf_reader::status status = read_corpus(binary, corpus_ptr);
REQUIRE(corpus_ptr);
REQUIRE(status
== (dwarf_reader::STATUS_OK
| dwarf_reader::STATUS_DEBUG_INFO_NOT_FOUND));
}
// this value indicates in the following helper method, that we do not want to
// assert for this particular value. In other words, N is a placeholder for an
// arbitrary value.
#define N std::numeric_limits<size_t>::max()
corpus_sptr
assert_symbol_count(const std::string& path,
size_t function_symbols = 0,
size_t variable_symbols = 0,
size_t undefined_function_symbols = 0,
size_t undefined_variable_symbols = 0)
{
corpus_sptr corpus_ptr;
const dwarf_reader::status status = read_corpus(path, corpus_ptr);
REQUIRE(corpus_ptr);
tests: Add kernel symtab test suite Add (Catch based) test suite to test kernel symbol table (ksymtab) reading through the result persisted in abigail::corpus. The test cases are created through simple kernel module C source files targeting the desired properties ((gpl) exported / local functions / variables). The kernel binaries are built without debug information to keep them reasonably small and reproducible. That is just enough sufficient to analyze ksymtabs. The Makefile that comes with them recreates the test cases from the sources, given a kernel source tree with the appropriate version, e.g. make KDIR=/path/to/4.14 This covers ksymtab reading and ensuring we detect the kernel binary correctly. The kernel versions are selected based on features introduced into the Linux kernel that affect the ksymtab representation. - Linux v4.14 - reasonably old kernel to start with (actually v4.14.180) - Linux v4.19 - first version having position relative relocations (PREL) in ksymtab entries on some platforms (actually v4.19.123) - Linux v5.4 - first version having symbol namespaces (actually v5.4.41) - Linux v5.6 - latest released stable kernel as of writing (actually v5.6.13) * tests/data/Makefile.am: add new test data for runtestsymtab * tests/data/test-symtab/kernel-4.14/Makefile: New test case makefile. * tests/data/test-symtab/kernel-4.14/empty.c: Likewise. * tests/data/test-symtab/kernel-4.14/one_of_each.c: Likewise. * tests/data/test-symtab/kernel-4.14/single_function.c: Likewise. * tests/data/test-symtab/kernel-4.14/single_function_gpl.c: Likewise. * tests/data/test-symtab/kernel-4.14/single_variable.c: Likewise. * tests/data/test-symtab/kernel-4.14/single_variable_gpl.c: Likewise. * tests/data/test-symtab/kernel-4.14/empty.ko: New test data. * tests/data/test-symtab/kernel-4.14/one_of_each.ko: Likewise. * tests/data/test-symtab/kernel-4.14/single_function.ko: Likewise. * tests/data/test-symtab/kernel-4.14/single_function_gpl.ko: Likewise. * tests/data/test-symtab/kernel-4.14/single_variable.ko: Likewise. * tests/data/test-symtab/kernel-4.14/single_variable_gpl.ko: Likewise. * tests/data/test-symtab/kernel-4.19/Makefile: New test case makefile. * tests/data/test-symtab/kernel-4.19/empty.c: Likewise. * tests/data/test-symtab/kernel-4.19/one_of_each.c: Likewise. * tests/data/test-symtab/kernel-4.19/single_function.c: Likewise. * tests/data/test-symtab/kernel-4.19/single_function_gpl.c: Likewise. * tests/data/test-symtab/kernel-4.19/single_variable.c: Likewise. * tests/data/test-symtab/kernel-4.19/single_variable_gpl.c: Likewise. * tests/data/test-symtab/kernel-4.19/empty.ko: New test data. * tests/data/test-symtab/kernel-4.19/one_of_each.ko: Likewise. * tests/data/test-symtab/kernel-4.19/single_function.ko: Likewise. * tests/data/test-symtab/kernel-4.19/single_function_gpl.ko: Likewise. * tests/data/test-symtab/kernel-4.19/single_variable.ko: Likewise. * tests/data/test-symtab/kernel-4.19/single_variable_gpl.ko: Likewise. * tests/data/test-symtab/kernel-5.4/Makefile: New test case makefile. * tests/data/test-symtab/kernel-5.4/empty.c: Likewise. * tests/data/test-symtab/kernel-5.4/one_of_each.c: Likewise. * tests/data/test-symtab/kernel-5.4/single_function.c: Likewise. * tests/data/test-symtab/kernel-5.4/single_function_gpl.c: Likewise. * tests/data/test-symtab/kernel-5.4/single_variable.c: Likewise. * tests/data/test-symtab/kernel-5.4/single_variable_gpl.c: Likewise. * tests/data/test-symtab/kernel-5.4/empty.ko: New test data. * tests/data/test-symtab/kernel-5.4/one_of_each.ko: Likewise. * tests/data/test-symtab/kernel-5.4/single_function.ko: Likewise. * tests/data/test-symtab/kernel-5.4/single_function_gpl.ko: Likewise. * tests/data/test-symtab/kernel-5.4/single_variable.ko: Likewise. * tests/data/test-symtab/kernel-5.4/single_variable_gpl.ko: Likewise. * tests/data/test-symtab/kernel-5.6/Makefile: New test case makefile. * tests/data/test-symtab/kernel-5.6/empty.c: Likewise. * tests/data/test-symtab/kernel-5.6/one_of_each.c: Likewise. * tests/data/test-symtab/kernel-5.6/single_function.c: Likewise. * tests/data/test-symtab/kernel-5.6/single_function_gpl.c: Likewise. * tests/data/test-symtab/kernel-5.6/single_variable.c: Likewise. * tests/data/test-symtab/kernel-5.6/single_variable_gpl.c: Likewise. * tests/data/test-symtab/kernel-5.6/empty.ko: New test data. * tests/data/test-symtab/kernel-5.6/one_of_each.ko: Likewise. * tests/data/test-symtab/kernel-5.6/single_function.ko: Likewise. * tests/data/test-symtab/kernel-5.6/single_function_gpl.ko: Likewise. * tests/data/test-symtab/kernel-5.6/single_variable.ko: Likewise. * tests/data/test-symtab/kernel-5.6/single_variable_gpl.ko: Likewise. * tests/data/test-symtab/kernel/Makefile: New test case source file. * tests/data/test-symtab/kernel/empty.c: Likewise. * tests/data/test-symtab/kernel/one_of_each.c: Likewise. * tests/data/test-symtab/kernel/single_function.c: Likewise. * tests/data/test-symtab/kernel/single_function_gpl.c: Likewise. * tests/data/test-symtab/kernel/single_variable.c: Likewise. * tests/data/test-symtab/kernel/single_variable_gpl.c: Likewise. * tests/test-symtab.cc: New test case to test kernel symtabs. Signed-off-by: Matthias Maennich <maennich@google.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-18 11:50:14 +00:00
REQUIRE((status & dwarf_reader::STATUS_OK));
tests: Add symtab test suite Add (Catch based) test suite to test symbol table reading through the result persisted in abigail::corpus. The test cases are created through simple C source files targeting the desired properties (having an undefined/export function or both). The Makefile that comes with them recreates the test cases from the sources. This covers reading sorted_(undefined_)var|fun_symbols as well as the corresponding symbols maps accessible through the accessors of abigail::corpus. * tests/Makefile.am: add new test runtestsymtab * tests/data/Makefile.am: add new test data for runtestsymtab * tests/data/test-symtab/Makefile: Add this to build the binaries below from their source code. * tests/data/test-symtab/basic/empty.c: New test case source. * tests/data/test-symtab/basic/link_against_me.c: Likewise. * tests/data/test-symtab/basic/no_debug_info.c: Likewise. * tests/data/test-symtab/basic/one_function_one_variable.c: Likewise. * tests/data/test-symtab/basic/one_function_one_variable_undefined.c: Likewise. * tests/data/test-symtab/basic/single_function.c: Likewise. * tests/data/test-symtab/basic/single_undefined_function.c: Likewise. * tests/data/test-symtab/basic/single_undefined_variable.c: Likewise. * tests/data/test-symtab/basic/single_variable.c: Likewise. * tests/data/test-symtab/basic/empty.so: New test data, built from the Makefile above. * tests/data/test-symtab/basic/link_against_me.so: Likewise. * tests/data/test-symtab/basic/no_debug_info.so: Likewise. * tests/data/test-symtab/basic/one_function_one_variable.so: Likewise. * tests/data/test-symtab/basic/one_function_one_variable_undefined.so: Likewise. * tests/data/test-symtab/basic/single_function.so: Likewise. * tests/data/test-symtab/basic/single_undefined_function.so: Likewise. * tests/data/test-symtab/basic/single_undefined_variable.so: Likewise. * tests/data/test-symtab/basic/single_variable.so: Likewise. * tests/test-symtab.cc: New test driver. Signed-off-by: Matthias Maennich <maennich@google.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-18 11:50:13 +00:00
const corpus& corpus = *corpus_ptr;
if (function_symbols != N)
{
CHECK(corpus.get_sorted_fun_symbols().size() == function_symbols);
CHECK(corpus.get_fun_symbol_map().size() == function_symbols);
CHECK(corpus.get_fun_symbol_map_sptr()->size() == function_symbols);
}
if (variable_symbols != N)
{
CHECK(corpus.get_sorted_var_symbols().size() == variable_symbols);
CHECK(corpus.get_var_symbol_map().size() == variable_symbols);
CHECK(corpus.get_var_symbol_map_sptr()->size() == variable_symbols);
}
if (undefined_variable_symbols != N)
{
CHECK(corpus.get_sorted_undefined_fun_symbols().size()
== undefined_function_symbols);
CHECK(corpus.get_undefined_fun_symbol_map().size()
== undefined_function_symbols);
CHECK(corpus.get_undefined_fun_symbol_map_sptr()->size()
== undefined_function_symbols);
}
if (undefined_function_symbols != N)
{
CHECK(corpus.get_sorted_undefined_var_symbols().size()
== undefined_variable_symbols);
CHECK(corpus.get_undefined_var_symbol_map().size()
== undefined_variable_symbols);
CHECK(corpus.get_undefined_var_symbol_map_sptr()->size()
== undefined_variable_symbols);
}
return corpus_ptr;
}
TEST_CASE("Symtab::SimpleSymtabs", "[symtab, basic]")
{
GIVEN("a binary with no exported symbols")
{
// TODO: should pass, but does currently not as empty tables are treated
// like the error case, but this is an edge case anyway.
// assert_symbol_count("empty.so");
}
GIVEN("a binary with a single exported function")
{
const std::string binary = "basic/single_function.so";
const corpus_sptr& corpus = assert_symbol_count(binary, 1, 0);
const elf_symbol_sptr& symbol =
corpus->lookup_function_symbol("exported_function");
REQUIRE(symbol);
CHECK(!corpus->lookup_variable_symbol("exported_function"));
CHECK(symbol == corpus->lookup_function_symbol(*symbol));
CHECK(symbol != corpus->lookup_variable_symbol(*symbol));
}
GIVEN("a binary with a single exported variable")
{
const std::string binary = "basic/single_variable.so";
const corpus_sptr& corpus = assert_symbol_count(binary, 0, 1);
const elf_symbol_sptr& symbol =
corpus->lookup_variable_symbol("exported_variable");
REQUIRE(symbol);
CHECK(!corpus->lookup_function_symbol("exported_variable"));
CHECK(symbol == corpus->lookup_variable_symbol(*symbol));
CHECK(symbol != corpus->lookup_function_symbol(*symbol));
}
GIVEN("a binary with one function and one variable exported")
{
const std::string binary = "basic/one_function_one_variable.so";
const corpus_sptr& corpus = assert_symbol_count(binary, 1, 1);
CHECK(corpus->lookup_function_symbol("exported_function"));
CHECK(!corpus->lookup_variable_symbol("exported_function"));
CHECK(corpus->lookup_variable_symbol("exported_variable"));
CHECK(!corpus->lookup_function_symbol("exported_variable"));
}
GIVEN("a binary with a single undefined function")
{
const std::string binary = "basic/single_undefined_function.so";
const corpus_sptr& corpus = assert_symbol_count(binary, 0, 0, 1, 0);
}
GIVEN("a binary with a single undefined variable")
{
const std::string binary = "basic/single_undefined_variable.so";
const corpus_sptr& corpus = assert_symbol_count(binary, 0, 0, 0, 1);
}
GIVEN("a binary with one function and one variable undefined")
{
const std::string binary = "basic/one_function_one_variable_undefined.so";
const corpus_sptr& corpus = assert_symbol_count(binary, 0, 0, 1, 1);
}
}
tests: Add kernel symtab test suite Add (Catch based) test suite to test kernel symbol table (ksymtab) reading through the result persisted in abigail::corpus. The test cases are created through simple kernel module C source files targeting the desired properties ((gpl) exported / local functions / variables). The kernel binaries are built without debug information to keep them reasonably small and reproducible. That is just enough sufficient to analyze ksymtabs. The Makefile that comes with them recreates the test cases from the sources, given a kernel source tree with the appropriate version, e.g. make KDIR=/path/to/4.14 This covers ksymtab reading and ensuring we detect the kernel binary correctly. The kernel versions are selected based on features introduced into the Linux kernel that affect the ksymtab representation. - Linux v4.14 - reasonably old kernel to start with (actually v4.14.180) - Linux v4.19 - first version having position relative relocations (PREL) in ksymtab entries on some platforms (actually v4.19.123) - Linux v5.4 - first version having symbol namespaces (actually v5.4.41) - Linux v5.6 - latest released stable kernel as of writing (actually v5.6.13) * tests/data/Makefile.am: add new test data for runtestsymtab * tests/data/test-symtab/kernel-4.14/Makefile: New test case makefile. * tests/data/test-symtab/kernel-4.14/empty.c: Likewise. * tests/data/test-symtab/kernel-4.14/one_of_each.c: Likewise. * tests/data/test-symtab/kernel-4.14/single_function.c: Likewise. * tests/data/test-symtab/kernel-4.14/single_function_gpl.c: Likewise. * tests/data/test-symtab/kernel-4.14/single_variable.c: Likewise. * tests/data/test-symtab/kernel-4.14/single_variable_gpl.c: Likewise. * tests/data/test-symtab/kernel-4.14/empty.ko: New test data. * tests/data/test-symtab/kernel-4.14/one_of_each.ko: Likewise. * tests/data/test-symtab/kernel-4.14/single_function.ko: Likewise. * tests/data/test-symtab/kernel-4.14/single_function_gpl.ko: Likewise. * tests/data/test-symtab/kernel-4.14/single_variable.ko: Likewise. * tests/data/test-symtab/kernel-4.14/single_variable_gpl.ko: Likewise. * tests/data/test-symtab/kernel-4.19/Makefile: New test case makefile. * tests/data/test-symtab/kernel-4.19/empty.c: Likewise. * tests/data/test-symtab/kernel-4.19/one_of_each.c: Likewise. * tests/data/test-symtab/kernel-4.19/single_function.c: Likewise. * tests/data/test-symtab/kernel-4.19/single_function_gpl.c: Likewise. * tests/data/test-symtab/kernel-4.19/single_variable.c: Likewise. * tests/data/test-symtab/kernel-4.19/single_variable_gpl.c: Likewise. * tests/data/test-symtab/kernel-4.19/empty.ko: New test data. * tests/data/test-symtab/kernel-4.19/one_of_each.ko: Likewise. * tests/data/test-symtab/kernel-4.19/single_function.ko: Likewise. * tests/data/test-symtab/kernel-4.19/single_function_gpl.ko: Likewise. * tests/data/test-symtab/kernel-4.19/single_variable.ko: Likewise. * tests/data/test-symtab/kernel-4.19/single_variable_gpl.ko: Likewise. * tests/data/test-symtab/kernel-5.4/Makefile: New test case makefile. * tests/data/test-symtab/kernel-5.4/empty.c: Likewise. * tests/data/test-symtab/kernel-5.4/one_of_each.c: Likewise. * tests/data/test-symtab/kernel-5.4/single_function.c: Likewise. * tests/data/test-symtab/kernel-5.4/single_function_gpl.c: Likewise. * tests/data/test-symtab/kernel-5.4/single_variable.c: Likewise. * tests/data/test-symtab/kernel-5.4/single_variable_gpl.c: Likewise. * tests/data/test-symtab/kernel-5.4/empty.ko: New test data. * tests/data/test-symtab/kernel-5.4/one_of_each.ko: Likewise. * tests/data/test-symtab/kernel-5.4/single_function.ko: Likewise. * tests/data/test-symtab/kernel-5.4/single_function_gpl.ko: Likewise. * tests/data/test-symtab/kernel-5.4/single_variable.ko: Likewise. * tests/data/test-symtab/kernel-5.4/single_variable_gpl.ko: Likewise. * tests/data/test-symtab/kernel-5.6/Makefile: New test case makefile. * tests/data/test-symtab/kernel-5.6/empty.c: Likewise. * tests/data/test-symtab/kernel-5.6/one_of_each.c: Likewise. * tests/data/test-symtab/kernel-5.6/single_function.c: Likewise. * tests/data/test-symtab/kernel-5.6/single_function_gpl.c: Likewise. * tests/data/test-symtab/kernel-5.6/single_variable.c: Likewise. * tests/data/test-symtab/kernel-5.6/single_variable_gpl.c: Likewise. * tests/data/test-symtab/kernel-5.6/empty.ko: New test data. * tests/data/test-symtab/kernel-5.6/one_of_each.ko: Likewise. * tests/data/test-symtab/kernel-5.6/single_function.ko: Likewise. * tests/data/test-symtab/kernel-5.6/single_function_gpl.ko: Likewise. * tests/data/test-symtab/kernel-5.6/single_variable.ko: Likewise. * tests/data/test-symtab/kernel-5.6/single_variable_gpl.ko: Likewise. * tests/data/test-symtab/kernel/Makefile: New test case source file. * tests/data/test-symtab/kernel/empty.c: Likewise. * tests/data/test-symtab/kernel/one_of_each.c: Likewise. * tests/data/test-symtab/kernel/single_function.c: Likewise. * tests/data/test-symtab/kernel/single_function_gpl.c: Likewise. * tests/data/test-symtab/kernel/single_variable.c: Likewise. * tests/data/test-symtab/kernel/single_variable_gpl.c: Likewise. * tests/test-symtab.cc: New test case to test kernel symtabs. Signed-off-by: Matthias Maennich <maennich@google.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-18 11:50:14 +00:00
static const char* kernel_versions[] = { "4.14", "4.19", "5.4", "5.6" };
static const size_t nr_kernel_versions =
sizeof(kernel_versions) / sizeof(kernel_versions[0]);
TEST_CASE("Symtab::SimpleKernelSymtabs", "[symtab, basic, kernel, ksymtab]")
{
for (size_t i = 0; i < nr_kernel_versions; ++i)
{
const std::string base_path =
"kernel-" + std::string(kernel_versions[i]) + "/";
GIVEN("The binaries in " + base_path)
{
GIVEN("a kernel module with no exported symbols")
{
// TODO: should pass, but does currently not as empty tables are
// treated
// like the error case, but this is an edge case anyway.
// assert_symbol_count(base_path + "empty.so");
}
GIVEN("a kernel module with a single exported function")
{
const std::string binary = base_path + "single_function.ko";
const corpus_sptr& corpus = assert_symbol_count(binary, 1, 0);
const elf_symbol_sptr& symbol =
corpus->lookup_function_symbol("exported_function");
REQUIRE(symbol);
CHECK(!corpus->lookup_variable_symbol("exported_function"));
CHECK(symbol == corpus->lookup_function_symbol(*symbol));
CHECK(symbol != corpus->lookup_variable_symbol(*symbol));
}
GIVEN("a kernel module with a single GPL exported function")
{
const std::string binary = base_path + "single_function_gpl.ko";
const corpus_sptr& corpus = assert_symbol_count(binary, 1, 0);
const elf_symbol_sptr& symbol =
corpus->lookup_function_symbol("exported_function_gpl");
REQUIRE(symbol);
CHECK(!corpus->lookup_variable_symbol("exported_function_gpl"));
CHECK(symbol == corpus->lookup_function_symbol(*symbol));
CHECK(symbol != corpus->lookup_variable_symbol(*symbol));
}
GIVEN("a binary with a single exported variable")
{
const std::string binary = base_path + "single_variable.ko";
const corpus_sptr& corpus = assert_symbol_count(binary, 0, 1);
const elf_symbol_sptr& symbol =
corpus->lookup_variable_symbol("exported_variable");
REQUIRE(symbol);
CHECK(!corpus->lookup_function_symbol("exported_variable"));
CHECK(symbol == corpus->lookup_variable_symbol(*symbol));
CHECK(symbol != corpus->lookup_function_symbol(*symbol));
}
GIVEN("a binary with a single GPL exported variable")
{
const std::string binary = base_path + "single_variable_gpl.ko";
const corpus_sptr& corpus = assert_symbol_count(binary, 0, 1);
const elf_symbol_sptr& symbol =
corpus->lookup_variable_symbol("exported_variable_gpl");
REQUIRE(symbol);
CHECK(!corpus->lookup_function_symbol("exported_variable_gpl"));
CHECK(symbol == corpus->lookup_variable_symbol(*symbol));
CHECK(symbol != corpus->lookup_function_symbol(*symbol));
}
GIVEN("a binary with one function and one variable (GPL) exported")
{
const std::string binary = base_path + "one_of_each.ko";
const corpus_sptr& corpus = assert_symbol_count(binary, 2, 2);
CHECK(corpus->lookup_function_symbol("exported_function"));
CHECK(!corpus->lookup_variable_symbol("exported_function"));
CHECK(corpus->lookup_function_symbol("exported_function_gpl"));
CHECK(!corpus->lookup_variable_symbol("exported_function_gpl"));
CHECK(corpus->lookup_variable_symbol("exported_variable"));
CHECK(!corpus->lookup_function_symbol("exported_variable"));
CHECK(corpus->lookup_variable_symbol("exported_variable_gpl"));
CHECK(!corpus->lookup_function_symbol("exported_variable_gpl"));
}
}
}
}