2 Test that --allow-jit=false does disallow JITting:
7 import lldbsuite
.test
.lldbutil
as lldbutil
8 from lldbsuite
.test
.lldbtest
import *
9 from lldbsuite
.test
.decorators
import *
12 class TestAllowJIT(TestBase
):
13 # If your test case doesn't stress debug info, then
14 # set this to true. That way it won't be run once for
15 # each debug info format.
16 NO_DEBUG_INFO_TESTCASE
= True
18 def test_allow_jit_expr_command(self
):
19 """Test the --allow-jit command line flag"""
21 self
.main_source_file
= lldb
.SBFileSpec("main.c")
24 def test_allow_jit_options(self
):
25 """Test the SetAllowJIT SBExpressionOption setting"""
27 self
.main_source_file
= lldb
.SBFileSpec("main.c")
28 self
.expr_options_test()
30 def expr_cmd_test(self
):
31 (target
, process
, thread
, bkpt
) = lldbutil
.run_to_source_breakpoint(
32 self
, "Set a breakpoint here", self
.main_source_file
35 frame
= thread
.GetFrameAtIndex(0)
37 # First make sure we can call the function with
38 interp
= self
.dbg
.GetCommandInterpreter()
39 self
.expect("expr --allow-jit 1 -- call_me(10)", substrs
=["(int) $", "= 18"])
40 # Now make sure it fails with the "can't IR interpret message" if allow-jit is false:
42 "expr --allow-jit 0 -- call_me(10)",
44 substrs
=["Can't evaluate the expression without a running target"],
47 def expr_options_test(self
):
48 (target
, process
, thread
, bkpt
) = lldbutil
.run_to_source_breakpoint(
49 self
, "Set a breakpoint here", self
.main_source_file
52 frame
= thread
.GetFrameAtIndex(0)
54 # First make sure we can call the function with the default option set.
55 options
= lldb
.SBExpressionOptions()
56 # Check that the default is to allow JIT:
57 self
.assertTrue(options
.GetAllowJIT(), "Default is true")
59 # Now use the options:
60 result
= frame
.EvaluateExpression("call_me(10)", options
)
61 self
.assertSuccess(result
.GetError())
62 self
.assertEqual(result
.GetValueAsSigned(), 18, "got the right value.")
64 # Now disallow JIT and make sure it fails:
65 options
.SetAllowJIT(False)
66 # Check that we got the right value:
67 self
.assertFalse(options
.GetAllowJIT(), "Got False after setting to False")
69 # Again use it and ensure we fail:
70 result
= frame
.EvaluateExpression("call_me(10)", options
)
71 self
.assertTrue(result
.GetError().Fail(), "expression failed with no JIT")
73 "Can't evaluate the expression without a running target",
74 result
.GetError().GetCString(),
78 # Finally set the allow JIT value back to true and make sure that works:
79 options
.SetAllowJIT(True)
80 self
.assertTrue(options
.GetAllowJIT(), "Set back to True correctly")
82 # And again, make sure this works:
83 result
= frame
.EvaluateExpression("call_me(10)", options
)
84 self
.assertSuccess(result
.GetError())
85 self
.assertEqual(result
.GetValueAsSigned(), 18, "got the right value.")
87 def test_allow_jit_with_top_level(self
):
88 """Test combined --allow-jit and --top-level flags"""
89 # Can't force interpreting for top-level expressions which are always
92 "expr --allow-jit false --top-level -- int i;",
94 substrs
=["Can't disable JIT compilation for top-level expressions."],
98 lldbutil
.run_to_source_breakpoint(
99 self
, "Set a breakpoint here", lldb
.SBFileSpec("main.c")
101 # Allowing JITing for top-level expressions is redundant but should work.
103 "expr --allow-jit true --top-level -- int top_level_f() { return 2; }"
105 # Make sure we actually declared a working top-level function.
106 self
.expect_expr("top_level_f()", result_value
="2")