diff options
Diffstat (limited to 'meta/lib/patchtest/tests/test_patch.py')
-rw-r--r-- | meta/lib/patchtest/tests/test_patch.py | 100 |
1 files changed, 64 insertions, 36 deletions
diff --git a/meta/lib/patchtest/tests/test_patch.py b/meta/lib/patchtest/tests/test_patch.py index d7187a0cb1..d08b8a5019 100644 --- a/meta/lib/patchtest/tests/test_patch.py +++ b/meta/lib/patchtest/tests/test_patch.py | |||
@@ -7,16 +7,11 @@ | |||
7 | 7 | ||
8 | import base | 8 | import base |
9 | import os | 9 | import os |
10 | import parse_signed_off_by | 10 | import patchtest_patterns |
11 | import parse_upstream_status | ||
12 | import pyparsing | 11 | import pyparsing |
13 | 12 | ||
14 | class TestPatch(base.Base): | 13 | class TestPatch(base.Base): |
15 | 14 | ||
16 | re_cve_pattern = pyparsing.Regex("CVE\-\d{4}\-\d+") | ||
17 | re_cve_payload_tag = pyparsing.Regex("\+CVE:(\s+CVE\-\d{4}\-\d+)+") | ||
18 | upstream_status_regex = pyparsing.AtLineStart("+" + "Upstream-Status") | ||
19 | |||
20 | @classmethod | 15 | @classmethod |
21 | def setUpClassLocal(cls): | 16 | def setUpClassLocal(cls): |
22 | cls.newpatches = [] | 17 | cls.newpatches = [] |
@@ -25,17 +20,17 @@ class TestPatch(base.Base): | |||
25 | if patch.path.endswith('.patch') and patch.is_added_file: | 20 | if patch.path.endswith('.patch') and patch.is_added_file: |
26 | cls.newpatches.append(patch) | 21 | cls.newpatches.append(patch) |
27 | 22 | ||
28 | cls.mark = str(parse_signed_off_by.signed_off_by_mark).strip('"') | 23 | cls.mark = str(patchtest_patterns.signed_off_by_prefix).strip('"') |
29 | 24 | ||
30 | # match PatchSignedOffBy.mark with '+' preceding it | 25 | # match PatchSignedOffBy.mark with '+' preceding it |
31 | cls.prog = parse_signed_off_by.patch_signed_off_by | 26 | cls.prog = patchtest_patterns.patch_signed_off_by |
32 | 27 | ||
33 | def setUp(self): | 28 | def setUp(self): |
34 | if self.unidiff_parse_error: | 29 | if self.unidiff_parse_error: |
35 | self.skip('Parse error %s' % self.unidiff_parse_error) | 30 | self.skip('Parse error %s' % self.unidiff_parse_error) |
36 | 31 | ||
37 | self.valid_status = ', '.join(parse_upstream_status.upstream_status_nonliteral_valid_status) | 32 | self.valid_status = ", ".join(patchtest_patterns.upstream_status_nonliteral_valid_status) |
38 | self.standard_format = 'Upstream-Status: <Valid status>' | 33 | self.standard_format = "Upstream-Status: <Valid status>" |
39 | 34 | ||
40 | # we are just interested in series that introduce CVE patches, thus discard other | 35 | # we are just interested in series that introduce CVE patches, thus discard other |
41 | # possibilities: modification to current CVEs, patch directly introduced into the | 36 | # possibilities: modification to current CVEs, patch directly introduced into the |
@@ -50,31 +45,62 @@ class TestPatch(base.Base): | |||
50 | 45 | ||
51 | for newpatch in TestPatch.newpatches: | 46 | for newpatch in TestPatch.newpatches: |
52 | payload = newpatch.__str__() | 47 | payload = newpatch.__str__() |
53 | if not self.upstream_status_regex.search_string(payload): | 48 | if not patchtest_patterns.upstream_status_regex.search_string(payload): |
54 | self.fail('Added patch file is missing Upstream-Status: <Valid status> in the commit message', | 49 | self.fail( |
55 | data=[('Standard format', self.standard_format), ('Valid status', self.valid_status)]) | 50 | "Added patch file is missing Upstream-Status: <Valid status> in the commit message", |
51 | data=[ | ||
52 | ("Standard format", self.standard_format), | ||
53 | ("Valid status", self.valid_status), | ||
54 | ], | ||
55 | ) | ||
56 | for line in payload.splitlines(): | 56 | for line in payload.splitlines(): |
57 | if self.patchmetadata_regex.match(line): | 57 | if patchtest_patterns.patchmetadata_regex.match(line): |
58 | continue | 58 | continue |
59 | if self.upstream_status_regex.search_string(line): | 59 | if patchtest_patterns.upstream_status_regex.search_string(line): |
60 | if parse_upstream_status.inappropriate_status_mark.searchString(line): | 60 | if patchtest_patterns.inappropriate.searchString(line): |
61 | try: | 61 | try: |
62 | parse_upstream_status.upstream_status_inappropriate_info.parseString(line.lstrip('+')) | 62 | patchtest_patterns.upstream_status_inappropriate_info.parseString( |
63 | except pyparsing.ParseException as pe: | 63 | line.lstrip("+") |
64 | self.fail('Upstream-Status is Inappropriate, but no reason was provided', | 64 | ) |
65 | data=[('Current', pe.pstr), ('Standard format', 'Upstream-Status: Inappropriate [reason]')]) | 65 | except pyparsing.ParseException as pe: |
66 | elif parse_upstream_status.submitted_status_mark.searchString(line): | 66 | self.fail( |
67 | try: | 67 | "Upstream-Status is Inappropriate, but no reason was provided", |
68 | parse_upstream_status.upstream_status_submitted_info.parseString(line.lstrip('+')) | 68 | data=[ |
69 | except pyparsing.ParseException as pe: | 69 | ("Current", pe.pstr), |
70 | self.fail('Upstream-Status is Submitted, but it is not mentioned where', | 70 | ( |
71 | data=[('Current', pe.pstr), ('Standard format', 'Upstream-Status: Submitted [where]')]) | 71 | "Standard format", |
72 | else: | 72 | "Upstream-Status: Inappropriate [reason]", |
73 | try: | 73 | ), |
74 | parse_upstream_status.upstream_status.parseString(line.lstrip('+')) | 74 | ], |
75 | except pyparsing.ParseException as pe: | 75 | ) |
76 | self.fail('Upstream-Status is in incorrect format', | 76 | elif patchtest_patterns.submitted.searchString(line): |
77 | data=[('Current', pe.pstr), ('Standard format', self.standard_format), ('Valid status', self.valid_status)]) | 77 | try: |
78 | patchtest_patterns.upstream_status_submitted_info.parseString( | ||
79 | line.lstrip("+") | ||
80 | ) | ||
81 | except pyparsing.ParseException as pe: | ||
82 | self.fail( | ||
83 | "Upstream-Status is Submitted, but it is not mentioned where", | ||
84 | data=[ | ||
85 | ("Current", pe.pstr), | ||
86 | ( | ||
87 | "Standard format", | ||
88 | "Upstream-Status: Submitted [where]", | ||
89 | ), | ||
90 | ], | ||
91 | ) | ||
92 | else: | ||
93 | try: | ||
94 | patchtest_patterns.upstream_status.parseString(line.lstrip("+")) | ||
95 | except pyparsing.ParseException as pe: | ||
96 | self.fail( | ||
97 | "Upstream-Status is in incorrect format", | ||
98 | data=[ | ||
99 | ("Current", pe.pstr), | ||
100 | ("Standard format", self.standard_format), | ||
101 | ("Valid status", self.valid_status), | ||
102 | ], | ||
103 | ) | ||
78 | 104 | ||
79 | def test_signed_off_by_presence(self): | 105 | def test_signed_off_by_presence(self): |
80 | if not TestPatch.newpatches: | 106 | if not TestPatch.newpatches: |
@@ -83,7 +109,7 @@ class TestPatch(base.Base): | |||
83 | for newpatch in TestPatch.newpatches: | 109 | for newpatch in TestPatch.newpatches: |
84 | payload = newpatch.__str__() | 110 | payload = newpatch.__str__() |
85 | for line in payload.splitlines(): | 111 | for line in payload.splitlines(): |
86 | if self.patchmetadata_regex.match(line): | 112 | if patchtest_patterns.patchmetadata_regex.match(line): |
87 | continue | 113 | continue |
88 | if TestPatch.prog.search_string(payload): | 114 | if TestPatch.prog.search_string(payload): |
89 | break | 115 | break |
@@ -92,10 +118,12 @@ class TestPatch(base.Base): | |||
92 | 118 | ||
93 | def test_cve_tag_format(self): | 119 | def test_cve_tag_format(self): |
94 | for commit in TestPatch.commits: | 120 | for commit in TestPatch.commits: |
95 | if self.re_cve_pattern.search_string(commit.shortlog) or self.re_cve_pattern.search_string(commit.commit_message): | 121 | if patchtest_patterns.cve.search_string( |
122 | commit.shortlog | ||
123 | ) or patchtest_patterns.cve.search_string(commit.commit_message): | ||
96 | tag_found = False | 124 | tag_found = False |
97 | for line in commit.payload.splitlines(): | 125 | for line in commit.payload.splitlines(): |
98 | if self.re_cve_payload_tag.search_string(line): | 126 | if patchtest_patterns.cve_payload_tag.search_string(line): |
99 | tag_found = True | 127 | tag_found = True |
100 | break | 128 | break |
101 | if not tag_found: | 129 | if not tag_found: |