Re: [PATCH bpf-next v3 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/31/22 5:08 PM, Andrii Nakryiko wrote:
On Thu, May 26, 2022 at 11:55 AM 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>
---

LGTM.

Acked-by: Andrii Nakryiko <andrii@xxxxxxxxxx>

  tools/testing/selftests/bpf/btf_helpers.c     |  25 +++-
  .../selftests/bpf/prog_tests/btf_write.c      | 126 +++++++++++++-----
  2 files changed, 114 insertions(+), 37 deletions(-)

diff --git a/tools/testing/selftests/bpf/btf_helpers.c b/tools/testing/selftests/bpf/btf_helpers.c
index b5941d514e17..1c1c2c26690a 100644
--- a/tools/testing/selftests/bpf/btf_helpers.c
+++ b/tools/testing/selftests/bpf/btf_helpers.c
@@ -26,11 +26,12 @@ static const char * const btf_kind_str_mapping[] = {
         [BTF_KIND_FLOAT]        = "FLOAT",
         [BTF_KIND_DECL_TAG]     = "DECL_TAG",
         [BTF_KIND_TYPE_TAG]     = "TYPE_TAG",
+       [BTF_KIND_ENUM64]       = "ENUM64",
  };

  static const char *btf_kind_str(__u16 kind)
  {
-       if (kind > BTF_KIND_TYPE_TAG)
+       if (kind > BTF_KIND_ENUM64)
                 return "UNKNOWN";
         return btf_kind_str_mapping[kind];
  }
@@ -139,14 +140,32 @@ int fprintf_btf_type_raw(FILE *out, const struct btf *btf, __u32 id)
         }
         case BTF_KIND_ENUM: {
                 const struct btf_enum *v = btf_enum(t);
+               const char *fmt_str;

-               fprintf(out, " size=%u vlen=%u", t->size, vlen);
+               fmt_str = btf_kflag(t) ? "\n\t'%s' val=%d" : "\n\t'%s' val=%u";
+               fprintf(out, " encoding=%s size=%u vlen=%u",
+                       btf_kflag(t) ? "SIGNED" : "UNSIGNED", t->size, vlen);
                 for (i = 0; i < vlen; i++, v++) {
-                       fprintf(out, "\n\t'%s' val=%u",
+                       fprintf(out, fmt_str,
                                 btf_str(btf, v->name_off), v->val);
                 }
                 break;
         }
+       case BTF_KIND_ENUM64: {
+               const struct btf_enum64 *v = btf_enum64(t);
+               const char *fmt_str;
+
+               fmt_str = btf_kflag(t) ? "\n\t'%s' val=%lld" : "\n\t'%s' val=%llu";
+
+               fprintf(out, " encoding=%s size=%u vlen=%u",
+                       btf_kflag(t) ? "SIGNED" : "UNSIGNED", t->size, vlen);
+               for (i = 0; i < vlen; i++, v++) {
+                       fprintf(out, fmt_str,
+                               btf_str(btf, v->name_off),
+                               ((__u64)v->val_hi32 << 32) | v->val_lo32);

nit: btf_enum64_value()?

Right. missed this one. Will fix.


+               }
+               break;
+       }
         case BTF_KIND_FWD:
                 fprintf(out, " fwd_kind=%s", btf_kflag(t) ? "union" : "struct");
                 break;

[...]



[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