On Fri, Sep 17, 2021 at 6:56 PM Hou Tao <houtao1@xxxxxxxxxx> wrote: > > Add a writable bare tracepoint in bpf_testmod module, and > trigger its calling when reading /sys/kernel/bpf_testmod > with a specific buffer length. The reading will return > the value in writable context if the early return flag > is enabled in writable context. > > Signed-off-by: Hou Tao <houtao1@xxxxxxxxxx> > --- > .../bpf/bpf_testmod/bpf_testmod-events.h | 15 ++++++++ > .../selftests/bpf/bpf_testmod/bpf_testmod.c | 10 ++++++ > .../selftests/bpf/bpf_testmod/bpf_testmod.h | 5 +++ > .../selftests/bpf/prog_tests/module_attach.c | 36 +++++++++++++++++++ > .../selftests/bpf/progs/test_module_attach.c | 14 ++++++++ > 5 files changed, 80 insertions(+) > [...] > +static int trigger_module_test_writable(int *val) > +{ > + int fd, err; > + char buf[65]; > + ssize_t rd; > + > + fd = open("/sys/kernel/bpf_testmod", O_RDONLY); > + err = -errno; > + if (CHECK(fd < 0, "testmod_file_open", "failed: %d\n", err)) > + return err; > + > + rd = read(fd, buf, sizeof(buf) - 1); > + err = rd < 0 ? -errno : -ENODATA; > + if (CHECK(rd <= 0, "testmod_file_rd_val", "failed: rd %zd errno %d\n", > + rd, errno)) { > + close(fd); > + return err; > + } > + please use ASSERT_xxx() consistently > + buf[rd] = '\0'; > + *val = strtol(buf, NULL, 0); > + close(fd); > + > + return 0; > +} > + [...]