On 11/13, Alexis Lothoré (eBPF Foundation) wrote:
> We sometimes need to compare whole structures in an assert. It is
> possible to use the existing macros on each field, but when the whole
> structure has to be checked, it is more convenient to simply compare the
> whole structure memory
>
> Add a dedicated assert macro, ASSERT_MEMEQ, to allow bare memory
> comparision
>
> Signed-off-by: Alexis Lothoré (eBPF Foundation) <[email protected]>
> ---
> tools/testing/selftests/bpf/test_progs.h | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/test_progs.h
> b/tools/testing/selftests/bpf/test_progs.h
> index
> 74de33ae37e56c90646cd1e0bb58ed7e3f345ec0..bdde741543836991398daacfe5423e6af8ef9151
> 100644
> --- a/tools/testing/selftests/bpf/test_progs.h
> +++ b/tools/testing/selftests/bpf/test_progs.h
> @@ -186,6 +186,19 @@ void test__skip(void);
> void test__fail(void);
> int test__join_cgroup(const char *path);
[..]
> +#define DUMP_BUFFER(name, buf, len)
> \
> + ({
> \
> + fprintf(stdout, "%s:\n", name);
> \
> + for (int i = 0; i < len; i++) {
> \
> + if (i && !(i % 16))
> \
> + fprintf(stdout, "\n");
> \
> + if (i && !(i % 8) && (i % 16))
> \
> + fprintf(stdout, "\t");
> \
> + fprintf(stdout, "%02X ", ((uint8_t *)(buf))[i]);
> \
> + }
> \
> + fprintf(stdout, "\n");
> \
> + })
nit: should we rewrite this as a real function?
void hexdump(const char *prefix, void *buf, size_t len)
{
..
}