diff options
Diffstat (limited to 'bitbake/lib/bb/tests/fetch.py')
-rw-r--r-- | bitbake/lib/bb/tests/fetch.py | 569 |
1 files changed, 569 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py new file mode 100644 index 0000000000..d95b43a5e3 --- /dev/null +++ b/bitbake/lib/bb/tests/fetch.py | |||
@@ -0,0 +1,569 @@ | |||
1 | # ex:ts=4:sw=4:sts=4:et | ||
2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
3 | # | ||
4 | # BitBake Tests for the Fetcher (fetch2/) | ||
5 | # | ||
6 | # Copyright (C) 2012 Richard Purdie | ||
7 | # | ||
8 | # This program is free software; you can redistribute it and/or modify | ||
9 | # it under the terms of the GNU General Public License version 2 as | ||
10 | # published by the Free Software Foundation. | ||
11 | # | ||
12 | # This program is distributed in the hope that it will be useful, | ||
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | # GNU General Public License for more details. | ||
16 | # | ||
17 | # You should have received a copy of the GNU General Public License along | ||
18 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
20 | # | ||
21 | |||
22 | import unittest | ||
23 | import tempfile | ||
24 | import subprocess | ||
25 | import os | ||
26 | from bb.fetch2 import URI | ||
27 | import bb | ||
28 | |||
29 | class URITest(unittest.TestCase): | ||
30 | test_uris = { | ||
31 | "http://www.google.com/index.html" : { | ||
32 | 'uri': 'http://www.google.com/index.html', | ||
33 | 'scheme': 'http', | ||
34 | 'hostname': 'www.google.com', | ||
35 | 'port': None, | ||
36 | 'hostport': 'www.google.com', | ||
37 | 'path': '/index.html', | ||
38 | 'userinfo': '', | ||
39 | 'username': '', | ||
40 | 'password': '', | ||
41 | 'params': {}, | ||
42 | 'query': {}, | ||
43 | 'relative': False | ||
44 | }, | ||
45 | "http://www.google.com/index.html;param1=value1" : { | ||
46 | 'uri': 'http://www.google.com/index.html;param1=value1', | ||
47 | 'scheme': 'http', | ||
48 | 'hostname': 'www.google.com', | ||
49 | 'port': None, | ||
50 | 'hostport': 'www.google.com', | ||
51 | 'path': '/index.html', | ||
52 | 'userinfo': '', | ||
53 | 'username': '', | ||
54 | 'password': '', | ||
55 | 'params': { | ||
56 | 'param1': 'value1' | ||
57 | }, | ||
58 | 'query': {}, | ||
59 | 'relative': False | ||
60 | }, | ||
61 | "http://www.example.org/index.html?param1=value1" : { | ||
62 | 'uri': 'http://www.example.org/index.html?param1=value1', | ||
63 | 'scheme': 'http', | ||
64 | 'hostname': 'www.example.org', | ||
65 | 'port': None, | ||
66 | 'hostport': 'www.example.org', | ||
67 | 'path': '/index.html', | ||
68 | 'userinfo': '', | ||
69 | 'username': '', | ||
70 | 'password': '', | ||
71 | 'params': {}, | ||
72 | 'query': { | ||
73 | 'param1': 'value1' | ||
74 | }, | ||
75 | 'relative': False | ||
76 | }, | ||
77 | "http://www.example.org/index.html?qparam1=qvalue1;param2=value2" : { | ||
78 | 'uri': 'http://www.example.org/index.html?qparam1=qvalue1;param2=value2', | ||
79 | 'scheme': 'http', | ||
80 | 'hostname': 'www.example.org', | ||
81 | 'port': None, | ||
82 | 'hostport': 'www.example.org', | ||
83 | 'path': '/index.html', | ||
84 | 'userinfo': '', | ||
85 | 'username': '', | ||
86 | 'password': '', | ||
87 | 'params': { | ||
88 | 'param2': 'value2' | ||
89 | }, | ||
90 | 'query': { | ||
91 | 'qparam1': 'qvalue1' | ||
92 | }, | ||
93 | 'relative': False | ||
94 | }, | ||
95 | "http://www.example.com:8080/index.html" : { | ||
96 | 'uri': 'http://www.example.com:8080/index.html', | ||
97 | 'scheme': 'http', | ||
98 | 'hostname': 'www.example.com', | ||
99 | 'port': 8080, | ||
100 | 'hostport': 'www.example.com:8080', | ||
101 | 'path': '/index.html', | ||
102 | 'userinfo': '', | ||
103 | 'username': '', | ||
104 | 'password': '', | ||
105 | 'params': {}, | ||
106 | 'query': {}, | ||
107 | 'relative': False | ||
108 | }, | ||
109 | "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : { | ||
110 | 'uri': 'cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg', | ||
111 | 'scheme': 'cvs', | ||
112 | 'hostname': 'cvs.handhelds.org', | ||
113 | 'port': None, | ||
114 | 'hostport': 'cvs.handhelds.org', | ||
115 | 'path': '/cvs', | ||
116 | 'userinfo': 'anoncvs', | ||
117 | 'username': 'anoncvs', | ||
118 | 'password': '', | ||
119 | 'params': { | ||
120 | 'module': 'familiar/dist/ipkg' | ||
121 | }, | ||
122 | 'query': {}, | ||
123 | 'relative': False | ||
124 | }, | ||
125 | "cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg": { | ||
126 | 'uri': 'cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg', | ||
127 | 'scheme': 'cvs', | ||
128 | 'hostname': 'cvs.handhelds.org', | ||
129 | 'port': None, | ||
130 | 'hostport': 'cvs.handhelds.org', | ||
131 | 'path': '/cvs', | ||
132 | 'userinfo': 'anoncvs:anonymous', | ||
133 | 'username': 'anoncvs', | ||
134 | 'password': 'anonymous', | ||
135 | 'params': { | ||
136 | 'tag': 'V0-99-81', | ||
137 | 'module': 'familiar/dist/ipkg' | ||
138 | }, | ||
139 | 'query': {}, | ||
140 | 'relative': False | ||
141 | }, | ||
142 | "file://example.diff": { # NOTE: Not RFC compliant! | ||
143 | 'uri': 'file:example.diff', | ||
144 | 'scheme': 'file', | ||
145 | 'hostname': '', | ||
146 | 'port': None, | ||
147 | 'hostport': '', | ||
148 | 'path': 'example.diff', | ||
149 | 'userinfo': '', | ||
150 | 'username': '', | ||
151 | 'password': '', | ||
152 | 'params': {}, | ||
153 | 'query': {}, | ||
154 | 'relative': True | ||
155 | }, | ||
156 | "file:example.diff": { # NOTE: RFC compliant version of the former | ||
157 | 'uri': 'file:example.diff', | ||
158 | 'scheme': 'file', | ||
159 | 'hostname': '', | ||
160 | 'port': None, | ||
161 | 'hostport': '', | ||
162 | 'path': 'example.diff', | ||
163 | 'userinfo': '', | ||
164 | 'userinfo': '', | ||
165 | 'username': '', | ||
166 | 'password': '', | ||
167 | 'params': {}, | ||
168 | 'query': {}, | ||
169 | 'relative': True | ||
170 | }, | ||
171 | "file:///tmp/example.diff": { | ||
172 | 'uri': 'file:///tmp/example.diff', | ||
173 | 'scheme': 'file', | ||
174 | 'hostname': '', | ||
175 | 'port': None, | ||
176 | 'hostport': '', | ||
177 | 'path': '/tmp/example.diff', | ||
178 | 'userinfo': '', | ||
179 | 'userinfo': '', | ||
180 | 'username': '', | ||
181 | 'password': '', | ||
182 | 'params': {}, | ||
183 | 'query': {}, | ||
184 | 'relative': False | ||
185 | }, | ||
186 | "git:///path/example.git": { | ||
187 | 'uri': 'git:///path/example.git', | ||
188 | 'scheme': 'git', | ||
189 | 'hostname': '', | ||
190 | 'port': None, | ||
191 | 'hostport': '', | ||
192 | 'path': '/path/example.git', | ||
193 | 'userinfo': '', | ||
194 | 'userinfo': '', | ||
195 | 'username': '', | ||
196 | 'password': '', | ||
197 | 'params': {}, | ||
198 | 'query': {}, | ||
199 | 'relative': False | ||
200 | }, | ||
201 | "git:path/example.git": { | ||
202 | 'uri': 'git:path/example.git', | ||
203 | 'scheme': 'git', | ||
204 | 'hostname': '', | ||
205 | 'port': None, | ||
206 | 'hostport': '', | ||
207 | 'path': 'path/example.git', | ||
208 | 'userinfo': '', | ||
209 | 'userinfo': '', | ||
210 | 'username': '', | ||
211 | 'password': '', | ||
212 | 'params': {}, | ||
213 | 'query': {}, | ||
214 | 'relative': True | ||
215 | }, | ||
216 | "git://example.net/path/example.git": { | ||
217 | 'uri': 'git://example.net/path/example.git', | ||
218 | 'scheme': 'git', | ||
219 | 'hostname': 'example.net', | ||
220 | 'port': None, | ||
221 | 'hostport': 'example.net', | ||
222 | 'path': '/path/example.git', | ||
223 | 'userinfo': '', | ||
224 | 'userinfo': '', | ||
225 | 'username': '', | ||
226 | 'password': '', | ||
227 | 'params': {}, | ||
228 | 'query': {}, | ||
229 | 'relative': False | ||
230 | } | ||
231 | } | ||
232 | |||
233 | def test_uri(self): | ||
234 | for test_uri, ref in self.test_uris.items(): | ||
235 | uri = URI(test_uri) | ||
236 | |||
237 | self.assertEqual(str(uri), ref['uri']) | ||
238 | |||
239 | # expected attributes | ||
240 | self.assertEqual(uri.scheme, ref['scheme']) | ||
241 | |||
242 | self.assertEqual(uri.userinfo, ref['userinfo']) | ||
243 | self.assertEqual(uri.username, ref['username']) | ||
244 | self.assertEqual(uri.password, ref['password']) | ||
245 | |||
246 | self.assertEqual(uri.hostname, ref['hostname']) | ||
247 | self.assertEqual(uri.port, ref['port']) | ||
248 | self.assertEqual(uri.hostport, ref['hostport']) | ||
249 | |||
250 | self.assertEqual(uri.path, ref['path']) | ||
251 | self.assertEqual(uri.params, ref['params']) | ||
252 | |||
253 | self.assertEqual(uri.relative, ref['relative']) | ||
254 | |||
255 | def test_dict(self): | ||
256 | for test in self.test_uris.values(): | ||
257 | uri = URI() | ||
258 | |||
259 | self.assertEqual(uri.scheme, '') | ||
260 | self.assertEqual(uri.userinfo, '') | ||
261 | self.assertEqual(uri.username, '') | ||
262 | self.assertEqual(uri.password, '') | ||
263 | self.assertEqual(uri.hostname, '') | ||
264 | self.assertEqual(uri.port, None) | ||
265 | self.assertEqual(uri.path, '') | ||
266 | self.assertEqual(uri.params, {}) | ||
267 | |||
268 | |||
269 | uri.scheme = test['scheme'] | ||
270 | self.assertEqual(uri.scheme, test['scheme']) | ||
271 | |||
272 | uri.userinfo = test['userinfo'] | ||
273 | self.assertEqual(uri.userinfo, test['userinfo']) | ||
274 | self.assertEqual(uri.username, test['username']) | ||
275 | self.assertEqual(uri.password, test['password']) | ||
276 | |||
277 | # make sure changing the values doesn't do anything unexpected | ||
278 | uri.username = 'changeme' | ||
279 | self.assertEqual(uri.username, 'changeme') | ||
280 | self.assertEqual(uri.password, test['password']) | ||
281 | uri.password = 'insecure' | ||
282 | self.assertEqual(uri.username, 'changeme') | ||
283 | self.assertEqual(uri.password, 'insecure') | ||
284 | |||
285 | # reset back after our trickery | ||
286 | uri.userinfo = test['userinfo'] | ||
287 | self.assertEqual(uri.userinfo, test['userinfo']) | ||
288 | self.assertEqual(uri.username, test['username']) | ||
289 | self.assertEqual(uri.password, test['password']) | ||
290 | |||
291 | uri.hostname = test['hostname'] | ||
292 | self.assertEqual(uri.hostname, test['hostname']) | ||
293 | self.assertEqual(uri.hostport, test['hostname']) | ||
294 | |||
295 | uri.port = test['port'] | ||
296 | self.assertEqual(uri.port, test['port']) | ||
297 | self.assertEqual(uri.hostport, test['hostport']) | ||
298 | |||
299 | uri.path = test['path'] | ||
300 | self.assertEqual(uri.path, test['path']) | ||
301 | |||
302 | uri.params = test['params'] | ||
303 | self.assertEqual(uri.params, test['params']) | ||
304 | |||
305 | uri.query = test['query'] | ||
306 | self.assertEqual(uri.query, test['query']) | ||
307 | |||
308 | self.assertEqual(str(uri), test['uri']) | ||
309 | |||
310 | uri.params = {} | ||
311 | self.assertEqual(uri.params, {}) | ||
312 | self.assertEqual(str(uri), (str(uri).split(";"))[0]) | ||
313 | |||
314 | class FetcherTest(unittest.TestCase): | ||
315 | |||
316 | def setUp(self): | ||
317 | self.d = bb.data.init() | ||
318 | self.tempdir = tempfile.mkdtemp() | ||
319 | self.dldir = os.path.join(self.tempdir, "download") | ||
320 | os.mkdir(self.dldir) | ||
321 | self.d.setVar("DL_DIR", self.dldir) | ||
322 | self.unpackdir = os.path.join(self.tempdir, "unpacked") | ||
323 | os.mkdir(self.unpackdir) | ||
324 | persistdir = os.path.join(self.tempdir, "persistdata") | ||
325 | self.d.setVar("PERSISTENT_DIR", persistdir) | ||
326 | |||
327 | def tearDown(self): | ||
328 | bb.utils.prunedir(self.tempdir) | ||
329 | |||
330 | class MirrorUriTest(FetcherTest): | ||
331 | |||
332 | replaceuris = { | ||
333 | ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "http://somewhere.org/somedir/") | ||
334 | : "http://somewhere.org/somedir/git2_git.invalid.infradead.org.mtd-utils.git.tar.gz", | ||
335 | ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http") | ||
336 | : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http", | ||
337 | ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http") | ||
338 | : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http", | ||
339 | ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/\\2;protocol=http") | ||
340 | : "git://somewhere.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http", | ||
341 | ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890", "git://someserver.org/bitbake", "git://git.openembedded.org/bitbake") | ||
342 | : "git://git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890", | ||
343 | ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache") | ||
344 | : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz", | ||
345 | ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache/") | ||
346 | : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz", | ||
347 | ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org/somedir3") | ||
348 | : "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz", | ||
349 | ("http://somewhere.org/somedir1/somefile_1.2.3.tar.gz", "http://somewhere.org/somedir1/somefile_1.2.3.tar.gz", "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz") | ||
350 | : "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz", | ||
351 | ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://www.apache.org/dist", "http://archive.apache.org/dist") | ||
352 | : "http://archive.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", | ||
353 | ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://.*/.*", "file:///somepath/downloads/") | ||
354 | : "file:///somepath/downloads/subversion-1.7.1.tar.bz2", | ||
355 | ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http") | ||
356 | : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http", | ||
357 | ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http") | ||
358 | : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http", | ||
359 | ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/MIRRORNAME;protocol=http") | ||
360 | : "git://somewhere.org/somedir/git.invalid.infradead.org.foo.mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http", | ||
361 | |||
362 | #Renaming files doesn't work | ||
363 | #("http://somewhere.org/somedir1/somefile_1.2.3.tar.gz", "http://somewhere.org/somedir1/somefile_1.2.3.tar.gz", "http://somewhere2.org/somedir3/somefile_2.3.4.tar.gz") : "http://somewhere2.org/somedir3/somefile_2.3.4.tar.gz" | ||
364 | #("file://sstate-xyz.tgz", "file://.*/.*", "file:///somewhere/1234/sstate-cache") : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz", | ||
365 | } | ||
366 | |||
367 | mirrorvar = "http://.*/.* file:///somepath/downloads/ \n" \ | ||
368 | "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n" \ | ||
369 | "https://.*/.* file:///someotherpath/downloads/ \n" \ | ||
370 | "http://.*/.* file:///someotherpath/downloads/ \n" | ||
371 | |||
372 | def test_urireplace(self): | ||
373 | for k, v in self.replaceuris.items(): | ||
374 | ud = bb.fetch.FetchData(k[0], self.d) | ||
375 | ud.setup_localpath(self.d) | ||
376 | mirrors = bb.fetch2.mirror_from_string("%s %s" % (k[1], k[2])) | ||
377 | newuris, uds = bb.fetch2.build_mirroruris(ud, mirrors, self.d) | ||
378 | self.assertEqual([v], newuris) | ||
379 | |||
380 | def test_urilist1(self): | ||
381 | fetcher = bb.fetch.FetchData("http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d) | ||
382 | mirrors = bb.fetch2.mirror_from_string(self.mirrorvar) | ||
383 | uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d) | ||
384 | self.assertEqual(uris, ['file:///somepath/downloads/bitbake-1.0.tar.gz', 'file:///someotherpath/downloads/bitbake-1.0.tar.gz']) | ||
385 | |||
386 | def test_urilist2(self): | ||
387 | # Catch https:// -> files:// bug | ||
388 | fetcher = bb.fetch.FetchData("https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d) | ||
389 | mirrors = bb.fetch2.mirror_from_string(self.mirrorvar) | ||
390 | uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d) | ||
391 | self.assertEqual(uris, ['file:///someotherpath/downloads/bitbake-1.0.tar.gz']) | ||
392 | |||
393 | |||
394 | class FetcherLocalTest(FetcherTest): | ||
395 | def setUp(self): | ||
396 | def touch(fn): | ||
397 | with file(fn, 'a'): | ||
398 | os.utime(fn, None) | ||
399 | |||
400 | super(FetcherLocalTest, self).setUp() | ||
401 | self.localsrcdir = os.path.join(self.tempdir, 'localsrc') | ||
402 | os.makedirs(self.localsrcdir) | ||
403 | touch(os.path.join(self.localsrcdir, 'a')) | ||
404 | touch(os.path.join(self.localsrcdir, 'b')) | ||
405 | os.makedirs(os.path.join(self.localsrcdir, 'dir')) | ||
406 | touch(os.path.join(self.localsrcdir, 'dir', 'c')) | ||
407 | touch(os.path.join(self.localsrcdir, 'dir', 'd')) | ||
408 | os.makedirs(os.path.join(self.localsrcdir, 'dir', 'subdir')) | ||
409 | touch(os.path.join(self.localsrcdir, 'dir', 'subdir', 'e')) | ||
410 | self.d.setVar("FILESPATH", self.localsrcdir) | ||
411 | |||
412 | def fetchUnpack(self, uris): | ||
413 | fetcher = bb.fetch.Fetch(uris, self.d) | ||
414 | fetcher.download() | ||
415 | fetcher.unpack(self.unpackdir) | ||
416 | flst = [] | ||
417 | for root, dirs, files in os.walk(self.unpackdir): | ||
418 | for f in files: | ||
419 | flst.append(os.path.relpath(os.path.join(root, f), self.unpackdir)) | ||
420 | flst.sort() | ||
421 | return flst | ||
422 | |||
423 | def test_local(self): | ||
424 | tree = self.fetchUnpack(['file://a', 'file://dir/c']) | ||
425 | self.assertEqual(tree, ['a', 'dir/c']) | ||
426 | |||
427 | def test_local_wildcard(self): | ||
428 | tree = self.fetchUnpack(['file://a', 'file://dir/*']) | ||
429 | # FIXME: this is broken - it should return ['a', 'dir/c', 'dir/d', 'dir/subdir/e'] | ||
430 | # see https://bugzilla.yoctoproject.org/show_bug.cgi?id=6128 | ||
431 | self.assertEqual(tree, ['a', 'b', 'dir/c', 'dir/d', 'dir/subdir/e']) | ||
432 | |||
433 | def test_local_dir(self): | ||
434 | tree = self.fetchUnpack(['file://a', 'file://dir']) | ||
435 | self.assertEqual(tree, ['a', 'dir/c', 'dir/d', 'dir/subdir/e']) | ||
436 | |||
437 | def test_local_subdir(self): | ||
438 | tree = self.fetchUnpack(['file://dir/subdir']) | ||
439 | # FIXME: this is broken - it should return ['dir/subdir/e'] | ||
440 | # see https://bugzilla.yoctoproject.org/show_bug.cgi?id=6129 | ||
441 | self.assertEqual(tree, ['subdir/e']) | ||
442 | |||
443 | def test_local_subdir_file(self): | ||
444 | tree = self.fetchUnpack(['file://dir/subdir/e']) | ||
445 | self.assertEqual(tree, ['dir/subdir/e']) | ||
446 | |||
447 | def test_local_subdirparam(self): | ||
448 | tree = self.fetchUnpack(['file://a;subdir=bar']) | ||
449 | self.assertEqual(tree, ['bar/a']) | ||
450 | |||
451 | def test_local_deepsubdirparam(self): | ||
452 | tree = self.fetchUnpack(['file://dir/subdir/e;subdir=bar']) | ||
453 | self.assertEqual(tree, ['bar/dir/subdir/e']) | ||
454 | |||
455 | class FetcherNetworkTest(FetcherTest): | ||
456 | |||
457 | if os.environ.get("BB_SKIP_NETTESTS") == "yes": | ||
458 | print("Unset BB_SKIP_NETTESTS to run network tests") | ||
459 | else: | ||
460 | def test_fetch(self): | ||
461 | fetcher = bb.fetch.Fetch(["http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", "http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz"], self.d) | ||
462 | fetcher.download() | ||
463 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749) | ||
464 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.1.tar.gz"), 57892) | ||
465 | self.d.setVar("BB_NO_NETWORK", "1") | ||
466 | fetcher = bb.fetch.Fetch(["http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", "http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz"], self.d) | ||
467 | fetcher.download() | ||
468 | fetcher.unpack(self.unpackdir) | ||
469 | self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.0/")), 9) | ||
470 | self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.1/")), 9) | ||
471 | |||
472 | def test_fetch_mirror(self): | ||
473 | self.d.setVar("MIRRORS", "http://.*/.* http://downloads.yoctoproject.org/releases/bitbake") | ||
474 | fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d) | ||
475 | fetcher.download() | ||
476 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749) | ||
477 | |||
478 | def test_fetch_premirror(self): | ||
479 | self.d.setVar("PREMIRRORS", "http://.*/.* http://downloads.yoctoproject.org/releases/bitbake") | ||
480 | fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d) | ||
481 | fetcher.download() | ||
482 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749) | ||
483 | |||
484 | def gitfetcher(self, url1, url2): | ||
485 | def checkrevision(self, fetcher): | ||
486 | fetcher.unpack(self.unpackdir) | ||
487 | revision = bb.process.run("git rev-parse HEAD", shell=True, cwd=self.unpackdir + "/git")[0].strip() | ||
488 | self.assertEqual(revision, "270a05b0b4ba0959fe0624d2a4885d7b70426da5") | ||
489 | |||
490 | self.d.setVar("BB_GENERATE_MIRROR_TARBALLS", "1") | ||
491 | self.d.setVar("SRCREV", "270a05b0b4ba0959fe0624d2a4885d7b70426da5") | ||
492 | fetcher = bb.fetch.Fetch([url1], self.d) | ||
493 | fetcher.download() | ||
494 | checkrevision(self, fetcher) | ||
495 | # Wipe out the dldir clone and the unpacked source, turn off the network and check mirror tarball works | ||
496 | bb.utils.prunedir(self.dldir + "/git2/") | ||
497 | bb.utils.prunedir(self.unpackdir) | ||
498 | self.d.setVar("BB_NO_NETWORK", "1") | ||
499 | fetcher = bb.fetch.Fetch([url2], self.d) | ||
500 | fetcher.download() | ||
501 | checkrevision(self, fetcher) | ||
502 | |||
503 | def test_gitfetch(self): | ||
504 | url1 = url2 = "git://git.openembedded.org/bitbake" | ||
505 | self.gitfetcher(url1, url2) | ||
506 | |||
507 | def test_gitfetch_goodsrcrev(self): | ||
508 | # SRCREV is set but matches rev= parameter | ||
509 | url1 = url2 = "git://git.openembedded.org/bitbake;rev=270a05b0b4ba0959fe0624d2a4885d7b70426da5" | ||
510 | self.gitfetcher(url1, url2) | ||
511 | |||
512 | def test_gitfetch_badsrcrev(self): | ||
513 | # SRCREV is set but does not match rev= parameter | ||
514 | url1 = url2 = "git://git.openembedded.org/bitbake;rev=dead05b0b4ba0959fe0624d2a4885d7b70426da5" | ||
515 | self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2) | ||
516 | |||
517 | def test_gitfetch_tagandrev(self): | ||
518 | # SRCREV is set but does not match rev= parameter | ||
519 | url1 = url2 = "git://git.openembedded.org/bitbake;rev=270a05b0b4ba0959fe0624d2a4885d7b70426da5;tag=270a05b0b4ba0959fe0624d2a4885d7b70426da5" | ||
520 | self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2) | ||
521 | |||
522 | def test_gitfetch_premirror(self): | ||
523 | url1 = "git://git.openembedded.org/bitbake" | ||
524 | url2 = "git://someserver.org/bitbake" | ||
525 | self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n") | ||
526 | self.gitfetcher(url1, url2) | ||
527 | |||
528 | def test_gitfetch_premirror2(self): | ||
529 | url1 = url2 = "git://someserver.org/bitbake" | ||
530 | self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n") | ||
531 | self.gitfetcher(url1, url2) | ||
532 | |||
533 | def test_gitfetch_premirror3(self): | ||
534 | realurl = "git://git.openembedded.org/bitbake" | ||
535 | dummyurl = "git://someserver.org/bitbake" | ||
536 | self.sourcedir = self.unpackdir.replace("unpacked", "sourcemirror.git") | ||
537 | os.chdir(self.tempdir) | ||
538 | bb.process.run("git clone %s %s 2> /dev/null" % (realurl, self.sourcedir), shell=True) | ||
539 | self.d.setVar("PREMIRRORS", "%s git://%s;protocol=file \n" % (dummyurl, self.sourcedir)) | ||
540 | self.gitfetcher(dummyurl, dummyurl) | ||
541 | |||
542 | def test_git_submodule(self): | ||
543 | fetcher = bb.fetch.Fetch(["gitsm://git.yoctoproject.org/git-submodule-test;rev=f12e57f2edf0aa534cf1616fa983d165a92b0842"], self.d) | ||
544 | fetcher.download() | ||
545 | # Previous cwd has been deleted | ||
546 | os.chdir(os.path.dirname(self.unpackdir)) | ||
547 | fetcher.unpack(self.unpackdir) | ||
548 | |||
549 | class URLHandle(unittest.TestCase): | ||
550 | |||
551 | datatable = { | ||
552 | "http://www.google.com/index.html" : ('http', 'www.google.com', '/index.html', '', '', {}), | ||
553 | "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', '', {'module': 'familiar/dist/ipkg'}), | ||
554 | "cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg" : ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', 'anonymous', {'tag': 'V0-99-81', 'module': 'familiar/dist/ipkg'}), | ||
555 | "git://git.openembedded.org/bitbake;branch=@foo" : ('git', 'git.openembedded.org', '/bitbake', '', '', {'branch': '@foo'}) | ||
556 | } | ||
557 | |||
558 | def test_decodeurl(self): | ||
559 | for k, v in self.datatable.items(): | ||
560 | result = bb.fetch.decodeurl(k) | ||
561 | self.assertEqual(result, v) | ||
562 | |||
563 | def test_encodeurl(self): | ||
564 | for k, v in self.datatable.items(): | ||
565 | result = bb.fetch.encodeurl(v) | ||
566 | self.assertEqual(result, k) | ||
567 | |||
568 | |||
569 | |||