Commit 60ba87bb authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov

selftests/bpf: Update btf_dump__new() uses to v1.0+ variant

Update to-be-deprecated forms of btf_dump__new().
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211111053624.190580-8-andrii@kernel.org
parent 0b52a5f4
...@@ -238,7 +238,6 @@ const char *btf_type_c_dump(const struct btf *btf) ...@@ -238,7 +238,6 @@ const char *btf_type_c_dump(const struct btf *btf)
static char buf[16 * 1024]; static char buf[16 * 1024];
FILE *buf_file; FILE *buf_file;
struct btf_dump *d = NULL; struct btf_dump *d = NULL;
struct btf_dump_opts opts = {};
int err, i; int err, i;
buf_file = fmemopen(buf, sizeof(buf) - 1, "w"); buf_file = fmemopen(buf, sizeof(buf) - 1, "w");
...@@ -247,8 +246,7 @@ const char *btf_type_c_dump(const struct btf *btf) ...@@ -247,8 +246,7 @@ const char *btf_type_c_dump(const struct btf *btf)
return NULL; return NULL;
} }
opts.ctx = buf_file; d = btf_dump__new(btf, btf_dump_printf, buf_file, NULL);
d = btf_dump__new(btf, NULL, &opts, btf_dump_printf);
if (libbpf_get_error(d)) { if (libbpf_get_error(d)) {
fprintf(stderr, "Failed to create btf_dump instance: %ld\n", libbpf_get_error(d)); fprintf(stderr, "Failed to create btf_dump instance: %ld\n", libbpf_get_error(d));
goto err_out; goto err_out;
......
...@@ -13,25 +13,23 @@ static struct btf_dump_test_case { ...@@ -13,25 +13,23 @@ static struct btf_dump_test_case {
const char *name; const char *name;
const char *file; const char *file;
bool known_ptr_sz; bool known_ptr_sz;
struct btf_dump_opts opts;
} btf_dump_test_cases[] = { } btf_dump_test_cases[] = {
{"btf_dump: syntax", "btf_dump_test_case_syntax", true, {}}, {"btf_dump: syntax", "btf_dump_test_case_syntax", true},
{"btf_dump: ordering", "btf_dump_test_case_ordering", false, {}}, {"btf_dump: ordering", "btf_dump_test_case_ordering", false},
{"btf_dump: padding", "btf_dump_test_case_padding", true, {}}, {"btf_dump: padding", "btf_dump_test_case_padding", true},
{"btf_dump: packing", "btf_dump_test_case_packing", true, {}}, {"btf_dump: packing", "btf_dump_test_case_packing", true},
{"btf_dump: bitfields", "btf_dump_test_case_bitfields", true, {}}, {"btf_dump: bitfields", "btf_dump_test_case_bitfields", true},
{"btf_dump: multidim", "btf_dump_test_case_multidim", false, {}}, {"btf_dump: multidim", "btf_dump_test_case_multidim", false},
{"btf_dump: namespacing", "btf_dump_test_case_namespacing", false, {}}, {"btf_dump: namespacing", "btf_dump_test_case_namespacing", false},
}; };
static int btf_dump_all_types(const struct btf *btf, static int btf_dump_all_types(const struct btf *btf, void *ctx)
const struct btf_dump_opts *opts)
{ {
size_t type_cnt = btf__type_cnt(btf); size_t type_cnt = btf__type_cnt(btf);
struct btf_dump *d; struct btf_dump *d;
int err = 0, id; int err = 0, id;
d = btf_dump__new(btf, NULL, opts, btf_dump_printf); d = btf_dump__new(btf, btf_dump_printf, ctx, NULL);
err = libbpf_get_error(d); err = libbpf_get_error(d);
if (err) if (err)
return err; return err;
...@@ -88,8 +86,7 @@ static int test_btf_dump_case(int n, struct btf_dump_test_case *t) ...@@ -88,8 +86,7 @@ static int test_btf_dump_case(int n, struct btf_dump_test_case *t)
goto done; goto done;
} }
t->opts.ctx = f; err = btf_dump_all_types(btf, f);
err = btf_dump_all_types(btf, &t->opts);
fclose(f); fclose(f);
close(fd); close(fd);
if (CHECK(err, "btf_dump", "failure during C dumping: %d\n", err)) { if (CHECK(err, "btf_dump", "failure during C dumping: %d\n", err)) {
...@@ -137,7 +134,6 @@ static void test_btf_dump_incremental(void) ...@@ -137,7 +134,6 @@ static void test_btf_dump_incremental(void)
{ {
struct btf *btf = NULL; struct btf *btf = NULL;
struct btf_dump *d = NULL; struct btf_dump *d = NULL;
struct btf_dump_opts opts;
int id, err, i; int id, err, i;
dump_buf_file = open_memstream(&dump_buf, &dump_buf_sz); dump_buf_file = open_memstream(&dump_buf, &dump_buf_sz);
...@@ -146,8 +142,7 @@ static void test_btf_dump_incremental(void) ...@@ -146,8 +142,7 @@ static void test_btf_dump_incremental(void)
btf = btf__new_empty(); btf = btf__new_empty();
if (!ASSERT_OK_PTR(btf, "new_empty")) if (!ASSERT_OK_PTR(btf, "new_empty"))
goto err_out; goto err_out;
opts.ctx = dump_buf_file; d = btf_dump__new(btf, btf_dump_printf, dump_buf_file, NULL);
d = btf_dump__new(btf, NULL, &opts, btf_dump_printf);
if (!ASSERT_OK(libbpf_get_error(d), "btf_dump__new")) if (!ASSERT_OK(libbpf_get_error(d), "btf_dump__new"))
goto err_out; goto err_out;
...@@ -815,7 +810,6 @@ static void test_btf_datasec(struct btf *btf, struct btf_dump *d, char *str, ...@@ -815,7 +810,6 @@ static void test_btf_datasec(struct btf *btf, struct btf_dump *d, char *str,
static void test_btf_dump_datasec_data(char *str) static void test_btf_dump_datasec_data(char *str)
{ {
struct btf *btf; struct btf *btf;
struct btf_dump_opts opts = { .ctx = str };
char license[4] = "GPL"; char license[4] = "GPL";
struct btf_dump *d; struct btf_dump *d;
...@@ -823,7 +817,7 @@ static void test_btf_dump_datasec_data(char *str) ...@@ -823,7 +817,7 @@ static void test_btf_dump_datasec_data(char *str)
if (!ASSERT_OK_PTR(btf, "xdping_kern.o BTF not found")) if (!ASSERT_OK_PTR(btf, "xdping_kern.o BTF not found"))
return; return;
d = btf_dump__new(btf, NULL, &opts, btf_dump_snprintf); d = btf_dump__new(btf, btf_dump_snprintf, str, NULL);
if (!ASSERT_OK_PTR(d, "could not create BTF dump")) if (!ASSERT_OK_PTR(d, "could not create BTF dump"))
goto out; goto out;
...@@ -837,7 +831,6 @@ static void test_btf_dump_datasec_data(char *str) ...@@ -837,7 +831,6 @@ static void test_btf_dump_datasec_data(char *str)
void test_btf_dump() { void test_btf_dump() {
char str[STRSIZE]; char str[STRSIZE];
struct btf_dump_opts opts = { .ctx = str };
struct btf_dump *d; struct btf_dump *d;
struct btf *btf; struct btf *btf;
int i; int i;
...@@ -857,7 +850,7 @@ void test_btf_dump() { ...@@ -857,7 +850,7 @@ void test_btf_dump() {
if (!ASSERT_OK_PTR(btf, "no kernel BTF found")) if (!ASSERT_OK_PTR(btf, "no kernel BTF found"))
return; return;
d = btf_dump__new(btf, NULL, &opts, btf_dump_snprintf); d = btf_dump__new(btf, btf_dump_snprintf, str, NULL);
if (!ASSERT_OK_PTR(d, "could not create BTF dump")) if (!ASSERT_OK_PTR(d, "could not create BTF dump"))
return; return;
......
...@@ -13,7 +13,6 @@ static void btf_dump_printf(void *ctx, const char *fmt, va_list args) ...@@ -13,7 +13,6 @@ static void btf_dump_printf(void *ctx, const char *fmt, va_list args)
} }
void test_btf_split() { void test_btf_split() {
struct btf_dump_opts opts;
struct btf_dump *d = NULL; struct btf_dump *d = NULL;
const struct btf_type *t; const struct btf_type *t;
struct btf *btf1, *btf2; struct btf *btf1, *btf2;
...@@ -68,8 +67,7 @@ void test_btf_split() { ...@@ -68,8 +67,7 @@ void test_btf_split() {
dump_buf_file = open_memstream(&dump_buf, &dump_buf_sz); dump_buf_file = open_memstream(&dump_buf, &dump_buf_sz);
if (!ASSERT_OK_PTR(dump_buf_file, "dump_memstream")) if (!ASSERT_OK_PTR(dump_buf_file, "dump_memstream"))
return; return;
opts.ctx = dump_buf_file; d = btf_dump__new(btf2, btf_dump_printf, dump_buf_file, NULL);
d = btf_dump__new(btf2, NULL, &opts, btf_dump_printf);
if (!ASSERT_OK_PTR(d, "btf_dump__new")) if (!ASSERT_OK_PTR(d, "btf_dump__new"))
goto cleanup; goto cleanup;
for (i = 1; i < btf__type_cnt(btf2); i++) { for (i = 1; i < btf__type_cnt(btf2); i++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment