lib: Extend -D flag to support multiple debug levels
PATCH v2 1/2 lib: Extend -D flag to support multiple debug levels
This patch extends the LTP debugging framework by introducing multiple levels of verbosity for the '-D' command line option. Instead of a simple on/off toggle, it now allows developers to specify whether they want debug output exclusively from the test process, or from both the test and library processes.
The supported debug levels are:
-D0 : Disable all debug logs (default behavior)
-D1 (-D): Enable debug logs for the test process only
-D2 : Enable verbose debug logs for both the test and library processes
---
Notes:
v1 --> v2:
* drop the if (context->tdebug) condition in tst_reinit().
doc/developers/debugging.rst | 6 ++++++ lib/tst_test.c | 26 +++++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-)
doc/developers/debugging.rst +6 -0
@@ -12,6 +12,12 @@ The LTP framework supports ``TDEBUG`` flag test debug messages. These messages can be enabled using the ``-D`` parameter or setting ``LTP_ENABLE_DEBUG=1`` environment variable (see :doc:`../users/setup_tests`). +The ``-D`` parameter also supports the following verbosity levels: + + ``-D0``: Disable all debug logs (default behavior). + ``-D1`` (or ``-D``): Enable debug logs for the test process only. + ``-D2``: Enable verbose debug logs for both the test and library processes. + Tracing and debugging syscalls ------------------------------
lib/tst_test.c +15 -11
@@ -83,7 +83,7 @@ struct context {tst_atomic_t abort_flag; uint32_t mntpoint_mounted:1; uint32_t ovl_mounted:1; - uint32_t tdebug:1; +uint32_t tdebug; };struct results {
@@ -216,8 +216,7 @@ void tst_reinit(void) tst_futexes = ipc->futexes; tst_max_futexes = (size - offsetof(struct ipc_region , futexes)) /sizeof (futex_t); -if (context->tdebug) -tst_res (TINFO ,"Restored metadata for PID %d" ,getpid ()); +tst_res (TDEBUG ,"Restored metadata for PID %d" ,getpid ()); }extern char **environ;
@@ -490,19 +489,20 @@ void tst_res_(const char *file, const int lineno, int ttype,va_list va;/* -* Suppress TDEBUG output in these cases: +* Control 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) +* 2. Debug output is completely disabled (context->tdebug == 0). +* 3. Debug output is only for test process (context->tdebug == 1). +* 4. Debug output is enabled for both test and lib processes (context->tdebug == 2). */ if (ttype ==TDEBUG ) {if (!context)return ; -if (context->lib_pid ==getpid ()) +if (context->tdebug ==0 )return ; -if (!context->tdebug) +if (context->tdebug ==1 && context->lib_pid ==getpid ())return ; }
@@ -657,7 +657,7 @@ static struct option { {"h", "-h Prints this help"}, {"i:", "-i n Execute test n times"}, {"I:", "-I x Execute test for n seconds"}, - {"D", "-D Prints debug information"}, + {"D::", "-D[0-2] Prints debug information"}, {"V", "-V Prints LTP version"}, };
@@ -825,8 +825,12 @@ static void parse_opts(int argc, char *argv[])tst_brk (TBROK ,"Invalid option" );break ;case 'D' : -tst_res (TINFO ,"Enabling debug info" ); - context->tdebug =1 ; +if (optarg) + context->tdebug =SAFE_STRTOL (optarg,0 ,2 ); +else + context->tdebug =1 ; + +tst_res (TINFO ,"Enabling debug info (level %d)" , context->tdebug);break ;case 'h' :print_help ();
Signature · 5 lines
2.53.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/2 lib: Extend LTP_ENABLE_DEBUG to support verbosity levels
Following the introduction of verbosity levels for the -D command line flag, this patch extends the LTP_ENABLE_DEBUG environment variable to support the same levels (0, 1, and 2).
Previously, LTP_ENABLE_DEBUG acted as a simple boolean toggle. It now mirrors the behavior of -D, allowing developers to specify the exact level of debug verbosity required from the environment.
--- doc/developers/debugging.rst | 2 +- lib/newlib_tests/tst_res_flags.c | 2 +- lib/tst_test.c | 16 ++++++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-)
doc/developers/debugging.rst +1 -1
@@ -9,7 +9,7 @@ Debug messages -------------- The LTP framework supports ``TDEBUG`` flag test debug messages. These -messages can be enabled using the ``-D`` parameter or setting ``LTP_ENABLE_DEBUG=1`` +messages can be enabled using the ``-D[0-2]`` parameter or setting ``LTP_ENABLE_DEBUG=0,1,2`` environment variable (see :doc:`../users/setup_tests`). The ``-D`` parameter also supports the following verbosity levels:
lib/newlib_tests/tst_res_flags.c +1 -1
@@ -21,7 +21,7 @@ static struct tcase { {FLAG(TCONF)}, {FLAG(TWARN)}, {FLAG(TINFO)}, - {FLAG(TDEBUG), " (printed only with -D or LTP_ENABLE_DEBUG=1)"}, + {FLAG(TDEBUG), " (printed only with -D[0-2] or LTP_ENABLE_DEBUG=0,1,2)"}, }; static void do_cleanup(void)
lib/tst_test.c +12 -4
@@ -675,7 +675,7 @@ static void print_help(void)fprintf (stderr,"LTP_COLORIZE_OUTPUT Force colorized output behaviour (y/1 always, n/0: never)\n" );fprintf (stderr,"LTP_DEV Path to the block device to be used (for .needs_device)\n" );fprintf (stderr,"LTP_DEV_FS_TYPE Filesystem used for testing (default: %s)\n" ,DEFAULT_FS_TYPE ); -fprintf (stderr,"LTP_ENABLE_DEBUG Print debug messages (set 1 or y)\n" ); +fprintf (stderr,"LTP_ENABLE_DEBUG Print debug messages (set 0, 1 (y) or 2)\n" );fprintf (stderr,"LTP_REPRODUCIBLE_OUTPUT Values 1 or y discard the actual content of the messages printed by the test\n" );fprintf (stderr,"LTP_QUIET Values 1 or y will suppress printing TCONF, TWARN, TINFO, and TDEBUG messages\n" );fprintf (stderr,"LTP_SINGLE_FS_TYPE Specifies filesystem instead all supported (for .all_filesystems)\n" );
@@ -1444,9 +1444,17 @@ static void do_setup(int argc, char *argv[])parse_opts (argc, argv); -if (tdebug_env && (!strcmp (tdebug_env,"1" ) || !strcmp (tdebug_env,"y" ))) { -tst_res (TINFO ,"Enabling debug info" ); - context->tdebug =1 ; +if (tdebug_env) { +if (!strcmp (tdebug_env,"0" )) + context->tdebug =0 ; +else if (!strcmp (tdebug_env,"2" )) + context->tdebug =2 ; +else if (!strcmp (tdebug_env,"1" ) || !strcmp (tdebug_env,"y" )) + context->tdebug =1 ; +else +tst_res (TWARN ,"Invalid LTP_ENABLE_DEBUG value: %s" , tdebug_env); + +tst_res (TINFO ,"Enabling debug info (level %d)" , context->tdebug); }if (tst_test->needs_kconfigs &&tst_kconfig_check (tst_test->needs_kconfigs))
Signature · 5 lines
2.53.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/2] lib: Extend LTP_ENABLE_DEBUG to support verbosity levels
Hi Li,
I ran a review with my LLM config and obtained the following report. I thought it was interesting to share how the LTP review agent I'm developing is growing. Tested with Claude Sonnet 4.6
Issues Found
1. "Enabling debug info" printed for level 0 — misleading message (still unaddressed from v1)
Both -D0 and LTP_ENABLE_DEBUG=0 print "Enabling debug info (level 0)", which is the opposite of what is happening. Level 0 means disable all debug output. This was raised in the v1 review and remains unfixed.
$ ./getpid01 -D0 tst_test.c:833: TINFO: Enabling debug info (level 0)
Additionally, LTP_ENABLE_DEBUG=0 is a behavior regression: previously it was silently ignored (no output), now it prints a misleading "Enabling" message. The fix for the -D path is to guard the message:
if (context->tdebug)
tst_res(TINFO, "Enabling debug info (level %d)", context->tdebug);Same fix needed in the env var path.
2. LTP_ENABLE_DEBUG still silently overrides a more specific -D flag — core ordering issue unfixed from v1
The env var check runs after parse_opts(), so LTP_ENABLE_DEBUG always wins over the command-line -D flag:
$ LTP_ENABLE_DEBUG=1 ./getpid01 -D2 tst_test.c:833: TINFO: Enabling debug info (level 2) ← from -D2 tst_test.c:1457: TINFO: Enabling debug info (level 1) ← env var overrides!
And even disabling via the env var overrides an explicit command-line enable:
$ LTP_ENABLE_DEBUG=0 ./getpid01 -D2 tst_test.c:833: TINFO: Enabling debug info (level 2) ← from -D2 tst_test.c:1457: TINFO: Enabling debug info (level 0) ← env var kills it
Command-line should take precedence over environment variables. The fix is to skip the env var assignment when -D was already used:
if (tdebug_env && !context->tdebug) { /* only if -D wasn't passed */
...
} Or, more robustly, check the env var before parse_opts() so the command-line naturally wins.
Point 1. is clearly true, the Point 2. might be a design choice. I don't mind the priority of command line or env variable, but it's actually correct to assume that env should be skipped if -D is defined.
Kind regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/2] lib: Extend LTP_ENABLE_DEBUG to support verbosity levels
Hi Andrea,
The two points make sense, will fix in V3. Thanks for the feedback!
Quoted 68 lines · Andrea Cervesato
Hi Li,
I ran a review with my LLM config and obtained the following report. I thought it was interesting to share how the LTP review agent I'm developing is growing. Tested with Claude Sonnet 4.6
Issues Found
1. "Enabling debug info" printed for level 0 — misleading message (still unaddressed from v1)
Both -D0 and LTP_ENABLE_DEBUG=0 print "Enabling debug info (level 0)", which is the opposite of what is happening. Level 0 means disable all debug output. This was raised in the v1 review and remains unfixed.
$ ./getpid01 -D0 tst_test.c:833: TINFO: Enabling debug info (level 0)Additionally, LTP_ENABLE_DEBUG=0 is a behavior regression: previously it was silently ignored (no output), now it prints a misleading
"Enabling"
message. The fix for the -D path is to guard the message:if (context->tdebug) tst_res(TINFO, "Enabling debug info (level %d)", context->tdebug);Same fix needed in the env var path.
2.
LTP_ENABLE_DEBUGstill silently overrides a more specific -D flag — core ordering issue unfixed from v1The env var check runs after
parse_opts(), soLTP_ENABLE_DEBUGalways wins over the command-line -D flag:$ LTP_ENABLE_DEBUG=1 ./getpid01 -D2 tst_test.c:833: TINFO: Enabling debug info (level 2) ← from -D2 tst_test.c:1457: TINFO: Enabling debug info (level 1) ← env var overrides!And even disabling via the env var overrides an explicit command-line
enable:$ LTP_ENABLE_DEBUG=0 ./getpid01 -D2 tst_test.c:833: TINFO: Enabling debug info (level 2) ← from -D2 tst_test.c:1457: TINFO: Enabling debug info (level 0) ← env var kills itCommand-line should take precedence over environment variables. The fix is to skip the env var assignment when -D was already used:
if (tdebug_env && !context->tdebug) { /* only if -D wasn't passed */ ... }Or, more robustly, check the env var before
parse_opts()so the command-line naturally wins.Point 1. is clearly true, the Point 2. might be a design choice. I don't mind the priority of command line or env variable, but it's actually correct to assume that env should be skipped if -D is defined.
Kind regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp