diff mbox series

[1/4] kunit: Drop redundant text from suite init failure message

Message ID 20230925175733.1379-2-michal.wajdeczko@intel.com
State New
Headers show
Series kunit: Fix indentation of parameterized tests messages | expand

Commit Message

Michal Wajdeczko Sept. 25, 2023, 5:57 p.m. UTC
If a suite initialization fails, then our diagnostic message
will include redundant indent and hash sign as all this was
already added by the kunit_printk() used by kunit_err() macro.

This could be easily seen if we force some error in our example
test by modyfing example_test_init_suite() and running:

$ ./tools/testing/kunit/kunit.py run --raw_output \
	--kunitconfig ./lib/kunit/.kunitconfig "example.*"

    KTAP version 1
    1..1
        # example: initializing suite
        # example:     # failed to initialize (-19)
    not ok 1 example

Fix that and while around improve error code reporting by using
error pointer format %pe that gives more user friendly output:

    KTAP version 1
    1..1
        # example: initializing suite
        # example: failed to initialize (-ENODEV)
    not ok 1 example

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: David Gow <davidgow@google.com>
Cc: Rae Moar <rmoar@google.com>
---
 lib/kunit/test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Rae Moar Sept. 28, 2023, 8:51 p.m. UTC | #1
On Mon, Sep 25, 2023 at 1:58 PM Michal Wajdeczko
<michal.wajdeczko@intel.com> wrote:
>
> If a suite initialization fails, then our diagnostic message
> will include redundant indent and hash sign as all this was
> already added by the kunit_printk() used by kunit_err() macro.
>
> This could be easily seen if we force some error in our example
> test by modyfing example_test_init_suite() and running:
>
> $ ./tools/testing/kunit/kunit.py run --raw_output \
>         --kunitconfig ./lib/kunit/.kunitconfig "example.*"
>
>     KTAP version 1
>     1..1
>         # example: initializing suite
>         # example:     # failed to initialize (-19)
>     not ok 1 example
>
> Fix that and while around improve error code reporting by using
> error pointer format %pe that gives more user friendly output:
>
>     KTAP version 1
>     1..1
>         # example: initializing suite
>         # example: failed to initialize (-ENODEV)
>     not ok 1 example
>
> Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
> Cc: David Gow <davidgow@google.com>
> Cc: Rae Moar <rmoar@google.com>

Hello!

This change looks good to me.

Reviewed-by: Rae Moar <rmoar@google.com>

Thanks!
-Rae

> ---
>  lib/kunit/test.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/kunit/test.c b/lib/kunit/test.c
> index f2eb71f1a66c..fb5981ce578d 100644
> --- a/lib/kunit/test.c
> +++ b/lib/kunit/test.c
> @@ -568,8 +568,8 @@ int kunit_run_tests(struct kunit_suite *suite)
>         if (suite->suite_init) {
>                 suite->suite_init_err = suite->suite_init(suite);
>                 if (suite->suite_init_err) {
> -                       kunit_err(suite, KUNIT_SUBTEST_INDENT
> -                                 "# failed to initialize (%d)", suite->suite_init_err);
> +                       kunit_err(suite, "failed to initialize (%pe)",
> +                                 ERR_PTR(suite->suite_init_err));
>                         goto suite_end;
>                 }
>         }
> --
> 2.25.1
>
diff mbox series

Patch

diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index f2eb71f1a66c..fb5981ce578d 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -568,8 +568,8 @@  int kunit_run_tests(struct kunit_suite *suite)
 	if (suite->suite_init) {
 		suite->suite_init_err = suite->suite_init(suite);
 		if (suite->suite_init_err) {
-			kunit_err(suite, KUNIT_SUBTEST_INDENT
-				  "# failed to initialize (%d)", suite->suite_init_err);
+			kunit_err(suite, "failed to initialize (%pe)",
+				  ERR_PTR(suite->suite_init_err));
 			goto suite_end;
 		}
 	}