-
Notifications
You must be signed in to change notification settings - Fork 353
/
kernelexpand_unittest.py
executable file
·238 lines (184 loc) · 8.06 KB
/
kernelexpand_unittest.py
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/usr/bin/python
import unittest
try:
import autotest.common as common
except ImportError:
import common
from kernelexpand import decompose_kernel
from kernelexpand import mirror_kernel_components
from autotest.client.shared.global_config import global_config
from autotest.client.shared.test_utils import mock
km = 'http://www.kernel.org/pub/linux/kernel/'
akpm = km + 'people/akpm/patches/'
gw = 'http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git'
sgw = 'http://git.kernel.org/?p=linux/kernel/git/stable/linux-stable.git'
kml = 'http://www.example.com/mirror/kernel.org/'
akpml = 'http://www.example.com/mirror/akpm/'
mirrorA = [
[ akpm, akpml ],
[ km, kml ],
]
class kernelexpandTest(unittest.TestCase):
def setUp(self):
self.god = mock.mock_god(ut=self)
def tearDown(self):
self.god.unstub_all()
def test_decompose_simple(self):
correct = [ [ km + 'v2.6/linux-2.6.23.tar.bz2' ] ]
sample = decompose_kernel('2.6.23')
self.assertEqual(sample, correct)
def test_decompose_simple_30(self):
correct = [ [ km + 'v3.x/linux-3.0.14.tar.bz2' ] ]
sample = decompose_kernel('3.0.14')
self.assertEqual(sample, correct)
def test_decompose_simple_3X(self):
correct = [ [ km + 'v3.x/linux-3.2.1.tar.bz2' ] ]
sample = decompose_kernel('3.2.1')
self.assertEqual(sample, correct)
def test_decompose_nominor_30(self):
correct = [ [ km + 'v3.x/linux-3.0.tar.bz2' ] ]
sample = decompose_kernel('3.0')
self.assertEqual(sample, correct)
def test_decompose_nominor_26_fail(self):
success = False
try:
sample = decompose_kernel('2.6')
success = True
except NameError:
pass
except Exception, e:
self.fail('expected NameError, got something else')
if success:
self.fail('expected NameError, was successful')
def test_decompose_testing_26(self):
correct = km + 'v2.6/testing/linux-2.6.35-rc1.tar.bz2'
sample = decompose_kernel('2.6.35-rc1')[0][1]
self.assertEqual(sample, correct)
def test_decompose_testing_30(self):
correct = km + 'v3.x/testing/linux-3.2-rc1.tar.bz2'
sample = decompose_kernel('3.2-rc1')[0][0]
self.assertEqual(sample, correct)
def test_decompose_testing_30_fail(self):
success = False
try:
sample = decompose_kernel('3.2.1-rc1')
success = True
except NameError:
pass
except Exception, e:
self.fail('expected NameError, got something else')
if success:
self.fail('expected NameError, was successful')
def test_decompose_gitweb(self):
self.god.stub_function(global_config, "get_config_value")
global_config.get_config_value.expect_call('CLIENT', 'kernel_mirror', default='').and_return(km)
global_config.get_config_value.expect_call('CLIENT', 'kernel_gitweb', default='').and_return(gw)
global_config.get_config_value.expect_call('CLIENT', 'stable_kernel_gitweb', default='').and_return(sgw)
correct = [ [ km + 'v3.x/linux-3.0.tar.bz2', gw + ';a=snapshot;h=refs/tags/v3.0;sf=tgz' ] ]
sample = decompose_kernel('3.0')
self.assertEqual(sample, correct)
def test_decompose_sha1(self):
self.god.stub_function(global_config, "get_config_value")
global_config.get_config_value.expect_call('CLIENT', 'kernel_mirror', default='').and_return(km)
global_config.get_config_value.expect_call('CLIENT', 'kernel_gitweb', default='').and_return(gw)
global_config.get_config_value.expect_call('CLIENT', 'stable_kernel_gitweb', default='').and_return(sgw)
correct = [ [ gw + ';a=snapshot;h=02f8c6aee8df3cdc935e9bdd4f2d020306035dbe;sf=tgz', sgw + ';a=snapshot;h=02f8c6aee8df3cdc935e9bdd4f2d020306035dbe;sf=tgz' ] ]
sample = decompose_kernel('02f8c6aee8df3cdc935e9bdd4f2d020306035dbe')
self.assertEqual(sample, correct)
def test_decompose_fail(self):
success = False
try:
sample = decompose_kernel('1.0.0.0.0')
success = True
except NameError:
pass
except Exception, e:
self.fail('expected NameError, got something else')
if success:
self.fail('expected NameError, was successful')
def test_decompose_rcN(self):
correct = [
[ km + 'v2.6/testing/v2.6.23/linux-2.6.23-rc1.tar.bz2',
km + 'v2.6/testing/linux-2.6.23-rc1.tar.bz2']
]
sample = decompose_kernel('2.6.23-rc1')
self.assertEqual(sample, correct)
def test_decompose_mmN(self):
correct = [
[ km + 'v2.6/linux-2.6.23.tar.bz2' ],
[ akpm + '2.6/2.6.23/2.6.23-mm1/2.6.23-mm1.bz2' ]
]
sample = decompose_kernel('2.6.23-mm1')
self.assertEqual(sample, correct)
def test_decompose_gitN(self):
correct = [
[ km + 'v2.6/linux-2.6.23.tar.bz2' ],
[ km + 'v2.6/snapshots/old/patch-2.6.23-git1.bz2',
km + 'v2.6/snapshots/patch-2.6.23-git1.bz2']
]
sample = decompose_kernel('2.6.23-git1')
self.assertEqual(sample, correct)
def test_decompose_rcN_mmN(self):
correct = [
[ km + 'v2.6/testing/v2.6.23/linux-2.6.23-rc1.tar.bz2',
km + 'v2.6/testing/linux-2.6.23-rc1.tar.bz2' ],
[ akpm + '2.6/2.6.23-rc1/2.6.23-rc1-mm1/2.6.23-rc1-mm1.bz2']
]
sample = decompose_kernel('2.6.23-rc1-mm1')
self.assertEqual(sample, correct)
def test_mirrorA_simple(self):
correct = [
[ kml + 'v2.6/linux-2.6.23.tar.bz2',
km + 'v2.6/linux-2.6.23.tar.bz2' ]
]
sample = decompose_kernel('2.6.23')
sample = mirror_kernel_components(mirrorA, sample)
self.assertEqual(sample, correct)
def test_mirrorA_rcN(self):
correct = [
[ kml + 'v2.6/testing/v2.6.23/linux-2.6.23-rc1.tar.bz2',
kml + 'v2.6/testing/linux-2.6.23-rc1.tar.bz2',
km + 'v2.6/testing/v2.6.23/linux-2.6.23-rc1.tar.bz2',
km + 'v2.6/testing/linux-2.6.23-rc1.tar.bz2' ]
]
sample = decompose_kernel('2.6.23-rc1')
sample = mirror_kernel_components(mirrorA, sample)
self.assertEqual(sample, correct)
def test_mirrorA_mmN(self):
correct = [
[ kml + 'v2.6/linux-2.6.23.tar.bz2',
km + 'v2.6/linux-2.6.23.tar.bz2'],
[ akpml + '2.6/2.6.23/2.6.23-mm1/2.6.23-mm1.bz2',
kml + 'people/akpm/patches/2.6/2.6.23/2.6.23-mm1/2.6.23-mm1.bz2',
akpm + '2.6/2.6.23/2.6.23-mm1/2.6.23-mm1.bz2' ]
]
sample = decompose_kernel('2.6.23-mm1')
sample = mirror_kernel_components(mirrorA, sample)
self.assertEqual(sample, correct)
def test_mirrorA_gitN(self):
correct = [
[ kml + 'v2.6/linux-2.6.23.tar.bz2',
km + 'v2.6/linux-2.6.23.tar.bz2'],
[ kml + 'v2.6/snapshots/old/patch-2.6.23-git1.bz2',
kml + 'v2.6/snapshots/patch-2.6.23-git1.bz2',
km + 'v2.6/snapshots/old/patch-2.6.23-git1.bz2',
km + 'v2.6/snapshots/patch-2.6.23-git1.bz2' ]
]
sample = decompose_kernel('2.6.23-git1')
sample = mirror_kernel_components(mirrorA, sample)
self.assertEqual(sample, correct)
def test_mirrorA_rcN_mmN(self):
correct = [
[ kml + 'v2.6/testing/v2.6.23/linux-2.6.23-rc1.tar.bz2',
kml + 'v2.6/testing/linux-2.6.23-rc1.tar.bz2',
km + 'v2.6/testing/v2.6.23/linux-2.6.23-rc1.tar.bz2',
km + 'v2.6/testing/linux-2.6.23-rc1.tar.bz2'],
[ akpml + '2.6/2.6.23-rc1/2.6.23-rc1-mm1/2.6.23-rc1-mm1.bz2',
kml + 'people/akpm/patches/2.6/2.6.23-rc1/2.6.23-rc1-mm1/2.6.23-rc1-mm1.bz2',
akpm + '2.6/2.6.23-rc1/2.6.23-rc1-mm1/2.6.23-rc1-mm1.bz2' ]
]
sample = decompose_kernel('2.6.23-rc1-mm1')
sample = mirror_kernel_components(mirrorA, sample)
self.assertEqual(sample, correct)
if __name__ == '__main__':
unittest.main()