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
|
"""
Test lldb data formatter subsystem for bitset for libcxx and libstdcpp.
"""
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
USE_LIBSTDCPP = "USE_LIBSTDCPP"
USE_LIBCPP = "USE_LIBCPP"
VALUE = "VALUE"
REFERENCE = "REFERENCE"
POINTER = "POINTER"
class GenericBitsetDataFormatterTestCase(TestBase):
def setUp(self):
TestBase.setUp(self)
primes = [1] * 1000
primes[0] = primes[1] = 0
for i in range(2, len(primes)):
for j in range(2 * i, len(primes), i):
primes[j] = 0
self.primes = primes
def getBitsetVariant(self, size, variant):
if variant == VALUE:
return "std::bitset<" + str(size) + ">"
elif variant == REFERENCE:
return "std::bitset<" + str(size) + "> &"
elif variant == POINTER:
return "std::bitset<" + str(size) + "> *"
return ""
def check(self, name, size, variant):
var = self.frame().FindVariable(name)
self.assertTrue(var.IsValid())
self.assertEqual(var.GetNumChildren(), size)
children = []
for i in range(size):
child = var.GetChildAtIndex(i)
children.append(
ValueCheck(value=str(bool(child.GetValueAsUnsigned())).lower())
)
self.assertEqual(
child.GetValueAsUnsigned(),
self.primes[i],
"variable: %s, index: %d" % (name, size),
)
self.expect_var_path(
name, type=self.getBitsetVariant(size, variant), children=children
)
def do_test_value(self, stdlib_type):
"""Test that std::bitset is displayed correctly"""
self.build(dictionary={stdlib_type: "1"})
lldbutil.run_to_source_breakpoint(
self, "// break here", lldb.SBFileSpec("main.cpp", False)
)
self.check("empty", 0, VALUE)
self.check("small", 13, VALUE)
self.check("medium", 70, VALUE)
self.check("large", 1000, VALUE)
@add_test_categories(["libstdcxx"])
def test_value_libstdcpp(self):
self.do_test_value(USE_LIBSTDCPP)
@add_test_categories(["libc++"])
def test_value_libcpp(self):
self.do_test_value(USE_LIBCPP)
def do_test_ptr_and_ref(self, stdlib_type):
"""Test that ref and ptr to std::bitset is displayed correctly"""
self.build(dictionary={stdlib_type: "1"})
(_, process, _, bkpt) = lldbutil.run_to_source_breakpoint(
self, "Check ref and ptr", lldb.SBFileSpec("main.cpp", False)
)
self.check("ref", 13, REFERENCE)
self.check("ptr", 13, POINTER)
lldbutil.continue_to_breakpoint(process, bkpt)
self.check("ref", 70, REFERENCE)
self.check("ptr", 70, POINTER)
lldbutil.continue_to_breakpoint(process, bkpt)
self.check("ref", 1000, REFERENCE)
self.check("ptr", 1000, POINTER)
@add_test_categories(["libstdcxx"])
def test_ptr_and_ref_libstdcpp(self):
self.do_test_ptr_and_ref(USE_LIBSTDCPP)
@add_test_categories(["libc++"])
def test_ptr_and_ref_libcpp(self):
self.do_test_ptr_and_ref(USE_LIBCPP)
|