aboutsummaryrefslogtreecommitdiff
path: root/tools/patman
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2020-06-14 10:54:05 -0600
committerSimon Glass <sjg@chromium.org>2020-07-09 18:57:22 -0600
commit4148c20f533d908a4255c134601b335322a0d38f (patch)
tree3277f328e58a73bc5ea2ec49d70fe81edcc0b8ff /tools/patman
parent40d9734cb17897329389230c7ebd9502c95c899b (diff)
downloadu-boot-4148c20f533d908a4255c134601b335322a0d38f.zip
u-boot-4148c20f533d908a4255c134601b335322a0d38f.tar.gz
u-boot-4148c20f533d908a4255c134601b335322a0d38f.tar.bz2
patman: Add a test for the 'possible new uclass' check
It is quite likely that the number of U-Boot-specific tests in checkpatch.pl will increase over time. We should have tests for these to avoid undefined behaviour and bugs being introduced, which might cause people to ignore the warnings. Add a simple new class that can generate a patch with a single-line addition in it. Use that to add a test for one of the checkpatch checks. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/patman')
-rw-r--r--tools/patman/test_checkpatch.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/tools/patman/test_checkpatch.py b/tools/patman/test_checkpatch.py
index 03ff576..e841b9a 100644
--- a/tools/patman/test_checkpatch.py
+++ b/tools/patman/test_checkpatch.py
@@ -17,6 +17,74 @@ from patman import series
from patman import commit
+class Line:
+ def __init__(self, fname, text):
+ self.fname = fname
+ self.text = text
+
+
+class PatchMaker:
+ def __init__(self):
+ self.lines = []
+
+ def add_line(self, fname, text):
+ self.lines.append(Line(fname, text))
+
+ def get_patch_text(self):
+ base = '''From 125b77450f4c66b8fd9654319520bbe795c9ef31 Mon Sep 17 00:00:00 2001
+From: Simon Glass <sjg@chromium.org>
+Date: Sun, 14 Jun 2020 09:45:14 -0600
+Subject: [PATCH] Test commit
+
+This is a test commit.
+
+Signed-off-by: Simon Glass <sjg@chromium.org>
+---
+
+'''
+ lines = base.splitlines()
+
+ # Create the diffstat
+ change = 0
+ insert = 0
+ for line in self.lines:
+ lines.append(' %s | 1 +' % line.fname)
+ change += 1
+ insert += 1
+ lines.append(' %d files changed, %d insertions(+)' % (change, insert))
+ lines.append('')
+
+ # Create the patch info for each file
+ for line in self.lines:
+ lines.append('diff --git a/%s b/%s' % (line.fname, line.fname))
+ lines.append('index 7837d459f18..5ba7840f68e 100644')
+ lines.append('--- a/%s' % line.fname)
+ lines.append('+++ b/%s' % line.fname)
+ lines += ('''@@ -121,6 +121,7 @@ enum uclass_id {
+ UCLASS_W1, /* Dallas 1-Wire bus */
+ UCLASS_W1_EEPROM, /* one-wire EEPROMs */
+ UCLASS_WDT, /* Watchdog Timer driver */
++%s
+
+ UCLASS_COUNT,
+ UCLASS_INVALID = -1,
+''' % line.text).splitlines()
+ lines.append('---')
+ lines.append('2.17.1')
+
+ return '\n'.join(lines)
+
+ def get_patch(self):
+ inhandle, inname = tempfile.mkstemp()
+ infd = os.fdopen(inhandle, 'w')
+ infd.write(self.get_patch_text())
+ infd.close()
+ return inname
+
+ def run_checkpatch(self):
+ return checkpatch.CheckPatch(self.get_patch())
+
+
class TestPatch(unittest.TestCase):
"""Test the u_boot_line() function in checkpatch.pl"""
@@ -280,6 +348,15 @@ index 0000000..2234c87
self.assertEqual(result.lines, 62)
os.remove(inf)
+ def testUclass(self):
+ """Test for possible new uclass"""
+ pm = PatchMaker()
+ pm.add_line('include/dm/uclass-id.h', 'UCLASS_WIBBLE,')
+ result = pm.run_checkpatch()
+ self.assertEqual(result.warnings, 1)
+ self.assertEqual(len(result.problems), 1)
+ self.assertIn('Possible new uclass', result.problems[0]['msg'])
+
if __name__ == "__main__":
unittest.main()