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.py56
1 files changed, 20 insertions, 36 deletions
diff --git a/meta/lib/patchtest/tests/test_metadata.py b/meta/lib/patchtest/tests/test_metadata.py
index f5dbcf01ed..8c2305a184 100644
--- a/meta/lib/patchtest/tests/test_metadata.py
+++ b/meta/lib/patchtest/tests/test_metadata.py
@@ -6,27 +6,11 @@
6 6
7import base 7import base
8import os 8import os
9import patterns
9import pyparsing 10import pyparsing
10from data import PatchTestInput, PatchTestDataStore 11from data import PatchTestInput, PatchTestDataStore
11 12
12class TestMetadata(base.Metadata): 13class TestMetadata(base.Metadata):
13 metadata_lic = 'LICENSE'
14 invalid_license = 'PATCHTESTINVALID'
15 metadata_chksum = 'LIC_FILES_CHKSUM'
16 license_var = 'LICENSE'
17 closed = 'CLOSED'
18 lictag_re = pyparsing.AtLineStart("License-Update:")
19 lic_chksum_added = pyparsing.AtLineStart("+" + metadata_chksum)
20 lic_chksum_removed = pyparsing.AtLineStart("-" + metadata_chksum)
21 add_mark = pyparsing.Regex('\\+ ')
22 max_length = 200
23 metadata_src_uri = 'SRC_URI'
24 md5sum = 'md5sum'
25 sha256sum = 'sha256sum'
26 git_regex = pyparsing.Regex('^git\\:\\/\\/.*')
27 metadata_summary = 'SUMMARY'
28 cve_check_ignore_var = 'CVE_CHECK_IGNORE'
29 cve_status_var = 'CVE_STATUS'
30 14
31 def test_license_presence(self): 15 def test_license_presence(self):
32 if not self.added: 16 if not self.added:
@@ -41,13 +25,13 @@ class TestMetadata(base.Metadata):
41 open_flag = 'a' 25 open_flag = 'a'
42 with open(auto_conf, open_flag) as fd: 26 with open(auto_conf, open_flag) as fd:
43 for pn in self.added: 27 for pn in self.added:
44 fd.write('LICENSE ??= "%s"\n' % self.invalid_license) 28 fd.write('LICENSE ??= "%s"\n' % patterns.invalid_license)
45 29
46 no_license = False 30 no_license = False
47 for pn in self.added: 31 for pn in self.added:
48 rd = self.tinfoil.parse_recipe(pn) 32 rd = self.tinfoil.parse_recipe(pn)
49 license = rd.getVar(self.metadata_lic) 33 license = rd.getVar(patterns.metadata_lic)
50 if license == self.invalid_license: 34 if license == patterns.invalid_license:
51 no_license = True 35 no_license = True
52 break 36 break
53 37
@@ -74,11 +58,11 @@ class TestMetadata(base.Metadata):
74 # we are not interested in images 58 # we are not interested in images
75 if '/images/' in pathname: 59 if '/images/' in pathname:
76 continue 60 continue
77 lic_files_chksum = rd.getVar(self.metadata_chksum) 61 lic_files_chksum = rd.getVar(patterns.metadata_chksum)
78 if rd.getVar(self.license_var) == self.closed: 62 if rd.getVar(patterns.license_var) == patterns.closed:
79 continue 63 continue
80 if not lic_files_chksum: 64 if not lic_files_chksum:
81 self.fail('%s is missing in newly added recipe' % self.metadata_chksum) 65 self.fail('%s is missing in newly added recipe' % patterns.metadata_chksum)
82 66
83 def test_lic_files_chksum_modified_not_mentioned(self): 67 def test_lic_files_chksum_modified_not_mentioned(self):
84 if not self.modified: 68 if not self.modified:
@@ -89,10 +73,10 @@ class TestMetadata(base.Metadata):
89 if patch.path.endswith('.patch'): 73 if patch.path.endswith('.patch'):
90 continue 74 continue
91 payload = str(patch) 75 payload = str(patch)
92 if (self.lic_chksum_added.search_string(payload) or self.lic_chksum_removed.search_string(payload)): 76 if (patterns.lic_chksum_added.search_string(payload) or patterns.lic_chksum_removed.search_string(payload)):
93 # if any patch on the series contain reference on the metadata, fail 77 # if any patch on the series contain reference on the metadata, fail
94 for commit in self.commits: 78 for commit in self.commits:
95 if self.lictag_re.search_string(commit.commit_message): 79 if patterns.lictag_re.search_string(commit.commit_message):
96 break 80 break
97 else: 81 else:
98 self.fail('LIC_FILES_CHKSUM changed without "License-Update:" tag and description in commit message') 82 self.fail('LIC_FILES_CHKSUM changed without "License-Update:" tag and description in commit message')
@@ -104,10 +88,10 @@ class TestMetadata(base.Metadata):
104 continue 88 continue
105 payload = str(patch) 89 payload = str(patch)
106 for line in payload.splitlines(): 90 for line in payload.splitlines():
107 if self.add_mark.search_string(line): 91 if patterns.add_mark.search_string(line):
108 current_line_length = len(line[1:]) 92 current_line_length = len(line[1:])
109 if current_line_length > self.max_length: 93 if current_line_length > patterns.patch_max_line_length:
110 self.fail('Patch line too long (current length %s, maximum is %s)' % (current_line_length, self.max_length), 94 self.fail('Patch line too long (current length %s, maximum is %s)' % (current_line_length, patterns.patch_max_line_length),
111 data=[('Patch', patch.path), ('Line', '%s ...' % line[0:80])]) 95 data=[('Patch', patch.path), ('Line', '%s ...' % line[0:80])])
112 96
113 def pretest_src_uri_left_files(self): 97 def pretest_src_uri_left_files(self):
@@ -123,7 +107,7 @@ class TestMetadata(base.Metadata):
123 if 'core-image' in pn: 107 if 'core-image' in pn:
124 continue 108 continue
125 rd = self.tinfoil.parse_recipe(pn) 109 rd = self.tinfoil.parse_recipe(pn)
126 PatchTestDataStore['%s-%s-%s' % (self.shortid(), self.metadata_src_uri, pn)] = rd.getVar(self.metadata_src_uri) 110 PatchTestDataStore['%s-%s-%s' % (self.shortid(), patterns.metadata_src_uri, pn)] = rd.getVar(patterns.metadata_src_uri)
127 111
128 def test_src_uri_left_files(self): 112 def test_src_uri_left_files(self):
129 # these tests just make sense on patches that can be merged 113 # these tests just make sense on patches that can be merged
@@ -138,11 +122,11 @@ class TestMetadata(base.Metadata):
138 if 'core-image' in pn: 122 if 'core-image' in pn:
139 continue 123 continue
140 rd = self.tinfoil.parse_recipe(pn) 124 rd = self.tinfoil.parse_recipe(pn)
141 PatchTestDataStore['%s-%s-%s' % (self.shortid(), self.metadata_src_uri, pn)] = rd.getVar(self.metadata_src_uri) 125 PatchTestDataStore['%s-%s-%s' % (self.shortid(), patterns.metadata_src_uri, pn)] = rd.getVar(patterns.metadata_src_uri)
142 126
143 for pn in self.modified: 127 for pn in self.modified:
144 pretest_src_uri = PatchTestDataStore['pre%s-%s-%s' % (self.shortid(), self.metadata_src_uri, pn)].split() 128 pretest_src_uri = PatchTestDataStore['pre%s-%s-%s' % (self.shortid(), patterns.metadata_src_uri, pn)].split()
145 test_src_uri = PatchTestDataStore['%s-%s-%s' % (self.shortid(), self.metadata_src_uri, pn)].split() 129 test_src_uri = PatchTestDataStore['%s-%s-%s' % (self.shortid(), patterns.metadata_src_uri, pn)].split()
146 130
147 pretest_files = set([os.path.basename(patch) for patch in pretest_src_uri if patch.startswith('file://')]) 131 pretest_files = set([os.path.basename(patch) for patch in pretest_src_uri if patch.startswith('file://')])
148 test_files = set([os.path.basename(patch) for patch in test_src_uri if patch.startswith('file://')]) 132 test_files = set([os.path.basename(patch) for patch in test_src_uri if patch.startswith('file://')])
@@ -175,11 +159,11 @@ class TestMetadata(base.Metadata):
175 if 'core-image' in pn: 159 if 'core-image' in pn:
176 continue 160 continue
177 rd = self.tinfoil.parse_recipe(pn) 161 rd = self.tinfoil.parse_recipe(pn)
178 summary = rd.getVar(self.metadata_summary) 162 summary = rd.getVar(patterns.metadata_summary)
179 163
180 # "${PN} version ${PN}-${PR}" is the default, so fail if default 164 # "${PN} version ${PN}-${PR}" is the default, so fail if default
181 if summary.startswith('%s version' % pn): 165 if summary.startswith('%s version' % pn):
182 self.fail('%s is missing in newly added recipe' % self.metadata_summary) 166 self.fail('%s is missing in newly added recipe' % patterns.metadata_summary)
183 167
184 def test_cve_check_ignore(self): 168 def test_cve_check_ignore(self):
185 # Skip if we neither modified a recipe or target branches are not 169 # Skip if we neither modified a recipe or target branches are not
@@ -191,7 +175,7 @@ class TestMetadata(base.Metadata):
191 if 'core-image' in pn: 175 if 'core-image' in pn:
192 continue 176 continue
193 rd = self.tinfoil.parse_recipe(pn) 177 rd = self.tinfoil.parse_recipe(pn)
194 cve_check_ignore = rd.getVar(self.cve_check_ignore_var) 178 cve_check_ignore = rd.getVar(patterns.cve_check_ignore_var)
195 179
196 if cve_check_ignore is not None: 180 if cve_check_ignore is not None:
197 self.fail('%s is deprecated and should be replaced by %s' % (self.cve_check_ignore_var, self.cve_status_var)) 181 self.fail('%s is deprecated and should be replaced by %s' % (patterns.cve_check_ignore_var, patterns.cve_status_var))