1 """Tests IR interpreter handling of basic floating point operations (fadd, fsub, etc)."""
4 from lldbsuite
.test
.decorators
import *
5 from lldbsuite
.test
.lldbtest
import *
6 from lldbsuite
.test
import lldbutil
9 class FPEvalTestCase(TestBase
):
11 # Call super's setUp().
13 self
.jit_opts
= lldb
.SBExpressionOptions()
14 self
.jit_opts
.SetAllowJIT(True)
15 self
.no_jit_opts
= lldb
.SBExpressionOptions()
16 self
.no_jit_opts
.SetAllowJIT(False)
17 # Find the line number to break inside main().
18 self
.line
= line_number("main.c", "// Set break point at this line.")
21 """Test floating point expressions while jitter is disabled."""
23 exe
= self
.getBuildArtifact("a.out")
24 self
.runCmd("file " + exe
, CURRENT_EXECUTABLE_SET
)
26 # Break inside the main.
27 lldbutil
.run_break_set_by_file_and_line(
28 self
, "main.c", self
.line
, num_expected_locations
=1, loc_exact
=True
31 value
= self
.frame().EvaluateExpression("a + b", self
.no_jit_opts
)
33 self
.runCmd("run", RUN_SUCCEEDED
)
36 "expr --allow-jit false -- a + b",
37 VARIABLES_DISPLAYED_CORRECTLY
,
38 substrs
=["double", "44"],
41 "expr --allow-jit false -- a - b",
42 VARIABLES_DISPLAYED_CORRECTLY
,
43 substrs
=["double", "40"],
46 "expr --allow-jit false -- a / b",
47 VARIABLES_DISPLAYED_CORRECTLY
,
48 substrs
=["double", "21"],
51 "expr --allow-jit false -- a * b",
52 VARIABLES_DISPLAYED_CORRECTLY
,
53 substrs
=["double", "84"],
56 "expr --allow-jit false -- a + 2",
57 VARIABLES_DISPLAYED_CORRECTLY
,
58 substrs
=["double", "44"],
61 "expr --allow-jit false -- a > b",
62 VARIABLES_DISPLAYED_CORRECTLY
,
66 "expr --allow-jit false -- a >= b",
67 VARIABLES_DISPLAYED_CORRECTLY
,
71 "expr --allow-jit false -- a < b",
72 VARIABLES_DISPLAYED_CORRECTLY
,
76 "expr --allow-jit false -- a <= b",
77 VARIABLES_DISPLAYED_CORRECTLY
,
81 "expr --allow-jit false -- a == b",
82 VARIABLES_DISPLAYED_CORRECTLY
,
86 "expr --allow-jit false -- a != b",
87 VARIABLES_DISPLAYED_CORRECTLY
,
93 "expr --allow-jit false -- f + q",
94 VARIABLES_DISPLAYED_CORRECTLY
,
95 substrs
=["float", "44"],
98 "expr --allow-jit false -- f - q",
99 VARIABLES_DISPLAYED_CORRECTLY
,
100 substrs
=["float", "40"],
103 "expr --allow-jit false -- f / q",
104 VARIABLES_DISPLAYED_CORRECTLY
,
105 substrs
=["float", "21"],
108 "expr --allow-jit false -- f * q",
109 VARIABLES_DISPLAYED_CORRECTLY
,
110 substrs
=["float", "84"],
113 "expr --allow-jit false -- f + 2",
114 VARIABLES_DISPLAYED_CORRECTLY
,
115 substrs
=["float", "44"],
118 "expr --allow-jit false -- f > q",
119 VARIABLES_DISPLAYED_CORRECTLY
,
123 "expr --allow-jit false -- f >= q",
124 VARIABLES_DISPLAYED_CORRECTLY
,
128 "expr --allow-jit false -- f < q",
129 VARIABLES_DISPLAYED_CORRECTLY
,
133 "expr --allow-jit false -- f <= q",
134 VARIABLES_DISPLAYED_CORRECTLY
,
138 "expr --allow-jit false -- f == q",
139 VARIABLES_DISPLAYED_CORRECTLY
,
143 "expr --allow-jit false -- f != q",
144 VARIABLES_DISPLAYED_CORRECTLY
,
148 # compare jit and interpreter output
149 self
.assertTrue(self
.process().IsValid())
150 thread
= lldbutil
.get_stopped_thread(self
.process(), lldb
.eStopReasonBreakpoint
)
151 self
.assertTrue(thread
.IsValid())
152 frame
= thread
.GetSelectedFrame()
153 self
.assertTrue(frame
.IsValid())
155 dividents
= [42, 79, 666]
156 divisors
= [1.618, 2.718281828, 3.1415926535, 6.62607015]
160 vardef
= "double x = {0}, y = {1};".format(x
, y
)
161 v1
= frame
.EvaluateExpression(
162 "{0}; eval(x, y, 2)".format(vardef
), self
.jit_opts
164 v2
= frame
.EvaluateExpression(
165 "{0}; x / y".format(vardef
), self
.no_jit_opts
167 self
.assertTrue(v1
.IsValid() and v2
.IsValid())
168 self
.assertEqual(str(v1
.GetData()), str(v2
.GetData()))