1"""
2Test some ARM instruction emulation.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9
10class ARMEmulationTestCase(TestBase):
11
12    mydir = "arm_emulation"
13
14    def test_thumb_emulations (self):
15        current_dir = os.getcwd();
16        test_dir = os.path.join (current_dir, "new-test-files")
17        files = os.listdir (test_dir)
18        thumb_files = list()
19        for f in files:
20            if '-thumb.dat' in f:
21                thumb_files.append (f)
22
23        for f in thumb_files:
24            test_file = os.path.join (test_dir, f)
25            self.run_a_single_test (test_file)
26
27
28    def test_arm_emulations (self):
29        current_dir = os.getcwd();
30        test_dir = os.path.join (current_dir, "new-test-files")
31        files = os.listdir (test_dir)
32        arm_files = list()
33        for f in files:
34            if '-arm.dat' in f:
35                arm_files.append (f)
36
37        for f in arm_files:
38            test_file = os.path.join (test_dir, f)
39            self.run_a_single_test (test_file)
40
41    def run_a_single_test (self, filename):
42        insn = lldb.SBInstruction ();
43        stream = lldb.SBStream ();
44        success = insn.TestEmulation (stream, filename);
45        output = stream.GetData();
46        if self.TraceOn():
47            print '\nRunning test ' + os.path.basename(filename)
48            print output
49
50        self.assertTrue (success, 'Emulation test succeeded.')
51
52if __name__ == '__main__':
53    import atexit
54    lldb.SBDebugger.Initialize()
55    atexit.register(lambda: lldb.SBDebugger.Terminate())
56    unittest2.main()
57
58