> diff --git a/tools/testing/selftests/bpf/prog_tests/bpftool_map_batch.c
> b/tools/testing/selftests/bpf/prog_tests/bpftool_map_batch.c
> new file mode 100644
> index 000000000000..b4216ed778ef
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/bpftool_map_batch.c
[ ... ]
> +static void expected_record(char *record, const struct dump_case *test,
> + unsigned int index, bool json)
> +{
> + __u32 key = index, value = index * 37 + 11;
> + unsigned char short_key = index;
> + char key_hex[64], value_hex[64], formatted[96];
> +
> + hex_bytes(key_hex, test->key_size == 1 ? (void *)&short_key : &key,
> + test->key_size, json);
> + hex_bytes(value_hex, &value, test->value_size, json);
[ ... ]
> +static void run_dump_case(const struct dump_case *test)
> +{
[ ... ]
> + for (i = 0; i < test->count; i++) {
> + __u32 key = i, value = i * 37 + 11;
> + unsigned char short_key = i;
> + void *key_ptr = test->key_size == 1 ? (void *)&short_key : &key;
> +
> + if (!ASSERT_OK(bpf_map_update_elem(fd, key_ptr, &value,
> BPF_ANY),
> + "map_update"))
> + goto out;
> + }
This isn't a bug, but the key/value derivation appears in both
expected_record() and run_dump_case() with the same formula (index * 37
+ 11) and the same short_key narrowing logic. Would it be worth having
a single small helper that derives the key pointer and value for an
index, so the insert side and expectation side cannot drift apart?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/34074207177