diff options
| author | Ross Burton <ross.burton@intel.com> | 2016-10-11 13:19:43 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-10-11 22:19:21 +0100 |
| commit | 84198174bfacbca59aa9a22780f12d7718019b89 (patch) | |
| tree | dc7e22950a8c7ba783b0157733f03186adfff5ff /meta | |
| parent | 1de0cc9ed97b425b55ad1d9e1ee01c90dc926d49 (diff) | |
| download | poky-84198174bfacbca59aa9a22780f12d7718019b89.tar.gz | |
lib/oe/qa: add ELF machine to string function
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.
(From OE-Core rev: 72336003741fb16a7ecdd6b753eae56310413ff7)
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
| -rw-r--r-- | meta/lib/oe/qa.py | 20 | ||||
| -rw-r--r-- | meta/lib/oe/tests/test_elf.py | 21 |
2 files changed, 41 insertions, 0 deletions
diff --git a/meta/lib/oe/qa.py b/meta/lib/oe/qa.py index 75e7df8546..fbe719d8ec 100644 --- a/meta/lib/oe/qa.py +++ b/meta/lib/oe/qa.py | |||
| @@ -144,6 +144,26 @@ class ELFFile: | |||
| 144 | bb.note("%s %s %s failed: %s" % (objdump, cmd, self.name, e)) | 144 | bb.note("%s %s %s failed: %s" % (objdump, cmd, self.name, e)) |
| 145 | return "" | 145 | return "" |
| 146 | 146 | ||
| 147 | def elf_machine_to_string(machine): | ||
| 148 | """ | ||
| 149 | Return the name of a given ELF e_machine field or the hex value as a string | ||
| 150 | if it isn't recognised. | ||
| 151 | """ | ||
| 152 | try: | ||
| 153 | return { | ||
| 154 | 0x02: "SPARC", | ||
| 155 | 0x03: "x86", | ||
| 156 | 0x08: "MIPS", | ||
| 157 | 0x14: "PowerPC", | ||
| 158 | 0x28: "ARM", | ||
| 159 | 0x2A: "SuperH", | ||
| 160 | 0x32: "IA-64", | ||
| 161 | 0x3E: "x86-64", | ||
| 162 | 0xB7: "AArch64" | ||
| 163 | }[machine] | ||
| 164 | except: | ||
| 165 | return "Unknown (%s)" % repr(machine) | ||
| 166 | |||
| 147 | if __name__ == "__main__": | 167 | if __name__ == "__main__": |
| 148 | import sys | 168 | import sys |
| 149 | elf = ELFFile(sys.argv[1]) | 169 | 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 0000000000..1f59037ed9 --- /dev/null +++ b/meta/lib/oe/tests/test_elf.py | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | import unittest | ||
| 2 | import oe.qa | ||
| 3 | |||
| 4 | class TestElf(unittest.TestCase): | ||
| 5 | def test_machine_name(self): | ||
| 6 | """ | ||
| 7 | Test elf_machine_to_string() | ||
| 8 | """ | ||
| 9 | self.assertEqual(oe.qa.elf_machine_to_string(0x02), "SPARC") | ||
| 10 | self.assertEqual(oe.qa.elf_machine_to_string(0x03), "x86") | ||
| 11 | self.assertEqual(oe.qa.elf_machine_to_string(0x08), "MIPS") | ||
| 12 | self.assertEqual(oe.qa.elf_machine_to_string(0x14), "PowerPC") | ||
| 13 | self.assertEqual(oe.qa.elf_machine_to_string(0x28), "ARM") | ||
| 14 | self.assertEqual(oe.qa.elf_machine_to_string(0x2A), "SuperH") | ||
| 15 | self.assertEqual(oe.qa.elf_machine_to_string(0x32), "IA-64") | ||
| 16 | self.assertEqual(oe.qa.elf_machine_to_string(0x3E), "x86-64") | ||
| 17 | self.assertEqual(oe.qa.elf_machine_to_string(0xB7), "AArch64") | ||
| 18 | |||
| 19 | self.assertEqual(oe.qa.elf_machine_to_string(0x00), "Unknown (0)") | ||
| 20 | self.assertEqual(oe.qa.elf_machine_to_string(0xDEADBEEF), "Unknown (3735928559)") | ||
| 21 | self.assertEqual(oe.qa.elf_machine_to_string("foobar"), "Unknown ('foobar')") | ||
