Skip to contentSkip to conversation

test: Add helpers to preserve console silence state

PATCH In review Jerome Forissier 3 participants 7 messages Oct 27 – Oct 28

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test: Add helpers to preserve console silence state

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.

---
 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-0f663f735ee8@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

include/test/ut.h +17 -0
index 6510c35997fb..a528b49a7670 100644
@@ -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
  *
test/ut.c +15 -0
index a16fdfb3a93c..dd2fec8425a8 100644
@@ -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);
Signature · 1 line
2.48.1
#1 lore raw
Quoted 13 lines · Jerome Forissier

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.

---
 include/test/ut.h | 17 +++++++++++++++++
 test/ut.c         | 15 +++++++++++++++
 2 files changed, 32 insertions(+)
Quoted 8 lines

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-0f663f735ee8@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

Sorry, what's the unexpected error line(s) in 2?

Signature · 1 line
Tom
#2 lore raw

Hi Tom,

Quoted 20 lines · Tom Rini
Quoted 18 lines · Jerome Forissier

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.

---
 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].

Quoted 6 lines
Quoted 3 lines

[1] https://lore.kernel.org/u-boot/20261024-submit-lwip-tftp-combined-v1-v2-0-0f663f735ee8@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

Sorry, what's the unexpected error line(s) in 2?

The failed test is tftp_test_protected_autostart(). The unexpected error is:

## Error: !

The test marks "autostart" read-only and then calls the TFTP download helpers, expecting them to fail [4]. The helpers reach netboot_run(), which tries to set "autostart" to "no" [5]. The environment code [6] consequently starts printing:

## Error: Can't overwrite "autostart"

The Python console parser defines "## Error: " as an error pattern [7]. It registers that pattern in the list of bad console patterns [8]. While waiting for the U-Boot prompt, run_command() matches the bad patterns and raises BootFail [9]. The match occurs as soon as the "## Error: " prefix is received, hence the truncated diagnostic followed by pytest's "!" failure marker.

The amended test fixes this by silencing the console only around the calls expected to fail and restoring its previous state afterwards [10].

[4] https://git.u-boot-project.org/u-boot/custodians/u-boot-net/-/blob/af860eb6/test/dm/tftp.c#L1021-1038
[5] https://git.u-boot-project.org/u-boot/custodians/u-boot-net/-/blob/af860eb6/net/net-common.c#L77-87
[6] https://git.u-boot-project.org/u-boot/custodians/u-boot-net/-/blob/af860eb6/env/flags.c#L580-583
[7] https://git.u-boot-project.org/u-boot/custodians/u-boot-net/-/blob/af860eb6/test/py/console_base.py#L24
[8] https://git.u-boot-project.org/u-boot/custodians/u-boot-net/-/blob/af860eb6/test/py/console_base.py#L43-49
[9] https://git.u-boot-project.org/u-boot/custodians/u-boot-net/-/blob/af860eb6/test/py/console_base.py#L340-346
[10] https://git.u-boot-project.org/u-boot/custodians/u-boot-net/-/blob/85f0eff82bd7117b062167e0a37b7a235e7485a2/test/dm/tftp.c#L837-850

Thanks,
Jerome

#3 lore raw
Quoted 49 lines · Jerome Forissier

Hi Tom,

Quoted 20 lines · Tom Rini
Quoted 18 lines · Jerome Forissier

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.

---
 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].

Quoted 6 lines
Quoted 3 lines

[1] https://lore.kernel.org/u-boot/20261024-submit-lwip-tftp-combined-v1-v2-0-0f663f735ee8@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

Sorry, what's the unexpected error line(s) in 2?

The failed test is tftp_test_protected_autostart(). The unexpected error is:

## Error: !

The test marks "autostart" read-only and then calls the TFTP download helpers, expecting them to fail [4]. The helpers reach netboot_run(), which tries to set "autostart" to "no" [5]. The environment code [6] consequently starts printing:

## Error: Can't overwrite "autostart"

The Python console parser defines "## Error: " as an error pattern [7]. It registers that pattern in the list of bad console patterns [8]. While waiting for the U-Boot prompt, run_command() matches the bad patterns and raises BootFail [9]. The match occurs as soon as the "## Error: " prefix is received, hence the truncated diagnostic followed by pytest's "!" failure marker.

Quoted 2 lines

The amended test fixes this by silencing the console only around the calls expected to fail and restoring its previous state afterwards [10].

Ah. But looking at test/py/tests/test_env.py we have a test doing:
def test_env_printenv_non_existent(state_test_env):
"""Test printenv error message for non-existant variables."""

var = state_test_env.set_var
c = state_test_env.ubman
with c.disable_check('error_notification'):
response = c.run_command('printenv %s' % var)
assert response == '## Error: "%s" not defined' % var

So can we do something similar for this test?

Signature · 1 line
Tom
#4 lore raw
Quoted 57 lines · Tom Rini
Quoted 49 lines · Jerome Forissier

Hi Tom,

Quoted 20 lines · Tom Rini
Quoted 18 lines · Jerome Forissier

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.

---
 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].

Quoted 6 lines
Quoted 3 lines

[1] https://lore.kernel.org/u-boot/20261024-submit-lwip-tftp-combined-v1-v2-0-0f663f735ee8@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

Sorry, what's the unexpected error line(s) in 2?

The failed test is tftp_test_protected_autostart(). The unexpected error is:

## Error: !

The test marks "autostart" read-only and then calls the TFTP download helpers, expecting them to fail [4]. The helpers reach netboot_run(), which tries to set "autostart" to "no" [5]. The environment code [6] consequently starts printing:

## Error: Can't overwrite "autostart"

The Python console parser defines "## Error: " as an error pattern [7]. It registers that pattern in the list of bad console patterns [8]. While waiting for the U-Boot prompt, run_command() matches the bad patterns and raises BootFail [9]. The match occurs as soon as the "## Error: " prefix is received, hence the truncated diagnostic followed by pytest's "!" failure marker.

Quoted 2 lines

The amended test fixes this by silencing the console only around the calls expected to fail and restoring its previous state afterwards [10].

Ah. But looking at test/py/tests/test_env.py we have a test doing:
def test_env_printenv_non_existent(state_test_env):
"""Test printenv error message for non-existant variables."""

Quoted 8 lines

var = state_test_env.set_var
c = state_test_env.ubman
with c.disable_check('error_notification'):
response = c.run_command('printenv %s' % var)
assert response == '## Error: "%s" not defined' % var

So can we do something similar for this test?

Absolutely. Simon G. mentioned this too. I will use disable_check('error_notification') where appropriate in James' series.

Thanks,

Signature · 1 line
Jerome
#5 lore raw
In reply to Jerome Forissier

Hi Jerome,

Quoted 17 lines · Jerome Forissier

test: Add helpers to preserve console silence state

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.

 include/test/ut.h | 17 +++++++++++++++++
 test/ut.c         | 15 +++++++++++++++
 2 files changed, 32 insertions(+)

include/test/ut.h long ut_check_delta(ulong last); · line 557

Quoted 9 lines
include/test/ut.h +9 -0
@@ -549,6 +549,23 @@ long ut_check_delta(ulong last);
+/**
+ * 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);

My understanding is that you need the 'force' variant because test/py always starts sandbox with -v (see console_sandbox.py), so ut_silence_console() never takes effect under pytest.

The downside is that it also hides the output when someone runs the test by hand with -v to debug it, which is exactly when they want to see it! Expected errors are normally handled on the Python side with ubman.disable_check(), or the test avoids printing a line that matches a bad pattern. If the C test must stay quiet, it would be worth checking the expected output with console recording and ut_assert_nextline(), since recording still works while the console is silent.

If we really need this, it might be better to change the signature of the existing ut_silence_console() and ut_unsilence_console() rather than adding a second pair alongside them. What do you think?

Regards,
Simon

#6 lore raw

Hi Simon,

Quoted 18 lines · Simon Glass

Hi Jerome,

Quoted 14 lines · Jerome Forissier

test: Add helpers to preserve console silence state

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.

 include/test/ut.h | 17 +++++++++++++++++
 test/ut.c         | 15 +++++++++++++++
 2 files changed, 32 insertions(+)
Quoted 15 lines

include/test/ut.h long ut_check_delta(ulong last); · line 557

Quoted 11 lines
include/test/ut.h +9 -0
@@ -549,6 +549,23 @@ long ut_check_delta(ulong last);
+/**
+ * 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);

My understanding is that you need the 'force' variant because test/py always starts sandbox with -v (see console_sandbox.py), so ut_silence_console() never takes effect under pytest.

Correct.

Quoted 3 lines

The downside is that it also hides the output when someone runs the test by hand with -v to debug it, which is exactly when they want to see it!

Not a good thing indeed ;)

Quoted 3 lines

Expected errors are normally handled on the Python side with ubman.disable_check(), or the test avoids printing a line that matches a bad pattern.

In fact I'd rather adjust the test framework than the C code. Ideally the implementation should not need to know it is being run under a test framework. Thanks for pointing me to ubman.disable_check(), I like this option. I will update the failing tests with a small exception in test_ut().

Therefore this patch can be dropped.

Thanks,

Signature · 1 line
Jerome> If the C test must stay quiet, it would be worth
Quoted 10 lines

checking the expected output with console recording and ut_assert_nextline(), since recording still works while the console is silent.

If we really need this, it might be better to change the signature of the existing ut_silence_console() and ut_unsilence_console() rather than adding a second pair alongside them. What do you think?

Regards,
Simon