summaryrefslogtreecommitdiffstats
path: root/meta/lib/patchtest/tests/test_metadata.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/patchtest/tests/test_metadata.py')
-rw-r--r--meta/lib/patchtest/tests/test_metadata.py91
1 files changed, 61 insertions, 30 deletions
diff --git a/meta/lib/patchtest/tests/test_metadata.py b/meta/lib/patchtest/tests/test_metadata.py
index d7e5e187f6..2dee80b002 100644
--- a/meta/lib/patchtest/tests/test_metadata.py
+++ b/meta/lib/patchtest/tests/test_metadata.py
@@ -5,10 +5,14 @@
5# SPDX-License-Identifier: GPL-2.0-only 5# SPDX-License-Identifier: GPL-2.0-only
6 6
7import base 7import base
8import collections
8import os 9import os
9import patterns 10import patchtest_patterns
10import pyparsing 11import pyparsing
11from data import PatchTestInput, PatchTestDataStore 12from patchtest_parser import PatchtestParser
13
14# Data store commonly used to share values between pre and post-merge tests
15PatchTestDataStore = collections.defaultdict(str)
12 16
13class TestMetadata(base.Metadata): 17class TestMetadata(base.Metadata):
14 18
@@ -25,13 +29,13 @@ class TestMetadata(base.Metadata):
25 open_flag = 'a' 29 open_flag = 'a'
26 with open(auto_conf, open_flag) as fd: 30 with open(auto_conf, open_flag) as fd:
27 for pn in self.added: 31 for pn in self.added:
28 fd.write('LICENSE ??= "%s"\n' % patterns.invalid_license) 32 fd.write('LICENSE ??= "%s"\n' % patchtest_patterns.invalid_license)
29 33
30 no_license = False 34 no_license = False
31 for pn in self.added: 35 for pn in self.added:
32 rd = self.tinfoil.parse_recipe(pn) 36 rd = self.tinfoil.parse_recipe(pn)
33 license = rd.getVar(patterns.metadata_lic) 37 license = rd.getVar(patchtest_patterns.metadata_lic)
34 if license == patterns.invalid_license: 38 if license == patchtest_patterns.invalid_license:
35 no_license = True 39 no_license = True
36 break 40 break
37 41
@@ -58,11 +62,13 @@ class TestMetadata(base.Metadata):
58 # we are not interested in images 62 # we are not interested in images
59 if '/images/' in pathname: 63 if '/images/' in pathname:
60 continue 64 continue
61 lic_files_chksum = rd.getVar(patterns.metadata_chksum) 65 lic_files_chksum = rd.getVar(patchtest_patterns.metadata_chksum)
62 if rd.getVar(patterns.license_var) == patterns.closed: 66 if rd.getVar(patchtest_patterns.license_var) == patchtest_patterns.closed:
63 continue 67 continue
64 if not lic_files_chksum: 68 if not lic_files_chksum:
65 self.fail('%s is missing in newly added recipe' % patterns.metadata_chksum) 69 self.fail(
70 "%s is missing in newly added recipe" % patchtest_patterns.metadata_chksum
71 )
66 72
67 def test_lic_files_chksum_modified_not_mentioned(self): 73 def test_lic_files_chksum_modified_not_mentioned(self):
68 if not self.modified: 74 if not self.modified:
@@ -73,11 +79,13 @@ class TestMetadata(base.Metadata):
73 if patch.path.endswith('.patch'): 79 if patch.path.endswith('.patch'):
74 continue 80 continue
75 payload = str(patch) 81 payload = str(patch)
76 if (patterns.lic_chksum_added.search_string(payload) or patterns.lic_chksum_removed.search_string(payload)): 82 if patchtest_patterns.lic_chksum_added.search_string(
83 payload
84 ) or patchtest_patterns.lic_chksum_removed.search_string(payload):
77 # if any patch on the series contain reference on the metadata, fail 85 # if any patch on the series contain reference on the metadata, fail
78 for commit in self.commits: 86 for commit in self.commits:
79 if patterns.lictag_re.search_string(commit.commit_message): 87 if patchtest_patterns.lictag_re.search_string(commit.commit_message):
80 break 88 break
81 else: 89 else:
82 self.fail('LIC_FILES_CHKSUM changed without "License-Update:" tag and description in commit message') 90 self.fail('LIC_FILES_CHKSUM changed without "License-Update:" tag and description in commit message')
83 91
@@ -88,16 +96,22 @@ class TestMetadata(base.Metadata):
88 continue 96 continue
89 payload = str(patch) 97 payload = str(patch)
90 for line in payload.splitlines(): 98 for line in payload.splitlines():
91 if patterns.add_mark.search_string(line): 99 if patchtest_patterns.add_mark.search_string(line):
92 current_line_length = len(line[1:]) 100 current_line_length = len(line[1:])
93 if current_line_length > patterns.patch_max_line_length: 101 if current_line_length > patchtest_patterns.patch_max_line_length:
94 self.fail('Patch line too long (current length %s, maximum is %s)' % (current_line_length, patterns.patch_max_line_length), 102 self.fail(
95 data=[('Patch', patch.path), ('Line', '%s ...' % line[0:80])]) 103 "Patch line too long (current length %s, maximum is %s)"
104 % (current_line_length, patchtest_patterns.patch_max_line_length),
105 data=[
106 ("Patch", patch.path),
107 ("Line", "%s ..." % line[0:80]),
108 ],
109 )
96 110
97 def pretest_src_uri_left_files(self): 111 def pretest_src_uri_left_files(self):
98 # these tests just make sense on patches that can be merged 112 # these tests just make sense on patches that can be merged
99 if not PatchTestInput.repo.canbemerged: 113 if not PatchtestParser.repo.canbemerged:
100 self.skip('Patch cannot be merged') 114 self.skip("Patch cannot be merged")
101 if not self.modified: 115 if not self.modified:
102 self.skip('No modified recipes, skipping pretest') 116 self.skip('No modified recipes, skipping pretest')
103 117
@@ -107,12 +121,14 @@ class TestMetadata(base.Metadata):
107 if 'core-image' in pn: 121 if 'core-image' in pn:
108 continue 122 continue
109 rd = self.tinfoil.parse_recipe(pn) 123 rd = self.tinfoil.parse_recipe(pn)
110 PatchTestDataStore['%s-%s-%s' % (self.shortid(), patterns.metadata_src_uri, pn)] = rd.getVar(patterns.metadata_src_uri) 124 PatchTestDataStore[
125 "%s-%s-%s" % (self.shortid(), patchtest_patterns.metadata_src_uri, pn)
126 ] = rd.getVar(patchtest_patterns.metadata_src_uri)
111 127
112 def test_src_uri_left_files(self): 128 def test_src_uri_left_files(self):
113 # these tests just make sense on patches that can be merged 129 # these tests just make sense on patches that can be merged
114 if not PatchTestInput.repo.canbemerged: 130 if not PatchtestParser.repo.canbemerged:
115 self.skip('Patch cannot be merged') 131 self.skip("Patch cannot be merged")
116 if not self.modified: 132 if not self.modified:
117 self.skip('No modified recipes, skipping pretest') 133 self.skip('No modified recipes, skipping pretest')
118 134
@@ -122,11 +138,17 @@ class TestMetadata(base.Metadata):
122 if 'core-image' in pn: 138 if 'core-image' in pn:
123 continue 139 continue
124 rd = self.tinfoil.parse_recipe(pn) 140 rd = self.tinfoil.parse_recipe(pn)
125 PatchTestDataStore['%s-%s-%s' % (self.shortid(), patterns.metadata_src_uri, pn)] = rd.getVar(patterns.metadata_src_uri) 141 PatchTestDataStore[
142 "%s-%s-%s" % (self.shortid(), patchtest_patterns.metadata_src_uri, pn)
143 ] = rd.getVar(patchtest_patterns.metadata_src_uri)
126 144
127 for pn in self.modified: 145 for pn in self.modified:
128 pretest_src_uri = PatchTestDataStore['pre%s-%s-%s' % (self.shortid(), patterns.metadata_src_uri, pn)].split() 146 pretest_src_uri = PatchTestDataStore[
129 test_src_uri = PatchTestDataStore['%s-%s-%s' % (self.shortid(), patterns.metadata_src_uri, pn)].split() 147 "pre%s-%s-%s" % (self.shortid(), patchtest_patterns.metadata_src_uri, pn)
148 ].split()
149 test_src_uri = PatchTestDataStore[
150 "%s-%s-%s" % (self.shortid(), patchtest_patterns.metadata_src_uri, pn)
151 ].split()
130 152
131 pretest_files = set([os.path.basename(patch) for patch in pretest_src_uri if patch.startswith('file://')]) 153 pretest_files = set([os.path.basename(patch) for patch in pretest_src_uri if patch.startswith('file://')])
132 test_files = set([os.path.basename(patch) for patch in test_src_uri if patch.startswith('file://')]) 154 test_files = set([os.path.basename(patch) for patch in test_src_uri if patch.startswith('file://')])
@@ -159,23 +181,32 @@ class TestMetadata(base.Metadata):
159 if 'core-image' in pn: 181 if 'core-image' in pn:
160 continue 182 continue
161 rd = self.tinfoil.parse_recipe(pn) 183 rd = self.tinfoil.parse_recipe(pn)
162 summary = rd.getVar(patterns.metadata_summary) 184 summary = rd.getVar(patchtest_patterns.metadata_summary)
163 185
164 # "${PN} version ${PN}-${PR}" is the default, so fail if default 186 # "${PN} version ${PN}-${PR}" is the default, so fail if default
165 if summary.startswith('%s version' % pn): 187 if summary.startswith("%s version" % pn):
166 self.fail('%s is missing in newly added recipe' % patterns.metadata_summary) 188 self.fail(
189 "%s is missing in newly added recipe" % patchtest_patterns.metadata_summary
190 )
167 191
168 def test_cve_check_ignore(self): 192 def test_cve_check_ignore(self):
169 # Skip if we neither modified a recipe or target branches are not 193 # Skip if we neither modified a recipe or target branches are not
170 # Nanbield and newer. CVE_CHECK_IGNORE was first deprecated in Nanbield. 194 # Nanbield and newer. CVE_CHECK_IGNORE was first deprecated in Nanbield.
171 if not self.modified or PatchTestInput.repo.patch.branch == "kirkstone" or PatchTestInput.repo.patch.branch == "dunfell": 195 if (
172 self.skip('No modified recipes or older target branch, skipping test') 196 not self.modified
197 or PatchtestParser.repo.patch.branch == "kirkstone"
198 or PatchtestParser.repo.patch.branch == "dunfell"
199 ):
200 self.skip("No modified recipes or older target branch, skipping test")
173 for pn in self.modified: 201 for pn in self.modified:
174 # we are not interested in images 202 # we are not interested in images
175 if 'core-image' in pn: 203 if 'core-image' in pn:
176 continue 204 continue
177 rd = self.tinfoil.parse_recipe(pn) 205 rd = self.tinfoil.parse_recipe(pn)
178 cve_check_ignore = rd.getVar(patterns.cve_check_ignore_var) 206 cve_check_ignore = rd.getVar(patchtest_patterns.cve_check_ignore_var)
179 207
180 if cve_check_ignore is not None: 208 if cve_check_ignore is not None:
181 self.fail('%s is deprecated and should be replaced by %s' % (patterns.cve_check_ignore_var, patterns.cve_status_var)) 209 self.fail(
210 "%s is deprecated and should be replaced by %s"
211 % (patchtest_patterns.cve_check_ignore_var, patchtest_patterns.cve_status_var)
212 )