Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / native_client_sdk / src / tools / lib / tests / elf_test.py
blob8c57e8d9c9003ccefb8930c9e3460b0f98005f82
1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 import os
7 import sys
8 import unittest
10 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
11 PARENT_DIR = os.path.dirname(SCRIPT_DIR)
12 DATA_DIR = os.path.join(SCRIPT_DIR, 'data')
14 sys.path.append(PARENT_DIR)
16 import elf
19 class TestIsDynamicElf(unittest.TestCase):
20 def test_arm(self):
21 static_nexe = os.path.join(DATA_DIR, 'test_static_arm.nexe')
22 self.assertFalse(elf.IsDynamicElf(static_nexe, False))
24 def test_x86_32(self):
25 dyn_nexe = os.path.join(DATA_DIR, 'test_dynamic_x86_32.nexe')
26 static_nexe = os.path.join(DATA_DIR, 'test_static_x86_32.nexe')
27 self.assertTrue(elf.IsDynamicElf(dyn_nexe, False))
28 self.assertFalse(elf.IsDynamicElf(static_nexe, False))
30 def test_x86_64(self):
31 dyn_nexe = os.path.join(DATA_DIR, 'test_dynamic_x86_64.nexe')
32 static_nexe = os.path.join(DATA_DIR, 'test_static_x86_64.nexe')
33 self.assertTrue(elf.IsDynamicElf(dyn_nexe, True))
34 self.assertFalse(elf.IsDynamicElf(static_nexe, True))
37 class TestParseElfHeader(unittest.TestCase):
38 def test_invalid_elf(self):
39 self.assertRaises(elf.Error, elf.ParseElfHeader, __file__)
41 def test_arm_elf_parse(self):
42 """Test parsing of ARM elf header."""
43 static_nexe = os.path.join(DATA_DIR, 'test_static_arm.nexe')
44 arch, dynamic = elf.ParseElfHeader(static_nexe)
45 self.assertEqual(arch, 'arm')
46 self.assertFalse(dynamic)
48 def test_x86_32_elf_parse(self):
49 """Test parsing of x86-32 elf header."""
50 dyn_nexe = os.path.join(DATA_DIR, 'test_dynamic_x86_32.nexe')
51 static_nexe = os.path.join(DATA_DIR, 'test_static_x86_32.nexe')
53 arch, dynamic = elf.ParseElfHeader(dyn_nexe)
54 self.assertEqual(arch, 'x86-32')
55 self.assertTrue(dynamic)
57 arch, dynamic = elf.ParseElfHeader(static_nexe)
58 self.assertEqual(arch, 'x86-32')
59 self.assertFalse(dynamic)
61 def test_x86_64_elf_parse(self):
62 """Test parsing of x86-64 elf header."""
63 dyn_nexe = os.path.join(DATA_DIR, 'test_dynamic_x86_64.nexe')
64 static_nexe = os.path.join(DATA_DIR, 'test_static_x86_64.nexe')
66 arch, dynamic = elf.ParseElfHeader(dyn_nexe)
67 self.assertEqual(arch, 'x86-64')
68 self.assertTrue(dynamic)
70 arch, dynamic = elf.ParseElfHeader(static_nexe)
71 self.assertEqual(arch, 'x86-64')
72 self.assertFalse(dynamic)
75 if __name__ == '__main__':
76 unittest.main()