* [LTP] [PATCH v3] lib: tst_test: Add reproducible output.
@ 2025-05-15 10:31 Cyril Hrubis
2025-05-15 12:44 ` Petr Vorel
0 siblings, 1 reply; 4+ messages in thread
From: Cyril Hrubis @ 2025-05-15 10:31 UTC (permalink / raw)
To: ltp; +Cc: valgrind-developers
This commit adds an environment variable LTP_REPRODUCIBLE_OUTPUT that
when set to 1 or y skips printing parts of the test messages that may
contain data that differ on subsequent runs (e.g. pids).
With this you can run a test twice under a different conditions and
check if the test codeflow was identical by simply doing diff of the
outputs from the two runs.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Suggested-by: Martin Doucha <mdoucha@suse.cz>
Reviewed-by: Martin Doucha <mdoucha@suse.cz>
Reviewed-by: Avinesh Kumar <akumar@suse.de>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
CC: valgrind-developers@lists.sourceforge.net
---
doc/users/setup_tests.rst | 4 ++++
lib/tst_test.c | 33 ++++++++++++++++++++++-----------
2 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/doc/users/setup_tests.rst b/doc/users/setup_tests.rst
index 2766ed719..2cce85fdf 100644
--- a/doc/users/setup_tests.rst
+++ b/doc/users/setup_tests.rst
@@ -42,6 +42,10 @@ users.
- Path to the block device to be used. C Language: ``.needs_device = 1``.
Shell language: ``TST_NEEDS_DEVICE=1``.
+ * - LTP_REPRODUCIBLE_OUTPUT
+ - When set to ``1`` or ``y`` discards the actual content of the messages
+ printed by the test (suitable for a reproducible output).
+
* - LTP_SINGLE_FS_TYPE
- Testing only - specifies filesystem instead all supported
(for tests with ``.all_filesystems``).
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 923ecf7be..297c376da 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -63,6 +63,7 @@ static int mntpoint_mounted;
static int ovl_mounted;
static struct timespec tst_start_time; /* valid only for test pid */
static int tdebug;
+static int reproducible_output;
struct results {
int passed;
@@ -316,6 +317,9 @@ static void print_result(const char *file, const int lineno, int ttype,
str += ret;
size -= ret;
+ if (reproducible_output)
+ goto print;
+
ssize = size - 2;
ret = vsnprintf(str, size, fmt, va);
str += MIN(ret, ssize);
@@ -333,6 +337,7 @@ static void print_result(const char *file, const int lineno, int ttype,
"Next message is too long and truncated:");
}
+print:
snprintf(str, size, "\n");
/* we might be called from signal handler, so use write() */
@@ -606,17 +611,18 @@ static void print_help(void)
/* see doc/users/setup_tests.rst, which lists also shell API variables */
fprintf(stderr, "Environment Variables\n");
fprintf(stderr, "---------------------\n");
- fprintf(stderr, "KCONFIG_PATH Specify kernel config file\n");
- fprintf(stderr, "KCONFIG_SKIP_CHECK Skip kernel config check if variable set (not set by default)\n");
- fprintf(stderr, "LTPROOT Prefix for installed LTP (default: /opt/ltp)\n");
- 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_SINGLE_FS_TYPE Testing only - specifies filesystem instead all supported (for .all_filesystems)\n");
- fprintf(stderr, "LTP_TIMEOUT_MUL Timeout multiplier (must be a number >=1)\n");
- fprintf(stderr, "LTP_RUNTIME_MUL Runtime multiplier (must be a number >=1)\n");
- fprintf(stderr, "LTP_VIRT_OVERRIDE Overrides virtual machine detection (values: \"\"|kvm|microsoft|xen|zvm)\n");
- fprintf(stderr, "TMPDIR Base directory for template directory (for .needs_tmpdir, default: %s)\n", TEMPDIR);
+ fprintf(stderr, "KCONFIG_PATH Specify kernel config file\n");
+ fprintf(stderr, "KCONFIG_SKIP_CHECK Skip kernel config check if variable set (not set by default)\n");
+ fprintf(stderr, "LTPROOT Prefix for installed LTP (default: /opt/ltp)\n");
+ 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_REPRODUCIBLE_OUTPUT When set to 1 or y discards the actual content of the messages printed by the test\n");
+ fprintf(stderr, "LTP_SINGLE_FS_TYPE Testing only - specifies filesystem instead all supported (for .all_filesystems)\n");
+ fprintf(stderr, "LTP_TIMEOUT_MUL Timeout multiplier (must be a number >=1)\n");
+ fprintf(stderr, "LTP_RUNTIME_MUL Runtime multiplier (must be a number >=1)\n");
+ fprintf(stderr, "LTP_VIRT_OVERRIDE Overrides virtual machine detection (values: \"\"|kvm|microsoft|xen|zvm)\n");
+ fprintf(stderr, "TMPDIR Base directory for template directory (for .needs_tmpdir, default: %s)\n", TEMPDIR);
fprintf(stderr, "\n");
fprintf(stderr, "Timeout and runtime\n");
@@ -1298,6 +1304,7 @@ static const char *default_fs_type(void)
static void do_setup(int argc, char *argv[])
{
char *tdebug_env = getenv("LTP_ENABLE_DEBUG");
+ char *reproducible_env = getenv("LTP_REPRODUCIBLE_OUTPUT");
if (!tst_test)
tst_brk(TBROK, "No tests to run");
@@ -1316,6 +1323,10 @@ static void do_setup(int argc, char *argv[])
if (tst_test->supported_archs && !tst_is_on_arch(tst_test->supported_archs))
tst_brk(TCONF, "This arch '%s' is not supported for test!", tst_arch.name);
+ if (reproducible_env &&
+ (!strcmp(reproducible_env, "1") || !strcmp(reproducible_env, "y")))
+ reproducible_output = 1;
+
assert_test_fn();
TCID = tid = get_tid(argv);
--
2.49.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v3] lib: tst_test: Add reproducible output.
2025-05-15 10:31 [LTP] [PATCH v3] lib: tst_test: Add reproducible output Cyril Hrubis
@ 2025-05-15 12:44 ` Petr Vorel
2025-05-15 13:58 ` Petr Vorel
0 siblings, 1 reply; 4+ messages in thread
From: Petr Vorel @ 2025-05-15 12:44 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: valgrind-developers, ltp
Hi Cyril,
> This commit adds an environment variable LTP_REPRODUCIBLE_OUTPUT that
> when set to 1 or y skips printing parts of the test messages that may
> contain data that differ on subsequent runs (e.g. pids).
> With this you can run a test twice under a different conditions and
> check if the test codeflow was identical by simply doing diff of the
> outputs from the two runs.
Thanks for fixing n and 0 and updating the docs.
Tested-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v3] lib: tst_test: Add reproducible output.
2025-05-15 12:44 ` Petr Vorel
@ 2025-05-15 13:58 ` Petr Vorel
2025-05-16 9:08 ` Cyril Hrubis
0 siblings, 1 reply; 4+ messages in thread
From: Petr Vorel @ 2025-05-15 13:58 UTC (permalink / raw)
To: Cyril Hrubis, valgrind-developers, ltp
Hi Cyril,
+ fprintf(stderr, "LTP_REPRODUCIBLE_OUTPUT When set to 1 or y discards the actual content of the messages printed by the test\n");
nit: "When set to 1 or y" is slightly verbose to me. Maybe just "1/y discards
the actual content of the messages printed by the test" ?
But anyway that's very minor, therefore I kept the same approach when adding
LTP_ENABLE_DEBUG in the next patch I'm going to send now.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v3] lib: tst_test: Add reproducible output.
2025-05-15 13:58 ` Petr Vorel
@ 2025-05-16 9:08 ` Cyril Hrubis
0 siblings, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2025-05-16 9:08 UTC (permalink / raw)
To: Petr Vorel; +Cc: valgrind-developers, ltp
Hi!
> + fprintf(stderr, "LTP_REPRODUCIBLE_OUTPUT When set to 1 or y discards the actual content of the messages printed by the test\n");
>
> nit: "When set to 1 or y" is slightly verbose to me. Maybe just "1/y discards
> the actual content of the messages printed by the test" ?
I've shortened it to "Values 1 or y discard ..." and pushed the patch.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-05-16 9:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-15 10:31 [LTP] [PATCH v3] lib: tst_test: Add reproducible output Cyril Hrubis
2025-05-15 12:44 ` Petr Vorel
2025-05-15 13:58 ` Petr Vorel
2025-05-16 9:08 ` Cyril Hrubis
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.