[Concept,09/18] buildman: Add test for IDE mode output

Message ID 20260109183116.3262115-10-sjg@u-boot.org
State New
Headers
Series buildman: Improve test coverage for builder.py |

Commit Message

Simon Glass Jan. 9, 2026, 6:31 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Add testCurrentSourceIde() to verify that IDE mode (-I flag) correctly
outputs build errors to stderr and suppresses progress output to stdout.

Also update _HandleMake() to support error injection for current source
builds where the commit parameter is the string 'current'.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 tools/buildman/func_test.py | 74 +++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
  

Patch

diff --git a/tools/buildman/func_test.py b/tools/buildman/func_test.py
index 0ee52d16703..efd66796a65 100644
--- a/tools/buildman/func_test.py
+++ b/tools/buildman/func_test.py
@@ -525,6 +525,9 @@  Some images are invalid'''
                     stderr = "binman: Filename 'fsp.bin' not found in input path"
             elif type(commit) is not str:
                 stderr = self._error.get((brd.target, commit.sequence))
+            else:
+                # For current source builds, commit is 'current'
+                stderr = self._error.get((brd.target, commit))
 
             if stderr:
                 return command.CommandResult(return_code=2, stderr=stderr)
@@ -593,6 +596,77 @@  Some images are invalid'''
         self.assertEqual(self._builder.count, self._total_builds)
         self.assertEqual(self._builder.fail, 0)
 
+    def testCurrentSourceIde(self):
+        """Test building current source with IDE mode enabled
+
+        This tests that:
+        - Build errors are written to stderr
+        - Progress output does not go to stdout in IDE mode
+        - Summary mode (-s) shows output again
+        """
+        # Set up a build error for sandbox board (board4) which has toolchain
+        # For current source builds, commit is 'current' string
+        error_msg = 'test_error_msg.c:123: error: test failure\n'
+        self._error['board4', 'current'] = error_msg
+
+        # Capture stderr during the build
+        captured_stderr = io.StringIO()
+        old_stderr = sys.stderr
+        try:
+            sys.stderr = captured_stderr
+            terminal.get_print_test_lines()  # Clear any previous output
+            self._RunControl('-o', self._output_dir, '-I')
+        finally:
+            sys.stderr = old_stderr
+
+        # Verify there is a build failure
+        self.assertEqual(self._builder.fail, 1)
+
+        # Check stderr has exactly the expected error
+        self.assertEqual(captured_stderr.getvalue(),
+                         'test_error_msg.c:123: error: test failure\n')
+
+        # In IDE mode, there should be no stdout output at all
+        self.assertEqual(terminal.get_print_test_lines(), [])
+
+        # Now run with -s to show summary - output should appear again
+        terminal.get_print_test_lines()  # Clear
+        self._RunControl('-o', self._output_dir, '-s', clean_dir=False)
+        lines = terminal.get_print_test_lines()
+        self.assertEqual(len(lines), 2)
+        self.assertIn('Summary of', lines[0].text)
+        self.assertIn('board4', lines[1].text)
+
+    def testBranchIde(self):
+        """Test building a branch with IDE mode and summary
+
+        This tests _print_ide_output() which outputs errors to stderr during
+        the summary phase for branch builds.
+        """
+        # Set up error for commit 1 on sandbox board
+        error_msg = 'branch_error.c:456: error: branch failure\n'
+        self._error['board4', 1] = error_msg
+
+        # Build branch normally first (writes results to disk)
+        terminal.get_print_test_lines()
+        self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir)
+        self.assertEqual(self._builder.fail, 1)
+
+        # Run summary with IDE mode - errors go to stderr via _print_ide_output
+        captured_stderr = io.StringIO()
+        old_stderr = sys.stderr
+        try:
+            sys.stderr = captured_stderr
+            terminal.get_print_test_lines()
+            self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir, '-sI',
+                             clean_dir=False)
+        finally:
+            sys.stderr = old_stderr
+
+        # Check stderr has the error from _print_ide_output
+        self.assertEqual(captured_stderr.getvalue(),
+                         'branch_error.c:456: error: branch failure\n')
+
     def testBranchSummary(self):
         """Test building a branch and then showing a summary"""
         self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir)