diff options
author | Trevor Gamblin <tgamblin@baylibre.com> | 2023-10-26 10:07:46 -0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-10-26 21:11:28 +0100 |
commit | 207a5a21d38f4ed1b71aed0158ce067b57502cc7 (patch) | |
tree | 2f612a8d475ed4d4dc0f994b3ca320e5e073c10e /meta/lib/patchtest/tests/test_patch.py | |
parent | cdee2b22e1f3b35eb77fed0d431acdf3c358ee6c (diff) | |
download | poky-207a5a21d38f4ed1b71aed0158ce067b57502cc7.tar.gz |
patchtest: simplify test directory structure
Consolidate the various mbox tests into a new TestMbox class, metadata
tests into TestMetadata, and patch tests into TestPatch. Also update the
selftest filenames to match the changes. The test contents are not
significantly changed (other than to reference the new class names).
While this doesn't improve overall readability, it does result in more
obvious categorization, and more importantly reduces the number of calls
to setup tinfoil in the tests, resulting in a roughly 25% reduction in
runtime.
Before:
[tgamblin@megalith poky]$ time ./meta/lib/patchtest/selftest/selftest
XPASS: PatchSignedOffBy.test_signed_off_by_presence (file: PatchSignedOffBy.test_signed_off_by_presence.pass)
XFAIL: Shortlog.test_shortlog_format (file: Shortlog.test_shortlog_format.fail)
XFAIL: MboxFormat.test_mbox_format (file: MboxFormat.test_mbox_format.1.fail)
XPASS: Shortlog.test_shortlog_length (file: Shortlog.test_shortlog_length.pass)
XFAIL: CommitMessage.test_commit_message_presence (file: CommitMessage.test_commit_message_presence.fail)
XFAIL: SrcUri.test_src_uri_left_files (file: SrcUri.test_src_uri_left_files.fail)
XPASS: Author.test_author_valid (file: Author.test_author_valid.1.pass)
XFAIL: LicFilesChkSum.test_lic_files_chksum_modified_not_mentioned (file: LicFilesChkSum.test_lic_files_chksum_modified_not_mentioned.fail)
XPASS: CVE.test_cve_tag_format (file: CVE.test_cve_tag_format.pass)
XPASS: CVE.test_cve_presence_in_commit_message (file: CVE.test_cve_presence_in_commit_message.pass)
XFAIL: CVE.test_cve_tag_format (file: CVE.test_cve_tag_format.fail)
XFAIL: Author.test_author_valid (file: Author.test_author_valid.1.fail)
XFAIL: LicFilesChkSum.test_lic_files_chksum_presence (file: LicFilesChkSum.test_lic_files_chksum_presence.fail)
XSKIP: Merge.test_series_merge_on_head (file: Merge.test_series_merge_on_head.2.skip)
XPASS: MboxFormat.test_mbox_format (file: MboxFormat.test_mbox_format.pass)
XFAIL: SignedOffBy.test_signed_off_by_presence (file: SignedOffBy.test_signed_off_by_presence.1.fail)
XPASS: Shortlog.test_shortlog_format (file: Shortlog.test_shortlog_format.pass)
XFAIL: SignedOffBy.test_signed_off_by_presence (file: SignedOffBy.test_signed_off_by_presence.2.fail)
XFAIL: MboxFormat.test_mbox_format (file: MboxFormat.test_mbox_format.2.fail)
XFAIL: Summary.test_summary_presence (file: Summary.test_summary_presence.fail)
XPASS: Author.test_author_valid (file: Author.test_author_valid.2.pass)
XSKIP: Merge.test_series_merge_on_head (file: Merge.test_series_merge_on_head.1.skip)
XPASS: Bugzilla.test_bugzilla_entry_format (file: Bugzilla.test_bugzilla_entry_format.pass)
XFAIL: CVE.test_cve_presence_in_commit_message (file: CVE.test_cve_presence_in_commit_message.fail)
XPASS: SignedOffBy.test_signed_off_by_presence (file: SignedOffBy.test_signed_off_by_presence.pass)
XPASS: LicFilesChkSum.test_lic_files_chksum_presence (file: LicFilesChkSum.test_lic_files_chksum_presence.pass)
XPASS: CommitMessage.test_commit_message_presence (file: CommitMessage.test_commit_message_presence.pass)
XPASS: Summary.test_summary_presence (file: Summary.test_summary_presence.pass)
XPASS: LicFilesChkSum.test_lic_files_chksum_modified_not_mentioned (file: LicFilesChkSum.test_lic_files_chksum_modified_not_mentioned.pass)
XFAIL: Shortlog.test_shortlog_length (file: Shortlog.test_shortlog_length.fail)
XFAIL: PatchSignedOffBy.test_signed_off_by_presence (file: PatchSignedOffBy.test_signed_off_by_presence.fail)
XFAIL: Bugzilla.test_bugzilla_entry_format (file: Bugzilla.test_bugzilla_entry_format.fail)
XPASS: SrcUri.test_src_uri_left_files (file: SrcUri.test_src_uri_left_files.pass)
XFAIL: Author.test_author_valid (file: Author.test_author_valid.2.fail)
============================================================================
Testsuite summary for patchtest
============================================================================
============================================================================
real 24m14.386s
user 1m13.599s
sys 0m21.477s
After:
[tgamblin@megalith poky]$ time ./meta/lib/patchtest/selftest/selftest
XFAIL: TestMbox.test_bugzilla_entry_format (file: TestMbox.test_bugzilla_entry_format.fail)
XPASS: TestMetadata.test_summary_presence (file: TestMetadata.test_summary_presence.pass)
XFAIL: TestMbox.test_mbox_format (file: TestMbox.test_mbox_format.1.fail)
XFAIL: TestMetadata.test_src_uri_left_files (file: TestMetadata.test_src_uri_left_files.fail)
XSKIP: TestMbox.test_series_merge_on_head (file: TestMbox.test_series_merge_on_head.2.skip)
XPASS: TestMbox.test_commit_message_presence (file: TestMbox.test_commit_message_presence.pass)
XFAIL: TestMbox.test_commit_message_presence (file: TestMbox.test_commit_message_presence.fail)
XPASS: TestMbox.test_signed_off_by_presence (file: TestMbox.test_signed_off_by_presence.pass)
XFAIL: TestPatch.test_cve_tag_format (file: TestPatch.test_cve_tag_format.fail)
XFAIL: TestMbox.test_author_valid (file: TestMbox.test_author_valid.1.fail)
XFAIL: TestMbox.test_shortlog_length (file: TestMbox.test_shortlog_length.fail)
XPASS: TestMbox.test_mbox_format (file: TestMbox.test_mbox_format.pass)
XFAIL: TestPatch.test_signed_off_by_presence (file: TestPatch.test_signed_off_by_presence.fail)
XFAIL: TestMbox.test_shortlog_format (file: TestMbox.test_shortlog_format.fail)
XFAIL: TestMbox.test_mbox_format (file: TestMbox.test_mbox_format.2.fail)
XPASS: TestPatch.test_cve_tag_format (file: TestPatch.test_cve_tag_format.pass)
XSKIP: TestMbox.test_series_merge_on_head (file: TestMbox.test_series_merge_on_head.1.skip)
XPASS: TestMbox.test_author_valid (file: TestMbox.test_author_valid.2.pass)
XPASS: TestMetadata.test_lic_files_chksum_modified_not_mentioned (file: TestMetadata.test_lic_files_chksum_modified_not_mentioned.pass)
XPASS: TestMbox.test_bugzilla_entry_format (file: TestMbox.test_bugzilla_entry_format.pass)
XPASS: TestMetadata.test_src_uri_left_files (file: TestMetadata.test_src_uri_left_files.pass)
XPASS: TestMetadata.test_lic_files_chksum_presence (file: TestMetadata.test_lic_files_chksum_presence.pass)
XPASS: TestMbox.test_cve_presence_in_commit_message (file: TestMbox.test_cve_presence_in_commit_message.pass)
XFAIL: TestMbox.test_signed_off_by_presence (file: TestMbox.test_signed_off_by_presence.2.fail)
XFAIL: TestMbox.test_author_valid (file: TestMbox.test_author_valid.2.fail)
XFAIL: TestMetadata.test_lic_files_chksum_presence (file: TestMetadata.test_lic_files_chksum_presence.fail)
XPASS: TestMbox.test_shortlog_format (file: TestMbox.test_shortlog_format.pass)
XPASS: TestMbox.test_author_valid (file: TestMbox.test_author_valid.1.pass)
XPASS: TestPatch.test_signed_off_by_presence (file: TestPatch.test_signed_off_by_presence.pass)
XFAIL: TestMetadata.test_lic_files_chksum_modified_not_mentioned (file: TestMetadata.test_lic_files_chksum_modified_not_mentioned.fail)
XPASS: TestMbox.test_shortlog_length (file: TestMbox.test_shortlog_length.pass)
XFAIL: TestMbox.test_signed_off_by_presence (file: TestMbox.test_signed_off_by_presence.1.fail)
XFAIL: TestMbox.test_cve_presence_in_commit_message (file: TestMbox.test_cve_presence_in_commit_message.fail)
XFAIL: TestMetadata.test_summary_presence (file: TestMetadata.test_summary_presence.fail)
============================================================================
Testsuite summary for patchtest
============================================================================
============================================================================
real 18m39.749s
user 0m41.857s
sys 0m14.708s
(From OE-Core rev: f788592da2fd0e21638ce2c3326675a060ba51cf)
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 | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/meta/lib/patchtest/tests/test_patch.py b/meta/lib/patchtest/tests/test_patch.py new file mode 100644 index 0000000000..b6904b185f --- /dev/null +++ b/meta/lib/patchtest/tests/test_patch.py | |||
@@ -0,0 +1,102 @@ | |||
1 | # Checks related to the patch's CVE lines | ||
2 | # | ||
3 | # Copyright (C) 2016 Intel Corporation | ||
4 | # | ||
5 | # SPDX-License-Identifier: GPL-2.0-only | ||
6 | # | ||
7 | |||
8 | import base | ||
9 | import parse_signed_off_by | ||
10 | import parse_upstream_status | ||
11 | import pyparsing | ||
12 | |||
13 | class TestPatch(base.Base): | ||
14 | |||
15 | re_cve_pattern = pyparsing.Regex("CVE\-\d{4}\-\d+") | ||
16 | re_cve_payload_tag = pyparsing.Regex("\+CVE:(\s+CVE\-\d{4}\-\d+)+") | ||
17 | upstream_status_regex = pyparsing.AtLineStart("+" + "Upstream-Status") | ||
18 | |||
19 | @classmethod | ||
20 | def setUpClassLocal(cls): | ||
21 | cls.newpatches = [] | ||
22 | # get just those relevant patches: new software patches | ||
23 | for patch in cls.patchset: | ||
24 | if patch.path.endswith('.patch') and patch.is_added_file: | ||
25 | cls.newpatches.append(patch) | ||
26 | |||
27 | cls.mark = str(parse_signed_off_by.signed_off_by_mark).strip('"') | ||
28 | |||
29 | # match PatchSignedOffBy.mark with '+' preceding it | ||
30 | cls.prog = parse_signed_off_by.patch_signed_off_by | ||
31 | |||
32 | def setUp(self): | ||
33 | if self.unidiff_parse_error: | ||
34 | self.skip('Parse error %s' % self.unidiff_parse_error) | ||
35 | |||
36 | self.valid_status = ', '.join(parse_upstream_status.upstream_status_nonliteral_valid_status) | ||
37 | self.standard_format = 'Upstream-Status: <Valid status>' | ||
38 | |||
39 | # we are just interested in series that introduce CVE patches, thus discard other | ||
40 | # possibilities: modification to current CVEs, patch directly introduced into the | ||
41 | # recipe, upgrades already including the CVE, etc. | ||
42 | new_cves = [p for p in self.patchset if p.path.endswith('.patch') and p.is_added_file] | ||
43 | if not new_cves: | ||
44 | self.skip('No new CVE patches introduced') | ||
45 | |||
46 | def test_upstream_status_presence_format(self): | ||
47 | if not TestPatch.newpatches: | ||
48 | self.skip("There are no new software patches, no reason to test Upstream-Status presence/format") | ||
49 | |||
50 | for newpatch in TestPatch.newpatches: | ||
51 | payload = newpatch.__str__() | ||
52 | if not self.upstream_status_regex.search_string(payload): | ||
53 | self.fail('Added patch file is missing Upstream-Status in the header. Add Upstream-Status: <Valid status> to the header', | ||
54 | data=[('Standard format', self.standard_format), ('Valid status', self.valid_status)]) | ||
55 | for line in payload.splitlines(): | ||
56 | if self.patchmetadata_regex.match(line): | ||
57 | continue | ||
58 | if self.upstream_status_regex.search_string(line): | ||
59 | if parse_upstream_status.inappropriate_status_mark.searchString(line): | ||
60 | try: | ||
61 | parse_upstream_status.upstream_status_inappropriate_info.parseString(line.lstrip('+')) | ||
62 | except pyparsing.ParseException as pe: | ||
63 | self.fail('Upstream-Status is Inappropriate, but no reason was provided', | ||
64 | data=[('Current', pe.pstr), ('Standard format', 'Upstream-Status: Inappropriate [reason]')]) | ||
65 | elif parse_upstream_status.submitted_status_mark.searchString(line): | ||
66 | try: | ||
67 | parse_upstream_status.upstream_status_submitted_info.parseString(line.lstrip('+')) | ||
68 | except pyparsing.ParseException as pe: | ||
69 | self.fail('Upstream-Status is Submitted, but it is not mentioned where', | ||
70 | data=[('Current', pe.pstr), ('Standard format', 'Upstream-Status: Submitted [where]')]) | ||
71 | else: | ||
72 | try: | ||
73 | parse_upstream_status.upstream_status.parseString(line.lstrip('+')) | ||
74 | except pyparsing.ParseException as pe: | ||
75 | self.fail('Upstream-Status is in incorrect format', | ||
76 | data=[('Current', pe.pstr), ('Standard format', self.standard_format), ('Valid status', self.valid_status)]) | ||
77 | |||
78 | def test_signed_off_by_presence(self): | ||
79 | if not TestPatch.newpatches: | ||
80 | self.skip("There are no new software patches, no reason to test %s presence" % PatchSignedOffBy.mark) | ||
81 | |||
82 | for newpatch in TestPatch.newpatches: | ||
83 | payload = newpatch.__str__() | ||
84 | for line in payload.splitlines(): | ||
85 | if self.patchmetadata_regex.match(line): | ||
86 | continue | ||
87 | if TestPatch.prog.search_string(payload): | ||
88 | break | ||
89 | else: | ||
90 | self.fail('A patch file has been added, but does not have a Signed-off-by tag. Sign off the added patch file (%s)' % newpatch.path) | ||
91 | |||
92 | def test_cve_tag_format(self): | ||
93 | for commit in TestPatch.commits: | ||
94 | if self.re_cve_pattern.search_string(commit.shortlog) or self.re_cve_pattern.search_string(commit.commit_message): | ||
95 | tag_found = False | ||
96 | for line in commit.payload.splitlines(): | ||
97 | if self.re_cve_payload_tag.search_string(line): | ||
98 | tag_found = True | ||
99 | break | ||
100 | if not tag_found: | ||
101 | self.fail('Missing or incorrectly formatted CVE tag in patch file. Correct or include the CVE tag in the patch with format: "CVE: CVE-YYYY-XXXX"', | ||
102 | commit=commit) | ||