[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CACT4Y+a3EPcAS4yB8c2d65+T3zXoTYwN6-G4G0C_JDWBEo6EOA@mail.gmail.com>
Date: Wed, 21 May 2025 12:07:13 +0200
From: Dmitry Vyukov <dvyukov@...gle.com>
To: Thomas Gleixner <tglx@...utronix.de>
Cc: 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 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__)
Powered by blists - more mailing lists