summaryrefslogtreecommitdiffstats
path: root/lldb/tools/intel-mpx/test/TestMPXTable.py
blob: f2468abd59a12dc285555f6ee89c9d6a2b45d8be (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
"""
Test mpx-table command.
"""

from __future__ import print_function


import os
import time
import re
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class TestMPXTable(TestBase):

    mydir = TestBase.compute_mydir(__file__)

    def setUp(self):
        TestBase.setUp(self)

    @skipIf(compiler="clang")
    @skipIf(oslist=no_match(['linux']))
    @skipIf(archs=no_match(['i386', 'x86_64']))
    @skipIf(compiler="gcc", compiler_version=["<", "5"]) #GCC version >= 5 supports Intel(R) MPX.
    def test_show_command(self):
        """Test 'mpx-table show' command"""
        self.build()

        lldb_exec_dir = os.environ["LLDB_IMPLIB_DIR"]
        lldb_lib_dir = os.path.join(lldb_exec_dir, os.pardir, "lib")
        plugin_file = os.path.join(lldb_lib_dir, "liblldb-intel-mpxtable.so")
        if not os.path.isfile(plugin_file):
            self.skipTest("Intel(R) mpx-table plugin missing.")
        plugin_command = " "
        seq = ("plugin", "load", plugin_file)
        plugin_command = plugin_command.join(seq)
        self.runCmd(plugin_command)

        exe = os.path.join(os.getcwd(), "a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        self.b1 = line_number('main.cpp', '// Break 1.')
        self.b2 = line_number('main.cpp', '// Break 2.')
        self.b3 = line_number('main.cpp', '// Break 3.')
        self.b4 = line_number('main.cpp', '// Break 4.')
        lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.b1, num_expected_locations=1)
        lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.b2, num_expected_locations=1)
        lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.b3, num_expected_locations=1)
        lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.b4, num_expected_locations=1)
        self.runCmd("run", RUN_SUCCEEDED)

        target = self.dbg.GetSelectedTarget()
        process = target.GetProcess()

        if (process.GetState() == lldb.eStateExited):
            self.skipTest("Intel(R) MPX is not supported.")
        else:
            self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
                        substrs = ["stop reason = breakpoint 1."])

        self.expect("mpx-table show a",
                     substrs = ['lbound = 0x',
                                ', ubound = 0x',
                                '(pointer value = 0x',
                                ', metadata = 0x',
                                ')'],
                     error = False)

        self.expect("continue", STOPPED_DUE_TO_BREAKPOINT,
                     substrs = ["stop reason = breakpoint 2."])

        # Check that out of scope pointer cannot be reached.
        #
        self.expect("mpx-table show a",
                     substrs = ['Invalid pointer.'],
                     error = True)

        self.expect("mpx-table show tmp",
                     substrs = ['lbound = 0x',
                                ', ubound = 0x',
                                '(pointer value = 0x',
                                ', metadata = 0x',
                                ')'],
                     error = False)

        self.expect("continue", STOPPED_DUE_TO_BREAKPOINT,
                     substrs = ["stop reason = breakpoint 3."])

        # Check that the pointer value is correctly updated.
        #
        self.expect("mpx-table show tmp",
                     substrs = ['lbound = 0x',
                                ', ubound = 0x',
                                '(pointer value = 0x2',
                                ', metadata = 0x',
                                ')'],
                     error = False)

        self.expect("continue", STOPPED_DUE_TO_BREAKPOINT,
                     substrs = ["stop reason = breakpoint 4."])

        # After going back to main(), check that out of scope pointer cannot be
        # reached.
        #
        self.expect("mpx-table show tmp",
                     substrs = ['Invalid pointer.'],
                     error = True)

        self.expect("mpx-table show a",
                     substrs = ['lbound = 0x',
                                ', ubound = 0x',
                                '(pointer value = 0x',
                                ', metadata = 0x',
                                ')'],
                     error = False)

    def test_set_command(self):
        """Test 'mpx-table set' command"""
        self.build()

        lldb_exec_dir = os.environ["LLDB_IMPLIB_DIR"]
        lldb_lib_dir = os.path.join(lldb_exec_dir, os.pardir, "lib")
        plugin_file = os.path.join(lldb_lib_dir, "liblldb-intel-mpxtable.so")
        if not os.path.isfile(plugin_file):
            self.skipTest("Intel(R) mpx-table plugin missing.")
        plugin_command = " "
        seq = ("plugin", "load", plugin_file)
        plugin_command = plugin_command.join(seq)
        self.runCmd(plugin_command)

        exe = os.path.join(os.getcwd(), "a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        self.b1 = line_number('main.cpp', '// Break 1.')
        lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.b1, num_expected_locations=1)
        self.runCmd("run", RUN_SUCCEEDED)

        target = self.dbg.GetSelectedTarget()
        process = target.GetProcess()

        if (process.GetState() == lldb.eStateExited):
            self.skipTest("Intel(R) MPX is not supported.")
        else:
            self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
                        substrs = ["stop reason = breakpoint 1."])

        # Check that the BT Entry doesn't already contain the test values.
        #
        self.expect("mpx-table show a", matching=False,
                     substrs = ['lbound = 0xcafecafe',
                                ', ubound = 0xbeefbeef'])

        # Set the test values.
        #
        self.expect("mpx-table set a 0xcafecafe 0xbeefbeef", error = False)

        # Verify that the test values have been correctly written in the BT
        # entry.
        #
        self.expect("mpx-table show a",
                     substrs = ['lbound = 0xcafecafe',
                                ', ubound = 0xbeefbeef'],
                     error = False)


OpenPOWER on IntegriCloud