89 lines · python
1"""Test that importing modules in C works as expected."""2 3 4import os5 6import lldb7from lldbsuite.test.decorators import *8from lldbsuite.test.lldbtest import *9from lldbsuite.test import lldbutil10 11 12class CModulesTestCase(TestBase):13 @expectedFailureAll(14 oslist=["freebsd", "linux"],15 bugnumber="http://llvm.org/pr23456 'fopen' has unknown return type",16 )17 @expectedFailureAll(18 oslist=["windows"],19 bugnumber="llvm.org/pr24489: Name lookup not working correctly on Windows",20 )21 @skipIf(macos_version=["<", "10.12"])22 @expectedFailureNetBSD23 def test_expr(self):24 self.build()25 exe = self.getBuildArtifact("a.out")26 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)27 28 # Break inside the foo function which takes a bar_ptr argument.29 lldbutil.run_break_set_by_file_and_line(30 self, "main.c", self.line, num_expected_locations=1, loc_exact=True31 )32 33 self.runCmd("run", RUN_SUCCEEDED)34 35 # The stop reason of the thread should be breakpoint.36 self.expect(37 "thread list",38 STOPPED_DUE_TO_BREAKPOINT,39 substrs=["stopped", "stop reason = breakpoint"],40 )41 42 # The breakpoint should have a hit count of 1.43 lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)44 45 # Enable logging of the imported AST.46 log_file = self.getBuildArtifact("lldb-ast-log.txt")47 self.runCmd("log enable lldb ast -f '%s'" % log_file)48 49 self.expect(50 "expr -l objc++ -- @import Darwin; 3",51 VARIABLES_DISPLAYED_CORRECTLY,52 substrs=["int", "3"],53 )54 55 # This expr command imports __sFILE with definition56 # (FILE is a typedef to __sFILE.)57 self.expect(58 'expr *fopen("/dev/zero", "w")',59 VARIABLES_DISPLAYED_CORRECTLY,60 substrs=["FILE", "_close"],61 )62 63 # Check that the AST log contains exactly one definition of __sFILE.64 f = open(log_file)65 log_lines = f.readlines()66 f.close()67 os.remove(log_file)68 self.assertEqual(" ".join(log_lines).count("struct __sFILE definition"), 1)69 70 self.expect(71 "expr *myFile", VARIABLES_DISPLAYED_CORRECTLY, substrs=["a", "5", "b", "9"]72 )73 74 self.expect(75 "expr MIN((uint64_t)2, (uint64_t)3)",76 VARIABLES_DISPLAYED_CORRECTLY,77 substrs=["uint64_t", "2"],78 )79 80 self.expect(81 "expr stdin", VARIABLES_DISPLAYED_CORRECTLY, substrs=["(FILE *)", "0x"]82 )83 84 def setUp(self):85 # Call super's setUp().86 TestBase.setUp(self)87 # Find the line number to break inside main().88 self.line = line_number("main.c", "// Set breakpoint 0 here.")89