[LTP] [PATCH v3 3/4] lib: Prefer LTP_DEBUG over -D
Petr Vorel
pvorel@suse.cz
Fri Mar 27 18:32:51 CET 2026
Environment variable has usually higher preference than getopt.
This includes disabling debugging even on -D:
LTP_DEBUG= ./test05 -D2 means debugging disabled.
Also reduce duplicity of "Enabling debug info (level %d)" message and
document that on -h and developers/debugging.rst.
Fixes: e434de62b4 ("lib: Extend LTP_ENABLE_DEBUG to support verbosity levels")
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Changes v2->v3:
* Simplify -D code (Li)
doc/developers/debugging.rst | 2 ++
lib/tst_test.c | 25 +++++++++++--------------
2 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/doc/developers/debugging.rst b/doc/developers/debugging.rst
index 36dda0d90f..4e162068b4 100644
--- a/doc/developers/debugging.rst
+++ b/doc/developers/debugging.rst
@@ -19,6 +19,8 @@ The ``-D`` parameter also supports the following verbosity levels:
Suppress all debug logs if no '-D' flag passed (default behavior).
+``LTP_DEBUG`` has higher preference than ``-D``.
+
Tracing and debugging syscalls
------------------------------
diff --git a/lib/tst_test.c b/lib/tst_test.c
index ea1aa5d306..61e357af3f 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -654,11 +654,11 @@ static struct option {
char *optstr;
char *help;
} options[] = {
- {"h", "-h Prints this help"},
- {"i:", "-i n Execute test n times"},
- {"I:", "-I x Execute test for n seconds"},
- {"D::", "-D[1,2] Prints debug information"},
- {"V", "-V Prints LTP version"},
+ {"h", "-h Prints this help"},
+ {"i:", "-i n Execute test n times"},
+ {"I:", "-I x Execute test for n seconds"},
+ {"D::", "-D[1,2] Prints debug information (can be overwriten by LTP_DEBUG"},
+ {"V", "-V Prints LTP version"},
};
static void print_help(void)
@@ -825,13 +825,9 @@ static void parse_opts(int argc, char *argv[])
tst_brk(TBROK, "Invalid option");
break;
case 'D':
- if (optarg)
- context->tdebug = SAFE_STRTOL(optarg, 1, 2);
- else
- context->tdebug = 1;
-
- if (context->tdebug)
- tst_res(TINFO, "Enabling debug info (level %d)", context->tdebug);
+ if (getenv("LTP_DEBUG"))
+ break;
+ context->tdebug = optarg ? SAFE_STRTOL(optarg, 1, 2) : 1;
break;
case 'h':
print_help();
@@ -1453,10 +1449,11 @@ static void do_setup(int argc, char *argv[])
else
tst_res(TWARN, "Invalid LTP_DEBUG value: '%s'", tdebug_env);
- if (context->tdebug)
- tst_res(TINFO, "Enabling debug info (level %d)", context->tdebug);
}
+ if (context->tdebug)
+ tst_res(TINFO, "Enabling debug info (level %d)", context->tdebug);
+
if (tst_test->needs_kconfigs && tst_kconfig_check(tst_test->needs_kconfigs))
tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
--
2.53.0
More information about the ltp
mailing list