diff options
author | Trevor Gamblin <tgamblin@baylibre.com> | 2024-09-24 07:55:01 -0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-09-30 17:00:50 +0100 |
commit | 4c378fc89566a329d0974bbcfefc7405779bc919 (patch) | |
tree | 4175c6d63b024e39dc9a7f02a77f1ff3cab8088f /meta/lib/patchtest/tests/test_patch.py | |
parent | 18a65c77c0e729dd1835852336e57ff4922f2674 (diff) | |
download | poky-4c378fc89566a329d0974bbcfefc7405779bc919.tar.gz |
patchtest: simplify, rename modules
- simplify base.py, data.py
- move some leftover regex patterns to patterns.py
- remove pyparsing path logic, since this is no longer needed
- rename PatchTestInput class to PatchtestParser
- data.py: rename to patchtest_parser.py
- patterns.py: rename to patchtest_patterns.py
- move PatchTestDataStore to test_metadata.py since that's the only
place it's used
- remove unused logger code
(From OE-Core rev: 1e971b05b036b0b1eb0bdbd9b26b54d06e74294c)
Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/patchtest/tests/test_patch.py')
-rw-r--r-- | meta/lib/patchtest/tests/test_patch.py | 95 |
1 files changed, 64 insertions, 31 deletions
diff --git a/meta/lib/patchtest/tests/test_patch.py b/meta/lib/patchtest/tests/test_patch.py index d856b216f0..d08b8a5019 100644 --- a/meta/lib/patchtest/tests/test_patch.py +++ b/meta/lib/patchtest/tests/test_patch.py | |||
@@ -7,7 +7,7 @@ | |||
7 | 7 | ||
8 | import base | 8 | import base |
9 | import os | 9 | import os |
10 | import patterns | 10 | import patchtest_patterns |
11 | import pyparsing | 11 | import pyparsing |
12 | 12 | ||
13 | class TestPatch(base.Base): | 13 | class TestPatch(base.Base): |
@@ -20,17 +20,17 @@ class TestPatch(base.Base): | |||
20 | if patch.path.endswith('.patch') and patch.is_added_file: | 20 | if patch.path.endswith('.patch') and patch.is_added_file: |
21 | cls.newpatches.append(patch) | 21 | cls.newpatches.append(patch) |
22 | 22 | ||
23 | cls.mark = str(patterns.signed_off_by_prefix).strip('"') | 23 | cls.mark = str(patchtest_patterns.signed_off_by_prefix).strip('"') |
24 | 24 | ||
25 | # match PatchSignedOffBy.mark with '+' preceding it | 25 | # match PatchSignedOffBy.mark with '+' preceding it |
26 | cls.prog = patterns.patch_signed_off_by | 26 | cls.prog = patchtest_patterns.patch_signed_off_by |
27 | 27 | ||
28 | def setUp(self): | 28 | def setUp(self): |
29 | if self.unidiff_parse_error: | 29 | if self.unidiff_parse_error: |
30 | self.skip('Parse error %s' % self.unidiff_parse_error) | 30 | self.skip('Parse error %s' % self.unidiff_parse_error) |
31 | 31 | ||
32 | self.valid_status = ', '.join(patterns.upstream_status_nonliteral_valid_status) | 32 | self.valid_status = ", ".join(patchtest_patterns.upstream_status_nonliteral_valid_status) |
33 | self.standard_format = 'Upstream-Status: <Valid status>' | 33 | self.standard_format = "Upstream-Status: <Valid status>" |
34 | 34 | ||
35 | # 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 |
36 | # possibilities: modification to current CVEs, patch directly introduced into the | 36 | # possibilities: modification to current CVEs, patch directly introduced into the |
@@ -45,31 +45,62 @@ class TestPatch(base.Base): | |||
45 | 45 | ||
46 | for newpatch in TestPatch.newpatches: | 46 | for newpatch in TestPatch.newpatches: |
47 | payload = newpatch.__str__() | 47 | payload = newpatch.__str__() |
48 | if not patterns.upstream_status_regex.search_string(payload): | 48 | if not patchtest_patterns.upstream_status_regex.search_string(payload): |
49 | self.fail('Added patch file is missing Upstream-Status: <Valid status> in the commit message', | 49 | self.fail( |
50 | 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 | ) | ||
51 | for line in payload.splitlines(): | 56 | for line in payload.splitlines(): |
52 | if self.patchmetadata_regex.match(line): | 57 | if patchtest_patterns.patchmetadata_regex.match(line): |
53 | continue | 58 | continue |
54 | if patterns.upstream_status_regex.search_string(line): | 59 | if patchtest_patterns.upstream_status_regex.search_string(line): |
55 | if patterns.inappropriate.searchString(line): | 60 | if patchtest_patterns.inappropriate.searchString(line): |
56 | try: | 61 | try: |
57 | patterns.upstream_status_inappropriate_info.parseString(line.lstrip('+')) | 62 | patchtest_patterns.upstream_status_inappropriate_info.parseString( |
58 | except pyparsing.ParseException as pe: | 63 | line.lstrip("+") |
59 | self.fail('Upstream-Status is Inappropriate, but no reason was provided', | 64 | ) |
60 | data=[('Current', pe.pstr), ('Standard format', 'Upstream-Status: Inappropriate [reason]')]) | 65 | except pyparsing.ParseException as pe: |
61 | elif patterns.submitted.searchString(line): | 66 | self.fail( |
62 | try: | 67 | "Upstream-Status is Inappropriate, but no reason was provided", |
63 | patterns.upstream_status_submitted_info.parseString(line.lstrip('+')) | 68 | data=[ |
64 | except pyparsing.ParseException as pe: | 69 | ("Current", pe.pstr), |
65 | self.fail('Upstream-Status is Submitted, but it is not mentioned where', | 70 | ( |
66 | data=[('Current', pe.pstr), ('Standard format', 'Upstream-Status: Submitted [where]')]) | 71 | "Standard format", |
67 | else: | 72 | "Upstream-Status: Inappropriate [reason]", |
68 | try: | 73 | ), |
69 | patterns.upstream_status.parseString(line.lstrip('+')) | 74 | ], |
70 | except pyparsing.ParseException as pe: | 75 | ) |
71 | self.fail('Upstream-Status is in incorrect format', | 76 | elif patchtest_patterns.submitted.searchString(line): |
72 | 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 | ) | ||
73 | 104 | ||
74 | def test_signed_off_by_presence(self): | 105 | def test_signed_off_by_presence(self): |
75 | if not TestPatch.newpatches: | 106 | if not TestPatch.newpatches: |
@@ -78,7 +109,7 @@ class TestPatch(base.Base): | |||
78 | for newpatch in TestPatch.newpatches: | 109 | for newpatch in TestPatch.newpatches: |
79 | payload = newpatch.__str__() | 110 | payload = newpatch.__str__() |
80 | for line in payload.splitlines(): | 111 | for line in payload.splitlines(): |
81 | if self.patchmetadata_regex.match(line): | 112 | if patchtest_patterns.patchmetadata_regex.match(line): |
82 | continue | 113 | continue |
83 | if TestPatch.prog.search_string(payload): | 114 | if TestPatch.prog.search_string(payload): |
84 | break | 115 | break |
@@ -87,10 +118,12 @@ class TestPatch(base.Base): | |||
87 | 118 | ||
88 | def test_cve_tag_format(self): | 119 | def test_cve_tag_format(self): |
89 | for commit in TestPatch.commits: | 120 | for commit in TestPatch.commits: |
90 | if patterns.cve.search_string(commit.shortlog) or patterns.cve.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): | ||
91 | tag_found = False | 124 | tag_found = False |
92 | for line in commit.payload.splitlines(): | 125 | for line in commit.payload.splitlines(): |
93 | if patterns.cve_payload_tag.search_string(line): | 126 | if patchtest_patterns.cve_payload_tag.search_string(line): |
94 | tag_found = True | 127 | tag_found = True |
95 | break | 128 | break |
96 | if not tag_found: | 129 | if not tag_found: |