diff options
| author | Joshua Lock <josh@linux.intel.com> | 2010-04-30 16:35:50 +0100 |
|---|---|---|
| committer | Joshua Lock <josh@linux.intel.com> | 2010-05-06 12:48:05 +0100 |
| commit | ac023d775b651c9b1e28a7a725e72949fe54ad47 (patch) | |
| tree | da69e91c7d2ce4785ddf6af6b756758d1789d5a2 /meta/lib/oe/qa.py | |
| parent | 14196cb03190d9dac93be309763e3076385eb831 (diff) | |
| download | poky-ac023d775b651c9b1e28a7a725e72949fe54ad47.tar.gz | |
lib/oe: Import oe lib from OE.dev
This library moves the common Python methods into modules of an 'oe' Python
package.
Signed-off-by: Joshua Lock <josh@linux.intel.com>
Diffstat (limited to 'meta/lib/oe/qa.py')
| -rw-r--r-- | meta/lib/oe/qa.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/meta/lib/oe/qa.py b/meta/lib/oe/qa.py new file mode 100644 index 0000000000..01813931bb --- /dev/null +++ b/meta/lib/oe/qa.py | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | class ELFFile: | ||
| 2 | EI_NIDENT = 16 | ||
| 3 | |||
| 4 | EI_CLASS = 4 | ||
| 5 | EI_DATA = 5 | ||
| 6 | EI_VERSION = 6 | ||
| 7 | EI_OSABI = 7 | ||
| 8 | EI_ABIVERSION = 8 | ||
| 9 | |||
| 10 | # possible values for EI_CLASS | ||
| 11 | ELFCLASSNONE = 0 | ||
| 12 | ELFCLASS32 = 1 | ||
| 13 | ELFCLASS64 = 2 | ||
| 14 | |||
| 15 | # possible value for EI_VERSION | ||
| 16 | EV_CURRENT = 1 | ||
| 17 | |||
| 18 | # possible values for EI_DATA | ||
| 19 | ELFDATANONE = 0 | ||
| 20 | ELFDATA2LSB = 1 | ||
| 21 | ELFDATA2MSB = 2 | ||
| 22 | |||
| 23 | def my_assert(self, expectation, result): | ||
| 24 | if not expectation == result: | ||
| 25 | #print "'%x','%x' %s" % (ord(expectation), ord(result), self.name) | ||
| 26 | raise Exception("This does not work as expected") | ||
| 27 | |||
| 28 | def __init__(self, name, bits32): | ||
| 29 | self.name = name | ||
| 30 | self.bits32 = bits32 | ||
| 31 | |||
| 32 | def open(self): | ||
| 33 | self.file = file(self.name, "r") | ||
| 34 | self.data = self.file.read(ELFFile.EI_NIDENT+4) | ||
| 35 | |||
| 36 | self.my_assert(len(self.data), ELFFile.EI_NIDENT+4) | ||
| 37 | self.my_assert(self.data[0], chr(0x7f) ) | ||
| 38 | self.my_assert(self.data[1], 'E') | ||
| 39 | self.my_assert(self.data[2], 'L') | ||
| 40 | self.my_assert(self.data[3], 'F') | ||
| 41 | if self.bits32 : | ||
| 42 | self.my_assert(self.data[ELFFile.EI_CLASS], chr(ELFFile.ELFCLASS32)) | ||
| 43 | else: | ||
| 44 | self.my_assert(self.data[ELFFile.EI_CLASS], chr(ELFFile.ELFCLASS64)) | ||
| 45 | self.my_assert(self.data[ELFFile.EI_VERSION], chr(ELFFile.EV_CURRENT) ) | ||
| 46 | |||
| 47 | self.sex = self.data[ELFFile.EI_DATA] | ||
| 48 | if self.sex == chr(ELFFile.ELFDATANONE): | ||
| 49 | raise Exception("self.sex == ELFDATANONE") | ||
| 50 | elif self.sex == chr(ELFFile.ELFDATA2LSB): | ||
| 51 | self.sex = "<" | ||
| 52 | elif self.sex == chr(ELFFile.ELFDATA2MSB): | ||
| 53 | self.sex = ">" | ||
| 54 | else: | ||
| 55 | raise Exception("Unknown self.sex") | ||
| 56 | |||
| 57 | def osAbi(self): | ||
| 58 | return ord(self.data[ELFFile.EI_OSABI]) | ||
| 59 | |||
| 60 | def abiVersion(self): | ||
| 61 | return ord(self.data[ELFFile.EI_ABIVERSION]) | ||
| 62 | |||
| 63 | def isLittleEndian(self): | ||
| 64 | return self.sex == "<" | ||
| 65 | |||
| 66 | def isBigEngian(self): | ||
| 67 | return self.sex == ">" | ||
| 68 | |||
| 69 | def machine(self): | ||
| 70 | """ | ||
| 71 | We know the sex stored in self.sex and we | ||
| 72 | know the position | ||
| 73 | """ | ||
| 74 | import struct | ||
| 75 | (a,) = struct.unpack(self.sex+"H", self.data[18:20]) | ||
| 76 | return a | ||
