[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CACT4Y+ZFMGdvO8e5TenNKNCwBJYtY-kB=uB-CLBEe2vrr3TWdQ@mail.gmail.com>
Date: Wed, 21 May 2025 15:00:15 +0200
From: Dmitry Vyukov <dvyukov@...gle.com>
To: Thomas Weißschuh <linux@...ssschuh.net>
Cc: Thomas Gleixner <tglx@...utronix.de>, krisman@...labora.com, luto@...nel.org,
peterz@...radead.org, keescook@...omium.org, gregory.price@...verge.com,
Marco Elver <elver@...gle.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 2/3] selftests: Fix errno checking in
syscall_user_dispatch test
On Wed, 21 May 2025 at 13:10, Thomas Weißschuh <linux@...ssschuh.net> wrote:
>
> On 2025-05-21 12:07:13+0200, Dmitry Vyukov wrote:
> > On Sat, 8 Mar 2025 at 13:34, Thomas Gleixner <tglx@...utronix.de> wrote:
> > >
> > > On Mon, Feb 24 2025 at 09:45, Dmitry Vyukov wrote:
> > > >
> > > > Also use EXPECT/ASSERT consistently. Currently there is an inconsistent mix
> > > > without obvious reasons for usage of one or another.
> > > >
> > > > Signed-off-by: Dmitry Vyukov <dvyukov@...gle.com>
> > >
> > > As Gregory said, this should be the first patch in the series with a
> > > proper Fixes tag.
> > >
> > > > /* Invalid op */
> > > > op = -1;
> > > > - prctl(PR_SET_SYSCALL_USER_DISPATCH, op, 0, 0, &sel);
> > > > - ASSERT_EQ(EINVAL, errno);
> >
> > > > + EXPECT_EQ(-1, prctl(PR_SET_SYSCALL_USER_DISPATCH, op, 0, 0, &sel));
> > > > + EXPECT_EQ(EINVAL, errno);
> > >
> > > Seriously?
> > >
> > > Something like:
> > >
> > > static void prctl_invalid(unsigned long op, unsigned long offs, unsigned long len,
> > > void *sel, int err)
> > > {
> > > EXPECT_EQ(-1, prctl(PR_SET_SYSCALL_USER_DISPATCH, op, offs, len, 0, (unsigned long)sel));
> > > EXPECT_EQ(err, errno);
> > > }
> > >
> > > static void prctl_valid(unsigned long op, unsigned long offs, unsigned long len,
> > > void *sel)
> > > {
> > > EXPECT_EQ(0, prctl(PR_SET_SYSCALL_USER_DISPATCH, op, offs, len, 0, (unsigned long)sel));
> > > }
> > >
> > > ....
> > > /* Invalid op */
> > > prctl_invalid(-1, 0, 0, &sel, -EINVAL);
> > > /* offset != 0 */
> > > prctl_invalid(PR_SYS_DISPATCH_OFF, 1, 0, NULL, -EINVAL);
> > > ....
> > > /* The odd valid test in bad_prctl_param() */
> > > prctl_valid(PR_SYS_DISPATCH_OFF, 0, 0, NULL);
> > >
> > > But that's not enough macro uglyness sprinkled all over the place and
> > > too readable, right?
> >
> > The EXPECT* macros unfortunately can't be used in helper functions,
> > they require some hidden _metadata variable that is present only in
> > TEST/TEST_F functions:
> >
> > sud_test.c: In function ‘prctl_valid’:
> > ../kselftest_harness.h:107:45: error: ‘_metadata’ undeclared (first
> > use in this function)
> > 107 | __FILE__, __LINE__, _metadata->name,
> > ##__VA_ARGS__)
>
> You can pass the _metadata parameter to your helper functions.
> While it's a bit iffy, many selftests do this.
> Also the upcoming harness selftests will make sure that this pattern
> keeps working.
This works, thanks. I will include this in v3.
Powered by blists - more mailing lists