[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4Bzb1z2KOHsMTrSP2t3S0iT3UrYMAWsO1_OqD_EYMECsZ-w@mail.gmail.com>
Date: Fri, 26 Mar 2021 16:05:24 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Florent Revest <revest@...omium.org>
Cc: bpf <bpf@...r.kernel.org>, Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Yonghong Song <yhs@...com>, KP Singh <kpsingh@...nel.org>,
Brendan Jackman <jackmanb@...omium.org>,
open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH bpf-next v2 6/6] selftests/bpf: Add a series of tests for bpf_snprintf
On Tue, Mar 23, 2021 at 7:23 PM Florent Revest <revest@...omium.org> wrote:
>
> This exercises most of the format specifiers when things go well.
>
> Signed-off-by: Florent Revest <revest@...omium.org>
> ---
Looks good. Please add a no-argument test case as well.
Acked-by: Andrii Nakryiko <andrii@...nel.org>
> .../selftests/bpf/prog_tests/snprintf.c | 65 +++++++++++++++++++
> .../selftests/bpf/progs/test_snprintf.c | 59 +++++++++++++++++
> 2 files changed, 124 insertions(+)
> create mode 100644 tools/testing/selftests/bpf/prog_tests/snprintf.c
> create mode 100644 tools/testing/selftests/bpf/progs/test_snprintf.c
>
[...]
> +
> +SEC("raw_tp/sys_enter")
> +int handler(const void *ctx)
> +{
> + /* Convenient values to pretty-print */
> + const __u8 ex_ipv4[] = {127, 0, 0, 1};
> + const __u8 ex_ipv6[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
> + const char str1[] = "str1";
> + const char longstr[] = "longstr";
> + extern const void schedule __ksym;
oh, fancy. I'd move it out of this function into global space, though,
to make it more apparent. I almost missed that it's a special one.
> +
> + /* Integer types */
> + num_ret = BPF_SNPRINTF(num_out, sizeof(num_out),
> + "%d %u %x %li %llu %lX",
> + -8, 9, 150, -424242, 1337, 0xDABBAD00);
> + /* IP addresses */
> + ip_ret = BPF_SNPRINTF(ip_out, sizeof(ip_out), "%pi4 %pI6",
> + &ex_ipv4, &ex_ipv6);
> + /* Symbol lookup formatting */
> + sym_ret = BPF_SNPRINTF(sym_out, sizeof(sym_out), "%ps %pS %pB",
> + &schedule, &schedule, &schedule);
> + /* Kernel pointers */
> + addr_ret = BPF_SNPRINTF(addr_out, sizeof(addr_out), "%pK %px %p",
> + 0, 0xFFFF00000ADD4E55, 0xFFFF00000ADD4E55);
> + /* Strings embedding */
> + str_ret = BPF_SNPRINTF(str_out, sizeof(str_out), "%s %+05s",
> + str1, longstr);
> + /* Overflow */
> + over_ret = BPF_SNPRINTF(over_out, sizeof(over_out), "%%overflow");
> +
> + return 0;
> +}
> +
> +char _license[] SEC("license") = "GPL";
> --
> 2.31.0.291.g576ba9dcdaf-goog
>
Powered by blists - more mailing lists