patchtest: improve test issue messages

The patchtest tests provide vague feedback to the user, and many of them
also provide redundant 'fix' strings that could easily be incorporated
into the issue messages themselves. Simplify them so that it is more
clear what the errors are and how they can be addressed. No
recommendation is given when the issue string adequately conveys the
issue, e.g. with a missing "LICENSE" entry in a newly-created recipe.

(From OE-Core rev: 0bfb3614244ec7aa79b6424bc63f9f2bccdabe98)

Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Trevor Gamblin 2023-10-12 09:24:58 -04:00 committed by Richard Purdie
parent 575b00dca5
commit 2fdabc368a
18 changed files with 29 additions and 52 deletions

View File

@ -21,9 +21,9 @@ class Author(base.Base):
for commit in self.commits: for commit in self.commits:
for invalid in self.invalids: for invalid in self.invalids:
if invalid.search(commit.author): if invalid.search(commit.author):
self.fail('Invalid author %s' % commit.author, 'Resend the series with a valid patch\'s author', commit) self.fail('Invalid author %s. Resend the series with a valid patch author' % commit.author, commit=commit)
def test_non_auh_upgrade(self): def test_non_auh_upgrade(self):
for commit in self.commits: for commit in self.commits:
if self.auh_email in commit.payload: if self.auh_email in commit.payload:
self.fail('Invalid author %s in commit message' % self.auh_email, 'Resend the series with a valid patch\'s author', commit) self.fail('Invalid author %s. Resend the series with a valid patch author' % self.auh_email, commit=commit)

View File

@ -16,7 +16,5 @@ class Bugzilla(base.Base):
for line in commit.commit_message.splitlines(): for line in commit.commit_message.splitlines():
if self.rexp_detect.match(line): if self.rexp_detect.match(line):
if not self.rexp_validation.match(line): if not self.rexp_validation.match(line):
self.fail('Yocto Project bugzilla tag is not correctly formatted', self.fail('Bugzilla issue ID is not correctly formatted - specify it with format: "[YOCTO #<bugzilla ID>]"', commit=commit)
'Specify bugzilla ID in commit description with format: "[YOCTO #<bugzilla ID>]"',
commit)

View File

@ -44,6 +44,5 @@ class CVE(base.Base):
if self.revert_shortlog_regex.match(commit.shortlog): if self.revert_shortlog_regex.match(commit.shortlog):
continue continue
if not self.prog.search_string(commit.payload): if not self.prog.search_string(commit.payload):
self.fail('Missing or incorrectly formatted CVE tag in mbox', 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"',
'Correct or include the CVE tag in the mbox with format: "CVE: CVE-YYYY-XXXX"', commit=commit)
commit)

View File

@ -11,7 +11,5 @@ class CommitMessage(base.Base):
def test_commit_message_presence(self): def test_commit_message_presence(self):
for commit in CommitMessage.commits: for commit in CommitMessage.commits:
if not commit.commit_message.strip(): if not commit.commit_message.strip():
self.fail('Patch is missing a descriptive commit message', self.fail('Mbox is missing a descriptive commit message. Please include a commit message on your patch explaining the change', commit=commit)
'Please include a commit message on your patch explaining the change (most importantly why the change is being made)',
commit)

View File

@ -11,6 +11,5 @@ class MboxFormat(base.Base):
def test_mbox_format(self): def test_mbox_format(self):
if self.unidiff_parse_error: if self.unidiff_parse_error:
self.fail('Series cannot be parsed correctly due to malformed diff lines', 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',
'Create the series again using git-format-patch and ensure it can be applied using git am',
data=[('Diff line', re.sub('^.+:\s(?<!$)','',self.unidiff_parse_error))]) data=[('Diff line', re.sub('^.+:\s(?<!$)','',self.unidiff_parse_error))])

View File

@ -43,16 +43,15 @@ class MailingList(base.Base):
for commit in MailingList.commits: for commit in MailingList.commits:
match = project_regex.match(commit.subject) match = project_regex.match(commit.subject)
if match: if match:
self.fail('Series sent to the wrong mailing list', 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'),
'Check the project\'s README (%s) and send the patch to the indicated list' % match.group('project'), commit=commit)
commit)
for patch in self.patchset: for patch in self.patchset:
folders = patch.path.split('/') folders = patch.path.split('/')
base_path = folders[0] base_path = folders[0]
for project in [self.bitbake, self.doc, self.oe, self.poky]: for project in [self.bitbake, self.doc, self.oe, self.poky]:
if base_path in project.paths: if base_path in project.paths:
self.fail('Series sent to the wrong mailing list or some patches from the series correspond to different mailing lists', 'Send the series again to the correct mailing list (ML)', self.fail('Series sent to the wrong mailing list or some patches from the series correspond to different mailing lists. Send the series again to the correct mailing list (ML)',
data=[('Suggested ML', '%s [%s]' % (project.listemail, project.gitrepo)), data=[('Suggested ML', '%s [%s]' % (project.listemail, project.gitrepo)),
('Patch\'s path:', patch.path)]) ('Patch\'s path:', patch.path)])
@ -60,5 +59,5 @@ class MailingList(base.Base):
if base_path.startswith('scripts'): if base_path.startswith('scripts'):
for poky_file in self.poky_scripts: for poky_file in self.poky_scripts:
if patch.path.startswith(poky_file): if patch.path.startswith(poky_file):
self.fail('Series sent to the wrong mailing list or some patches from the series correspond to different mailing lists', 'Send the series again to the correct mailing list (ML)', self.fail('Series sent to the wrong mailing list or some patches from the series correspond to different mailing lists. Send the series again to the correct mailing list (ML)',
data=[('Suggested ML', '%s [%s]' % (self.poky.listemail, self.poky.gitrepo)),('Patch\'s path:', patch.path)]) data=[('Suggested ML', '%s [%s]' % (self.poky.listemail, self.poky.gitrepo)),('Patch\'s path:', patch.path)])

View File

@ -20,6 +20,5 @@ class Merge(base.Base):
def test_series_merge_on_head(self): def test_series_merge_on_head(self):
if not PatchTestInput.repo.ismerged: if not PatchTestInput.repo.ismerged:
commithash, author, date, shortlog = headlog() commithash, author, date, shortlog = headlog()
self.fail('Series does not apply on top of target branch', self.fail('Series does not apply on top of target branch. Rebase your series and ensure the target is correct',
'Rebase your series on top of targeted branch',
data=[('Targeted branch', '%s (currently at %s)' % (PatchTestInput.repo.branch, commithash))]) data=[('Targeted branch', '%s (currently at %s)' % (PatchTestInput.repo.branch, commithash))])

View File

@ -24,9 +24,8 @@ class Shortlog(base.Base):
try: try:
parse_shortlog.shortlog.parseString(shortlog) parse_shortlog.shortlog.parseString(shortlog)
except pyparsing.ParseException as pe: except pyparsing.ParseException as pe:
self.fail('Shortlog does not follow expected format', self.fail('Commit shortlog (first line of commit message) should follow the format "<target>: <summary>"',
'Commit shortlog (first line of commit message) should follow the format "<target>: <summary>"', commit=commit)
commit)
def test_shortlog_length(self): def test_shortlog_length(self):
for commit in Shortlog.commits: for commit in Shortlog.commits:
@ -36,6 +35,5 @@ class Shortlog(base.Base):
continue continue
l = len(shortlog) l = len(shortlog)
if l > maxlength: if l > maxlength:
self.fail('Commit shortlog is too long', self.fail('Edit shortlog so that it is %d characters or less (currently %d characters)' % (maxlength, l),
'Edit shortlog so that it is %d characters or less (currently %d characters)' % (maxlength, l), commit=commit)
commit)

View File

@ -23,6 +23,5 @@ class SignedOffBy(base.Base):
if self.revert_shortlog_regex.match(commit.shortlog): if self.revert_shortlog_regex.match(commit.shortlog):
continue continue
if not SignedOffBy.prog.search_string(commit.payload): if not SignedOffBy.prog.search_string(commit.payload):
self.fail('Patch is missing Signed-off-by', self.fail('Mbox is missing Signed-off-by. Add it manually or with "git commit --amend -s"',
'Sign off the patch (either manually or with "git commit --amend -s")', commit=commit)
commit)

View File

@ -34,8 +34,7 @@ class LicFilesChkSum(base.Metadata):
if rd.getVar(self.license) == self.closed: if rd.getVar(self.license) == self.closed:
continue continue
if not lic_files_chksum: if not lic_files_chksum:
self.fail('%s is missing in newly added recipe' % self.metadata, self.fail('%s is missing in newly added recipe' % self.metadata)
'Specify the variable %s in %s' % (self.metadata, pn))
def pretest_lic_files_chksum_modified_not_mentioned(self): def pretest_lic_files_chksum_modified_not_mentioned(self):
if not self.modified: if not self.modified:
@ -77,6 +76,5 @@ class LicFilesChkSum(base.Metadata):
if self.lictag_re.search(commit.commit_message): if self.lictag_re.search(commit.commit_message):
break break
else: else:
self.fail('LIC_FILES_CHKSUM changed on target %s but there is no "%s" tag in commit message' % (pn, self.lictag), 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),
'Include "%s: <description>" into the commit message with a brief description' % self.lictag,
data=[('Current checksum', pretest), ('New checksum', test)]) data=[('Current checksum', pretest), ('New checksum', test)])

View File

@ -51,5 +51,5 @@ class License(base.Metadata):
fd.write(''.join(lines[:-1])) fd.write(''.join(lines[:-1]))
if no_license: if no_license:
self.fail('Recipe does not have the LICENSE field set', 'Include a LICENSE into the new recipe') self.fail('Recipe does not have the LICENSE field set.')

View File

@ -21,6 +21,5 @@ class MaxLength(base.Base):
if self.add_mark.match(line): if self.add_mark.match(line):
current_line_length = len(line[1:]) current_line_length = len(line[1:])
if current_line_length > self.max_length: if current_line_length > self.max_length:
self.fail('Patch line too long (current length %s)' % current_line_length, self.fail('Patch line too long (current length %s, maximum is %s)' % (current_line_length, self.max_length),
'Shorten the corresponding patch line (max length supported %s)' % self.max_length,
data=[('Patch', patch.path), ('Line', '%s ...' % line[0:80])]) data=[('Patch', patch.path), ('Line', '%s ...' % line[0:80])])

View File

@ -69,7 +69,6 @@ class SrcUri(base.Metadata):
# TODO: we are not taking into account renames, so test may raise false positives # TODO: we are not taking into account renames, so test may raise false positives
not_removed = filesremoved_from_usr_uri - filesremoved_from_patchset not_removed = filesremoved_from_usr_uri - filesremoved_from_patchset
if not_removed: if not_removed:
self.fail('Patches not removed from tree', self.fail('Patches not removed from tree. Remove them and amend the submitted mbox',
'Amend the patch containing the software patch file removal',
data=[('Patch', f) for f in not_removed]) data=[('Patch', f) for f in not_removed])

View File

@ -28,5 +28,4 @@ class Summary(base.Metadata):
# "${PN} version ${PN}-${PR}" is the default, so fail if default # "${PN} version ${PN}-${PR}" is the default, so fail if default
if summary.startswith('%s version' % pn): if summary.startswith('%s version' % pn):
self.fail('%s is missing in newly added recipe' % self.metadata, self.fail('%s is missing in newly added recipe' % self.metadata)
'Specify the variable %s in %s' % (self.metadata, pn))

View File

@ -46,6 +46,5 @@ class CVE(base.Base):
tag_found = True tag_found = True
break break
if not tag_found: if not tag_found:
self.fail('Missing or incorrectly formatted CVE tag in included patch file', 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"',
'Correct or include the CVE tag on cve patch with format: "CVE: CVE-YYYY-XXXX"', commit=commit)
commit)

View File

@ -39,5 +39,4 @@ class PatchSignedOffBy(base.Base):
if PatchSignedOffBy.prog.search_string(payload): if PatchSignedOffBy.prog.search_string(payload):
break break
else: else:
self.fail('A patch file has been added, but does not have a Signed-off-by tag', 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)
'Sign off the added patch file (%s)' % newpatch.path)

View File

@ -34,8 +34,7 @@ class PatchUpstreamStatus(base.Base):
for newpatch in PatchUpstreamStatus.newpatches: for newpatch in PatchUpstreamStatus.newpatches:
payload = newpatch.__str__() payload = newpatch.__str__()
if not self.upstream_status_regex.search_string(payload): if not self.upstream_status_regex.search_string(payload):
self.fail('Added patch file is missing Upstream-Status in the header', self.fail('Added patch file is missing Upstream-Status in the header. Add Upstream-Status: <Valid status> to the header',
'Add Upstream-Status: <Valid status> to the header of %s' % newpatch.path,
data=[('Standard format', self.standard_format), ('Valid status', self.valid_status)]) data=[('Standard format', self.standard_format), ('Valid status', self.valid_status)])
for line in payload.splitlines(): for line in payload.splitlines():
if self.patchmetadata_regex.match(line): if self.patchmetadata_regex.match(line):
@ -46,19 +45,16 @@ class PatchUpstreamStatus(base.Base):
parse_upstream_status.upstream_status_inappropriate_info.parseString(line.lstrip('+')) parse_upstream_status.upstream_status_inappropriate_info.parseString(line.lstrip('+'))
except pyparsing.ParseException as pe: except pyparsing.ParseException as pe:
self.fail('Upstream-Status is Inappropriate, but no reason was provided', self.fail('Upstream-Status is Inappropriate, but no reason was provided',
'Include a brief reason why %s is inappropriate' % os.path.basename(newpatch.path),
data=[('Current', pe.pstr), ('Standard format', 'Upstream-Status: Inappropriate [reason]')]) data=[('Current', pe.pstr), ('Standard format', 'Upstream-Status: Inappropriate [reason]')])
elif parse_upstream_status.submitted_status_mark.searchString(line): elif parse_upstream_status.submitted_status_mark.searchString(line):
try: try:
parse_upstream_status.upstream_status_submitted_info.parseString(line.lstrip('+')) parse_upstream_status.upstream_status_submitted_info.parseString(line.lstrip('+'))
except pyparsing.ParseException as pe: except pyparsing.ParseException as pe:
self.fail('Upstream-Status is Submitted, but it is not mentioned where', self.fail('Upstream-Status is Submitted, but it is not mentioned where',
'Include where %s was submitted' % os.path.basename(newpatch.path),
data=[('Current', pe.pstr), ('Standard format', 'Upstream-Status: Submitted [where]')]) data=[('Current', pe.pstr), ('Standard format', 'Upstream-Status: Submitted [where]')])
else: else:
try: try:
parse_upstream_status.upstream_status.parseString(line.lstrip('+')) parse_upstream_status.upstream_status.parseString(line.lstrip('+'))
except pyparsing.ParseException as pe: except pyparsing.ParseException as pe:
self.fail('Upstream-Status is in incorrect format', self.fail('Upstream-Status is in incorrect format',
'Fix Upstream-Status format in %s' % os.path.basename(newpatch.path),
data=[('Current', pe.pstr), ('Standard format', self.standard_format), ('Valid status', self.valid_status)]) data=[('Current', pe.pstr), ('Standard format', self.standard_format), ('Valid status', self.valid_status)])

View File

@ -56,6 +56,5 @@ class PyLint(base.Base):
for issue in self.pylint_test: for issue in self.pylint_test:
if self.pylint_test[issue] not in self.pylint_pretest.values(): if self.pylint_test[issue] not in self.pylint_pretest.values():
self.fail('Errors in your Python code were encountered', self.fail('Errors in your Python code were encountered. Please check your code with a linter and resubmit',
'Correct the lines introduced by your patch',
data=[('Output', 'Please, fix the listed issues:'), ('', issue + ' ' + self.pylint_test[issue])]) data=[('Output', 'Please, fix the listed issues:'), ('', issue + ' ' + self.pylint_test[issue])])