/* * Utility function uppercasing an entire string.
*/ staticvoid uppercase(char *s)
{ for (; *s != '\0'; s++)
*s = toupper(*s);
}
/* * Test case to check that all bpf_attach_type variants are covered by * libbpf_bpf_attach_type_str.
*/ staticvoid test_libbpf_bpf_attach_type_str(void)
{ struct btf *btf; conststruct btf_type *t; conststruct btf_enum *e; int i, n, id;
btf = btf__parse("/sys/kernel/btf/vmlinux", NULL); if (!ASSERT_OK_PTR(btf, "btf_parse")) return;
/* find enum bpf_attach_type and enumerate each value */
id = btf__find_by_name_kind(btf, "bpf_attach_type", BTF_KIND_ENUM); if (!ASSERT_GT(id, 0, "bpf_attach_type_id")) goto cleanup;
t = btf__type_by_id(btf, id);
e = btf_enum(t);
n = btf_vlen(t); for (i = 0; i < n; e++, i++) { enum bpf_attach_type attach_type = (enum bpf_attach_type)e->val; constchar *attach_type_name; constchar *attach_type_str; char buf[256];
if (attach_type == __MAX_BPF_ATTACH_TYPE) continue;
/* * Test case to check that all bpf_link_type variants are covered by * libbpf_bpf_link_type_str.
*/ staticvoid test_libbpf_bpf_link_type_str(void)
{ struct btf *btf; conststruct btf_type *t; conststruct btf_enum *e; int i, n, id;
btf = btf__parse("/sys/kernel/btf/vmlinux", NULL); if (!ASSERT_OK_PTR(btf, "btf_parse")) return;
/* find enum bpf_link_type and enumerate each value */
id = btf__find_by_name_kind(btf, "bpf_link_type", BTF_KIND_ENUM); if (!ASSERT_GT(id, 0, "bpf_link_type_id")) goto cleanup;
t = btf__type_by_id(btf, id);
e = btf_enum(t);
n = btf_vlen(t); for (i = 0; i < n; e++, i++) { enum bpf_link_type link_type = (enum bpf_link_type)e->val; constchar *link_type_name; constchar *link_type_str; char buf[256];
/* * Test case to check that all bpf_map_type variants are covered by * libbpf_bpf_map_type_str.
*/ staticvoid test_libbpf_bpf_map_type_str(void)
{ struct btf *btf; conststruct btf_type *t; conststruct btf_enum *e; int i, n, id;
btf = btf__parse("/sys/kernel/btf/vmlinux", NULL); if (!ASSERT_OK_PTR(btf, "btf_parse")) return;
/* find enum bpf_map_type and enumerate each value */
id = btf__find_by_name_kind(btf, "bpf_map_type", BTF_KIND_ENUM); if (!ASSERT_GT(id, 0, "bpf_map_type_id")) goto cleanup;
t = btf__type_by_id(btf, id);
e = btf_enum(t);
n = btf_vlen(t); for (i = 0; i < n; e++, i++) { enum bpf_map_type map_type = (enum bpf_map_type)e->val; constchar *map_type_name; constchar *map_type_str; char buf[256];
/* Special case for map_type_name BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED * where it and BPF_MAP_TYPE_CGROUP_STORAGE have the same enum value * (map_type). For this enum value, libbpf_bpf_map_type_str() picks * BPF_MAP_TYPE_CGROUP_STORAGE. The same for * BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE_DEPRECATED and * BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE.
*/ if (strcmp(map_type_name, "BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED") == 0) continue; if (strcmp(map_type_name, "BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE_DEPRECATED") == 0) continue;
/* * Test case to check that all bpf_prog_type variants are covered by * libbpf_bpf_prog_type_str.
*/ staticvoid test_libbpf_bpf_prog_type_str(void)
{ struct btf *btf; conststruct btf_type *t; conststruct btf_enum *e; int i, n, id;
btf = btf__parse("/sys/kernel/btf/vmlinux", NULL); if (!ASSERT_OK_PTR(btf, "btf_parse")) return;
/* find enum bpf_prog_type and enumerate each value */
id = btf__find_by_name_kind(btf, "bpf_prog_type", BTF_KIND_ENUM); if (!ASSERT_GT(id, 0, "bpf_prog_type_id")) goto cleanup;
t = btf__type_by_id(btf, id);
e = btf_enum(t);
n = btf_vlen(t); for (i = 0; i < n; e++, i++) { enum bpf_prog_type prog_type = (enum bpf_prog_type)e->val; constchar *prog_type_name; constchar *prog_type_str; char buf[256];
/* * Run all libbpf str conversion tests.
*/ void test_libbpf_str(void)
{ if (test__start_subtest("bpf_attach_type_str"))
test_libbpf_bpf_attach_type_str();
if (test__start_subtest("bpf_link_type_str"))
test_libbpf_bpf_link_type_str();
if (test__start_subtest("bpf_map_type_str"))
test_libbpf_bpf_map_type_str();
if (test__start_subtest("bpf_prog_type_str"))
test_libbpf_bpf_prog_type_str();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.