48 lines · python
1import lldb2from lldbsuite.test.decorators import *3from lldbsuite.test.lldbtest import *4from lldbsuite.test import lldbutil5 6 7class StaticInitializers(TestBase):8 @expectedFailureAll(9 archs="aarch64",10 oslist=["freebsd"],11 bugnumber="llvm.org/pr44053",12 )13 def test(self):14 """Test a static initializer."""15 self.build()16 17 lldbutil.run_to_source_breakpoint(18 self, "// break here", lldb.SBFileSpec("main.cpp", False)19 )20 21 # We use counter to observe if the initializer was called.22 self.expect_expr("counter", result_type="int", result_value="0")23 self.expect("expr -p -- struct Foo { Foo() { inc_counter(); } }; Foo f;")24 self.expect_expr("counter", result_type="int", result_value="1")25 26 def test_failing_init(self):27 """Test a static initializer that fails to execute."""28 self.build()29 30 lldbutil.run_to_source_breakpoint(31 self, "// break here", lldb.SBFileSpec("main.cpp", False)32 )33 34 # FIXME: This error message is not even remotely helpful.35 self.expect(36 "expr -p -- struct Foo2 { Foo2() { do_abort(); } }; Foo2 f;",37 error=True,38 substrs=["couldn't run static initializer:"],39 )40 41 def test_without_process(self):42 """Test a static initializer without a running process."""43 self.expect(44 "expr -p -- int i = 0; struct Foo3 { Foo3() { ++i; } }; Foo3 f;",45 error=True,46 substrs=["Top-level code needs to be inserted into a runnable target"],47 )48