Re: [PATCH bpf-next v2 13/18] selftests/bpf: Test new enum kflag and enum64 API functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 5/17/22 4:40 PM, Andrii Nakryiko wrote:
On Fri, May 13, 2022 at 8:13 PM Yonghong Song <yhs@xxxxxx> wrote:

Add tests to use the new enum kflag and enum64 API functions
in selftest btf_write.

Signed-off-by: Yonghong Song <yhs@xxxxxx>
---
  tools/testing/selftests/bpf/btf_helpers.c     |  21 +++-
  .../selftests/bpf/prog_tests/btf_write.c      | 114 +++++++++++++-----
  2 files changed, 105 insertions(+), 30 deletions(-)

[...]

@@ -307,6 +308,48 @@ static void gen_btf(struct btf *btf)
         ASSERT_EQ(t->type, 1, "tag_type");
         ASSERT_STREQ(btf_type_raw_dump(btf, 20),
                      "[20] TYPE_TAG 'tag1' type_id=1", "raw_dump");
+
+       /* ENUM64 */
+       id = btf__add_enum64(btf, "e1", 8, true);
+       ASSERT_EQ(id, 21, "enum64_id");
+       err = btf__add_enum64_value(btf, "v1", -1);
+       ASSERT_OK(err, "v1_res");
+       err = btf__add_enum64_value(btf, "v2", 0x123456789); /* 4886718345 */
+       ASSERT_OK(err, "v2_res");
+       t = btf__type_by_id(btf, 21);
+       ASSERT_STREQ(btf__str_by_offset(btf, t->name_off), "e1", "enum64_name");
+       ASSERT_EQ(btf_kind(t), BTF_KIND_ENUM64, "enum64_kind");
+       ASSERT_EQ(btf_vlen(t), 2, "enum64_vlen");
+       ASSERT_EQ(t->size, 8, "enum64_sz");
+       v64 = btf_enum64(t) + 0;
+       ASSERT_STREQ(btf__str_by_offset(btf, v64->name_off), "v1", "v1_name");
+       ASSERT_EQ(v64->val_hi32, 0xffffffff, "v1_val");
+       ASSERT_EQ(v64->val_lo32, 0xffffffff, "v1_val");
+       v64 = btf_enum64(t) + 1;
+       ASSERT_STREQ(btf__str_by_offset(btf, v64->name_off), "v2", "v2_name");
+       ASSERT_EQ(v64->val_hi32, 0x1, "v2_val");
+       ASSERT_EQ(v64->val_lo32, 0x23456789, "v2_val");
+       ASSERT_STREQ(btf_type_raw_dump(btf, 21),
+                    "[21] ENUM64 'e1' size=8 vlen=2\n"

we should emit and validate kflag for enum/enum64. Or maybe
"encoding=SIGNED|UNSIGNED" to match INT's output, not sure which one
is best, but we probably want to make sure that kflag is reflected in
bpftool and selftests output, right?

My intention is the value print out itself will show it is signed or
unsigned as below. But it doesn't hurt to explicit print out kflag as well. Will do.


+                    "\t'v1' val=-1\n"
+                    "\t'v2' val=4886718345", "raw_dump");
+
+       id = btf__add_enum64(btf, "e1", 8, false);
+       ASSERT_EQ(id, 22, "enum64_id");
+       err = btf__add_enum64_value(btf, "v1", 0xffffffffFFFFFFFF); /* 18446744073709551615 */
+       ASSERT_OK(err, "v1_res");
+       t = btf__type_by_id(btf, 22);
+       ASSERT_STREQ(btf__str_by_offset(btf, t->name_off), "e1", "enum64_name");
+       ASSERT_EQ(btf_kind(t), BTF_KIND_ENUM64, "enum64_kind");
+       ASSERT_EQ(btf_vlen(t), 1, "enum64_vlen");
+       ASSERT_EQ(t->size, 8, "enum64_sz");
+       v64 = btf_enum64(t) + 0;
+       ASSERT_STREQ(btf__str_by_offset(btf, v64->name_off), "v1", "v1_name");
+       ASSERT_EQ(v64->val_hi32, 0xffffffff, "v1_val");
+       ASSERT_EQ(v64->val_lo32, 0xffffffff, "v1_val");
+       ASSERT_STREQ(btf_type_raw_dump(btf, 22),
+                    "[22] ENUM64 'e1' size=8 vlen=1\n"
+                    "\t'v1' val=18446744073709551615", "raw_dump");
  }

  static void test_btf_add()

[...]



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux