Some tests intentionally trigger diagnostics that the Python console
parser treats as unexpected errors.

Add helpers that silence these diagnostics while preserving the previous
console state, allowing tests to hide expected errors without accessing
global data directly.

Signed-off-by: Jerome Forissier <[email protected]>
---
 include/test/ut.h | 17 +++++++++++++++++
 test/ut.c         | 15 +++++++++++++++
 2 files changed, 32 insertions(+)

I am proposing this patch as a prerequisite to merging the series "net:
lwip: restore TFTP client and command parity" by James H. [1] which would
otherwise introduce a CI error [2]. The error is fixed in pipeline 1762
[3].

[1] 
https://lore.kernel.org/u-boot/20261024-submit-lwip-tftp-combined-v1-v2-0-0f663f735...@gmail.com/
[2] 
https://git.u-boot-project.org/u-boot/custodians/u-boot-net/-/jobs/128187#L3716
[3] https://git.u-boot-project.org/u-boot/custodians/u-boot-net/-/pipelines/1762

diff --git a/include/test/ut.h b/include/test/ut.h
index 6510c35997fb..a528b49a7670 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -549,6 +549,23 @@ long ut_check_delta(ulong last);
  */
 void ut_silence_console(struct unit_test_state *uts);
 
+/**
+ * ut_silence_console_force() - Unconditionally silence the console
+ *
+ * This silences the console even when U-Boot is started with the sandbox -v
+ * option.
+ *
+ * Return: true if the console was already silent
+ */
+bool ut_silence_console_force(void);
+
+/**
+ * ut_restore_console_silence() - Restore the console silence state
+ *
+ * @was_silent: State returned by ut_silence_console_force()
+ */
+void ut_restore_console_silence(bool was_silent);
+
 /**
  * ut_unsilence_console() - Unsilence the console after a test
  *
diff --git a/test/ut.c b/test/ut.c
index a16fdfb3a93c..dd2fec8425a8 100644
--- a/test/ut.c
+++ b/test/ut.c
@@ -222,6 +222,21 @@ void ut_silence_console(struct unit_test_state *uts)
 #endif
 }
 
+bool ut_silence_console_force(void)
+{
+       bool was_silent = gd->flags & GD_FLG_SILENT;
+
+       gd->flags |= GD_FLG_SILENT;
+
+       return was_silent;
+}
+
+void ut_restore_console_silence(bool was_silent)
+{
+       if (!was_silent)
+               gd->flags &= ~GD_FLG_SILENT;
+}
+
 void ut_unsilence_console(struct unit_test_state *uts)
 {
        gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
-- 
2.48.1

Reply via email to