]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/expression_command/ir-interpreter/TestIRInterpreter.py
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / expression_command / ir-interpreter / TestIRInterpreter.py
1 """
2 Test the IR interpreter
3 """
4
5 from __future__ import print_function
6
7 import unittest2
8
9 import os, time
10 import lldb
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
14
15 class IRInterpreterTestCase(TestBase):
16
17     mydir = TestBase.compute_mydir(__file__)
18
19     def setUp(self):
20         # Call super's setUp().
21         TestBase.setUp(self)
22         # Find the line number to break for main.c.
23         self.line = line_number('main.c',
24                                 '// Set breakpoint here')
25
26         # Disable confirmation prompt to avoid infinite wait
27         self.runCmd("settings set auto-confirm true")
28         self.addTearDownHook(lambda: self.runCmd("settings clear auto-confirm"))
29
30     def build_and_run(self):
31         """Test the IR interpreter"""
32         self.build()
33
34         self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
35
36         lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=False)
37
38         self.runCmd("run", RUN_SUCCEEDED)
39
40     @add_test_categories(['pyapi'])
41     @expectedFailureAll(oslist=['windows'], bugnumber="http://llvm.org/pr21765")  # getpid() is POSIX, among other problems, see bug
42     @expectedFailureAll(oslist=['linux'], archs=['arm'], bugnumber="llvm.org/pr27868")
43     def test_ir_interpreter(self):
44         self.build_and_run()
45
46         options = lldb.SBExpressionOptions()
47         options.SetLanguage(lldb.eLanguageTypeC_plus_plus)
48
49         set_up_expressions = ["int $i = 9", "int $j = 3", "int $k = 5"]
50
51         expressions = ["$i + $j",
52                        "$i - $j",
53                        "$i * $j",
54                        "$i / $j",
55                        "$i % $k",
56                        "$i << $j",
57                        "$i & $j",
58                        "$i | $j",
59                        "$i ^ $j"]
60
61         for expression in set_up_expressions:
62             self.frame().EvaluateExpression(expression, options)
63
64         for expression in expressions:
65             interp_expression   = expression
66             jit_expression      = "(int)getpid(); " + expression
67
68             interp_result       = self.frame().EvaluateExpression(interp_expression, options).GetValueAsSigned()
69             jit_result          = self.frame().EvaluateExpression(jit_expression, options).GetValueAsSigned()
70
71             self.assertEqual(interp_result, jit_result, "While evaluating " + expression)
72