Skip to content

Commit

Permalink
selftests/bpf: Add __int128-specific tests for typed data dump
Browse files Browse the repository at this point in the history
Add tests for __int128 display for platforms that support it.
__int128s are dumped as hex values.

Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/1626770993-11073-3-git-send-email-alan.maguire@oracle.com
  • Loading branch information
Alan Maguire authored and Andrii Nakryiko committed Jul 20, 2021
1 parent a1d3cc3 commit a17553d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tools/testing/selftests/bpf/prog_tests/btf_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,14 @@ static int btf_dump_data(struct btf *btf, struct btf_dump *d,
static void test_btf_dump_int_data(struct btf *btf, struct btf_dump *d,
char *str)
{
#ifdef __SIZEOF_INT128__
__int128 i = 0xffffffffffffffff;

/* this dance is required because we cannot directly initialize
* a 128-bit value to anything larger than a 64-bit value.
*/
i = (i << 64) | (i - 1);
#endif
/* simple int */
TEST_BTF_DUMP_DATA_C(btf, d, NULL, str, int, BTF_F_COMPACT, 1234);
TEST_BTF_DUMP_DATA(btf, d, NULL, str, int, BTF_F_COMPACT | BTF_F_NONAME,
Expand All @@ -348,6 +356,15 @@ static void test_btf_dump_int_data(struct btf *btf, struct btf_dump *d,
TEST_BTF_DUMP_DATA(btf, d, NULL, str, int, 0, "(int)-4567", -4567);

TEST_BTF_DUMP_DATA_OVER(btf, d, NULL, str, int, sizeof(int)-1, "", 1);

#ifdef __SIZEOF_INT128__
TEST_BTF_DUMP_DATA(btf, d, NULL, str, __int128, BTF_F_COMPACT,
"(__int128)0xffffffffffffffff",
0xffffffffffffffff);
ASSERT_OK(btf_dump_data(btf, d, "__int128", NULL, 0, &i, 16, str,
"(__int128)0xfffffffffffffffffffffffffffffffe"),
"dump __int128");
#endif
}

static void test_btf_dump_float_data(struct btf *btf, struct btf_dump *d,
Expand Down

0 comments on commit a17553d

Please sign in to comment.