From patchwork Fri Jul 6 02:48:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emil Velikov via arch-projects X-Patchwork-Id: 677 Return-Path: Delivered-To: patchwork@archlinux.org Received: from apollo.archlinux.org (localhost [127.0.0.1]) by apollo.archlinux.org (Postfix) with ESMTP id B4CB2548D5E1 for ; Fri, 6 Jul 2018 02:49:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on apollo X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED=0.1, DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3,T_DKIMWL_WL_HIGH=-0.01 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-BL-Results: [127.0.9.2] Received: from orion.archlinux.org (orion.archlinux.org [IPv6:2a01:4f8:160:6087::1]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Fri, 6 Jul 2018 02:49:37 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id C1615BB225ABB; Fri, 6 Jul 2018 02:49:28 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [5.9.250.164]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by orion.archlinux.org (Postfix) with ESMTPS; Fri, 6 Jul 2018 02:49:28 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 9454F2C3B6; Fri, 6 Jul 2018 02:49:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=luna2; t=1530845368; bh=B0TaBbbMf4hknf0J13ajFLXtte0UlVLcoLBUrp2aJYk=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc; b=phJ+COxIT/WAtDacyMXH1I/7FfASTbIjKwaJCG1+NsNGW0yUs2C14QKzwopTYolVU HBOoBJz0LR2AjuqM6nKaVeQGRpubJtJMx62blE+WS6EZx9WJ7HwL4elgbItPDH0ae9 RUtRpfso2RBKgaNljviNqljpdsi4C/3IROqLRcE6jKmbO2JP3NhiUJMhqM5dCeErAk mgvXIdpo3E41fmjfAgNiVCi6AXquNBkXg37WSduxcfvLXL2TknaqdmHT4bbmYI7aIt 5Wga6a8V2+3wtueqKppagGVJIyIGgfbndV3miabc8wz681FlzwowyiaUpF9471T+N8 8y8THJkbfdDvVW7nZMjGOYqxgYaaq/swERqJ/TlZhnD3krM+C9LspwKpkI1TJQA03n 8dIumrKBRFBkQKs02h1P2fDlbt2UNH/IWd92aNVmhJ+euRF6TzV27SV1OuK6pyzS7F x6SyaeQYcEBrb7zfgdKGpCwZjiVVqofaclizJ0T1xZL5fmYZ/clXrftSZRI0A7l/3o 69G20KjnaM6qAtTG8SK13E8ABqzg9OoPRXP8mfkhtoZo3pQ3gvkmQO8USGGKkfQxy/ aCLqT4z2DoBefbooAcdsQ/A0RxcoyB9ACOTaIGXUykVNcQgFzzr0xHHYpb4xVSmhjy aW+LhZSMHW3ax3y4kiAQRVWY= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id C9BEA2C15F for ; Fri, 6 Jul 2018 02:49:25 +0000 (UTC) Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by luna.archlinux.org (Postfix) with ESMTPS for ; Fri, 6 Jul 2018 02:49:25 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 5E5ECBB225AA6; Fri, 6 Jul 2018 02:49:14 +0000 (UTC) Received: from didactylos.attlocal.net (unknown [IPv6:2600:1700:57f0:ca20:763a:c795:fcf6:91ea]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) (Authenticated sender: eschwartz) by orion.archlinux.org (Postfix) with ESMTPSA id CCE77BB225AA5; Fri, 6 Jul 2018 02:49:13 +0000 (UTC) To: arch-projects@archlinux.org Date: Thu, 5 Jul 2018 22:48:48 -0400 Message-Id: <20180706024848.25612-1-eschwartz@archlinux.org> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Subject: [arch-projects] [namcap] [PATCH] Fix testsuite to not hardcode the libalpm version. X-BeenThere: arch-projects@archlinux.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Arch Linux projects development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Eli Schwartz via arch-projects Reply-To: Arch Linux projects development discussion Cc: Eli Schwartz Errors-To: arch-projects-bounces@archlinux.org Sender: "arch-projects" Namcap already depends on pyelftools, which contains an elegant way to retrieve the soname information directly from libalpm.so (demonstrated in readelf.py). Using hardcoded strings means the testsuite periodically breaks (every time the external pacman project bumps their soname), for no good reason and at least a few bad ones. Signed-off-by: Eli Schwartz --- Namcap/tests/package/test_sodepends.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Namcap/tests/package/test_sodepends.py b/Namcap/tests/package/test_sodepends.py index 3a3d7b6..f94b3e9 100644 --- a/Namcap/tests/package/test_sodepends.py +++ b/Namcap/tests/package/test_sodepends.py @@ -2,7 +2,7 @@ # # namcap tests - sodepends # Copyright (C) 2011 Rémy Oudompheng -# +# # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or @@ -17,11 +17,23 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA -# +# import os from Namcap.tests.makepkg import MakepkgTest import Namcap.rules.sodepends +from elftools.elf.dynamic import DynamicSection +from elftools.elf.elffile import ELFFile + +def get_soname(filename): + with open(filename, 'rb') as f: + alpm = ELFFile(f) + for section in alpm.iter_sections(): + if not isinstance(section, DynamicSection): + continue + for tag in section.iter_tags(): + if tag.entry.d_tag == 'DT_SONAME': + return tag.soname class SoDependsTest(MakepkgTest): pkgbuild = """ @@ -47,6 +59,7 @@ package() { def test_sodepends(self): "Package with missing pacman dependency" pkgfile = "__namcap_test_sodepends-1.0-1-%(arch)s.pkg.tar" % { "arch": self.arch } + alpm_filename = os.path.join('usr/lib', get_soname('/usr/lib/libalpm.so')) with open(os.path.join(self.tmpdir, "PKGBUILD"), "w") as f: f.write(self.pkgbuild) self.run_makepkg() @@ -56,15 +69,15 @@ package() { ) self.assertEqual(pkg.detected_deps['pacman'], [ ('libraries-needed %s %s', - (str(['usr/lib/libalpm.so.10']), str(["usr/bin/main"])) + (str([alpm_filename]), str(["usr/bin/main"])) )] ) e, w, i = Namcap.depends.analyze_depends(pkg) self.assertEqual(e, [ ('dependency-detected-not-included %s (%s)', - ('pacman', "libraries ['usr/lib/libalpm.so.10'] needed in files ['usr/bin/main']")) + ('pacman', "libraries ['%s'] needed in files ['usr/bin/main']" % alpm_filename)) + ]) self.assertEqual(w, []) # vim: set ts=4 sw=4 noet: -