On Tue, Mar 3, 2020 at 6:13 AM KP Singh <kpsingh@xxxxxxxxxxxx> wrote: > > From: KP Singh <kpsingh@xxxxxxxxxx> > > Test for two scenarios: > > * When the fmod_ret program returns 0, the original function should > be called along with fentry and fexit programs. > * When the fmod_ret program returns a non-zero value, the original > function should not be called, no side effect should be observed and > fentry and fexit programs should be called. > > The result from the kernel function call and whether a side-effect is > observed is returned via the retval attr of the BPF_PROG_TEST_RUN (bpf) > syscall. > > Signed-off-by: KP Singh <kpsingh@xxxxxxxxxx> > --- minor nits only Acked-by: Andrii Nakryiko <andriin@xxxxxx> > net/bpf/test_run.c | 23 ++++++- > .../selftests/bpf/prog_tests/modify_return.c | 65 +++++++++++++++++++ > .../selftests/bpf/progs/modify_return.c | 49 ++++++++++++++ > 3 files changed, 135 insertions(+), 2 deletions(-) > create mode 100644 tools/testing/selftests/bpf/prog_tests/modify_return.c > create mode 100644 tools/testing/selftests/bpf/progs/modify_return.c > [...] > > - return 0; > + retval = (u32)side_effect << 16 | ret; uhm, I didn't look up operator priority table, but I'd rather have () around bit shift operation :) > + if (copy_to_user(&uattr->test.retval, &retval, sizeof(retval))) > + goto out; > > + return 0; > out: > trace_bpf_test_finish(&err); > return err; > diff --git a/tools/testing/selftests/bpf/prog_tests/modify_return.c b/tools/testing/selftests/bpf/prog_tests/modify_return.c > new file mode 100644 > index 000000000000..beab9a37f35c > --- /dev/null > +++ b/tools/testing/selftests/bpf/prog_tests/modify_return.c > @@ -0,0 +1,65 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +/* > + * Copyright 2020 Google LLC. > + */ > + > +#include <test_progs.h> > +#include "modify_return.skel.h" > + > +#define LOWER(x) (x & 0xffff) > +#define UPPER(x) (x >> 16) pedantic nit: (x) instead of just x > + > + [...]