-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathtest_list.py
More file actions
155 lines (127 loc) · 5.76 KB
/
test_list.py
File metadata and controls
155 lines (127 loc) · 5.76 KB
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
# -*- coding: utf-8 -*-
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
import unittest
import gdb
from crash.types.list import list_for_each, list_for_each_entry
from crash.types.list import ListCycleError, CorruptListError
def get_symbol(name):
return gdb.lookup_symbol(name, None)[0].value()
class TestList(unittest.TestCase):
def setUp(self):
gdb.execute("file tests/test-list")
self.list_head = gdb.lookup_type("struct list_head")
def tearDown(self):
gdb.execute("file")
def test_none_list(self):
count = 0
with self.assertRaises(TypeError):
for node in list_for_each(None):
count += 1
def test_invalid_value(self):
count = 0
gdbtype = gdb.lookup_type('unsigned int')
with self.assertRaises(TypeError):
for node in list_for_each(gdbtype):
count += 1
def test_invalid_value_pointer(self):
count = 0
gdbtype = gdb.lookup_type('unsigned int').pointer()
with self.assertRaises(TypeError):
for node in list_for_each(gdbtype):
count += 1
def test_bad_next_pointer_list(self):
head = get_symbol("bad_next_ptr_list")
count = 0
with self.assertRaises(BufferError):
for node in list_for_each(head):
count += 1
# Not a failure yet - we don't iterate the list backward
# def test_bad_prev_pointer_list(self):
# head = get_symbol("bad_prev_ptr_list")
# count = 0
#
# with self.assertRaises(BufferError):
# for node in list_for_each(head):
# count += 1
def test_normal_list(self):
normal_list = get_symbol("normal_head")
short_list = get_symbol("short_list")
expected_count = short_list.type.sizeof // short_list[0].type.sizeof
count = 0
for node in list_for_each(normal_list):
count += 1
self.assertTrue(count == expected_count)
def test_cycle_list(self):
normal_list = get_symbol("cycle_head")
short_list = get_symbol("short_list_with_cycle")
expected_count = short_list.type.sizeof // short_list[0].type.sizeof
count = 0
with self.assertRaises(ListCycleError):
for node in list_for_each(normal_list, exact_cycles=True):
count += 1
def test_corrupt_list(self):
normal_list = get_symbol("bad_list_head")
short_list = get_symbol("short_list_with_bad_prev")
expected_count = short_list.type.sizeof // short_list[0].type.sizeof
count = 0
with self.assertRaises(CorruptListError):
for node in list_for_each(normal_list, exact_cycles=True,
print_broken_links=False):
count += 1
def test_normal_container_list_with_string(self):
normal_list = get_symbol("good_container_list")
short_list = get_symbol("good_containers")
expected_count = short_list.type.sizeof // short_list[0].type.sizeof
count = 0
for node in list_for_each_entry(normal_list, 'struct container',
'list'):
count += 1
self.assertTrue(count == expected_count)
def test_normal_container_list_with_type(self):
normal_list = get_symbol("good_container_list")
short_list = get_symbol("good_containers")
expected_count = short_list.type.sizeof // short_list[0].type.sizeof
struct_container = gdb.lookup_type('struct container')
count = 0
for node in list_for_each_entry(normal_list, struct_container, 'list'):
count += 1
def test_cycle_container_list_with_string(self):
cycle_list = get_symbol("cycle_container_list")
short_list = get_symbol("cycle_containers")
expected_count = short_list.type.sizeof // short_list[0].type.sizeof
count = 0
with self.assertRaises(ListCycleError):
for node in list_for_each_entry(cycle_list, 'struct container',
'list', exact_cycles=True,
print_broken_links=False):
count += 1
def test_cycle_container_list_with_type(self):
cycle_list = get_symbol("cycle_container_list")
short_list = get_symbol("cycle_containers")
expected_count = short_list.type.sizeof // short_list[0].type.sizeof
struct_container = gdb.lookup_type('struct container')
count = 0
with self.assertRaises(ListCycleError):
for node in list_for_each_entry(cycle_list, struct_container,
'list', exact_cycles=True,
print_broken_links=False):
count += 1
def test_bad_container_list_with_string(self):
bad_list = get_symbol("bad_container_list")
short_list = get_symbol("bad_containers")
expected_count = short_list.type.sizeof // short_list[0].type.sizeof
count = 0
with self.assertRaises(CorruptListError):
for node in list_for_each_entry(bad_list, 'struct container',
'list', print_broken_links=False):
count += 1
def test_bad_container_list_with_type(self):
bad_list = get_symbol("bad_container_list")
short_list = get_symbol("bad_containers")
expected_count = short_list.type.sizeof // short_list[0].type.sizeof
struct_container = gdb.lookup_type('struct container')
count = 0
with self.assertRaises(CorruptListError):
for node in list_for_each_entry(bad_list, struct_container,
'list', print_broken_links=False):
count += 1