From patchwork Mon Oct 26 01:04:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1387378 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=HaWpoJMt; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CKGtt1ZC1z9sTD for ; Mon, 26 Oct 2020 12:08:53 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BD24182529; Mon, 26 Oct 2020 02:05:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="HaWpoJMt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5546D824CD; Mon, 26 Oct 2020 02:05:23 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x12b.google.com (mail-il1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E136382495 for ; Mon, 26 Oct 2020 02:05:19 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x12b.google.com with SMTP id k1so6746388ilc.10 for ; Sun, 25 Oct 2020 18:05:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nC0N9LEXM2f1aZSJv1RMOCMj/3OoXB90POlJZ0cqkCk=; b=HaWpoJMt4EMGigUAyke+wW/KrMysHVVu74ScaDEwS7hYb5BUuY+zjZaxQzyZRFOJPC zxxdVc2Kdq2bgkmBoKRe2JAgi79t2lyUsFvddp5+zIjfn4y7opKJSxYLulSW5M4YMzNi 6Ryt6tGTVhdgqMQa5wDGoVN31tGzunGeJrwO4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nC0N9LEXM2f1aZSJv1RMOCMj/3OoXB90POlJZ0cqkCk=; b=iKR0kQYQpzbWI220uj/tKjbyDf3EUfdLJFABkw9CkPvsiTFJk9OlrhmX4xFkKi7vRz SaosrNcypwbUNtHeEPbFMXC8PpBknlabguq2Ls6z1OBQ8EqhWldSibd8ahehzQzSHueE vrdCy1uItUxWmRlKKNEi/JOL98i+ZNP7YiMVtkBcrcaztzofd7Mo2ORmfDk8Kpq24DUJ PjWUoxJNVYvu3xn0Q+BnnoaW1R6qJdDbEpTucfUG4HlwK8mHbr3aXkICHJTU80clh1pH eF068UCmnaUpsGL4Wenx8VgeWX4HUws7bigQnD06L0Bo/6DOr6ib1pQWGM2zVOX2AESZ stZw== X-Gm-Message-State: AOAM532A/UAdCLwOpNtrTzhkWqaAcmrrfY2RauT2gR/9wufM5tFAHk+3 S46+Wq8T5cleSbm8Q/GsFaYXsv3cZYmfv1W0 X-Google-Smtp-Source: ABdhPJz1sbOHQoHeXXm+CBxMgJVkBEEr/BmRGK9CSNY8sECXrAvdoO7IlvTsdZaJjgwbobHtj2wMpA== X-Received: by 2002:a92:5f53:: with SMTP id t80mr7489548ilb.160.1603674318461; Sun, 25 Oct 2020 18:05:18 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id a6sm5231162ili.11.2020.10.25.18.05.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 18:05:18 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Doug Anderson , patchwork@lists.ozlabs.org, Simon Glass Subject: [PATCH v2 19/30] patman: Add some tests for warnings Date: Sun, 25 Oct 2020 19:04:31 -0600 Message-Id: <20201026010442.1606893-20-sjg@chromium.org> X-Mailer: git-send-email 2.29.0.rc2.309.g374f81d7ae-goog In-Reply-To: <20201026010442.1606893-1-sjg@chromium.org> References: <20201026010442.1606893-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Add tests that check that warnings are generated when expected. Signed-off-by: Simon Glass --- (no changes since v1) tools/patman/func_test.py | 111 +++++++++++++++++++++++++++++++++--- tools/patman/main.py | 16 +++++- tools/patman/patchstream.py | 2 +- 3 files changed, 116 insertions(+), 13 deletions(-) diff --git a/tools/patman/func_test.py b/tools/patman/func_test.py index 2a0da8b3ccf..02d46ae5f73 100644 --- a/tools/patman/func_test.py +++ b/tools/patman/func_test.py @@ -33,6 +33,9 @@ class TestFunctional(unittest.TestCase): """Functional tests for checking that patman behaves correctly""" leb = (b'Lord Edmund Blackadd\xc3\xabr '. decode('utf-8')) + fred = 'Fred Bloggs ' + joe = 'Joe Bloggs ' + mary = 'Mary Bloggs ' def setUp(self): self.tmpdir = tempfile.mkdtemp(prefix='patman.') @@ -180,7 +183,6 @@ class TestFunctional(unittest.TestCase): stefan = b'Stefan Br\xc3\xbcns '.decode('utf-8') rick = 'Richard III ' mel = b'Lord M\xc3\xablchett '.decode('utf-8') - fred = 'Fred Bloggs ' add_maintainers = [stefan, rick] dry_run = True in_reply_to = mel @@ -189,7 +191,7 @@ class TestFunctional(unittest.TestCase): 'fdt': ['simon'], 'u-boot': ['u-boot@lists.denx.de'], 'simon': [self.leb], - 'fred': [fred], + 'fred': [self.fred], } text = self._get_text('test01.txt') @@ -231,7 +233,7 @@ class TestFunctional(unittest.TestCase): self.assertEqual('Prefix:\t RFC', lines[line + 3]) self.assertEqual('Cover: 4 lines', lines[line + 4]) line += 5 - self.assertEqual(' Cc: %s' % fred, lines[line + 0]) + self.assertEqual(' Cc: %s' % self.fred, lines[line + 0]) self.assertEqual(' Cc: %s' % tools.FromUnicode(self.leb), lines[line + 1]) self.assertEqual(' Cc: %s' % tools.FromUnicode(mel), @@ -248,7 +250,7 @@ class TestFunctional(unittest.TestCase): self.assertEqual(('%s %s\0%s' % (args[0], rick, stefan)), tools.ToUnicode(cc_lines[0])) self.assertEqual( - '%s %s\0%s\0%s\0%s' % (args[1], fred, self.leb, rick, stefan), + '%s %s\0%s\0%s\0%s' % (args[1], self.fred, self.leb, rick, stefan), tools.ToUnicode(cc_lines[1])) expected = ''' @@ -487,12 +489,103 @@ complicated as possible''') text = '''This is a patch Signed-off-by: Terminator -Reviewed-by: Joe Bloggs -Reviewed-by: Mary Bloggs +Reviewed-by: %s +Reviewed-by: %s Tested-by: %s -''' % self.leb +''' % (self.joe, self.mary, self.leb) pstrm = PatchStream.process_text(text) self.assertEqual(pstrm.commit.rtags, { - 'Reviewed-by': {'Mary Bloggs ', - 'Joe Bloggs '}, + 'Reviewed-by': {self.joe, self.mary}, 'Tested-by': {self.leb}}) + + def testMissingEnd(self): + """Test a missing END tag""" + text = '''This is a patch + +Cover-letter: +This is the title +missing END after this line +Signed-off-by: Fred +''' + pstrm = PatchStream.process_text(text) + self.assertEqual(["Missing 'END' in section 'cover'"], + pstrm.commit.warn) + + def testMissingBlankLine(self): + """Test a missing blank line after a tag""" + text = '''This is a patch + +Series-changes: 2 +- First line of changes +- Missing blank line after this line +Signed-off-by: Fred +''' + pstrm = PatchStream.process_text(text) + self.assertEqual(["Missing 'blank line' in section 'Series-changes'"], + pstrm.commit.warn) + + def testInvalidCommitTag(self): + """Test an invalid Commit-xxx tag""" + text = '''This is a patch + +Commit-fred: testing +''' + pstrm = PatchStream.process_text(text) + self.assertEqual(["Line 3: Ignoring Commit-fred"], pstrm.commit.warn) + + def testSelfTest(self): + """Test a tested by tag by this user""" + test_line = 'Tested-by: %s@napier.com' % os.getenv('USER') + text = '''This is a patch + +%s +''' % test_line + pstrm = PatchStream.process_text(text) + self.assertEqual(["Ignoring '%s'" % test_line], pstrm.commit.warn) + + def testSpaceBeforeTab(self): + """Test a space before a tab""" + text = '''This is a patch + ++ \tSomething +''' + pstrm = PatchStream.process_text(text) + self.assertEqual(["Line 3/0 has space before tab"], pstrm.commit.warn) + + def testLinesAfterTest(self): + """Test detecting lines after TEST= line""" + text = '''This is a patch + +TEST=sometest +more lines +here +''' + pstrm = PatchStream.process_text(text) + self.assertEqual(["Found 2 lines after TEST="], pstrm.commit.warn) + + def testBlankLineAtEnd(self): + """Test detecting a blank line at the end of a file""" + text = '''This is a patch + +diff --git a/lib/fdtdec.c b/lib/fdtdec.c +index c072e54..942244f 100644 +--- a/lib/fdtdec.c ++++ b/lib/fdtdec.c +@@ -1200,7 +1200,8 @@ int fdtdec_setup_mem_size_base(void) + } + + gd->ram_size = (phys_size_t)(res.end - res.start + 1); +- debug("%s: Initial DRAM size %llx\n", __func__, (u64)gd->ram_size); ++ debug("%s: Initial DRAM size %llx\n", __func__, ++ (unsigned long long)gd->ram_size); ++ +diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c + +-- +2.7.4 + + ''' + pstrm = PatchStream.process_text(text) + self.assertEqual( + ["Found possible blank line(s) at end of file 'lib/fdtdec.c'"], + pstrm.commit.warn) diff --git a/tools/patman/main.py b/tools/patman/main.py index b96000807eb..d1a43c44fcd 100755 --- a/tools/patman/main.py +++ b/tools/patman/main.py @@ -86,6 +86,8 @@ AddCommonArgs(send) send.add_argument('patchfiles', nargs='*') test_parser = subparsers.add_parser('test', help='Run tests') +test_parser.add_argument('testname', type=str, default=None, nargs='?', + help="Specify the test to run") AddCommonArgs(test_parser) # Parse options twice: first to get the project and second to handle @@ -111,15 +113,23 @@ if args.cmd == 'test': sys.argv = [sys.argv[0]] result = unittest.TestResult() + suite = unittest.TestSuite() + loader = unittest.TestLoader() for module in (test_checkpatch.TestPatch, func_test.TestFunctional): - suite = unittest.TestLoader().loadTestsFromTestCase(module) - suite.run(result) + if args.testname: + try: + suite.addTests(loader.loadTestsFromName(args.testname, module)) + except AttributeError: + continue + else: + suite.addTests(loader.loadTestsFromTestCase(module)) + suite.run(result) for module in ['gitutil', 'settings', 'terminal']: suite = doctest.DocTestSuite(module) suite.run(result) - sys.exit(test_util.ReportResult('patman', None, result)) + sys.exit(test_util.ReportResult('patman', args.testname, result)) # Process commits, produce patches files, check them, email them elif args.cmd == 'send': diff --git a/tools/patman/patchstream.py b/tools/patman/patchstream.py index d6f6ae92513..1cb4d6ed0dd 100644 --- a/tools/patman/patchstream.py +++ b/tools/patman/patchstream.py @@ -419,7 +419,7 @@ class PatchStream: # Remove Tested-by self, since few will take much notice if (rtag_type == 'Tested-by' and who.find(os.getenv('USER') + '@') != -1): - self._add_warn("Ignoring %s" % line) + self._add_warn("Ignoring '%s'" % line) elif rtag_type == 'Patch-cc': self.commit.AddCc(who.split(',')) else: