blob: 4ba688bfeadaf1a59e5a9dfc32dd374c98ee17d6 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# 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
22import unittest
23import tempfile
24import subprocess
25import os
26from bb.fetch2 import URI
27from bb.fetch2 import FetchMethod
28import bb
29
30class URITest(unittest.TestCase):
31 test_uris = {
32 "http://www.google.com/index.html" : {
33 'uri': 'http://www.google.com/index.html',
34 'scheme': 'http',
35 'hostname': 'www.google.com',
36 'port': None,
37 'hostport': 'www.google.com',
38 'path': '/index.html',
39 'userinfo': '',
40 'username': '',
41 'password': '',
42 'params': {},
43 'query': {},
44 'relative': False
45 },
46 "http://www.google.com/index.html;param1=value1" : {
47 'uri': 'http://www.google.com/index.html;param1=value1',
48 'scheme': 'http',
49 'hostname': 'www.google.com',
50 'port': None,
51 'hostport': 'www.google.com',
52 'path': '/index.html',
53 'userinfo': '',
54 'username': '',
55 'password': '',
56 'params': {
57 'param1': 'value1'
58 },
59 'query': {},
60 'relative': False
61 },
62 "http://www.example.org/index.html?param1=value1" : {
63 'uri': 'http://www.example.org/index.html?param1=value1',
64 'scheme': 'http',
65 'hostname': 'www.example.org',
66 'port': None,
67 'hostport': 'www.example.org',
68 'path': '/index.html',
69 'userinfo': '',
70 'username': '',
71 'password': '',
72 'params': {},
73 'query': {
74 'param1': 'value1'
75 },
76 'relative': False
77 },
78 "http://www.example.org/index.html?qparam1=qvalue1;param2=value2" : {
79 'uri': 'http://www.example.org/index.html?qparam1=qvalue1;param2=value2',
80 'scheme': 'http',
81 'hostname': 'www.example.org',
82 'port': None,
83 'hostport': 'www.example.org',
84 'path': '/index.html',
85 'userinfo': '',
86 'username': '',
87 'password': '',
88 'params': {
89 'param2': 'value2'
90 },
91 'query': {
92 'qparam1': 'qvalue1'
93 },
94 'relative': False
95 },
96 "http://www.example.com:8080/index.html" : {
97 'uri': 'http://www.example.com:8080/index.html',
98 'scheme': 'http',
99 'hostname': 'www.example.com',
100 'port': 8080,
101 'hostport': 'www.example.com:8080',
102 'path': '/index.html',
103 'userinfo': '',
104 'username': '',
105 'password': '',
106 'params': {},
107 'query': {},
108 'relative': False
109 },
110 "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : {
111 'uri': 'cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg',
112 'scheme': 'cvs',
113 'hostname': 'cvs.handhelds.org',
114 'port': None,
115 'hostport': 'cvs.handhelds.org',
116 'path': '/cvs',
117 'userinfo': 'anoncvs',
118 'username': 'anoncvs',
119 'password': '',
120 'params': {
121 'module': 'familiar/dist/ipkg'
122 },
123 'query': {},
124 'relative': False
125 },
126 "cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg": {
127 'uri': 'cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg',
128 'scheme': 'cvs',
129 'hostname': 'cvs.handhelds.org',
130 'port': None,
131 'hostport': 'cvs.handhelds.org',
132 'path': '/cvs',
133 'userinfo': 'anoncvs:anonymous',
134 'username': 'anoncvs',
135 'password': 'anonymous',
136 'params': {
137 'tag': 'V0-99-81',
138 'module': 'familiar/dist/ipkg'
139 },
140 'query': {},
141 'relative': False
142 },
143 "file://example.diff": { # NOTE: Not RFC compliant!
144 'uri': 'file:example.diff',
145 'scheme': 'file',
146 'hostname': '',
147 'port': None,
148 'hostport': '',
149 'path': 'example.diff',
150 'userinfo': '',
151 'username': '',
152 'password': '',
153 'params': {},
154 'query': {},
155 'relative': True
156 },
157 "file:example.diff": { # NOTE: RFC compliant version of the former
158 'uri': 'file:example.diff',
159 'scheme': 'file',
160 'hostname': '',
161 'port': None,
162 'hostport': '',
163 'path': 'example.diff',
164 'userinfo': '',
165 'userinfo': '',
166 'username': '',
167 'password': '',
168 'params': {},
169 'query': {},
170 'relative': True
171 },
172 "file:///tmp/example.diff": {
173 'uri': 'file:///tmp/example.diff',
174 'scheme': 'file',
175 'hostname': '',
176 'port': None,
177 'hostport': '',
178 'path': '/tmp/example.diff',
179 'userinfo': '',
180 'userinfo': '',
181 'username': '',
182 'password': '',
183 'params': {},
184 'query': {},
185 'relative': False
186 },
187 "git:///path/example.git": {
188 'uri': 'git:///path/example.git',
189 'scheme': 'git',
190 'hostname': '',
191 'port': None,
192 'hostport': '',
193 'path': '/path/example.git',
194 'userinfo': '',
195 'userinfo': '',
196 'username': '',
197 'password': '',
198 'params': {},
199 'query': {},
200 'relative': False
201 },
202 "git:path/example.git": {
203 'uri': 'git:path/example.git',
204 'scheme': 'git',
205 'hostname': '',
206 'port': None,
207 'hostport': '',
208 'path': 'path/example.git',
209 'userinfo': '',
210 'userinfo': '',
211 'username': '',
212 'password': '',
213 'params': {},
214 'query': {},
215 'relative': True
216 },
217 "git://example.net/path/example.git": {
218 'uri': 'git://example.net/path/example.git',
219 'scheme': 'git',
220 'hostname': 'example.net',
221 'port': None,
222 'hostport': 'example.net',
223 'path': '/path/example.git',
224 'userinfo': '',
225 'userinfo': '',
226 'username': '',
227 'password': '',
228 'params': {},
229 'query': {},
230 'relative': False
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500231 },
232 "http://somesite.net;someparam=1": {
233 'uri': 'http://somesite.net;someparam=1',
234 'scheme': 'http',
235 'hostname': 'somesite.net',
236 'port': None,
237 'hostport': 'somesite.net',
238 'path': '',
239 'userinfo': '',
240 'userinfo': '',
241 'username': '',
242 'password': '',
243 'params': {"someparam" : "1"},
244 'query': {},
245 'relative': False
246 },
247 "file://somelocation;someparam=1": {
248 'uri': 'file:somelocation;someparam=1',
249 'scheme': 'file',
250 'hostname': '',
251 'port': None,
252 'hostport': '',
253 'path': 'somelocation',
254 'userinfo': '',
255 'userinfo': '',
256 'username': '',
257 'password': '',
258 'params': {"someparam" : "1"},
259 'query': {},
260 'relative': True
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500261 }
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500262
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500263 }
264
265 def test_uri(self):
266 for test_uri, ref in self.test_uris.items():
267 uri = URI(test_uri)
268
269 self.assertEqual(str(uri), ref['uri'])
270
271 # expected attributes
272 self.assertEqual(uri.scheme, ref['scheme'])
273
274 self.assertEqual(uri.userinfo, ref['userinfo'])
275 self.assertEqual(uri.username, ref['username'])
276 self.assertEqual(uri.password, ref['password'])
277
278 self.assertEqual(uri.hostname, ref['hostname'])
279 self.assertEqual(uri.port, ref['port'])
280 self.assertEqual(uri.hostport, ref['hostport'])
281
282 self.assertEqual(uri.path, ref['path'])
283 self.assertEqual(uri.params, ref['params'])
284
285 self.assertEqual(uri.relative, ref['relative'])
286
287 def test_dict(self):
288 for test in self.test_uris.values():
289 uri = URI()
290
291 self.assertEqual(uri.scheme, '')
292 self.assertEqual(uri.userinfo, '')
293 self.assertEqual(uri.username, '')
294 self.assertEqual(uri.password, '')
295 self.assertEqual(uri.hostname, '')
296 self.assertEqual(uri.port, None)
297 self.assertEqual(uri.path, '')
298 self.assertEqual(uri.params, {})
299
300
301 uri.scheme = test['scheme']
302 self.assertEqual(uri.scheme, test['scheme'])
303
304 uri.userinfo = test['userinfo']
305 self.assertEqual(uri.userinfo, test['userinfo'])
306 self.assertEqual(uri.username, test['username'])
307 self.assertEqual(uri.password, test['password'])
308
309 # make sure changing the values doesn't do anything unexpected
310 uri.username = 'changeme'
311 self.assertEqual(uri.username, 'changeme')
312 self.assertEqual(uri.password, test['password'])
313 uri.password = 'insecure'
314 self.assertEqual(uri.username, 'changeme')
315 self.assertEqual(uri.password, 'insecure')
316
317 # reset back after our trickery
318 uri.userinfo = test['userinfo']
319 self.assertEqual(uri.userinfo, test['userinfo'])
320 self.assertEqual(uri.username, test['username'])
321 self.assertEqual(uri.password, test['password'])
322
323 uri.hostname = test['hostname']
324 self.assertEqual(uri.hostname, test['hostname'])
325 self.assertEqual(uri.hostport, test['hostname'])
326
327 uri.port = test['port']
328 self.assertEqual(uri.port, test['port'])
329 self.assertEqual(uri.hostport, test['hostport'])
330
331 uri.path = test['path']
332 self.assertEqual(uri.path, test['path'])
333
334 uri.params = test['params']
335 self.assertEqual(uri.params, test['params'])
336
337 uri.query = test['query']
338 self.assertEqual(uri.query, test['query'])
339
340 self.assertEqual(str(uri), test['uri'])
341
342 uri.params = {}
343 self.assertEqual(uri.params, {})
344 self.assertEqual(str(uri), (str(uri).split(";"))[0])
345
346class FetcherTest(unittest.TestCase):
347
348 def setUp(self):
349 self.origdir = os.getcwd()
350 self.d = bb.data.init()
351 self.tempdir = tempfile.mkdtemp()
352 self.dldir = os.path.join(self.tempdir, "download")
353 os.mkdir(self.dldir)
354 self.d.setVar("DL_DIR", self.dldir)
355 self.unpackdir = os.path.join(self.tempdir, "unpacked")
356 os.mkdir(self.unpackdir)
357 persistdir = os.path.join(self.tempdir, "persistdata")
358 self.d.setVar("PERSISTENT_DIR", persistdir)
359
360 def tearDown(self):
361 os.chdir(self.origdir)
362 bb.utils.prunedir(self.tempdir)
363
364class MirrorUriTest(FetcherTest):
365
366 replaceuris = {
367 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "http://somewhere.org/somedir/")
368 : "http://somewhere.org/somedir/git2_git.invalid.infradead.org.mtd-utils.git.tar.gz",
369 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http")
370 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
371 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http")
372 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
373 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/\\2;protocol=http")
374 : "git://somewhere.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
375 ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890", "git://someserver.org/bitbake", "git://git.openembedded.org/bitbake")
376 : "git://git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890",
377 ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache")
378 : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
379 ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache/")
380 : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
381 ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org/somedir3")
382 : "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz",
383 ("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")
384 : "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz",
385 ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://www.apache.org/dist", "http://archive.apache.org/dist")
386 : "http://archive.apache.org/dist/subversion/subversion-1.7.1.tar.bz2",
387 ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://.*/.*", "file:///somepath/downloads/")
388 : "file:///somepath/downloads/subversion-1.7.1.tar.bz2",
389 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http")
390 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
391 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http")
392 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
393 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/MIRRORNAME;protocol=http")
394 : "git://somewhere.org/somedir/git.invalid.infradead.org.foo.mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
395
396 #Renaming files doesn't work
397 #("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"
398 #("file://sstate-xyz.tgz", "file://.*/.*", "file:///somewhere/1234/sstate-cache") : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
399 }
400
401 mirrorvar = "http://.*/.* file:///somepath/downloads/ \n" \
402 "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n" \
403 "https://.*/.* file:///someotherpath/downloads/ \n" \
404 "http://.*/.* file:///someotherpath/downloads/ \n"
405
406 def test_urireplace(self):
407 for k, v in self.replaceuris.items():
408 ud = bb.fetch.FetchData(k[0], self.d)
409 ud.setup_localpath(self.d)
410 mirrors = bb.fetch2.mirror_from_string("%s %s" % (k[1], k[2]))
411 newuris, uds = bb.fetch2.build_mirroruris(ud, mirrors, self.d)
412 self.assertEqual([v], newuris)
413
414 def test_urilist1(self):
415 fetcher = bb.fetch.FetchData("http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
416 mirrors = bb.fetch2.mirror_from_string(self.mirrorvar)
417 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
418 self.assertEqual(uris, ['file:///somepath/downloads/bitbake-1.0.tar.gz', 'file:///someotherpath/downloads/bitbake-1.0.tar.gz'])
419
420 def test_urilist2(self):
421 # Catch https:// -> files:// bug
422 fetcher = bb.fetch.FetchData("https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
423 mirrors = bb.fetch2.mirror_from_string(self.mirrorvar)
424 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
425 self.assertEqual(uris, ['file:///someotherpath/downloads/bitbake-1.0.tar.gz'])
426
427 def test_mirror_of_mirror(self):
428 # Test if mirror of a mirror works
429 mirrorvar = self.mirrorvar + " http://.*/.* http://otherdownloads.yoctoproject.org/downloads/ \n"
430 mirrorvar = mirrorvar + " http://otherdownloads.yoctoproject.org/.* http://downloads2.yoctoproject.org/downloads/ \n"
431 fetcher = bb.fetch.FetchData("http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
432 mirrors = bb.fetch2.mirror_from_string(mirrorvar)
433 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
434 self.assertEqual(uris, ['file:///somepath/downloads/bitbake-1.0.tar.gz',
435 'file:///someotherpath/downloads/bitbake-1.0.tar.gz',
436 'http://otherdownloads.yoctoproject.org/downloads/bitbake-1.0.tar.gz',
437 'http://downloads2.yoctoproject.org/downloads/bitbake-1.0.tar.gz'])
438
Patrick Williamsd7e96312015-09-22 08:09:05 -0500439 recmirrorvar = "https://.*/[^/]* http://AAAA/A/A/A/ \n" \
440 "https://.*/[^/]* https://BBBB/B/B/B/ \n"
441
442 def test_recursive(self):
443 fetcher = bb.fetch.FetchData("https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
444 mirrors = bb.fetch2.mirror_from_string(self.recmirrorvar)
445 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
446 self.assertEqual(uris, ['http://AAAA/A/A/A/bitbake/bitbake-1.0.tar.gz',
447 'https://BBBB/B/B/B/bitbake/bitbake-1.0.tar.gz',
448 'http://AAAA/A/A/A/B/B/bitbake/bitbake-1.0.tar.gz'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500449
450class FetcherLocalTest(FetcherTest):
451 def setUp(self):
452 def touch(fn):
453 with file(fn, 'a'):
454 os.utime(fn, None)
455
456 super(FetcherLocalTest, self).setUp()
457 self.localsrcdir = os.path.join(self.tempdir, 'localsrc')
458 os.makedirs(self.localsrcdir)
459 touch(os.path.join(self.localsrcdir, 'a'))
460 touch(os.path.join(self.localsrcdir, 'b'))
461 os.makedirs(os.path.join(self.localsrcdir, 'dir'))
462 touch(os.path.join(self.localsrcdir, 'dir', 'c'))
463 touch(os.path.join(self.localsrcdir, 'dir', 'd'))
464 os.makedirs(os.path.join(self.localsrcdir, 'dir', 'subdir'))
465 touch(os.path.join(self.localsrcdir, 'dir', 'subdir', 'e'))
466 self.d.setVar("FILESPATH", self.localsrcdir)
467
468 def fetchUnpack(self, uris):
469 fetcher = bb.fetch.Fetch(uris, self.d)
470 fetcher.download()
471 fetcher.unpack(self.unpackdir)
472 flst = []
473 for root, dirs, files in os.walk(self.unpackdir):
474 for f in files:
475 flst.append(os.path.relpath(os.path.join(root, f), self.unpackdir))
476 flst.sort()
477 return flst
478
479 def test_local(self):
480 tree = self.fetchUnpack(['file://a', 'file://dir/c'])
481 self.assertEqual(tree, ['a', 'dir/c'])
482
483 def test_local_wildcard(self):
484 tree = self.fetchUnpack(['file://a', 'file://dir/*'])
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500485 self.assertEqual(tree, ['a', 'dir/c', 'dir/d', 'dir/subdir/e'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500486
487 def test_local_dir(self):
488 tree = self.fetchUnpack(['file://a', 'file://dir'])
489 self.assertEqual(tree, ['a', 'dir/c', 'dir/d', 'dir/subdir/e'])
490
491 def test_local_subdir(self):
492 tree = self.fetchUnpack(['file://dir/subdir'])
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500493 self.assertEqual(tree, ['dir/subdir/e'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500494
495 def test_local_subdir_file(self):
496 tree = self.fetchUnpack(['file://dir/subdir/e'])
497 self.assertEqual(tree, ['dir/subdir/e'])
498
499 def test_local_subdirparam(self):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500500 tree = self.fetchUnpack(['file://a;subdir=bar', 'file://dir;subdir=foo/moo'])
501 self.assertEqual(tree, ['bar/a', 'foo/moo/dir/c', 'foo/moo/dir/d', 'foo/moo/dir/subdir/e'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500502
503 def test_local_deepsubdirparam(self):
504 tree = self.fetchUnpack(['file://dir/subdir/e;subdir=bar'])
505 self.assertEqual(tree, ['bar/dir/subdir/e'])
506
507class FetcherNetworkTest(FetcherTest):
508
509 if os.environ.get("BB_SKIP_NETTESTS") == "yes":
510 print("Unset BB_SKIP_NETTESTS to run network tests")
511 else:
512 def test_fetch(self):
513 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)
514 fetcher.download()
515 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
516 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.1.tar.gz"), 57892)
517 self.d.setVar("BB_NO_NETWORK", "1")
518 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)
519 fetcher.download()
520 fetcher.unpack(self.unpackdir)
521 self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.0/")), 9)
522 self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.1/")), 9)
523
524 def test_fetch_mirror(self):
525 self.d.setVar("MIRRORS", "http://.*/.* http://downloads.yoctoproject.org/releases/bitbake")
526 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
527 fetcher.download()
528 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
529
530 def test_fetch_mirror_of_mirror(self):
531 self.d.setVar("MIRRORS", "http://.*/.* http://invalid2.yoctoproject.org/ \n http://invalid2.yoctoproject.org/.* http://downloads.yoctoproject.org/releases/bitbake")
532 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
533 fetcher.download()
534 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
535
536 def test_fetch_file_mirror_of_mirror(self):
537 self.d.setVar("MIRRORS", "http://.*/.* file:///some1where/ \n file:///some1where/.* file://some2where/ \n file://some2where/.* http://downloads.yoctoproject.org/releases/bitbake")
538 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
539 os.mkdir(self.dldir + "/some2where")
540 fetcher.download()
541 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
542
543 def test_fetch_premirror(self):
544 self.d.setVar("PREMIRRORS", "http://.*/.* http://downloads.yoctoproject.org/releases/bitbake")
545 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
546 fetcher.download()
547 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
548
549 def gitfetcher(self, url1, url2):
550 def checkrevision(self, fetcher):
551 fetcher.unpack(self.unpackdir)
552 revision = bb.process.run("git rev-parse HEAD", shell=True, cwd=self.unpackdir + "/git")[0].strip()
553 self.assertEqual(revision, "270a05b0b4ba0959fe0624d2a4885d7b70426da5")
554
555 self.d.setVar("BB_GENERATE_MIRROR_TARBALLS", "1")
556 self.d.setVar("SRCREV", "270a05b0b4ba0959fe0624d2a4885d7b70426da5")
557 fetcher = bb.fetch.Fetch([url1], self.d)
558 fetcher.download()
559 checkrevision(self, fetcher)
560 # Wipe out the dldir clone and the unpacked source, turn off the network and check mirror tarball works
561 bb.utils.prunedir(self.dldir + "/git2/")
562 bb.utils.prunedir(self.unpackdir)
563 self.d.setVar("BB_NO_NETWORK", "1")
564 fetcher = bb.fetch.Fetch([url2], self.d)
565 fetcher.download()
566 checkrevision(self, fetcher)
567
568 def test_gitfetch(self):
569 url1 = url2 = "git://git.openembedded.org/bitbake"
570 self.gitfetcher(url1, url2)
571
572 def test_gitfetch_goodsrcrev(self):
573 # SRCREV is set but matches rev= parameter
574 url1 = url2 = "git://git.openembedded.org/bitbake;rev=270a05b0b4ba0959fe0624d2a4885d7b70426da5"
575 self.gitfetcher(url1, url2)
576
577 def test_gitfetch_badsrcrev(self):
578 # SRCREV is set but does not match rev= parameter
579 url1 = url2 = "git://git.openembedded.org/bitbake;rev=dead05b0b4ba0959fe0624d2a4885d7b70426da5"
580 self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2)
581
582 def test_gitfetch_tagandrev(self):
583 # SRCREV is set but does not match rev= parameter
584 url1 = url2 = "git://git.openembedded.org/bitbake;rev=270a05b0b4ba0959fe0624d2a4885d7b70426da5;tag=270a05b0b4ba0959fe0624d2a4885d7b70426da5"
585 self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2)
586
587 def test_gitfetch_premirror(self):
588 url1 = "git://git.openembedded.org/bitbake"
589 url2 = "git://someserver.org/bitbake"
590 self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n")
591 self.gitfetcher(url1, url2)
592
593 def test_gitfetch_premirror2(self):
594 url1 = url2 = "git://someserver.org/bitbake"
595 self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n")
596 self.gitfetcher(url1, url2)
597
598 def test_gitfetch_premirror3(self):
599 realurl = "git://git.openembedded.org/bitbake"
600 dummyurl = "git://someserver.org/bitbake"
601 self.sourcedir = self.unpackdir.replace("unpacked", "sourcemirror.git")
602 os.chdir(self.tempdir)
603 bb.process.run("git clone %s %s 2> /dev/null" % (realurl, self.sourcedir), shell=True)
604 self.d.setVar("PREMIRRORS", "%s git://%s;protocol=file \n" % (dummyurl, self.sourcedir))
605 self.gitfetcher(dummyurl, dummyurl)
606
607 def test_git_submodule(self):
608 fetcher = bb.fetch.Fetch(["gitsm://git.yoctoproject.org/git-submodule-test;rev=f12e57f2edf0aa534cf1616fa983d165a92b0842"], self.d)
609 fetcher.download()
610 # Previous cwd has been deleted
611 os.chdir(os.path.dirname(self.unpackdir))
612 fetcher.unpack(self.unpackdir)
613
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500614
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500615class TrustedNetworksTest(FetcherTest):
616 def test_trusted_network(self):
617 # Ensure trusted_network returns False when the host IS in the list.
618 url = "git://Someserver.org/foo;rev=1"
619 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org someserver.org server2.org server3.org")
620 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500621
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500622 def test_wild_trusted_network(self):
623 # Ensure trusted_network returns true when the *.host IS in the list.
624 url = "git://Someserver.org/foo;rev=1"
625 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
626 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500627
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500628 def test_prefix_wild_trusted_network(self):
629 # Ensure trusted_network returns true when the prefix matches *.host.
630 url = "git://git.Someserver.org/foo;rev=1"
631 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
632 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500633
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500634 def test_two_prefix_wild_trusted_network(self):
635 # Ensure trusted_network returns true when the prefix matches *.host.
636 url = "git://something.git.Someserver.org/foo;rev=1"
637 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
638 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500639
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500640 def test_port_trusted_network(self):
641 # Ensure trusted_network returns True, even if the url specifies a port.
642 url = "git://someserver.org:8080/foo;rev=1"
643 self.d.setVar("BB_ALLOWED_NETWORKS", "someserver.org")
644 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500645
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500646 def test_untrusted_network(self):
647 # Ensure trusted_network returns False when the host is NOT in the list.
648 url = "git://someserver.org/foo;rev=1"
649 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org")
650 self.assertFalse(bb.fetch.trusted_network(self.d, url))
651
652 def test_wild_untrusted_network(self):
653 # Ensure trusted_network returns False when the host is NOT in the list.
654 url = "git://*.someserver.org/foo;rev=1"
655 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org")
656 self.assertFalse(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500657
658class URLHandle(unittest.TestCase):
659
660 datatable = {
661 "http://www.google.com/index.html" : ('http', 'www.google.com', '/index.html', '', '', {}),
662 "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', '', {'module': 'familiar/dist/ipkg'}),
663 "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'}),
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500664 "git://git.openembedded.org/bitbake;branch=@foo" : ('git', 'git.openembedded.org', '/bitbake', '', '', {'branch': '@foo'}),
665 "file://somelocation;someparam=1": ('file', '', 'somelocation', '', '', {'someparam': '1'}),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500666 }
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500667 # we require a pathname to encodeurl but users can still pass such urls to
668 # decodeurl and we need to handle them
669 decodedata = datatable.copy()
670 decodedata.update({
671 "http://somesite.net;someparam=1": ('http', 'somesite.net', '', '', '', {'someparam': '1'}),
672 })
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500673
674 def test_decodeurl(self):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500675 for k, v in self.decodedata.items():
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500676 result = bb.fetch.decodeurl(k)
677 self.assertEqual(result, v)
678
679 def test_encodeurl(self):
680 for k, v in self.datatable.items():
681 result = bb.fetch.encodeurl(v)
682 self.assertEqual(result, k)
683
684class FetchLatestVersionTest(FetcherTest):
685
686 test_git_uris = {
687 # version pattern "X.Y.Z"
688 ("mx-1.0", "git://github.com/clutter-project/mx.git;branch=mx-1.4", "9b1db6b8060bd00b121a692f942404a24ae2960f", "")
689 : "1.99.4",
690 # version pattern "vX.Y"
691 ("mtd-utils", "git://git.infradead.org/mtd-utils.git", "ca39eb1d98e736109c64ff9c1aa2a6ecca222d8f", "")
692 : "1.5.0",
693 # version pattern "pkg_name-X.Y"
694 ("presentproto", "git://anongit.freedesktop.org/git/xorg/proto/presentproto", "24f3a56e541b0a9e6c6ee76081f441221a120ef9", "")
695 : "1.0",
696 # version pattern "pkg_name-vX.Y.Z"
697 ("dtc", "git://git.qemu.org/dtc.git", "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf", "")
698 : "1.4.0",
699 # combination version pattern
700 ("sysprof", "git://git.gnome.org/sysprof", "cd44ee6644c3641507fb53b8a2a69137f2971219", "")
701 : "1.2.0",
702 ("u-boot-mkimage", "git://git.denx.de/u-boot.git;branch=master;protocol=git", "62c175fbb8a0f9a926c88294ea9f7e88eb898f6c", "")
703 : "2014.01",
704 # version pattern "yyyymmdd"
705 ("mobile-broadband-provider-info", "git://git.gnome.org/mobile-broadband-provider-info", "4ed19e11c2975105b71b956440acdb25d46a347d", "")
706 : "20120614",
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500707 # packages with a valid UPSTREAM_CHECK_GITTAGREGEX
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500708 ("xf86-video-omap", "git://anongit.freedesktop.org/xorg/driver/xf86-video-omap", "ae0394e687f1a77e966cf72f895da91840dffb8f", "(?P<pver>(\d+\.(\d\.?)*))")
709 : "0.4.3",
710 ("build-appliance-image", "git://git.yoctoproject.org/poky", "b37dd451a52622d5b570183a81583cc34c2ff555", "(?P<pver>(([0-9][\.|_]?)+[0-9]))")
711 : "11.0.0",
712 ("chkconfig-alternatives-native", "git://github.com/kergoth/chkconfig;branch=sysroot", "cd437ecbd8986c894442f8fce1e0061e20f04dee", "chkconfig\-(?P<pver>((\d+[\.\-_]*)+))")
713 : "1.3.59",
714 ("remake", "git://github.com/rocky/remake.git", "f05508e521987c8494c92d9c2871aec46307d51d", "(?P<pver>(\d+\.(\d+\.)*\d*(\+dbg\d+(\.\d+)*)*))")
715 : "3.82+dbg0.9",
716 }
717
718 test_wget_uris = {
719 # packages with versions inside directory name
720 ("util-linux", "http://kernel.org/pub/linux/utils/util-linux/v2.23/util-linux-2.24.2.tar.bz2", "", "")
721 : "2.24.2",
722 ("enchant", "http://www.abisource.com/downloads/enchant/1.6.0/enchant-1.6.0.tar.gz", "", "")
723 : "1.6.0",
724 ("cmake", "http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz", "", "")
725 : "2.8.12.1",
726 # packages with versions only in current directory
727 ("eglic", "http://downloads.yoctoproject.org/releases/eglibc/eglibc-2.18-svnr23787.tar.bz2", "", "")
728 : "2.19",
729 ("gnu-config", "http://downloads.yoctoproject.org/releases/gnu-config/gnu-config-20120814.tar.bz2", "", "")
730 : "20120814",
731 # packages with "99" in the name of possible version
732 ("pulseaudio", "http://freedesktop.org/software/pulseaudio/releases/pulseaudio-4.0.tar.xz", "", "")
733 : "5.0",
734 ("xserver-xorg", "http://xorg.freedesktop.org/releases/individual/xserver/xorg-server-1.15.1.tar.bz2", "", "")
735 : "1.15.1",
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500736 # packages with valid UPSTREAM_CHECK_URI and UPSTREAM_CHECK_REGEX
737 ("cups", "http://www.cups.org/software/1.7.2/cups-1.7.2-source.tar.bz2", "https://github.com/apple/cups/releases", "(?P<name>cups\-)(?P<pver>((\d+[\.\-_]*)+))\-source\.tar\.gz")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500738 : "2.0.0",
739 ("db", "http://download.oracle.com/berkeley-db/db-5.3.21.tar.gz", "http://www.oracle.com/technetwork/products/berkeleydb/downloads/index-082944.html", "http://download.oracle.com/otn/berkeley-db/(?P<name>db-)(?P<pver>((\d+[\.\-_]*)+))\.tar\.gz")
740 : "6.1.19",
741 }
742 if os.environ.get("BB_SKIP_NETTESTS") == "yes":
743 print("Unset BB_SKIP_NETTESTS to run network tests")
744 else:
745 def test_git_latest_versionstring(self):
746 for k, v in self.test_git_uris.items():
747 self.d.setVar("PN", k[0])
748 self.d.setVar("SRCREV", k[2])
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500749 self.d.setVar("UPSTREAM_CHECK_GITTAGREGEX", k[3])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500750 ud = bb.fetch2.FetchData(k[1], self.d)
751 pupver= ud.method.latest_versionstring(ud, self.d)
752 verstring = pupver[0]
753 r = bb.utils.vercmp_string(v, verstring)
754 self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring))
755
756 def test_wget_latest_versionstring(self):
757 for k, v in self.test_wget_uris.items():
758 self.d.setVar("PN", k[0])
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500759 self.d.setVar("UPSTREAM_CHECK_URI", k[2])
760 self.d.setVar("UPSTREAM_CHECK_REGEX", k[3])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500761 ud = bb.fetch2.FetchData(k[1], self.d)
762 pupver = ud.method.latest_versionstring(ud, self.d)
763 verstring = pupver[0]
764 r = bb.utils.vercmp_string(v, verstring)
765 self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring))
766
767
768class FetchCheckStatusTest(FetcherTest):
769 test_wget_uris = ["http://www.cups.org/software/1.7.2/cups-1.7.2-source.tar.bz2",
770 "http://www.cups.org/software/ipptool/ipptool-20130731-linux-ubuntu-i686.tar.gz",
771 "http://www.cups.org/",
772 "http://downloads.yoctoproject.org/releases/sato/sato-engine-0.1.tar.gz",
773 "http://downloads.yoctoproject.org/releases/sato/sato-engine-0.2.tar.gz",
774 "http://downloads.yoctoproject.org/releases/sato/sato-engine-0.3.tar.gz",
775 "https://yoctoproject.org/",
776 "https://yoctoproject.org/documentation",
777 "http://downloads.yoctoproject.org/releases/opkg/opkg-0.1.7.tar.gz",
778 "http://downloads.yoctoproject.org/releases/opkg/opkg-0.3.0.tar.gz",
779 "ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.60.tar.gz",
780 "ftp://ftp.gnu.org/gnu/chess/gnuchess-5.08.tar.gz",
781 "ftp://ftp.gnu.org/gnu/gmp/gmp-4.0.tar.gz",
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500782 # GitHub releases are hosted on Amazon S3, which doesn't support HEAD
783 "https://github.com/kergoth/tslib/releases/download/1.1/tslib-1.1.tar.xz"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500784 ]
785
786 if os.environ.get("BB_SKIP_NETTESTS") == "yes":
787 print("Unset BB_SKIP_NETTESTS to run network tests")
788 else:
789
790 def test_wget_checkstatus(self):
791 fetch = bb.fetch2.Fetch(self.test_wget_uris, self.d)
792 for u in self.test_wget_uris:
793 ud = fetch.ud[u]
794 m = ud.method
795 ret = m.checkstatus(fetch, ud, self.d)
796 self.assertTrue(ret, msg="URI %s, can't check status" % (u))
797
798
799 def test_wget_checkstatus_connection_cache(self):
800 from bb.fetch2 import FetchConnectionCache
801
802 connection_cache = FetchConnectionCache()
803 fetch = bb.fetch2.Fetch(self.test_wget_uris, self.d,
804 connection_cache = connection_cache)
805
806 for u in self.test_wget_uris:
807 ud = fetch.ud[u]
808 m = ud.method
809 ret = m.checkstatus(fetch, ud, self.d)
810 self.assertTrue(ret, msg="URI %s, can't check status" % (u))
811
812 connection_cache.close_connections()