diff options
Diffstat (limited to 'meta/lib/patchtest/tests/test_metadata_src_uri.py')
-rw-r--r-- | meta/lib/patchtest/tests/test_metadata_src_uri.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/meta/lib/patchtest/tests/test_metadata_src_uri.py b/meta/lib/patchtest/tests/test_metadata_src_uri.py new file mode 100644 index 0000000000..718229d7ad --- /dev/null +++ b/meta/lib/patchtest/tests/test_metadata_src_uri.py | |||
@@ -0,0 +1,75 @@ | |||
1 | # Checks related to the patch's SRC_URI metadata variable | ||
2 | # | ||
3 | # Copyright (C) 2016 Intel Corporation | ||
4 | # | ||
5 | # SPDX-License-Identifier: GPL-2.0 | ||
6 | |||
7 | import subprocess | ||
8 | import base | ||
9 | import re | ||
10 | import os | ||
11 | from data import PatchTestInput, PatchTestDataStore | ||
12 | |||
13 | class SrcUri(base.Metadata): | ||
14 | |||
15 | metadata = 'SRC_URI' | ||
16 | md5sum = 'md5sum' | ||
17 | sha256sum = 'sha256sum' | ||
18 | git_regex = re.compile('^git\:\/\/.*') | ||
19 | |||
20 | def setUp(self): | ||
21 | # these tests just make sense on patches that can be merged | ||
22 | if not PatchTestInput.repo.canbemerged: | ||
23 | self.skip('Patch cannot be merged') | ||
24 | |||
25 | def pretest_src_uri_left_files(self): | ||
26 | if not self.modified: | ||
27 | self.skip('No modified recipes, skipping pretest') | ||
28 | |||
29 | # get the proper metadata values | ||
30 | for pn in self.modified: | ||
31 | # we are not interested in images | ||
32 | if 'core-image' in pn: | ||
33 | continue | ||
34 | rd = self.tinfoil.parse_recipe(pn) | ||
35 | PatchTestDataStore['%s-%s-%s' % (self.shortid(), self.metadata, pn)] = rd.getVar(self.metadata) | ||
36 | |||
37 | def test_src_uri_left_files(self): | ||
38 | if not self.modified: | ||
39 | self.skip('No modified recipes, skipping pretest') | ||
40 | |||
41 | # get the proper metadata values | ||
42 | for pn in self.modified: | ||
43 | # we are not interested in images | ||
44 | if 'core-image' in pn: | ||
45 | continue | ||
46 | rd = self.tinfoil.parse_recipe(pn) | ||
47 | PatchTestDataStore['%s-%s-%s' % (self.shortid(), self.metadata, pn)] = rd.getVar(self.metadata) | ||
48 | |||
49 | for pn in self.modified: | ||
50 | pretest_src_uri = PatchTestDataStore['pre%s-%s-%s' % (self.shortid(), self.metadata, pn)].split() | ||
51 | test_src_uri = PatchTestDataStore['%s-%s-%s' % (self.shortid(), self.metadata, pn)].split() | ||
52 | |||
53 | pretest_files = set([os.path.basename(patch) for patch in pretest_src_uri if patch.startswith('file://')]) | ||
54 | test_files = set([os.path.basename(patch) for patch in test_src_uri if patch.startswith('file://')]) | ||
55 | |||
56 | # check if files were removed | ||
57 | if len(test_files) < len(pretest_files): | ||
58 | |||
59 | # get removals from patchset | ||
60 | filesremoved_from_patchset = set() | ||
61 | for patch in self.patchset: | ||
62 | if patch.is_removed_file: | ||
63 | filesremoved_from_patchset.add(os.path.basename(patch.path)) | ||
64 | |||
65 | # get the deleted files from the SRC_URI | ||
66 | filesremoved_from_usr_uri = pretest_files - test_files | ||
67 | |||
68 | # finally, get those patches removed at SRC_URI and not removed from the patchset | ||
69 | # TODO: we are not taking into account renames, so test may raise false positives | ||
70 | not_removed = filesremoved_from_usr_uri - filesremoved_from_patchset | ||
71 | if not_removed: | ||
72 | self.fail('Patches not removed from tree', | ||
73 | 'Amend the patch containing the software patch file removal', | ||
74 | data=[('Patch', f) for f in not_removed]) | ||
75 | |||