e4632afe7b928455230360aca5aae7b0ace722d4
[openbsd] /
1 """
2 Check that vector types format properly
3 """
4
5 from __future__ import print_function
6
7
8 import lldb
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
12
13
14 class VectorTypesFormattingTestCase(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17
18     def setUp(self):
19         # Call super's setUp().
20         TestBase.setUp(self)
21         # Find the line number to break at.
22         self.line = line_number('main.cpp', '// break here')
23
24     # rdar://problem/14035604
25     @skipIf(compiler='gcc')  # gcc don't have ext_vector_type extension
26     def test_with_run_command(self):
27         """Check that vector types format properly"""
28         self.build()
29         self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
30
31         lldbutil.run_break_set_by_file_and_line(
32             self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
33
34         self.runCmd("run", RUN_SUCCEEDED)
35
36         # The stop reason of the thread should be breakpoint.
37         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
38                     substrs=['stopped',
39                              'stop reason = breakpoint'])
40
41         # This is the function to remove the custom formats in order to have a
42         # clean slate for the next test case.
43         def cleanup():
44             pass
45
46         # Execute the cleanup function during test case tear down.
47         self.addTearDownHook(cleanup)
48
49         pass  # my code never fails
50
51         v = self.frame().FindVariable("v")
52         v.SetPreferSyntheticValue(True)
53         v.SetFormat(lldb.eFormatVectorOfFloat32)
54
55         if self.TraceOn():
56             print(v)
57
58         self.assertTrue(
59             v.GetNumChildren() == 4,
60             "v as float32[] has 4 children")
61         self.assertTrue(v.GetChildAtIndex(0).GetData().float[
62                         0] == 1.25, "child 0 == 1.25")
63         self.assertTrue(v.GetChildAtIndex(1).GetData().float[
64                         0] == 1.25, "child 1 == 1.25")
65         self.assertTrue(v.GetChildAtIndex(2).GetData().float[
66                         0] == 2.50, "child 2 == 2.50")
67         self.assertTrue(v.GetChildAtIndex(3).GetData().float[
68                         0] == 2.50, "child 3 == 2.50")
69
70         self.expect("expr -f int16_t[] -- v",
71                     substrs=['(0, 16288, 0, 16288, 0, 16416, 0, 16416)'])
72         self.expect("expr -f uint128_t[] -- v",
73                     substrs=['(85236745249553456609335044694184296448)'])
74         self.expect(
75             "expr -f float32[] -- v",
76             substrs=['(1.25, 1.25, 2.5, 2.5)'])
77
78         oldValue = v.GetChildAtIndex(0).GetValue()
79         v.SetFormat(lldb.eFormatHex)
80         newValue = v.GetChildAtIndex(0).GetValue()
81         self.assertFalse(oldValue == newValue,
82                          "values did not change along with format")
83
84         v.SetFormat(lldb.eFormatVectorOfFloat32)
85         oldValueAgain = v.GetChildAtIndex(0).GetValue()
86         self.assertTrue(
87             oldValue == oldValueAgain,
88             "same format but different values")