From patchwork Tue Jan 6 14:28:25 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1301 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767709814; bh=hXHi8+K7HSCeg4hLsjTUlxTwwChSiw5GFs+9SBTOBHU=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=Ob7o4TE6x4uisOrAAhpFvmzk7IdlcBLT9Cr5bjGv9yPXm5E5MbimPDutME5dT3qOi tC/hjot++nNV/TK1tY86fPJuU0+6g+UH69ax16GskuYn0tW9kWHH1m8bdahcTL84yD s7H1c5l4gl/7+/lFi3zA/KoTGoYdxIF+r4wmjuJzALqaDyod8fwMqN5/V4UsjC5opV bpImvkjD8+CB6VdyIWBExHhB8L7NjN20CFQ1k/eS8Y1z638CRvlgz9bRgwJhcIT0nC QLoSVEXFedFgeA7CfsV2X6uB7RhfD+gXka3M/NLxvYB0CWLo8M1a5yEqf9GbeKlpAm yLxO7yiwHeNzg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CC24269087 for ; Tue, 6 Jan 2026 07:30:14 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id cx6ilE8yopxO for ; Tue, 6 Jan 2026 07:30:14 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767709814; bh=hXHi8+K7HSCeg4hLsjTUlxTwwChSiw5GFs+9SBTOBHU=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=Ob7o4TE6x4uisOrAAhpFvmzk7IdlcBLT9Cr5bjGv9yPXm5E5MbimPDutME5dT3qOi tC/hjot++nNV/TK1tY86fPJuU0+6g+UH69ax16GskuYn0tW9kWHH1m8bdahcTL84yD s7H1c5l4gl/7+/lFi3zA/KoTGoYdxIF+r4wmjuJzALqaDyod8fwMqN5/V4UsjC5opV bpImvkjD8+CB6VdyIWBExHhB8L7NjN20CFQ1k/eS8Y1z638CRvlgz9bRgwJhcIT0nC QLoSVEXFedFgeA7CfsV2X6uB7RhfD+gXka3M/NLxvYB0CWLo8M1a5yEqf9GbeKlpAm yLxO7yiwHeNzg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B985669118 for ; Tue, 6 Jan 2026 07:30:14 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767709812; bh=WSv9+v+tjbRQuknS3OwbMUCEFZeHrstT9CEYHCgmPbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a4uHLRbLX3YqJFsNuecXBrnBP5PEMxrCG7eW+XCUpvVGKgIkVuNxRKBa9pyQDmG2L RqS9O08Tfw2iWlTsZDyGzfPexxcmmQr7c4DgJr4ZuhgH6x0xCunVIVGX47YSb2h3Pc DKzSpr7g3Oe3utTcR3W6B9rcYrmF/kqZdtbclurlqgmUKfWAmHZoOjf9QYtN9UtnE0 Ykt3HxTKBpg1COc/UWjRFZ1Eqvvm68s9btjLxKGc6t1/5QkI+rVTfitrD2cM/hx0WT s79LUW7blB9CAq+C0U9fu45ozxRq+mRp2vnrUCnh/y+yVQcntXtKRPVnPKM5y3Dea6 S89JBmfwTYrpQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 367D169087; Tue, 6 Jan 2026 07:30:12 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id RG-n2h8_-nNZ; Tue, 6 Jan 2026 07:30:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767709807; bh=ufxgd3EEeEeRf7wYgRaqqmFA+8WVQeZZ1qzNehnc/zU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sNb6dThnCueubWPpmV02bRyqw7HtGukDBUAVT02P+3dK9UaaycIuUfKNnbNOxS0TH s9KIgrluwqvO34ndcHRs5TuW/yMQDsgtkdqhRg0wt2ikCVtWCXWTM2jaHohti32oRF Z+267kGIyGhxqBFVxgaEBXHg75yWGGWeN0CCOgLr0hEtl/YX/6aDmS2aIXdIZ86cg3 4HoJyq1nap84UFPokanzfyCNGxcUstZTOIVMkrdR71j3O4KHhxBdocvQvN9vRrXsAM 5nPMpLnTLoPJuCcZ4veAd6GeLM95CIy4J4gPBRhpLFiFaKoNyBldfuqh8Pb+FGNNYX v+fh0bnwxTCBw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 7C7D969054; Tue, 6 Jan 2026 07:30:07 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 6 Jan 2026 07:28:25 -0700 Message-ID: <20260106142834.2511220-21-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260106142834.2511220-1-sjg@u-boot.org> References: <20260106142834.2511220-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: TJQW3GBFNN7V5YRCX56POPM5OUE2ZWPM X-Message-ID-Hash: TJQW3GBFNN7V5YRCX56POPM5OUE2ZWPM X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 20/22] buildman: Refactor _check_output() in test.py List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Move add_line_prefix() out of _check_output() to be a standalone class method. Split _check_output() into two parts, with _check_output_part2() handling commits 5-7. This reduces the complexity of _check_output() and improves readability. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- tools/buildman/test.py | 98 +++++++++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 40 deletions(-) diff --git a/tools/buildman/test.py b/tools/buildman/test.py index 40ddb351b3c..eafe2acb122 100644 --- a/tools/buildman/test.py +++ b/tools/buildman/test.py @@ -278,6 +278,34 @@ class TestBuildOutput(TestBuildBase): terminal.echo_print_test_lines() return iter(terminal.get_print_test_lines()) + def _add_pfx(self, prefix, brds, error_str, colour): + """Add a prefix to each line of a string + + The trailing newline in error_str is removed before processing + + Args: + prefix (str): String prefix to add + brds (str): Board names to include in the output + error_str (str): Error string containing the lines + colour (int): Expected colour for the line. Note that the board + list, if present, always appears in magenta + + Returns: + str: New string where each line has the prefix added + """ + lines = error_str.strip().splitlines() + new_lines = [] + for line in lines: + if brds: + expect = self._col.build(colour, prefix + '(') + expect += self._col.build(self._col.MAGENTA, brds, + bright=False) + expect += self._col.build(colour, f') {line}') + else: + expect = self._col.build(colour, prefix + line) + new_lines.append(expect) + return '\n'.join(new_lines) + def _check_output(self, lines, list_error_boards=False, filter_dtb_warnings=False, filter_migration_warnings=False): @@ -290,34 +318,6 @@ class TestBuildOutput(TestBuildBase): filter_dtb_warnings: Adjust the check for output produced with the --filter-dtb-warnings flag """ - def add_line_prefix(prefix, brds, error_str, colour): - """Add a prefix to each line of a string - - The trailing newline in error_str is removed before processing - - Args: - prefix (str): String prefix to add - brds (str): Board names to include in the output - error_str (str): Error string containing the lines - colour (int): Expected colour for the line. Note that the board - list, if present, always appears in magenta - - Returns: - str: New string where each line has the prefix added - """ - lines = error_str.strip().splitlines() - new_lines = [] - for line in lines: - if brds: - expect = self._col.build(colour, prefix + '(') - expect += self._col.build(self._col.MAGENTA, brds, - bright=False) - expect += self._col.build(colour, f') {line}') - else: - expect = self._col.build(colour, prefix + line) - new_lines.append(expect) - return '\n'.join(new_lines) - col = terminal.Color() boards01234 = ('board0 board1 board2 board3 board4' if list_error_boards else '') @@ -338,7 +338,7 @@ class TestBuildOutput(TestBuildBase): outcome=OUTCOME_WARN) self.assertEqual(next(lines).text, - add_line_prefix('+', boards01234, MIGRATION, col.RED)) + self._add_pfx('+', boards01234, MIGRATION, col.RED)) # Second commit: all archs should fail with warnings self.assertEqual(next(lines).text, f'02: {COMMITS[1][1]}') @@ -353,7 +353,7 @@ class TestBuildOutput(TestBuildBase): # Second commit: The warnings should be listed self.assertEqual(next(lines).text, - add_line_prefix('w+', boards1234, ERRORS[0], col.YELLOW)) + self._add_pfx('w+', boards1234, ERRORS[0], col.YELLOW)) # Third commit: Still fails self.assertEqual(next(lines).text, f'03: {COMMITS[2][1]}') @@ -366,7 +366,7 @@ class TestBuildOutput(TestBuildBase): # Expect a compiler error self.assertEqual(next(lines).text, - add_line_prefix('+', boards234, ERRORS[1], col.RED)) + self._add_pfx('+', boards234, ERRORS[1], col.RED)) # Fourth commit: Compile errors are fixed, just have warning for board3 self.assertEqual(next(lines).text, f'04: {COMMITS[3][1]}') @@ -387,13 +387,31 @@ class TestBuildOutput(TestBuildBase): # Compile error fixed self.assertEqual(next(lines).text, - add_line_prefix('-', boards234, ERRORS[1], col.GREEN)) + self._add_pfx('-', boards234, ERRORS[1], col.GREEN)) if not filter_dtb_warnings: self.assertEqual( next(lines).text, - add_line_prefix('w+', boards34, ERRORS[2], col.YELLOW)) + self._add_pfx('w+', boards34, ERRORS[2], col.YELLOW)) + + self._check_output_part2(lines, col, boards01234, boards34, boards4, + filter_dtb_warnings, filter_migration_warnings) + def _check_output_part2(self, lines, col, boards01234, boards34, boards4, + filter_dtb_warnings, filter_migration_warnings): + """Check expected output from the build summary (commits 5-7) + + Args: + lines: Iterator containing the lines returned from the summary + col: terminal.Color object for building expected output + boards01234: Board string for all boards (or empty) + boards34: Board string for boards 3-4 (or empty) + boards4: Board string for board 4 (or empty) + filter_dtb_warnings: Adjust the check for output produced with the + --filter-dtb-warnings flag + filter_migration_warnings: Adjust the check for output produced + with the --filter-migration-warnings flag + """ # Fifth commit self.assertEqual(next(lines).text, f'05: {COMMITS[4][1]}') if filter_migration_warnings: @@ -406,12 +424,12 @@ class TestBuildOutput(TestBuildBase): expect = [expect[0]] + expect[2:] expect = '\n'.join(expect) self.assertEqual(next(lines).text, - add_line_prefix('+', boards4, expect, col.RED)) + self._add_pfx('+', boards4, expect, col.RED)) if not filter_dtb_warnings: self.assertEqual( next(lines).text, - add_line_prefix('w-', boards34, ERRORS[2], col.CYAN)) + self._add_pfx('w-', boards34, ERRORS[2], col.CYAN)) # Sixth commit self.assertEqual(next(lines).text, f'06: {COMMITS[5][1]}') @@ -427,9 +445,9 @@ class TestBuildOutput(TestBuildBase): expect = [expect[0]] + expect[2:] expect = '\n'.join(expect) self.assertEqual(next(lines).text, - add_line_prefix('-', boards4, expect, col.GREEN)) + self._add_pfx('-', boards4, expect, col.GREEN)) self.assertEqual(next(lines).text, - add_line_prefix('w-', boards4, ERRORS[0], col.CYAN)) + self._add_pfx('w-', boards4, ERRORS[0], col.CYAN)) # Seventh commit self.assertEqual(next(lines).text, f'07: {COMMITS[6][1]}') @@ -449,16 +467,16 @@ class TestBuildOutput(TestBuildBase): if not filter_migration_warnings: self.assertEqual( next(lines).text, - add_line_prefix('-', boards01234, MIGRATION, col.GREEN)) + self._add_pfx('-', boards01234, MIGRATION, col.GREEN)) self.assertEqual(next(lines).text, - add_line_prefix('+', boards4, expect, col.RED)) + self._add_pfx('+', boards4, expect, col.RED)) # Now the warnings lines expect = [expect_str[0]] + expect_str[10:12] + [expect_str[9]] expect = '\n'.join(expect) self.assertEqual(next(lines).text, - add_line_prefix('w+', boards4, expect, col.YELLOW)) + self._add_pfx('w+', boards4, expect, col.YELLOW)) def test_output(self): """Test basic builder operation and output