dd1308ba58f071619589f4a1e9c9dac5cca01fa0
[openbsd] /
1 """
2 Test the IR interpreter
3 """
4
5
6 import unittest2
7
8 import lldb
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
12
13
14 class IRInterpreterTestCase(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17     NO_DEBUG_INFO_TESTCASE = True
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(
29             lambda: self.runCmd("settings clear auto-confirm"))
30
31     def build_and_run(self):
32         """Test the IR interpreter"""
33         self.build()
34
35         self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
36
37         lldbutil.run_break_set_by_file_and_line(
38             self, "main.c", self.line, num_expected_locations=1, loc_exact=False)
39
40         self.runCmd("run", RUN_SUCCEEDED)
41
42     @add_test_categories(['pyapi'])
43     # getpid() is POSIX, among other problems, see bug
44     @expectedFailureAll(
45         oslist=['windows'],
46         bugnumber="http://llvm.org/pr21765")
47     @expectedFailureNetBSD
48     @expectedFailureAll(
49         oslist=['linux'],
50         archs=['arm'],
51         bugnumber="llvm.org/pr27868")
52     def test_ir_interpreter(self):
53         self.build_and_run()
54
55         options = lldb.SBExpressionOptions()
56         options.SetLanguage(lldb.eLanguageTypeC_plus_plus)
57
58         set_up_expressions = ["int $i = 9", "int $j = 3", "int $k = 5"]
59
60         expressions = ["$i + $j",
61                        "$i - $j",
62                        "$i * $j",
63                        "$i / $j",
64                        "$i % $k",
65                        "$i << $j",
66                        "$i & $j",
67                        "$i | $j",
68                        "$i ^ $j"]
69
70         for expression in set_up_expressions:
71             self.frame().EvaluateExpression(expression, options)
72
73         for expression in expressions:
74             interp_expression = expression
75             jit_expression = "(int)getpid(); " + expression
76
77             interp_result = self.frame().EvaluateExpression(
78                 interp_expression, options).GetValueAsSigned()
79             jit_result = self.frame().EvaluateExpression(
80                 jit_expression, options).GetValueAsSigned()
81
82             self.assertEqual(
83                 interp_result,
84                 jit_result,
85                 "While evaluating " +
86                 expression)
87
88     def test_type_conversions(self):
89         target = self.dbg.GetDummyTarget()
90         short_val = target.EvaluateExpression("(short)-1")
91         self.assertEqual(short_val.GetValueAsSigned(), -1)
92         long_val = target.EvaluateExpression("(long) "+ short_val.GetName())
93         self.assertEqual(long_val.GetValueAsSigned(), -1)