linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
* [Linux-kernel-mentees] [PATCH] kunit: fix: kunit_binary_assert_format() only prints signed int
@ 2020-08-19 19:46 Vitor Massaru Iha
  2020-08-19 21:30 ` Brendan Higgins via Linux-kernel-mentees
  0 siblings, 1 reply; 5+ messages in thread
From: Vitor Massaru Iha @ 2020-08-19 19:46 UTC (permalink / raw)
  To: kunit-dev; +Cc: linux-kernel-mentees, brendanhiggins, linux-kselftest

Some tests, such as overflow_kunit(), uses unsigned int,
But kunit_binary_assert_format() only prints signed int,
this commit also deals with the unsigned int print.

Signed-off-by: Vitor Massaru Iha <vitor@massaru.org>
---
 lib/kunit/assert.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c
index 202f9fdeed0e..3ae90c09986a 100644
--- a/lib/kunit/assert.c
+++ b/lib/kunit/assert.c
@@ -104,12 +104,23 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,
 				  binary_assert->left_text,
 				  binary_assert->operation,
 				  binary_assert->right_text);
-		string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
+
+		if (binary_assert->left_value - 1 < 0) {
+			string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
+				  binary_assert->left_text,
+				  binary_assert->left_value);
+			string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
+				  binary_assert->right_text,
+				  binary_assert->right_value);
+		}
+		else {
+			string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu\n",
 				  binary_assert->left_text,
 				  binary_assert->left_value);
-		string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
+			string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu",
 				  binary_assert->right_text,
 				  binary_assert->right_value);
+		}
 	}
 	kunit_assert_print_msg(assert, stream);
 }

base-commit: d43c7fb05765152d4d4a39a8ef957c4ea14d8847
prerequisite-patch-id: bf4b0962b0b955e4e45f5d25fece889562118158
-- 
2.26.2

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH] kunit: fix: kunit_binary_assert_format() only prints signed int
  2020-08-19 19:46 [Linux-kernel-mentees] [PATCH] kunit: fix: kunit_binary_assert_format() only prints signed int Vitor Massaru Iha
@ 2020-08-19 21:30 ` Brendan Higgins via Linux-kernel-mentees
  2020-08-19 21:37   ` Vitor Massaru Iha
  0 siblings, 1 reply; 5+ messages in thread
From: Brendan Higgins via Linux-kernel-mentees @ 2020-08-19 21:30 UTC (permalink / raw)
  To: Vitor Massaru Iha
  Cc: linux-kernel-mentees, open list:KERNEL SELFTEST FRAMEWORK,
	KUnit Development

On Wed, Aug 19, 2020 at 12:46 PM Vitor Massaru Iha <vitor@massaru.org> wrote:
>
> Some tests, such as overflow_kunit(), uses unsigned int,
> But kunit_binary_assert_format() only prints signed int,
> this commit also deals with the unsigned int print.
>
> Signed-off-by: Vitor Massaru Iha <vitor@massaru.org>
> ---
>  lib/kunit/assert.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c
> index 202f9fdeed0e..3ae90c09986a 100644
> --- a/lib/kunit/assert.c
> +++ b/lib/kunit/assert.c
> @@ -104,12 +104,23 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,
>                                   binary_assert->left_text,
>                                   binary_assert->operation,
>                                   binary_assert->right_text);
> -               string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
> +
> +               if (binary_assert->left_value - 1 < 0) {
> +                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
> +                                 binary_assert->left_text,
> +                                 binary_assert->left_value);
> +                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
> +                                 binary_assert->right_text,
> +                                 binary_assert->right_value);
> +               }
> +               else {
> +                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu\n",
>                                   binary_assert->left_text,
>                                   binary_assert->left_value);
> -               string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
> +                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu",
>                                   binary_assert->right_text,
>                                   binary_assert->right_value);
> +               }

I agree that you found a bug here; however, I disagree that this is
the correct fix. Given that the value is stored as a long long; isn't
the value always stored as a signed value? So if the value overflows,
won't it still not pass the check you have here?

>         }
>         kunit_assert_print_msg(assert, stream);
>  }
>
> base-commit: d43c7fb05765152d4d4a39a8ef957c4ea14d8847
> prerequisite-patch-id: bf4b0962b0b955e4e45f5d25fece889562118158
> --
> 2.26.2
>
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH] kunit: fix: kunit_binary_assert_format() only prints signed int
  2020-08-19 21:30 ` Brendan Higgins via Linux-kernel-mentees
@ 2020-08-19 21:37   ` Vitor Massaru Iha
  2020-08-19 22:00     ` Vitor Massaru Iha
  0 siblings, 1 reply; 5+ messages in thread
From: Vitor Massaru Iha @ 2020-08-19 21:37 UTC (permalink / raw)
  To: Brendan Higgins
  Cc: linux-kernel-mentees, open list:KERNEL SELFTEST FRAMEWORK,
	KUnit Development

On Wed, Aug 19, 2020 at 6:30 PM Brendan Higgins
<brendanhiggins@google.com> wrote:
>
> On Wed, Aug 19, 2020 at 12:46 PM Vitor Massaru Iha <vitor@massaru.org> wrote:
> >
> > Some tests, such as overflow_kunit(), uses unsigned int,
> > But kunit_binary_assert_format() only prints signed int,
> > this commit also deals with the unsigned int print.

Oops, Thanks!
I'll fix it.

> >
> > Signed-off-by: Vitor Massaru Iha <vitor@massaru.org>
> > ---
> >  lib/kunit/assert.c | 15 +++++++++++++--
> >  1 file changed, 13 insertions(+), 2 deletions(-)
> >
> > diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c
> > index 202f9fdeed0e..3ae90c09986a 100644
> > --- a/lib/kunit/assert.c
> > +++ b/lib/kunit/assert.c
> > @@ -104,12 +104,23 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,
> >                                   binary_assert->left_text,
> >                                   binary_assert->operation,
> >                                   binary_assert->right_text);
> > -               string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
> > +
> > +               if (binary_assert->left_value - 1 < 0) {
> > +                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
> > +                                 binary_assert->left_text,
> > +                                 binary_assert->left_value);
> > +                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
> > +                                 binary_assert->right_text,
> > +                                 binary_assert->right_value);
> > +               }
> > +               else {
> > +                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu\n",
> >                                   binary_assert->left_text,
> >                                   binary_assert->left_value);
> > -               string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
> > +                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu",
> >                                   binary_assert->right_text,
> >                                   binary_assert->right_value);
> > +               }
>
> I agree that you found a bug here; however, I disagree that this is
> the correct fix. Given that the value is stored as a long long; isn't
> the value always stored as a signed value? So if the value overflows,
> won't it still not pass the check you have here?
>
> >         }
> >         kunit_assert_print_msg(assert, stream);
> >  }
> >
> > base-commit: d43c7fb05765152d4d4a39a8ef957c4ea14d8847
> > prerequisite-patch-id: bf4b0962b0b955e4e45f5d25fece889562118158
> > --
> > 2.26.2
> >
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH] kunit: fix: kunit_binary_assert_format() only prints signed int
  2020-08-19 21:37   ` Vitor Massaru Iha
@ 2020-08-19 22:00     ` Vitor Massaru Iha
  2020-08-19 22:19       ` Brendan Higgins via Linux-kernel-mentees
  0 siblings, 1 reply; 5+ messages in thread
From: Vitor Massaru Iha @ 2020-08-19 22:00 UTC (permalink / raw)
  To: Brendan Higgins
  Cc: linux-kernel-mentees, open list:KERNEL SELFTEST FRAMEWORK,
	KUnit Development

Hi Brendan,

Actually https://patchwork.kernel.org/patch/11724995/
solves my problem with unsigned int, since I can customize
the Expected message with this patch.

I think you can ignore this patch :)





On Wed, Aug 19, 2020 at 6:37 PM Vitor Massaru Iha <vitor@massaru.org> wrote:
>
> On Wed, Aug 19, 2020 at 6:30 PM Brendan Higgins
> <brendanhiggins@google.com> wrote:
> >
> > On Wed, Aug 19, 2020 at 12:46 PM Vitor Massaru Iha <vitor@massaru.org> wrote:
> > >
> > > Some tests, such as overflow_kunit(), uses unsigned int,
> > > But kunit_binary_assert_format() only prints signed int,
> > > this commit also deals with the unsigned int print.
>
> Oops, Thanks!
> I'll fix it.
>
> > >
> > > Signed-off-by: Vitor Massaru Iha <vitor@massaru.org>
> > > ---
> > >  lib/kunit/assert.c | 15 +++++++++++++--
> > >  1 file changed, 13 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c
> > > index 202f9fdeed0e..3ae90c09986a 100644
> > > --- a/lib/kunit/assert.c
> > > +++ b/lib/kunit/assert.c
> > > @@ -104,12 +104,23 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,
> > >                                   binary_assert->left_text,
> > >                                   binary_assert->operation,
> > >                                   binary_assert->right_text);
> > > -               string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
> > > +
> > > +               if (binary_assert->left_value - 1 < 0) {
> > > +                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
> > > +                                 binary_assert->left_text,
> > > +                                 binary_assert->left_value);
> > > +                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
> > > +                                 binary_assert->right_text,
> > > +                                 binary_assert->right_value);
> > > +               }
> > > +               else {
> > > +                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu\n",
> > >                                   binary_assert->left_text,
> > >                                   binary_assert->left_value);
> > > -               string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
> > > +                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu",
> > >                                   binary_assert->right_text,
> > >                                   binary_assert->right_value);
> > > +               }
> >
> > I agree that you found a bug here; however, I disagree that this is
> > the correct fix. Given that the value is stored as a long long; isn't
> > the value always stored as a signed value? So if the value overflows,
> > won't it still not pass the check you have here?
> >
> > >         }
> > >         kunit_assert_print_msg(assert, stream);
> > >  }
> > >
> > > base-commit: d43c7fb05765152d4d4a39a8ef957c4ea14d8847
> > > prerequisite-patch-id: bf4b0962b0b955e4e45f5d25fece889562118158
> > > --
> > > 2.26.2
> > >
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH] kunit: fix: kunit_binary_assert_format() only prints signed int
  2020-08-19 22:00     ` Vitor Massaru Iha
@ 2020-08-19 22:19       ` Brendan Higgins via Linux-kernel-mentees
  0 siblings, 0 replies; 5+ messages in thread
From: Brendan Higgins via Linux-kernel-mentees @ 2020-08-19 22:19 UTC (permalink / raw)
  To: Vitor Massaru Iha
  Cc: linux-kernel-mentees, open list:KERNEL SELFTEST FRAMEWORK,
	KUnit Development

On Wed, Aug 19, 2020 at 3:01 PM Vitor Massaru Iha <vitor@massaru.org> wrote:
>
> Hi Brendan,
>
> Actually https://patchwork.kernel.org/patch/11724995/
> solves my problem with unsigned int, since I can customize
> the Expected message with this patch.
>
> I think you can ignore this patch :)

Got it. Sounds good :-)

> On Wed, Aug 19, 2020 at 6:37 PM Vitor Massaru Iha <vitor@massaru.org> wrote:
> >
> > On Wed, Aug 19, 2020 at 6:30 PM Brendan Higgins
> > <brendanhiggins@google.com> wrote:
> > >
> > > On Wed, Aug 19, 2020 at 12:46 PM Vitor Massaru Iha <vitor@massaru.org> wrote:
> > > >
> > > > Some tests, such as overflow_kunit(), uses unsigned int,
> > > > But kunit_binary_assert_format() only prints signed int,
> > > > this commit also deals with the unsigned int print.
> >
> > Oops, Thanks!
> > I'll fix it.
> >
> > > >
> > > > Signed-off-by: Vitor Massaru Iha <vitor@massaru.org>
> > > > ---
> > > >  lib/kunit/assert.c | 15 +++++++++++++--
> > > >  1 file changed, 13 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c
> > > > index 202f9fdeed0e..3ae90c09986a 100644
> > > > --- a/lib/kunit/assert.c
> > > > +++ b/lib/kunit/assert.c
> > > > @@ -104,12 +104,23 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,
> > > >                                   binary_assert->left_text,
> > > >                                   binary_assert->operation,
> > > >                                   binary_assert->right_text);
> > > > -               string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
> > > > +
> > > > +               if (binary_assert->left_value - 1 < 0) {
> > > > +                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
> > > > +                                 binary_assert->left_text,
> > > > +                                 binary_assert->left_value);
> > > > +                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
> > > > +                                 binary_assert->right_text,
> > > > +                                 binary_assert->right_value);
> > > > +               }
> > > > +               else {
> > > > +                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu\n",
> > > >                                   binary_assert->left_text,
> > > >                                   binary_assert->left_value);
> > > > -               string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
> > > > +                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu",
> > > >                                   binary_assert->right_text,
> > > >                                   binary_assert->right_value);
> > > > +               }
> > >
> > > I agree that you found a bug here; however, I disagree that this is
> > > the correct fix. Given that the value is stored as a long long; isn't
> > > the value always stored as a signed value? So if the value overflows,
> > > won't it still not pass the check you have here?
> > >
> > > >         }
> > > >         kunit_assert_print_msg(assert, stream);
> > > >  }
> > > >
> > > > base-commit: d43c7fb05765152d4d4a39a8ef957c4ea14d8847
> > > > prerequisite-patch-id: bf4b0962b0b955e4e45f5d25fece889562118158
> > > > --
> > > > 2.26.2
> > > >
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-08-19 22:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-19 19:46 [Linux-kernel-mentees] [PATCH] kunit: fix: kunit_binary_assert_format() only prints signed int Vitor Massaru Iha
2020-08-19 21:30 ` Brendan Higgins via Linux-kernel-mentees
2020-08-19 21:37   ` Vitor Massaru Iha
2020-08-19 22:00     ` Vitor Massaru Iha
2020-08-19 22:19       ` Brendan Higgins via Linux-kernel-mentees

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).