]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/data-formatter/parray/TestPrintArray.py
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / data-formatter / parray / TestPrintArray.py
1 """
2 Test lldb data formatter subsystem.
3 """
4
5 from __future__ import print_function
6
7
8
9 import datetime
10 import os, time
11 import lldb
12 from lldbsuite.test.decorators import *
13 from lldbsuite.test.lldbtest import *
14 from lldbsuite.test import lldbutil
15
16 class PrintArrayTestCase(TestBase):
17
18     mydir = TestBase.compute_mydir(__file__)
19
20     def test_print_array(self):
21         """Test that expr -Z works"""
22         self.build()
23         self.printarray_data_formatter_commands()
24
25     def setUp(self):
26         # Call super's setUp().
27         TestBase.setUp(self)
28         # Find the line number to break at.
29         self.line = line_number('main.cpp', 'break here')
30
31     def printarray_data_formatter_commands(self):
32         """Test that expr -Z works"""
33         self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
34
35         lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
36
37         self.runCmd("run", RUN_SUCCEEDED)
38
39         # The stop reason of the thread should be breakpoint.
40         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
41             substrs = ['stopped',
42                        'stop reason = breakpoint'])
43
44         # This is the function to remove the custom formats in order to have a
45         # clean slate for the next test case.
46         def cleanup():
47             self.runCmd('type format clear', check=False)
48             self.runCmd('type summary clear', check=False)
49             self.runCmd('type synth clear', check=False)
50
51         # Execute the cleanup function during test case tear down.
52         self.addTearDownHook(cleanup)
53         
54         self.expect('expr --element-count 3 -- data', substrs=['[0] = 1', '[1] = 3', '[2] = 5'])
55         self.expect('expr data', substrs=['int *', '$', '0x'])
56         self.expect('expr -f binary --element-count 0 -- data', substrs=['int *', '$', '0b'])
57         self.expect('expr -f hex --element-count 3 -- data', substrs=['[0] = 0x', '1', '[1] = 0x', '3', '[2] = 0x', '5'])
58         self.expect('expr -f binary --element-count 2 -- data', substrs=['int *', '$', '0x', '[0] = 0b', '1', '[1] = 0b', '11'])
59         self.expect('parray 3 data', substrs=['[0] = 1', '[1] = 3', '[2] = 5'])
60         self.expect('parray `1 + 1 + 1` data', substrs=['[0] = 1', '[1] = 3', '[2] = 5'])
61         self.expect('parray `data[1]` data', substrs=['[0] = 1', '[1] = 3', '[2] = 5'])
62         self.expect('parray/x 3 data', substrs=['[0] = 0x', '1', '[1] = 0x', '3', '[2] = 0x', '5'])
63         self.expect('parray/x `data[1]` data', substrs=['[0] = 0x', '1', '[1] = 0x', '3', '[2] = 0x', '5'])
64
65         # check error conditions
66         self.expect('expr --element-count 10 -- 123', error=True, substrs=['expression cannot be used with --element-count as it does not refer to a pointer'])
67         self.expect('expr --element-count 10 -- (void*)123', error=True, substrs=['expression cannot be used with --element-count as it refers to a pointer to void'])
68         self.expect('parray data', error=True, substrs=["invalid element count 'data'"])
69         self.expect('parray data data', error=True, substrs=["invalid element count 'data'"])
70         self.expect('parray', error=True, substrs=['Not enough arguments provided'])