aboutsummaryrefslogtreecommitdiff
path: root/test/lang/cpp/unique-types/TestUniqueTypes.py
blob: 3579f7a939497d26fde8756455f8d7b70071b694 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
Test that template instaniations of std::vector<long> and <short> in the same module have the correct types.
"""

import unittest2
import lldb
import lldbutil
from lldbtest import *

class UniqueTypesTestCase(TestBase):

    mydir = os.path.join("lang", "cpp", "unique-types")

    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
    @dsym_test
    def test_with_dsym(self):
        """Test for unique types of std::vector<long> and std::vector<short>."""
        self.buildDsym()
        self.unique_types()

    @dwarf_test
    def test_with_dwarf(self):
        """Test for unique types of std::vector<long> and std::vector<short>."""
        self.buildDwarf()
        self.unique_types()

    def setUp(self):
        # Call super's setUp().
        TestBase.setUp(self)
        # Find the line number inside main.cpp.
        self.line = line_number("main.cpp",
          "// Set breakpoint here to verify that std::vector 'longs' and 'shorts' have unique types.")

    def unique_types(self):
        """Test for unique types of std::vector<long> and std::vector<short>."""

        compiler = self.getCompiler()
        compiler_basename = os.path.basename(compiler)
        if "clang" in compiler_basename and int(self.getCompilerVersion().split('.')[0]) < 3:
            self.skipTest("rdar://problem/9173060 lldb hangs while running unique-types for clang version < 3")

        exe = os.path.join(os.getcwd(), "a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
        lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True)

        self.runCmd("run", RUN_SUCCEEDED)

        # The stop reason of the thread should be breakpoint.
        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
            substrs = ['stopped',
                       'stop reason = breakpoint'])

        # Do a "frame variable --show-types longs" and verify "long" is in each line of output.
        self.runCmd("frame variable --show-types longs")
        output = self.res.GetOutput()
        for x in [line.strip() for line in output.split(os.linesep)]:
            # Skip empty line, closing brace, and messages about more variables than can be displayed.
            if not x or x == '}' or x == '...' or "Some of your variables have more members than the debugger will show by default" in x:
                continue
            self.expect(x, "Expect type 'long'", exe=False,
                substrs = ['long'])

        # Do a "frame variable --show-types shorts" and verify "short" is in each line of output.
        self.runCmd("frame variable --show-types shorts")
        output = self.res.GetOutput()
        for x in [line.strip() for line in output.split(os.linesep)]:
            # Skip empty line, closing brace, and messages about more variables than can be displayed.
            if not x or x == '}' or x == '...' or "Some of your variables have more members than the debugger will show by default" in x:
                continue
            self.expect(x, "Expect type 'short'", exe=False,
                substrs = ['short'])
        

if __name__ == '__main__':
    import atexit
    lldb.SBDebugger.Initialize()
    atexit.register(lambda: lldb.SBDebugger.Terminate())
    unittest2.main()