From patchwork Fri Jul 3 16:46:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 39899 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BC6443844079; Fri, 3 Jul 2020 16:48:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC6443844079 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1593794895; bh=ACW4NTs2rb1Hm2r6942mLHToSqbV3FL5hMaO186AlZE=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=pEsq3SSgdj3ltQ46wIOwddCWAgJapkzo5OrHW8eA1vQPqScfQ9MSNReksitSvM9rs RRIIiS19SXqFveCGmZYKYQneGwgENhiJ5EVWVda+DqEuZgDF8SgUK2j4tOI6dvylZr 4VeeuERs2ayOhUtwmppUp5H0joTBnSNYokTh/q+0= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by sourceware.org (Postfix) with ESMTPS id 5A038386F028 for ; Fri, 3 Jul 2020 16:48:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5A038386F028 Received: by mail-qk1-x749.google.com with SMTP id i145so3121206qke.2 for ; Fri, 03 Jul 2020 09:48:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ACW4NTs2rb1Hm2r6942mLHToSqbV3FL5hMaO186AlZE=; b=jVvM+V8XlhA0CPdRMEncg8Gwii7O36yi6kLpH2kjI7YwQMISyqf6NPxuTJ67QB24Kd b/sTFnFrEYeD7nxsZ1o6QWmKegIwxzEiU6tWwgxIb4+sARTH3dEl0nA+oulinYtPpsf3 k1LS4uFc8bPXRCFjAcfoPfryyUykWAGMVIY+hgasIkcG2hm5qnv/EpDSi1QFJDpyDXzN F8OwYP6kiQ7kVduCe50jc7fppmVt53shVQ1fhhgW3mHWfWT9JD4+wx9o3B4lCUjW5EsD nWe0v3HAE9RHs4yoOa7oOKBu0UB8TGOHdce0hMjms02vCCikuUYgx9swyLme4UZwq7JZ W0DA== X-Gm-Message-State: AOAM530uqKRt4G9DdA21njjFs+uhnUl+NS594Ng7oDjmLPP93I0bN5qF P8nkwYz18+8BUnLSKqFZ2Vrgu6lFQ9vHTp8RVImoRS9jh+LMIjvO57Hqgh2iiMs8GN/iXqyciqh BmExOSG6m7mKWMW/PIuY3P+H9S+rflL7HKMYxqRznGxaWa4lxLFmPRUs3RBbaP9nWvpbS2tw= X-Google-Smtp-Source: ABdhPJyQSgjNu4cRsYTycTlw/cmYcYNefw7qWE8QoK/tYWmZpyIPxZxTmdzIGuykRu6jw0V2xZe32l2R50n3jQ== X-Received: by 2002:a0c:bd2c:: with SMTP id m44mr36884517qvg.195.1593794891901; Fri, 03 Jul 2020 09:48:11 -0700 (PDT) Date: Fri, 3 Jul 2020 18:46:47 +0200 In-Reply-To: <20200703164651.1510825-1-maennich@google.com> Message-Id: <20200703164651.1510825-18-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20200703164651.1510825-1-maennich@google.com> X-Mailer: git-send-email 2.27.0.212.ge8ba1cc988-goog Subject: [PATCH v2 17/21] test-symtab: add tests for whitelisted functions To: libabigail@sourceware.org X-Spam-Status: No, score=-22.7 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Matthias Maennich via Libabigail From: =?utf-8?q?Matthias_M=C3=A4nnich?= Reply-To: Matthias Maennich Cc: maennich@google.com, kernel-team@android.com Errors-To: libabigail-bounces@sourceware.org Sender: "Libabigail" Extend the test functionality in test-symtab to allow processing of KMI whitelists and add additional test cases for whitelist handling. * tests/data/Makefile.am: add new test files * tests/data/test-symtab/basic/ofov_all.whitelist: New test file, * tests/data/test-symtab/basic/ofov_function.whitelist: Likewise. * tests/data/test-symtab/basic/ofov_irrelevant.whitelist: Likewise. * tests/data/test-symtab/basic/ofov_variable.whitelist: Likewise. * tests/test-symtab.cc (read_corpus): Add support for whitelists. (assert_symbol_count): Likewise. (Symtab::SymtabWithWhitelist): New testcase. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- tests/data/Makefile.am | 4 + .../one_function_one_variable_all.whitelist | 3 + ...e_function_one_variable_function.whitelist | 2 + ...function_one_variable_irrelevant.whitelist | 2 + ...e_function_one_variable_variable.whitelist | 2 + tests/test-symtab.cc | 103 ++++++++++++++++-- 6 files changed, 109 insertions(+), 7 deletions(-) create mode 100644 tests/data/test-symtab/basic/one_function_one_variable_all.whitelist create mode 100644 tests/data/test-symtab/basic/one_function_one_variable_function.whitelist create mode 100644 tests/data/test-symtab/basic/one_function_one_variable_irrelevant.whitelist create mode 100644 tests/data/test-symtab/basic/one_function_one_variable_variable.whitelist diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index 8ccd50a0d5bc..cf86fb51d492 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -1768,6 +1768,10 @@ test-symtab/basic/no_debug_info.c \ test-symtab/basic/no_debug_info.so \ test-symtab/basic/one_function_one_variable.c \ test-symtab/basic/one_function_one_variable.so \ +test-symtab/basic/one_function_one_variable_variable.whitelist \ +test-symtab/basic/one_function_one_variable_function.whitelist \ +test-symtab/basic/one_function_one_variable_irrelevant.whitelist \ +test-symtab/basic/one_function_one_variable_all.whitelist \ test-symtab/basic/one_function_one_variable_undefined.c \ test-symtab/basic/one_function_one_variable_undefined.so \ test-symtab/basic/single_function.c \ diff --git a/tests/data/test-symtab/basic/one_function_one_variable_all.whitelist b/tests/data/test-symtab/basic/one_function_one_variable_all.whitelist new file mode 100644 index 000000000000..02ea310960ff --- /dev/null +++ b/tests/data/test-symtab/basic/one_function_one_variable_all.whitelist @@ -0,0 +1,3 @@ +[abi_whitelist] + exported_function + exported_variable diff --git a/tests/data/test-symtab/basic/one_function_one_variable_function.whitelist b/tests/data/test-symtab/basic/one_function_one_variable_function.whitelist new file mode 100644 index 000000000000..893accc14118 --- /dev/null +++ b/tests/data/test-symtab/basic/one_function_one_variable_function.whitelist @@ -0,0 +1,2 @@ +[abi_whitelist] + exported_function diff --git a/tests/data/test-symtab/basic/one_function_one_variable_irrelevant.whitelist b/tests/data/test-symtab/basic/one_function_one_variable_irrelevant.whitelist new file mode 100644 index 000000000000..180ef9064e8f --- /dev/null +++ b/tests/data/test-symtab/basic/one_function_one_variable_irrelevant.whitelist @@ -0,0 +1,2 @@ +[abi_whitelist] + irrelevant diff --git a/tests/data/test-symtab/basic/one_function_one_variable_variable.whitelist b/tests/data/test-symtab/basic/one_function_one_variable_variable.whitelist new file mode 100644 index 000000000000..49d838f2c559 --- /dev/null +++ b/tests/data/test-symtab/basic/one_function_one_variable_variable.whitelist @@ -0,0 +1,2 @@ +[abi_whitelist] + exported_variable diff --git a/tests/test-symtab.cc b/tests/test-symtab.cc index c144b1d080f6..09e5193fa667 100644 --- a/tests/test-symtab.cc +++ b/tests/test-symtab.cc @@ -26,11 +26,14 @@ #include #include +#include #include #include "abg-corpus.h" #include "abg-dwarf-reader.h" +#include "abg-fwd.h" #include "abg-ir.h" +#include "abg-tools-utils.h" #include "lib/catch.hpp" #include "test-utils.h" @@ -41,12 +44,16 @@ using dwarf_reader::read_context_sptr; using dwarf_reader::read_corpus_from_elf; using ir::environment; using ir::environment_sptr; +using suppr::suppressions_type; 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) +read_corpus( + const std::string& path, + corpus_sptr& result, + const std::vector& whitelist_paths = std::vector()) { const std::string& absolute_path = test_data_dir + path; @@ -56,6 +63,15 @@ read_corpus(const std::string path, corpus_sptr& result) absolute_path, debug_info_root_paths, env.get(), /* load_all_type = */ true, /* linux_kernel_mode = */ true); + if (!whitelist_paths.empty()) + { + const suppressions_type& wl_suppr = + tools_utils::gen_suppr_spec_from_kernel_abi_whitelists( + whitelist_paths); + REQUIRE_FALSE(wl_suppr.empty()); + dwarf_reader::add_read_context_suppressions(*ctxt, wl_suppr); + } + dwarf_reader::status status = dwarf_reader::STATUS_UNKNOWN; result = read_corpus_from_elf(*ctxt, status); @@ -91,14 +107,17 @@ TEST_CASE("Symtab::NoDebugInfo", "[symtab, basic]") #define N std::numeric_limits::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) +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, + const std::vector& whitelist_paths = std::vector()) { corpus_sptr corpus_ptr; - const dwarf_reader::status status = read_corpus(path, corpus_ptr); + const dwarf_reader::status status = + read_corpus(path, corpus_ptr, whitelist_paths); REQUIRE(corpus_ptr); REQUIRE((status & dwarf_reader::STATUS_OK)); @@ -203,6 +222,76 @@ TEST_CASE("Symtab::SimpleSymtabs", "[symtab, basic]") } } +TEST_CASE("Symtab::SymtabWithWhitelist", "[symtab, whitelist]") +{ + GIVEN("a binary with one function and one variable exported") + { + const std::string binary = "basic/one_function_one_variable.so"; + + GIVEN("we read the binary without any whitelists") + { + 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("we read the binary with all symbols on the whitelists") + { + std::vector whitelists; + whitelists.push_back(test_data_dir + + "basic/one_function_one_variable_all.whitelist"); + const corpus_sptr& corpus = + assert_symbol_count(binary, 1, 1, 0, 0, whitelists); + 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("we read the binary with only irrelevant symbols whitelisted") + { + std::vector whitelists; + whitelists.push_back( + test_data_dir + + "basic/one_function_one_variable_irrelevant.whitelist"); + + corpus_sptr corpus_ptr; + const dwarf_reader::status status = + read_corpus(binary, corpus_ptr, whitelists); + REQUIRE(!corpus_ptr); + REQUIRE((status & dwarf_reader::STATUS_NO_SYMBOLS_FOUND)); + } + + GIVEN("we read the binary with only the function whitelisted") + { + std::vector whitelists; + whitelists.push_back( + test_data_dir + "basic/one_function_one_variable_function.whitelist"); + const corpus_sptr& corpus = + assert_symbol_count(binary, 1, 0, 0, 0, whitelists); + 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("we read the binary with only the variable whitelisted") + { + std::vector whitelists; + whitelists.push_back( + test_data_dir + "basic/one_function_one_variable_variable.whitelist"); + const corpus_sptr& corpus = + assert_symbol_count(binary, 0, 1, 0, 0, whitelists); + 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")); + } + } +} + 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]);