[AMDGPU] Add True16 register classes.
[llvm-project.git] / lldb / test / API / commands / expression / dont_allow_jit / TestAllowJIT.py
blob307d4521427dcfc22aebdec9112f36d764c3cbd7
1 """
2 Test that --allow-jit=false does disallow JITting:
3 """
6 import lldb
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"""
20 self.build()
21 self.main_source_file = lldb.SBFileSpec("main.c")
22 self.expr_cmd_test()
24 def test_allow_jit_options(self):
25 """Test the SetAllowJIT SBExpressionOption setting"""
26 self.build()
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:
41 self.expect(
42 "expr --allow-jit 0 -- call_me(10)",
43 error=True,
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.assertEqual(options.GetAllowJIT(), True, "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.assertEqual(
68 options.GetAllowJIT(), False, "Got False after setting to False"
71 # Again use it and ensure we fail:
72 result = frame.EvaluateExpression("call_me(10)", options)
73 self.assertTrue(result.GetError().Fail(), "expression failed with no JIT")
74 self.assertIn(
75 "Can't evaluate the expression without a running target",
76 result.GetError().GetCString(),
77 "Got right error",
80 # Finally set the allow JIT value back to true and make sure that works:
81 options.SetAllowJIT(True)
82 self.assertEqual(options.GetAllowJIT(), True, "Set back to True correctly")
84 # And again, make sure this works:
85 result = frame.EvaluateExpression("call_me(10)", options)
86 self.assertSuccess(result.GetError())
87 self.assertEqual(result.GetValueAsSigned(), 18, "got the right value.")
89 def test_allow_jit_with_top_level(self):
90 """Test combined --allow-jit and --top-level flags"""
91 # Can't force interpreting for top-level expressions which are always
92 # injected.
93 self.expect(
94 "expr --allow-jit false --top-level -- int i;",
95 error=True,
96 substrs=["Can't disable JIT compilation for top-level expressions."],
99 self.build()
100 lldbutil.run_to_source_breakpoint(
101 self, "Set a breakpoint here", lldb.SBFileSpec("main.c")
103 # Allowing JITing for top-level expressions is redundant but should work.
104 self.expect(
105 "expr --allow-jit true --top-level -- int top_level_f() { return 2; }"
107 # Make sure we actually declared a working top-level function.
108 self.expect_expr("top_level_f()", result_value="2")