[LTP] [PATCH v2] lib: suppress early TDEBUG output before context initialization
Li Wang
liwang@redhat.com
Mon Jun 16 16:42:34 CEST 2025
After commit bf9589d5bd ("lib: move test infrastructure states into
a shared context structure"), each test began printing unexpected
TDEBUG messages like:
tst_test.c:142: TDEBUG: mmap((nil), 4096, PROT_READ | PROT_WRITE(3), 1, 3, 0)
tst_test.c:199: TDEBUG: mmap((nil), 4096, PROT_READ | PROT_WRITE(3), 1, 3, 0)
This happens because the logic in tst_res_():
if (ttype == TDEBUG && context && !context->tdebug)
allows TDEBUG messages to be printed even the context is not yet initialized.
During early test setup (such as in SAFE_MMAP), the shared context may
not be initialized yet, causing debug logs to be emitted unintentionally.
This patch refines the suppression logic in tst_res_() by explicitly checking:
- Whether `context` has been initialized
- Whether current is the library test process (`lib_pid`)
- Whether `tdebug` is enabled
This improves test log clarity and avoids misleading noise during test setup.
Follow-up: commit bf9589d5bd ("lib: move test infrastructure states into a shared context structure")
Signed-off-by: Li Wang <liwang@redhat.com>
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
---
lib/tst_test.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 6fcd40030..495e022f7 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -476,8 +476,22 @@ void tst_res_(const char *file, const int lineno, int ttype,
{
va_list va;
- if (ttype == TDEBUG && context && !context->tdebug)
- return;
+ /*
+ * Suppress TDEBUG output in these cases:
+ * 1. No context available (e.g., called before IPC initialization)
+ * 2. Called from the library process, unless explicitly enabled
+ * 3. Debug output is not enabled (context->tdebug == 0)
+ */
+ if (ttype == TDEBUG) {
+ if (!context)
+ return;
+
+ if (context->lib_pid == getpid())
+ return;
+
+ if (!context->tdebug)
+ return;
+ }
va_start(va, fmt);
tst_vres_(file, lineno, ttype, fmt, va);
--
2.49.0
More information about the ltp
mailing list