From patchwork Tue Oct 11 12:19:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Burton X-Patchwork-Id: 77476 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp322018qge; Tue, 11 Oct 2016 05:20:00 -0700 (PDT) X-Received: by 10.66.83.1 with SMTP id m1mr6392514pay.65.1476188400535; Tue, 11 Oct 2016 05:20:00 -0700 (PDT) Return-Path: Received: from mail.openembedded.org (mail.openembedded.org. [140.211.169.62]) by mx.google.com with ESMTP id hh6si3206942pac.293.2016.10.11.05.20.00; Tue, 11 Oct 2016 05:20:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) client-ip=140.211.169.62; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel-com.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) smtp.mailfrom=openembedded-core-bounces@lists.openembedded.org Received: from review.yoctoproject.org (localhost [127.0.0.1]) by mail.openembedded.org (Postfix) with ESMTP id 5CB6B71A3B; Tue, 11 Oct 2016 12:19:57 +0000 (UTC) X-Original-To: openembedded-core@lists.openembedded.org Delivered-To: openembedded-core@lists.openembedded.org Received: from mail-lf0-f44.google.com (mail-lf0-f44.google.com [209.85.215.44]) by mail.openembedded.org (Postfix) with ESMTP id 45F0265C5B for ; Tue, 11 Oct 2016 12:19:49 +0000 (UTC) Received: by mail-lf0-f44.google.com with SMTP id x79so39754369lff.0 for ; Tue, 11 Oct 2016 05:19:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id; bh=l2SMZiWlU8h0k9C9GB+qzUht7kKZVHGRtMeB9wixrmM=; b=qpD2YOUCdXFxshn3k9klBupiZoVmGeJ1g59RYWuaWD3jI7HMpIlpH1lt8au9iCfZvO HmrUoWxFvHRth+bu3zX2LmGe/HihsTt1FRyxBvRdBZFupBxNlk3Hmmi24FTMo0+vacuY vG87TuiSQCMxi5mMOiHVYiiLcVaWkjwTocq9NOwKXAcDNR4y1Afqu8f/xB8uABsuslY+ oBZ1poOYZto3KK0nk6UTFEaau4VPifr/LYWzgyAwbhWh4Mg0FOfwKjKcFOPZ/SWR4dRA Jyv/n9R/AsMQFJfEKVQo0fLkJ700vUvyP1r4oCByvNZKqIdcYJMg7KR2+FpztyKu5sdF 0kcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=l2SMZiWlU8h0k9C9GB+qzUht7kKZVHGRtMeB9wixrmM=; b=giIviA0Rb0nv1V4KAcucyHFqY4uKdsa17biY+b1Cn6brOpGG9axkrt5o84vWyEM07q WcPLtNbTgBiPxK/NcyG5DBeJ83OgCJWU9VByY+DTs3gb/ICIKaE7TPGPFIASMm+PJoGQ aofaI+F8O+Tpp2DX094CW2H45d9GZN1o8jwNfomEkfzQ7UwB2Cz241O+XZvwzABQJkk3 hwrvaXF4No/1E6Sjb8zEP/ncY/qQaAv1IAbG6VY0vOAGEYrAGBxtWoY915+y+C+azkxA udHXYIrPhouLiuRUIdXOa/gyutMWykwZ5f+6yjbVHEkMwqYvxBWshgudbY89axTamo6x w7rg== X-Gm-Message-State: AA6/9RnasTlKyDXeczDgSe3EEJs1S3cQlrik6KtxHVukSnqkA8UbMYP0NXli9v4X/hCA5iHC X-Received: by 10.194.129.137 with SMTP id nw9mr4625421wjb.13.1476188389585; Tue, 11 Oct 2016 05:19:49 -0700 (PDT) Received: from flashheart.burtonini.com (home.burtonini.com. [81.2.106.35]) by smtp.gmail.com with ESMTPSA id yo1sm6005196wjc.16.2016.10.11.05.19.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Oct 2016 05:19:48 -0700 (PDT) From: Ross Burton To: openembedded-core@lists.openembedded.org Date: Tue, 11 Oct 2016 13:19:43 +0100 Message-Id: <1476188384-16064-1-git-send-email-ross.burton@intel.com> X-Mailer: git-send-email 2.8.1 Subject: [OE-core] [PATCH 1/2] lib/oe/qa: add ELF machine to string function X-BeenThere: openembedded-core@lists.openembedded.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Patches and discussions about the oe-core layer List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: openembedded-core-bounces@lists.openembedded.org Errors-To: openembedded-core-bounces@lists.openembedded.org Add a function (and test suite) to turn the ELF machine field (e_machine) into a string, so we can tell the user "x86-64" instead of 0x3E. Signed-off-by: Ross Burton --- meta/lib/oe/qa.py | 20 ++++++++++++++++++++ meta/lib/oe/tests/test_elf.py | 21 +++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 meta/lib/oe/tests/test_elf.py -- 2.8.1 -- _______________________________________________ Openembedded-core mailing list Openembedded-core@lists.openembedded.org http://lists.openembedded.org/mailman/listinfo/openembedded-core diff --git a/meta/lib/oe/qa.py b/meta/lib/oe/qa.py index 75e7df8..fbe719d 100644 --- a/meta/lib/oe/qa.py +++ b/meta/lib/oe/qa.py @@ -144,6 +144,26 @@ class ELFFile: bb.note("%s %s %s failed: %s" % (objdump, cmd, self.name, e)) return "" +def elf_machine_to_string(machine): + """ + Return the name of a given ELF e_machine field or the hex value as a string + if it isn't recognised. + """ + try: + return { + 0x02: "SPARC", + 0x03: "x86", + 0x08: "MIPS", + 0x14: "PowerPC", + 0x28: "ARM", + 0x2A: "SuperH", + 0x32: "IA-64", + 0x3E: "x86-64", + 0xB7: "AArch64" + }[machine] + except: + return "Unknown (%s)" % repr(machine) + if __name__ == "__main__": import sys elf = ELFFile(sys.argv[1]) diff --git a/meta/lib/oe/tests/test_elf.py b/meta/lib/oe/tests/test_elf.py new file mode 100644 index 0000000..1f59037 --- /dev/null +++ b/meta/lib/oe/tests/test_elf.py @@ -0,0 +1,21 @@ +import unittest +import oe.qa + +class TestElf(unittest.TestCase): + def test_machine_name(self): + """ + Test elf_machine_to_string() + """ + self.assertEqual(oe.qa.elf_machine_to_string(0x02), "SPARC") + self.assertEqual(oe.qa.elf_machine_to_string(0x03), "x86") + self.assertEqual(oe.qa.elf_machine_to_string(0x08), "MIPS") + self.assertEqual(oe.qa.elf_machine_to_string(0x14), "PowerPC") + self.assertEqual(oe.qa.elf_machine_to_string(0x28), "ARM") + self.assertEqual(oe.qa.elf_machine_to_string(0x2A), "SuperH") + self.assertEqual(oe.qa.elf_machine_to_string(0x32), "IA-64") + self.assertEqual(oe.qa.elf_machine_to_string(0x3E), "x86-64") + self.assertEqual(oe.qa.elf_machine_to_string(0xB7), "AArch64") + + self.assertEqual(oe.qa.elf_machine_to_string(0x00), "Unknown (0)") + self.assertEqual(oe.qa.elf_machine_to_string(0xDEADBEEF), "Unknown (3735928559)") + self.assertEqual(oe.qa.elf_machine_to_string("foobar"), "Unknown ('foobar')")