]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/cpp/virtual/TestVirtual.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / cpp / virtual / TestVirtual.py
1 """
2 Test C++ virtual function and virtual inheritance.
3 """
4
5 from __future__ import print_function
6
7 import os, time
8 import re
9 import lldb
10 from lldbsuite.test.lldbtest import *
11 import lldbsuite.test.lldbutil as lldbutil
12
13 def Msg(expr, val):
14     return "'expression %s' matches the output (from compiled code): %s" % (expr, val)
15
16 class CppVirtualMadness(TestBase):
17
18     mydir = TestBase.compute_mydir(__file__)
19
20     # This is the pattern by design to match the "my_expr = 'value'" output from
21     # printf() stmts (see main.cpp).
22     pattern = re.compile("^([^=]*) = '([^=]*)'$")
23
24     # Assert message.
25     PRINTF_OUTPUT_GROKKED = "The printf output from compiled code is parsed correctly"
26
27     def setUp(self):
28         # Call super's setUp().
29         TestBase.setUp(self)
30         # Find the line number to break for main.cpp.
31         self.source = 'main.cpp'
32         self.line = line_number(self.source, '// Set first breakpoint here.')
33
34     @expectedFailureIcc('llvm.org/pr16808') # lldb does not call the correct virtual function with icc
35     @expectedFailureAll(oslist=['windows'])
36     def test_virtual_madness(self):
37         """Test that expression works correctly with virtual inheritance as well as virtual function."""
38         self.build()
39
40         # Bring the program to the point where we can issue a series of
41         # 'expression' command to compare against the golden output.
42         self.dbg.SetAsync(False)
43         
44         # Create a target by the debugger.
45         target = self.dbg.CreateTarget("a.out")
46         self.assertTrue(target, VALID_TARGET)
47
48         # Create the breakpoint inside function 'main'.
49         breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
50         self.assertTrue(breakpoint, VALID_BREAKPOINT)
51
52         # Now launch the process, and do not stop at entry point.
53         process = target.LaunchSimple (None, None, self.get_process_working_directory())
54         self.assertTrue(process, PROCESS_IS_VALID)
55         
56         self.assertTrue(process.GetState() == lldb.eStateStopped)
57         thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
58         self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint condition")
59
60         # First, capture the golden output from the program itself from the
61         # series of printf statements.
62         stdout = process.GetSTDOUT(1024)
63         
64         self.assertIsNotNone(stdout, "Encountered an error reading the process's output")
65
66         # This golden list contains a list of "my_expr = 'value' pairs extracted
67         # from the golden output.
68         gl = []
69
70         # Scan the golden output line by line, looking for the pattern:
71         #
72         #     my_expr = 'value'
73         #
74         for line in stdout.split(os.linesep):
75             match = self.pattern.search(line)
76             if match:
77                 my_expr, val = match.group(1), match.group(2)
78                 gl.append((my_expr, val))
79         #print("golden list:", gl)
80
81         # Now iterate through the golden list, comparing against the output from
82         # 'expression var'.
83         for my_expr, val in gl:
84
85             self.runCmd("expression %s" % my_expr)
86             output = self.res.GetOutput()
87             
88             # The expression output must match the oracle.
89             self.expect(output, Msg(my_expr, val), exe=False,
90                 substrs = [val])