lib: tst_test: Add reproducible output.
PATCH v2 1/1 lib: tst_test: Add reproducible output.
This commit adds an environment variable LTP_REPRODUCIBLE_OUTPUT that when set 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.
--- lib/tst_test.c | 7 +++++++ 1 file changed, 7 insertions(+)
lib/tst_test.c +7 -0
@@ -64,6 +64,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;
@@ -312,6 +313,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);
@@ -329,6 +333,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() */
@@ -1312,6 +1317,8 @@ 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); + reproducible_output = !!getenv ("LTP_REPRODUCIBLE_OUTPUT" ); +assert_test_fn ();TCID = tid =get_tid (argv);
Signature · 5 lines
2.49.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi,
Quoted 54 lines · Cyril Hrubis
This commit adds an environment variable
LTP_REPRODUCIBLE_OUTPUTthat when set 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 <[email protected]>Suggested-by Martin Doucha <[email protected]>--- lib/tst_test.c | 7 +++++++ 1 file changed, 7 insertions(+)lib/tst_test.c +7
-0@@ -64,6 +64,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;@@ -312,6 +313,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);@@ -329,6 +333,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() */ @@ -1312,6 +1317,8 @@ 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); + reproducible_output = !!getenv ("LTP_REPRODUCIBLE_OUTPUT" ); +assert_test_fn ();TCID = tid =get_tid (argv);
Signature · 10 lines
Martin Doucha [email protected] SW Quality Engineer SUSE LINUX, s.r.o. CORSO IIa Krizikova 148/34 186 00 Prague 8 Czech Republic -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi,
Quoted 47 lines · CEST Cyril Hrubis
This commit adds an environment variable
LTP_REPRODUCIBLE_OUTPUTthat when set 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 <[email protected]>Suggested-by Martin Doucha <[email protected]>--- lib/tst_test.c | 7 +++++++ 1 file changed, 7 insertions(+)lib/tst_test.c +5
-0@@ -64,6 +64,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;@@ -312,6 +313,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);@@ -329,6 +333,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() */
lib/tst_test.c static void do_setup(int argc, char *argv[]) · line 1324
Quoted 8 lines
lib/tst_test.c +2
-0@@ -1312,6 +1317,8 @@ 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); + reproducible_output = !!getenv ("LTP_REPRODUCIBLE_OUTPUT" ); +assert_test_fn ();TCID = tid =get_tid (argv);
Regards,
Avinesh
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Cyril,
Quoted 7 lines
This commit adds an environment variable
LTP_REPRODUCIBLE_OUTPUTthat when set 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.
LGTM, thanks!
Could you please add before the commit the variable to print_help() and to the docs doc/users/setup_tests.rst?
I suggest the diff below, which also sort the entries (ideally it'd be separated, but it's before the release, feel free to do it).
Quoted 38 lines
Signed-off-by Cyril Hrubis <[email protected]>Suggested-by Martin Doucha <[email protected]>--- lib/tst_test.c | 7 +++++++ 1 file changed, 7 insertions(+)lib/tst_test.c +5
-0@@ -64,6 +64,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;@@ -312,6 +313,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);@@ -329,6 +333,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() */
lib/tst_test.c static void do_setup(int argc, char *argv[]) · line 1320
Quoted 4 lines
lib/tst_test.c +1
-0@@ -1312,6 +1317,8 @@ 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); + reproducible_output = !!getenv ("LTP_REPRODUCIBLE_OUTPUT" );
LTP_COLORIZE_OUTPUT allows more complicated setup (y/1 always, n/0: never), but any value here enables the feature (e.g. LTP_COLORIZE_OUTPUT=0). This would be nice to unify, but I'm ok to ignore it as it's before release.
lib/tst_test.c static void do_setup(int argc, char *argv[]) · line 1324
Quoted 4 lines
lib/tst_test.c +1
-0+assert_test_fn ();TCID = tid =get_tid (argv);
Adding docs (+ sort variables while at it).
Kind regards,
Petr
+++ doc/users/setup_tests.rst
@@ -49,11 +49,12 @@ users.
* - LTP_DEV_FS_TYPE
- Filesystem used for testing (default: ``ext2``).
- * - LTP_TIMEOUT_MUL
- - Multiplies timeout, must be number >= 0.1 (> 1 is useful for slow
- machines to avoid unexpected timeout). It's mainly for shell API, which - does not have LTP_RUNTIME_MUL. In C API it scales the default 30 sec - safety margin, probably LTP_RUNTIME_MUL should be used instead.
+ * - LTP_IMA_LOAD_POLICY
+ - Load IMA example policy, see :master:testcases/kernel/security/integrity/ima/README.md.
+
+ * - LTP_REPRODUCIBLE_OUTPUT
+ - Dischard the actual content of the messages printed by the test
+ (suitable for a reproducible output).
* - LTP_RUNTIME_MUL
- Multiplies maximal test iteration runtime. Tests that run for more than a
@@ -61,8 +62,11 @@ users.
both up and down with this multiplier. This is not yet implemented in the shell API.
- * - LTP_IMA_LOAD_POLICY
- - Load IMA example policy, see :master:testcases/kernel/security/integrity/ima/README.md.
+ * - LTP_TIMEOUT_MUL
+ - Multiplies timeout, must be number >= 0.1 (> 1 is useful for slow
+ machines to avoid unexpected timeout). It's mainly for shell API, which + does not have LTP_RUNTIME_MUL. In C API it scales the default 30 sec + safety margin, probably LTP_RUNTIME_MUL should be used instead.
* - LTP_VIRT_OVERRIDE
- Overrides virtual machine detection in the test library. Setting it to
tst_test.c +2 -1
@@ -613,9 +613,10 @@ 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_REPRODUCIBLE_OUTPUT Dischard the actual content of the messages printed by the test\n" ); +fprintf (stderr,"LTP_RUNTIME_MUL Runtime multiplier (must be a number >=1)\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" );
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 3 lines
LTP_COLORIZE_OUTPUTallows more complicated setup (y/1 always, n/0: never), but any value here enables the feature (e.g. LTP_COLORIZE_OUTPUT=0). This would be nice to unify, but I'm ok to ignore it as it's before release.
We also have LTP_ENABLE_DEBUG that has the same values so let's keep the API the same. I've send v3 with this and the docs changes.
Quoted 6 lines
Review
Quoted 4 lines
(quoted diff) +1
-0+ assert_test_fn(); TCID = tid = get_tid(argv);Adding docs (+ sort variables while at it).
I've only added the docs for LTP_REPRODUCIBLE_OUTPUT in v3, the sorting should go in a separate patch. We also miss at least TST_ENABLE_DEBUG in the output of -h switch as well.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 11 lines · Cyril Hrubis
Hi!
Quoted 3 lines
LTP_COLORIZE_OUTPUTallows more complicated setup (y/1 always, n/0: never), but any value here enables the feature (e.g. LTP_COLORIZE_OUTPUT=0). This would be nice to unify, but I'm ok to ignore it as it's before release.We also have
LTP_ENABLE_DEBUGthat has the same values so let's keep the API the same. I've send v3 with this and the docs changes.Quoted 3 lines
Quoted 2 lines
(quoted diff) +1
-0+ assert_test_fn();
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
TCID = tid =
get_tid(argv);Adding docs (+ sort variables while at it).
I've only added the docs for
LTP_REPRODUCIBLE_OUTPUTin v3, the sorting should go in a separate patch. We also miss at leastTST_ENABLE_DEBUGin the output of -h switch as well.
Thank-you, guys. I've added a preparation to the valgrind-ltp tester:
Once the new version of LTP ships, we can try dropping our workarounds.
Cheers,
Martin
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp