diff options
author | Trevor Gamblin <tgamblin@baylibre.com> | 2023-10-12 09:24:59 -0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-10-13 11:53:06 +0100 |
commit | fd06e4f2664b69a2776cdc8188dba6e6e958d86a (patch) | |
tree | 2b26efe798c2169eeeea6e9c24ae5ac72d9fa9df | |
parent | 2fdabc368a52a9bf60f76f33e92b94de843688a8 (diff) | |
download | poky-fd06e4f2664b69a2776cdc8188dba6e6e958d86a.tar.gz |
patchtest: clean up test suite
Various tweaks to make the test suite cleaner and more efficient:
- Replace use of "re" module with "pyparsing" in tests (but not base.py)
- Make test_mbox_cve only check for CVE tags in the commit if the added
patch has them
- Make test_mbox_cve SKIP instead of PASS if there's no CVE tag
- Simplify the bugzilla tag checking test now that pyparsing is used
- Modify the selftest script to correctly parse the new result output
(From OE-Core rev: 7a187c2475aa762e2bc830950f608143f2535a72)
Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-x | meta/lib/patchtest/selftest/selftest | 2 | ||||
-rw-r--r-- | meta/lib/patchtest/tests/test_mbox_author.py | 14 | ||||
-rw-r--r-- | meta/lib/patchtest/tests/test_mbox_bugzilla.py | 14 | ||||
-rw-r--r-- | meta/lib/patchtest/tests/test_mbox_cve.py | 17 | ||||
-rw-r--r-- | meta/lib/patchtest/tests/test_mbox_format.py | 3 | ||||
-rw-r--r-- | meta/lib/patchtest/tests/test_mbox_mailinglist.py | 6 | ||||
-rw-r--r-- | meta/lib/patchtest/tests/test_mbox_signed_off_by.py | 6 | ||||
-rw-r--r-- | meta/lib/patchtest/tests/test_metadata_lic_files_chksum.py | 6 | ||||
-rw-r--r-- | meta/lib/patchtest/tests/test_metadata_max_length.py | 6 | ||||
-rw-r--r-- | meta/lib/patchtest/tests/test_metadata_src_uri.py | 4 | ||||
-rw-r--r-- | meta/lib/patchtest/tests/test_patch_cve.py | 10 | ||||
-rw-r--r-- | meta/lib/patchtest/tests/test_patch_signed_off_by.py | 1 |
12 files changed, 45 insertions, 44 deletions
diff --git a/meta/lib/patchtest/selftest/selftest b/meta/lib/patchtest/selftest/selftest index d2b61e951a..f8985314f5 100755 --- a/meta/lib/patchtest/selftest/selftest +++ b/meta/lib/patchtest/selftest/selftest | |||
@@ -63,7 +63,7 @@ if __name__ == '__main__': | |||
63 | 63 | ||
64 | for resultline in results.splitlines(): | 64 | for resultline in results.splitlines(): |
65 | if testid in resultline: | 65 | if testid in resultline: |
66 | result, _ = resultline.split(' ', 1) | 66 | result, _ = resultline.split(':', 1) |
67 | 67 | ||
68 | if expected_result.upper() == "FAIL" and result.upper() == "FAIL": | 68 | if expected_result.upper() == "FAIL" and result.upper() == "FAIL": |
69 | xfailcount = xfailcount + 1 | 69 | xfailcount = xfailcount + 1 |
diff --git a/meta/lib/patchtest/tests/test_mbox_author.py b/meta/lib/patchtest/tests/test_mbox_author.py index fb8f10e1fd..e68e7a5ac4 100644 --- a/meta/lib/patchtest/tests/test_mbox_author.py +++ b/meta/lib/patchtest/tests/test_mbox_author.py | |||
@@ -5,22 +5,22 @@ | |||
5 | # SPDX-License-Identifier: GPL-2.0 | 5 | # SPDX-License-Identifier: GPL-2.0 |
6 | 6 | ||
7 | import base | 7 | import base |
8 | import re | 8 | import pyparsing |
9 | 9 | ||
10 | class Author(base.Base): | 10 | class Author(base.Base): |
11 | 11 | ||
12 | auh_email = '<auh@auh.yoctoproject.org>' | 12 | auh_email = 'auh@auh.yoctoproject.org' |
13 | 13 | ||
14 | invalids = [re.compile("^Upgrade Helper.+"), | 14 | invalids = [pyparsing.Regex("^Upgrade Helper.+"), |
15 | re.compile(re.escape(auh_email)), | 15 | pyparsing.Regex(auh_email), |
16 | re.compile("uh@not\.set"), | 16 | pyparsing.Regex("uh@not\.set"), |
17 | re.compile("\S+@example\.com")] | 17 | pyparsing.Regex("\S+@example\.com")] |
18 | 18 | ||
19 | 19 | ||
20 | def test_author_valid(self): | 20 | def test_author_valid(self): |
21 | for commit in self.commits: | 21 | for commit in self.commits: |
22 | for invalid in self.invalids: | 22 | for invalid in self.invalids: |
23 | if invalid.search(commit.author): | 23 | if invalid.search_string(commit.author): |
24 | self.fail('Invalid author %s. Resend the series with a valid patch author' % commit.author, commit=commit) | 24 | self.fail('Invalid author %s. Resend the series with a valid patch author' % commit.author, commit=commit) |
25 | 25 | ||
26 | def test_non_auh_upgrade(self): | 26 | def test_non_auh_upgrade(self): |
diff --git a/meta/lib/patchtest/tests/test_mbox_bugzilla.py b/meta/lib/patchtest/tests/test_mbox_bugzilla.py index aa53b77f87..adf46b5d59 100644 --- a/meta/lib/patchtest/tests/test_mbox_bugzilla.py +++ b/meta/lib/patchtest/tests/test_mbox_bugzilla.py | |||
@@ -4,17 +4,17 @@ | |||
4 | # | 4 | # |
5 | # SPDX-License-Identifier: GPL-2.0 | 5 | # SPDX-License-Identifier: GPL-2.0 |
6 | 6 | ||
7 | import re | 7 | import pyparsing |
8 | import base | 8 | import base |
9 | 9 | ||
10 | class Bugzilla(base.Base): | 10 | class Bugzilla(base.Base): |
11 | rexp_detect = re.compile("\[\s?YOCTO.*\]", re.IGNORECASE) | 11 | rexp_detect = pyparsing.Regex('\[\s?YOCTO.*\]') |
12 | rexp_validation = re.compile("\[(\s?YOCTO\s?#\s?(\d+)\s?,?)+\]", re.IGNORECASE) | 12 | rexp_validation = pyparsing.Regex('\[(\s?YOCTO\s?#\s?(\d+)\s?,?)+\]') |
13 | 13 | ||
14 | def test_bugzilla_entry_format(self): | 14 | def test_bugzilla_entry_format(self): |
15 | for commit in Bugzilla.commits: | 15 | for commit in Bugzilla.commits: |
16 | for line in commit.commit_message.splitlines(): | 16 | if not self.rexp_detect.search_string(commit.commit_message): |
17 | if self.rexp_detect.match(line): | 17 | self.skip("No bug ID found") |
18 | if not self.rexp_validation.match(line): | 18 | elif not self.rexp_validation.search_string(commit.commit_message): |
19 | self.fail('Bugzilla issue ID is not correctly formatted - specify it with format: "[YOCTO #<bugzilla ID>]"', commit=commit) | 19 | self.fail('Bugzilla issue ID is not correctly formatted - specify it with format: "[YOCTO #<bugzilla ID>]"', commit=commit) |
20 | 20 | ||
diff --git a/meta/lib/patchtest/tests/test_mbox_cve.py b/meta/lib/patchtest/tests/test_mbox_cve.py index 36548aa10c..af3712c192 100644 --- a/meta/lib/patchtest/tests/test_mbox_cve.py +++ b/meta/lib/patchtest/tests/test_mbox_cve.py | |||
@@ -20,12 +20,13 @@ | |||
20 | import base | 20 | import base |
21 | import os | 21 | import os |
22 | import parse_cve_tags | 22 | import parse_cve_tags |
23 | import re | 23 | import pyparsing |
24 | 24 | ||
25 | class CVE(base.Base): | 25 | class CVE(base.Base): |
26 | 26 | ||
27 | revert_shortlog_regex = re.compile('Revert\s+".*"') | 27 | revert_shortlog_regex = pyparsing.Regex('Revert\s+".*"') |
28 | prog = parse_cve_tags.cve_tag | 28 | prog = parse_cve_tags.cve_tag |
29 | patch_prog = parse_cve_tags.patch_cve_tag | ||
29 | 30 | ||
30 | def setUp(self): | 31 | def setUp(self): |
31 | if self.unidiff_parse_error: | 32 | if self.unidiff_parse_error: |
@@ -34,15 +35,17 @@ class CVE(base.Base): | |||
34 | # 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 |
35 | # possibilities: modification to current CVEs, patch directly introduced into the | 36 | # possibilities: modification to current CVEs, patch directly introduced into the |
36 | # recipe, upgrades already including the CVE, etc. | 37 | # recipe, upgrades already including the CVE, etc. |
37 | new_cves = [p for p in self.patchset if p.path.endswith('.patch') and p.is_added_file] | 38 | new_patches = [p for p in self.patchset if p.path.endswith('.patch') and p.is_added_file] |
38 | if not new_cves: | 39 | if not new_patches: |
39 | self.skip('No new CVE patches introduced') | 40 | self.skip('No new patches introduced') |
40 | 41 | ||
41 | def test_cve_presence_in_commit_message(self): | 42 | def test_cve_presence_in_commit_message(self): |
42 | for commit in CVE.commits: | 43 | for commit in CVE.commits: |
43 | # skip those patches that revert older commits, these do not required the tag presence | 44 | # skip those patches that revert older commits, these do not required the tag presence |
44 | if self.revert_shortlog_regex.match(commit.shortlog): | 45 | if self.revert_shortlog_regex.search_string(commit.shortlog): |
45 | continue | 46 | continue |
46 | if not self.prog.search_string(commit.payload): | 47 | if not self.patch_prog.search_string(commit.payload): |
48 | self.skip("No CVE tag in added patch, so not needed in mbox") | ||
49 | elif not self.prog.search_string(commit.payload): | ||
47 | self.fail('Missing or incorrectly formatted CVE tag in mbox. Correct or include the CVE tag in the mbox with format: "CVE: CVE-YYYY-XXXX"', | 50 | self.fail('Missing or incorrectly formatted CVE tag in mbox. Correct or include the CVE tag in the mbox with format: "CVE: CVE-YYYY-XXXX"', |
48 | commit=commit) | 51 | commit=commit) |
diff --git a/meta/lib/patchtest/tests/test_mbox_format.py b/meta/lib/patchtest/tests/test_mbox_format.py index 42a8491a09..c9e0465835 100644 --- a/meta/lib/patchtest/tests/test_mbox_format.py +++ b/meta/lib/patchtest/tests/test_mbox_format.py | |||
@@ -5,11 +5,10 @@ | |||
5 | # SPDX-License-Identifier: GPL-2.0 | 5 | # SPDX-License-Identifier: GPL-2.0 |
6 | 6 | ||
7 | import base | 7 | import base |
8 | import re | ||
9 | 8 | ||
10 | class MboxFormat(base.Base): | 9 | class MboxFormat(base.Base): |
11 | 10 | ||
12 | def test_mbox_format(self): | 11 | def test_mbox_format(self): |
13 | if self.unidiff_parse_error: | 12 | if self.unidiff_parse_error: |
14 | self.fail('Series cannot be parsed correctly due to malformed diff lines. Create the series again using git-format-patch and ensure it can be applied using git am', | 13 | self.fail('Series cannot be parsed correctly due to malformed diff lines. Create the series again using git-format-patch and ensure it can be applied using git am', |
15 | data=[('Diff line', re.sub('^.+:\s(?<!$)','',self.unidiff_parse_error))]) | 14 | data=[('Diff line',self.unidiff_parse_error)]) |
diff --git a/meta/lib/patchtest/tests/test_mbox_mailinglist.py b/meta/lib/patchtest/tests/test_mbox_mailinglist.py index 1f9e0be07f..c02c71ac6a 100644 --- a/meta/lib/patchtest/tests/test_mbox_mailinglist.py +++ b/meta/lib/patchtest/tests/test_mbox_mailinglist.py | |||
@@ -7,7 +7,7 @@ | |||
7 | import subprocess | 7 | import subprocess |
8 | import collections | 8 | import collections |
9 | import base | 9 | import base |
10 | import re | 10 | import pyparsing |
11 | from data import PatchTestInput | 11 | from data import PatchTestInput |
12 | 12 | ||
13 | class MailingList(base.Base): | 13 | class MailingList(base.Base): |
@@ -39,9 +39,9 @@ class MailingList(base.Base): | |||
39 | 39 | ||
40 | # a meta project may be indicted in the message subject, if this is the case, just fail | 40 | # a meta project may be indicted in the message subject, if this is the case, just fail |
41 | # TODO: there may be other project with no-meta prefix, we also need to detect these | 41 | # TODO: there may be other project with no-meta prefix, we also need to detect these |
42 | project_regex = re.compile("\[(?P<project>meta-.+)\]") | 42 | project_regex = pyparsing.Regex("\[(?P<project>meta-.+)\]") |
43 | for commit in MailingList.commits: | 43 | for commit in MailingList.commits: |
44 | match = project_regex.match(commit.subject) | 44 | match = project_regex.search_string(commit.subject) |
45 | if match: | 45 | if match: |
46 | self.fail('Series sent to the wrong mailing list. Check the project\'s README (%s) and send the patch to the indicated list' % match.group('project'), | 46 | self.fail('Series sent to the wrong mailing list. Check the project\'s README (%s) and send the patch to the indicated list' % match.group('project'), |
47 | commit=commit) | 47 | commit=commit) |
diff --git a/meta/lib/patchtest/tests/test_mbox_signed_off_by.py b/meta/lib/patchtest/tests/test_mbox_signed_off_by.py index 8fd705a2ef..59a89bd1bc 100644 --- a/meta/lib/patchtest/tests/test_mbox_signed_off_by.py +++ b/meta/lib/patchtest/tests/test_mbox_signed_off_by.py | |||
@@ -6,11 +6,11 @@ | |||
6 | 6 | ||
7 | import base | 7 | import base |
8 | import parse_signed_off_by | 8 | import parse_signed_off_by |
9 | import re | 9 | import pyparsing |
10 | 10 | ||
11 | class SignedOffBy(base.Base): | 11 | class SignedOffBy(base.Base): |
12 | 12 | ||
13 | revert_shortlog_regex = re.compile('Revert\s+".*"') | 13 | revert_shortlog_regex = pyparsing.Regex('Revert\s+".*"') |
14 | 14 | ||
15 | @classmethod | 15 | @classmethod |
16 | def setUpClassLocal(cls): | 16 | def setUpClassLocal(cls): |
@@ -20,7 +20,7 @@ class SignedOffBy(base.Base): | |||
20 | def test_signed_off_by_presence(self): | 20 | def test_signed_off_by_presence(self): |
21 | for commit in SignedOffBy.commits: | 21 | for commit in SignedOffBy.commits: |
22 | # skip those patches that revert older commits, these do not required the tag presence | 22 | # skip those patches that revert older commits, these do not required the tag presence |
23 | if self.revert_shortlog_regex.match(commit.shortlog): | 23 | if self.revert_shortlog_regex.search_string(commit.shortlog): |
24 | continue | 24 | continue |
25 | if not SignedOffBy.prog.search_string(commit.payload): | 25 | if not SignedOffBy.prog.search_string(commit.payload): |
26 | self.fail('Mbox is missing Signed-off-by. Add it manually or with "git commit --amend -s"', | 26 | self.fail('Mbox is missing Signed-off-by. Add it manually or with "git commit --amend -s"', |
diff --git a/meta/lib/patchtest/tests/test_metadata_lic_files_chksum.py b/meta/lib/patchtest/tests/test_metadata_lic_files_chksum.py index a25a65c6db..784d432f01 100644 --- a/meta/lib/patchtest/tests/test_metadata_lic_files_chksum.py +++ b/meta/lib/patchtest/tests/test_metadata_lic_files_chksum.py | |||
@@ -5,7 +5,7 @@ | |||
5 | # SPDX-License-Identifier: GPL-2.0 | 5 | # SPDX-License-Identifier: GPL-2.0 |
6 | 6 | ||
7 | import base | 7 | import base |
8 | import re | 8 | import pyparsing |
9 | from data import PatchTestInput, PatchTestDataStore | 9 | from data import PatchTestInput, PatchTestDataStore |
10 | 10 | ||
11 | class LicFilesChkSum(base.Metadata): | 11 | class LicFilesChkSum(base.Metadata): |
@@ -13,7 +13,7 @@ class LicFilesChkSum(base.Metadata): | |||
13 | license = 'LICENSE' | 13 | license = 'LICENSE' |
14 | closed = 'CLOSED' | 14 | closed = 'CLOSED' |
15 | lictag = 'License-Update' | 15 | lictag = 'License-Update' |
16 | lictag_re = re.compile("^%s:" % lictag, re.MULTILINE) | 16 | lictag_re = pyparsing.Regex("^%s:" % lictag) |
17 | 17 | ||
18 | def setUp(self): | 18 | def setUp(self): |
19 | # these tests just make sense on patches that can be merged | 19 | # these tests just make sense on patches that can be merged |
@@ -73,7 +73,7 @@ class LicFilesChkSum(base.Metadata): | |||
73 | if pretest != test: | 73 | if pretest != test: |
74 | # if any patch on the series contain reference on the metadata, fail | 74 | # if any patch on the series contain reference on the metadata, fail |
75 | for commit in self.commits: | 75 | for commit in self.commits: |
76 | if self.lictag_re.search(commit.commit_message): | 76 | if self.lictag_re.search_string(commit.commit_message): |
77 | break | 77 | break |
78 | else: | 78 | else: |
79 | self.fail('LIC_FILES_CHKSUM changed on target %s but there is no "%s" tag in commit message. Include it with a brief description' % (pn, self.lictag), | 79 | self.fail('LIC_FILES_CHKSUM changed on target %s but there is no "%s" tag in commit message. Include it with a brief description' % (pn, self.lictag), |
diff --git a/meta/lib/patchtest/tests/test_metadata_max_length.py b/meta/lib/patchtest/tests/test_metadata_max_length.py index b3a5dc9b79..477a9bff57 100644 --- a/meta/lib/patchtest/tests/test_metadata_max_length.py +++ b/meta/lib/patchtest/tests/test_metadata_max_length.py | |||
@@ -5,10 +5,10 @@ | |||
5 | # SPDX-License-Identifier: GPL-2.0 | 5 | # SPDX-License-Identifier: GPL-2.0 |
6 | 6 | ||
7 | import base | 7 | import base |
8 | import re | 8 | import pyparsing |
9 | 9 | ||
10 | class MaxLength(base.Base): | 10 | class MaxLength(base.Base): |
11 | add_mark = re.compile('\+ ') | 11 | add_mark = pyparsing.Regex('\+ ') |
12 | max_length = 200 | 12 | max_length = 200 |
13 | 13 | ||
14 | def test_max_line_length(self): | 14 | def test_max_line_length(self): |
@@ -18,7 +18,7 @@ class MaxLength(base.Base): | |||
18 | continue | 18 | continue |
19 | payload = str(patch) | 19 | payload = str(patch) |
20 | for line in payload.splitlines(): | 20 | for line in payload.splitlines(): |
21 | if self.add_mark.match(line): | 21 | if self.add_mark.search_string(line): |
22 | current_line_length = len(line[1:]) | 22 | current_line_length = len(line[1:]) |
23 | if current_line_length > self.max_length: | 23 | if current_line_length > self.max_length: |
24 | self.fail('Patch line too long (current length %s, maximum is %s)' % (current_line_length, self.max_length), | 24 | self.fail('Patch line too long (current length %s, maximum is %s)' % (current_line_length, self.max_length), |
diff --git a/meta/lib/patchtest/tests/test_metadata_src_uri.py b/meta/lib/patchtest/tests/test_metadata_src_uri.py index ce2ace17bb..c19582ec2d 100644 --- a/meta/lib/patchtest/tests/test_metadata_src_uri.py +++ b/meta/lib/patchtest/tests/test_metadata_src_uri.py | |||
@@ -6,8 +6,8 @@ | |||
6 | 6 | ||
7 | import subprocess | 7 | import subprocess |
8 | import base | 8 | import base |
9 | import re | ||
10 | import os | 9 | import os |
10 | import pyparsing | ||
11 | from data import PatchTestInput, PatchTestDataStore | 11 | from data import PatchTestInput, PatchTestDataStore |
12 | 12 | ||
13 | class SrcUri(base.Metadata): | 13 | class SrcUri(base.Metadata): |
@@ -15,7 +15,7 @@ class SrcUri(base.Metadata): | |||
15 | metadata = 'SRC_URI' | 15 | metadata = 'SRC_URI' |
16 | md5sum = 'md5sum' | 16 | md5sum = 'md5sum' |
17 | sha256sum = 'sha256sum' | 17 | sha256sum = 'sha256sum' |
18 | git_regex = re.compile('^git\:\/\/.*') | 18 | git_regex = pyparsing.Regex('^git\:\/\/.*') |
19 | 19 | ||
20 | def setUp(self): | 20 | def setUp(self): |
21 | # these tests just make sense on patches that can be merged | 21 | # these tests just make sense on patches that can be merged |
diff --git a/meta/lib/patchtest/tests/test_patch_cve.py b/meta/lib/patchtest/tests/test_patch_cve.py index 144e130707..0ae85adcf9 100644 --- a/meta/lib/patchtest/tests/test_patch_cve.py +++ b/meta/lib/patchtest/tests/test_patch_cve.py | |||
@@ -19,12 +19,12 @@ | |||
19 | 19 | ||
20 | import base | 20 | import base |
21 | import os | 21 | import os |
22 | import re | 22 | import pyparsing |
23 | 23 | ||
24 | class CVE(base.Base): | 24 | class CVE(base.Base): |
25 | 25 | ||
26 | re_cve_pattern = re.compile("CVE\-\d{4}\-\d+", re.IGNORECASE) | 26 | re_cve_pattern = pyparsing.Regex("CVE\-\d{4}\-\d+") |
27 | re_cve_payload_tag = re.compile("\+CVE:(\s+CVE\-\d{4}\-\d+)+") | 27 | re_cve_payload_tag = pyparsing.Regex("\+CVE:(\s+CVE\-\d{4}\-\d+)+") |
28 | 28 | ||
29 | def setUp(self): | 29 | def setUp(self): |
30 | if self.unidiff_parse_error: | 30 | if self.unidiff_parse_error: |
@@ -39,10 +39,10 @@ class CVE(base.Base): | |||
39 | 39 | ||
40 | def test_cve_tag_format(self): | 40 | def test_cve_tag_format(self): |
41 | for commit in CVE.commits: | 41 | for commit in CVE.commits: |
42 | if self.re_cve_pattern.search(commit.shortlog) or self.re_cve_pattern.search(commit.commit_message): | 42 | if self.re_cve_pattern.search_string(commit.shortlog) or self.re_cve_pattern.search_string(commit.commit_message): |
43 | tag_found = False | 43 | tag_found = False |
44 | for line in commit.payload.splitlines(): | 44 | for line in commit.payload.splitlines(): |
45 | if self.re_cve_payload_tag.match(line): | 45 | if self.re_cve_payload_tag.search_string(line): |
46 | tag_found = True | 46 | tag_found = True |
47 | break | 47 | break |
48 | if not tag_found: | 48 | if not tag_found: |
diff --git a/meta/lib/patchtest/tests/test_patch_signed_off_by.py b/meta/lib/patchtest/tests/test_patch_signed_off_by.py index 5892033af0..2df6419d26 100644 --- a/meta/lib/patchtest/tests/test_patch_signed_off_by.py +++ b/meta/lib/patchtest/tests/test_patch_signed_off_by.py | |||
@@ -6,7 +6,6 @@ | |||
6 | 6 | ||
7 | import base | 7 | import base |
8 | import parse_signed_off_by | 8 | import parse_signed_off_by |
9 | import re | ||
10 | 9 | ||
11 | class PatchSignedOffBy(base.Base): | 10 | class PatchSignedOffBy(base.Base): |
12 | 11 | ||