linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: SeongJae Park <sjpark@amazon.com>
To: Brendan Higgins <brendanhiggins@google.com>
Cc: SeongJae Park <sjpark@amazon.com>,
	Bernd Petrovitsch <bernd@petrovitsch.priv.at>,
	"open list:KERNEL SELFTEST FRAMEWORK" 
	<linux-kselftest@vger.kernel.org>,
	KUnit Development <kunit-dev@googlegroups.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	SeongJae Park <sj38.park@gmail.com>
Subject: Re: Re: Re: What is the best way to compare an unsigned and a constant?
Date: Tue, 7 Jan 2020 14:49:10 +0100	[thread overview]
Message-ID: <20200107134910.20347-1-sjpark@amazon.com> (raw)
In-Reply-To: <CAFd5g47-wi0duBAVxvevDKT7eb7WGT9JMFoKgCJQQSa0P0h9Jw@mail.gmail.com>

On   Tue, 7 Jan 2020 05:35:21 -0800   Brendan Higgins <brendanhiggins@google.com> wrote:

> Sorry for the delay, I was on vacation. (I still am, but I was too ;-).)

Happy new year, Brendan :)

> 
> On Tue, Jan 7, 2020 at 3:52 AM SeongJae Park <sjpark@amazon.com> wrote:
> >
> > On   Fri, 27 Dec 2019 13:52:27 +0100   Bernd Petrovitsch <bernd@petrovits=
> ch.priv.at> wrote:
> >
> > > This is a multi-part message in MIME format.
> > > --------------D98A0A31D62B0BC2939BAEE9
> > > Content-Type: text/plain; charset=3Dutf-8
> > > Content-Transfer-Encoding: quoted-printable
> > >
> > > Hi all!
> > >
> > > On 27/12/2019 13:39, SeongJae Park wrote:
> > > [...]
> > > > I have a function returning 'unsigned long', and would like to write =
> a =3D
> > > kunit
> > > > test for the function, as below.
> > > >=3D20
> > > >     unsigned long foo(void)
> > > >     {
> > > >             return 42;
> > > >     }
> > > >=3D20
> > > >     static void foo_test(struct kunit *test)
> > > >     {
> > > >         KUNIT_EXPECT_EQ(test, 42, foo());
> > > >     }
> > >
> > > For this case: shouldn't=3D20
> > > ----  snip  ----
> > > static void foo_test(struct kunit *test)
> > > {
> > >      KUNIT_EXPECT_EQ(test, 42ul, foo());
> > > }
> > > ----  snip  ----
> > > do the trick?
> >
> > Unfortunately, it doesn't works.
> >
> >     [13:04:58] Building KUnit Kernel ...
> >     In file included from /.../linux/include/linux/list.h:9:0,
> >                      from /.../linux/include/linux/wait.h:7,
> >                      from /.../linux/include/linux/wait_bit.h:8,
> >                      from /.../linux/include/linux/fs.h:6,
> >                      from /.../linux/include/linux/debugfs.h:15,
> >                      from /.../linux/mm/damon.c:12:
> >     /.../linux/mm/damon-test.h: In function =E2=80=98damon_test_foo=E2=80=
> =99:
> >     /.../linux/include/linux/kernel.h:842:29: warning: comparison of dist=
> inct pointer types lacks a cast
> >        (!!(sizeof((typeof(x) *)1 =3D=3D (typeof(y) *)1)))
> >                                  ^
> >     /.../linux/include/kunit/test.h:493:9: note: in expansion of macro =
> =E2=80=98__typecheck=E2=80=99
> >       ((void)__typecheck(__left, __right));           \
> >              ^~~~~~~~~~~
> >     /.../linux/include/kunit/test.h:517:2: note: in expansion of macro =
> =E2=80=98KUNIT_BASE_BINARY_ASSERTION=E2=80=99
> >       KUNIT_BASE_BINARY_ASSERTION(test,           \
> >       ^~~~~~~~~~~~~~~~~~~~~~~~~~~
> >     /.../linux/include/kunit/test.h:606:2: note: in expansion of macro =
> =E2=80=98KUNIT_BASE_EQ_MSG_ASSERTION=E2=80=99
> >       KUNIT_BASE_EQ_MSG_ASSERTION(test,           \
> >       ^~~~~~~~~~~~~~~~~~~~~~~~~~~
> >     /.../linux/include/kunit/test.h:616:2: note: in expansion of macro =
> =E2=80=98KUNIT_BINARY_EQ_MSG_ASSERTION=E2=80=99
> >       KUNIT_BINARY_EQ_MSG_ASSERTION(test,           \
> >       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >     /.../linux/include/kunit/test.h:979:2: note: in expansion of macro =
> =E2=80=98KUNIT_BINARY_EQ_ASSERTION=E2=80=99
> >       KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
> >       ^~~~~~~~~~~~~~~~~~~~~~~~~
> >     /.../linux/mm/damon-test.h:565:2: note: in expansion of macro =E2=80=
> =98KUNIT_EXPECT_EQ=E2=80=99
> >       KUNIT_EXPECT_EQ(test, 42ul, (int)foo());
> >       ^~~~~~~~~~~~~~~
> 
> Isn't the issue here that you fixed the 42, but are now casting the
> result of foo() to an int?

Oh, right...  Removing the non-sense casting fixed the problem.  Thanks,
Brendan!


Thanks,
SeongJae Park

> 
> Or have you fixed that now too?
> 
> Worst case (gross) scenario, you could just cast 42 to whatever type
> foo() returns.
> 
> > Some other thoughts?
> >
> >
> > Thanks,
> > SeongJae Park
> >
> >
> > >
> > > MfG,
> > >       Bernd
> > > --=3D20
> > > "I dislike type abstraction if it has no real reason. And saving
> > > on typing is not a good reason - if your typing speed is the main
> > > issue when you're coding, you're doing something seriously wrong."
> > >     - Linus Torvalds
> 

  reply	other threads:[~2020-01-07 13:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-27 12:39 What is the best way to compare an unsigned and a constant? SeongJae Park
2019-12-27 12:52 ` Bernd Petrovitsch
2019-12-27 13:08   ` SeongJae Park
2020-01-07 11:52   ` SeongJae Park
2020-01-07 13:35     ` Brendan Higgins
2020-01-07 13:49       ` SeongJae Park [this message]
2020-01-08 14:12         ` Brendan Higgins
2020-01-08 14:26           ` SeongJae Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200107134910.20347-1-sjpark@amazon.com \
    --to=sjpark@amazon.com \
    --cc=bernd@petrovitsch.priv.at \
    --cc=brendanhiggins@google.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=sj38.park@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).