void test_libbpf_probe_prog_types(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); if (!ASSERT_OK_PTR(t, "bpf_prog_type_enum")) goto cleanup;
for (e = btf_enum(t), i = 0, n = btf_vlen(t); i < n; e++, i++) { constchar *prog_type_name = btf__str_by_offset(btf, e->name_off); enum bpf_prog_type prog_type = (enum bpf_prog_type)e->val; int res;
if (prog_type == BPF_PROG_TYPE_UNSPEC) continue; if (strcmp(prog_type_name, "__MAX_BPF_PROG_TYPE") == 0) continue;
if (!test__start_subtest(prog_type_name)) continue;
res = libbpf_probe_bpf_prog_type(prog_type, NULL);
ASSERT_EQ(res, 1, prog_type_name);
}
cleanup:
btf__free(btf);
}
void test_libbpf_probe_map_types(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); if (!ASSERT_OK_PTR(t, "bpf_map_type_enum")) goto cleanup;
for (e = btf_enum(t), i = 0, n = btf_vlen(t); i < n; e++, i++) { constchar *map_type_name = btf__str_by_offset(btf, e->name_off); enum bpf_map_type map_type = (enum bpf_map_type)e->val; int res;
if (map_type == BPF_MAP_TYPE_UNSPEC) continue; if (strcmp(map_type_name, "__MAX_BPF_MAP_TYPE") == 0) continue;
if (!test__start_subtest(map_type_name)) continue;
res = libbpf_probe_bpf_map_type(map_type, NULL);
ASSERT_EQ(res, 1, map_type_name);
}
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.