Re: [PATCH bpf-next v1 5/8] selftests/bpf: bad_struct_ops test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Feb 28, 2024 at 3:44 PM Eduard Zingerman <eddyz87@xxxxxxxxx> wrote:
>
> On Wed, 2024-02-28 at 15:40 -0800, Andrii Nakryiko wrote:
> [...]
>
> > > +static libbpf_print_fn_t old_print_cb;
> > > +static bool msg_found;
> > > +
> > > +static int print_cb(enum libbpf_print_level level, const char *fmt, va_list args)
> > > +{
> > > +       old_print_cb(level, fmt, args);
> > > +       if (level == LIBBPF_WARN && strncmp(fmt, EXPECTED_MSG, strlen(EXPECTED_MSG)) == 0)
> > > +               msg_found = true;
> > > +
> > > +       return 0;
> > > +}
> > > +
> > > +static void test_bad_struct_ops(void)
> > > +{
> > > +       struct bad_struct_ops *skel;
> > > +       int err;
> > > +
> > > +       old_print_cb = libbpf_set_print(print_cb);
> > > +       skel = bad_struct_ops__open_and_load();
> >
> > we want to check that the load step failed specifically, right? So
> > please split open from load, make sure that open succeeds, but load
> > fails
>
> Ok
>
> >
> > > +       err = errno;
> > > +       libbpf_set_print(old_print_cb);
> > > +       if (!ASSERT_NULL(skel, "bad_struct_ops__open_and_load"))
> > > +               return;
> > > +
> > > +       ASSERT_EQ(err, EINVAL, "errno should be EINVAL");
> > > +       ASSERT_TRUE(msg_found, "expected message");
> > > +
> > > +       bad_struct_ops__destroy(skel);
> > > +}
> > > +
> > > +void serial_test_bad_struct_ops(void)
> >
> > why does it have to be a serial test?
>
> Because it hijacks libbpf print callback.

each non-serial test runs in its own *process*, there is no
multi-threading here, so it's fine if non-serial test temporarily
hijacks print callback, as long as it restores it properly before
finishing

>
> [...]





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux