BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Tianci Cao <ziye@zju.edu.cn>
Cc: andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org,
	daniel@iogearbox.net, 	haoluo@google.com,
	john.fastabend@gmail.com, jolsa@kernel.org, kpsingh@kernel.org,
		martin.lau@linux.dev, sdf@fomichev.me, shenghaoyuan0928@163.com,
	song@kernel.org,  tangyazhou518@outlook.com,
	yonghong.song@linux.dev
Subject: Re: [PATCH bpf-next 2/2] selftests/bpf: Add tests for BPF_END bitwise tracking
Date: Tue, 03 Feb 2026 15:16:09 -0800	[thread overview]
Message-ID: <cde3706275830169d289d664d425df1a47b50f31.camel@gmail.com> (raw)
In-Reply-To: <20260203102015.5570-1-ziye@zju.edu.cn>

On Tue, 2026-02-03 at 18:20 +0800, Tianci Cao wrote:

[...]

> However, I noticed that using macros does reduce readability somewhat - the test logic
> is now more abstracted. Given that this is test code, do you think this trade-off is
> acceptable, or would you prefer a middle ground?

Why not like this?

#define BSWAP_RANGE_TEST(name, op, in_value, out_value) \
        SEC("socket") \
        __success __log_level(2) \
        __msg("r0 &= {{.*}}; R0=scalar({{.*}},var_off=(0x0; " #in_value "))") \
        __msg("r0 = " op " r0 {{.*}}; R0=scalar({{.*}},var_off=(0x0; " #out_value "))") \
        __naked void name(void) \
        { \
                asm volatile (                                  \
                "call %[bpf_get_prandom_u32];"                  \
                "r0 &= " #in_value ";"                          \
                "r0 =  " op " r0;"                              \
                "r2 =  " #out_value " ll;"                      \
                "if r0 > r2 goto trap_%=;"                      \
                "r0 = 0;"                                       \
                "exit;"                                         \
        "trap_%=:"                                              \
                "r1 = 42;"                                      \
                "r0 = *(u64 *)(r1 + 0);"                        \
                "exit;"                                         \
        :                                                       \
        : __imm(bpf_get_prandom_u32)                            \
        : __clobber_all);                                       \
        }

BSWAP_RANGE_TEST(bswap16_range, "bswap16", 0x3f00, 0x3f)
BSWAP_RANGE_TEST(bswap32_range, "bswap32", 0x3f00, 0x3f0000)
BSWAP_RANGE_TEST(bswap64_range, "bswap64", 0x3f00, 0x3f000000000000)
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
BSWAP_RANGE_TEST(be16_range, "be16", 0x3f00, 0x3f)
BSWAP_RANGE_TEST(be32_range, "be32", 0x3f00, 0x3f0000)
BSWAP_RANGE_TEST(be64_range, "be64", 0x3f00, 0x3f000000000000)
BSWAP_RANGE_TEST(le16_range, "le16", 0x3f00, 0x3f00)
BSWAP_RANGE_TEST(le32_range, "le32", 0x3f00, 0x3f00)
BSWAP_RANGE_TEST(le64_range, "le64", 0x3f00, 0x3f00)
#else
BSWAP_RANGE_TEST(be16_range, "be16", 0x3f00, 0x3f00)
BSWAP_RANGE_TEST(be32_range, "be32", 0x3f00, 0x3f00)
BSWAP_RANGE_TEST(be64_range, "be64", 0x3f00, 0x3f00)
BSWAP_RANGE_TEST(le16_range, "le16", 0x3f00, 0x3f)
BSWAP_RANGE_TEST(le32_range, "le32", 0x3f00, 0x3f0000)
BSWAP_RANGE_TEST(le64_range, "le64", 0x3f00, 0x3f000000000000)
#endif

  reply	other threads:[~2026-02-03 23:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-02 13:35 [PATCH bpf-next 0/2] bpf: Add bitwise tracking for BPF_END Tianci Cao
2026-02-02 13:35 ` [PATCH bpf-next 1/2] " Tianci Cao
2026-02-02 20:03   ` Eduard Zingerman
2026-02-03 10:17     ` Tianci Cao
2026-02-03 22:36       ` Eduard Zingerman
2026-02-02 13:35 ` [PATCH bpf-next 2/2] selftests/bpf: Add tests for BPF_END bitwise tracking Tianci Cao
2026-02-02 20:23   ` Eduard Zingerman
2026-02-03 10:20     ` Tianci Cao
2026-02-03 23:16       ` Eduard Zingerman [this message]
2026-02-04  6:08         ` Tianci Cao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cde3706275830169d289d664d425df1a47b50f31.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@fomichev.me \
    --cc=shenghaoyuan0928@163.com \
    --cc=song@kernel.org \
    --cc=tangyazhou518@outlook.com \
    --cc=yonghong.song@linux.dev \
    --cc=ziye@zju.edu.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox