Skip to content

Commit e434de6

Browse files
committed
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 (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. And, command-line should take precedence over environment variables when set both. Signed-off-by: Li Wang <liwang@redhat.com> Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com>
1 parent cfeefc5 commit e434de6

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

doc/developers/debugging.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Debug messages
99
--------------
1010

1111
The LTP framework supports ``TDEBUG`` flag test debug messages. These
12-
messages can be enabled using the ``-D`` parameter or setting ``LTP_ENABLE_DEBUG=1``
12+
messages can be enabled using the ``-D[1,2]`` parameter or setting ``LTP_ENABLE_DEBUG=1,2``
1313
environment variable (see :doc:`../users/setup_tests`).
1414

1515
The ``-D`` parameter also supports the following verbosity levels:

lib/newlib_tests/tst_res_flags.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static struct tcase {
2121
{FLAG(TCONF)},
2222
{FLAG(TWARN)},
2323
{FLAG(TINFO)},
24-
{FLAG(TDEBUG), " (printed only with -D or LTP_ENABLE_DEBUG=1)"},
24+
{FLAG(TDEBUG), " (printed only with -D[1,2] or LTP_ENABLE_DEBUG=1,2)"},
2525
};
2626

2727
static void do_cleanup(void)

lib/tst_test.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ static void print_help(void)
675675
fprintf(stderr, "LTP_COLORIZE_OUTPUT Force colorized output behaviour (y/1 always, n/0: never)\n");
676676
fprintf(stderr, "LTP_DEV Path to the block device to be used (for .needs_device)\n");
677677
fprintf(stderr, "LTP_DEV_FS_TYPE Filesystem used for testing (default: %s)\n", DEFAULT_FS_TYPE);
678-
fprintf(stderr, "LTP_ENABLE_DEBUG Print debug messages (set 1 or y)\n");
678+
fprintf(stderr, "LTP_ENABLE_DEBUG Print debug messages (set 1(y) or 2)\n");
679679
fprintf(stderr, "LTP_REPRODUCIBLE_OUTPUT Values 1 or y discard the actual content of the messages printed by the test\n");
680680
fprintf(stderr, "LTP_QUIET Values 1 or y will suppress printing TCONF, TWARN, TINFO, and TDEBUG messages\n");
681681
fprintf(stderr, "LTP_SINGLE_FS_TYPE Specifies filesystem instead all supported (for .all_filesystems)\n");
@@ -1445,9 +1445,16 @@ static void do_setup(int argc, char *argv[])
14451445

14461446
parse_opts(argc, argv);
14471447

1448-
if (tdebug_env && (!strcmp(tdebug_env, "1") || !strcmp(tdebug_env, "y"))) {
1449-
tst_res(TINFO, "Enabling debug info");
1450-
context->tdebug = 1;
1448+
if (tdebug_env && !context->tdebug) {
1449+
if (!strcmp(tdebug_env, "2"))
1450+
context->tdebug = 2;
1451+
else if (!strcmp(tdebug_env, "1") || !strcmp(tdebug_env, "y"))
1452+
context->tdebug = 1;
1453+
else
1454+
tst_res(TWARN, "Invalid LTP_ENABLE_DEBUG value: %s", tdebug_env);
1455+
1456+
if (context->tdebug)
1457+
tst_res(TINFO, "Enabling debug info (level %d)", context->tdebug);
14511458
}
14521459

14531460
if (tst_test->needs_kconfigs && tst_kconfig_check(tst_test->needs_kconfigs))

0 commit comments

Comments
 (0)