diff options
author | Andrii Nakryiko <andriin@fb.com> | 2019-02-08 14:19:39 -0500 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2019-02-08 15:04:13 -0500 |
commit | 49b57e0d01db73c99f86d68480fb9b4014bb1060 (patch) | |
tree | a5b61868a7ba083c1828e438a07a33d9add96c6f | |
parent | ae4ab4b4117d23da49f04a7e1fe82a41e6074eeb (diff) |
tools/bpf: remove btf__get_strings() superseded by raw data API
Now that we have btf__get_raw_data() it's trivial for tests to iterate
over all strings for testing purposes, which eliminates the need for
btf__get_strings() API.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r-- | tools/lib/bpf/btf.c | 7 | ||||
-rw-r--r-- | tools/lib/bpf/btf.h | 2 | ||||
-rw-r--r-- | tools/lib/bpf/libbpf.map | 1 | ||||
-rw-r--r-- | tools/testing/selftests/bpf/test_btf.c | 39 |
4 files changed, 26 insertions, 23 deletions
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index f6b724ed1bdd..6953fedb88ff 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c | |||
@@ -449,13 +449,6 @@ const void *btf__get_raw_data(const struct btf *btf, __u32 *size) | |||
449 | return btf->data; | 449 | return btf->data; |
450 | } | 450 | } |
451 | 451 | ||
452 | void btf__get_strings(const struct btf *btf, const char **strings, | ||
453 | __u32 *str_len) | ||
454 | { | ||
455 | *strings = btf->strings; | ||
456 | *str_len = btf->hdr->str_len; | ||
457 | } | ||
458 | |||
459 | const char *btf__name_by_offset(const struct btf *btf, __u32 offset) | 452 | const char *btf__name_by_offset(const struct btf *btf, __u32 offset) |
460 | { | 453 | { |
461 | if (offset < btf->hdr->str_len) | 454 | if (offset < btf->hdr->str_len) |
diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h index 0306b54d54eb..94bbc249b0f1 100644 --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h | |||
@@ -67,8 +67,6 @@ LIBBPF_API __s64 btf__resolve_size(const struct btf *btf, __u32 type_id); | |||
67 | LIBBPF_API int btf__resolve_type(const struct btf *btf, __u32 type_id); | 67 | LIBBPF_API int btf__resolve_type(const struct btf *btf, __u32 type_id); |
68 | LIBBPF_API int btf__fd(const struct btf *btf); | 68 | LIBBPF_API int btf__fd(const struct btf *btf); |
69 | LIBBPF_API const void *btf__get_raw_data(const struct btf *btf, __u32 *size); | 69 | LIBBPF_API const void *btf__get_raw_data(const struct btf *btf, __u32 *size); |
70 | LIBBPF_API void btf__get_strings(const struct btf *btf, const char **strings, | ||
71 | __u32 *str_len); | ||
72 | LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset); | 70 | LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset); |
73 | LIBBPF_API int btf__get_from_id(__u32 id, struct btf **btf); | 71 | LIBBPF_API int btf__get_from_id(__u32 id, struct btf **btf); |
74 | LIBBPF_API int btf__get_map_kv_tids(const struct btf *btf, const char *map_name, | 72 | LIBBPF_API int btf__get_map_kv_tids(const struct btf *btf, const char *map_name, |
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index eb78c7c261d9..5fc8222209f8 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map | |||
@@ -137,7 +137,6 @@ LIBBPF_0.0.2 { | |||
137 | btf__get_map_kv_tids; | 137 | btf__get_map_kv_tids; |
138 | btf__get_nr_types; | 138 | btf__get_nr_types; |
139 | btf__get_raw_data; | 139 | btf__get_raw_data; |
140 | btf__get_strings; | ||
141 | btf__load; | 140 | btf__load; |
142 | btf_ext__free; | 141 | btf_ext__free; |
143 | btf_ext__func_info_rec_size; | 142 | btf_ext__func_info_rec_size; |
diff --git a/tools/testing/selftests/bpf/test_btf.c b/tools/testing/selftests/bpf/test_btf.c index 447acc34db94..bbcacba39590 100644 --- a/tools/testing/selftests/bpf/test_btf.c +++ b/tools/testing/selftests/bpf/test_btf.c | |||
@@ -5882,15 +5882,17 @@ static void dump_btf_strings(const char *strs, __u32 len) | |||
5882 | static int do_test_dedup(unsigned int test_num) | 5882 | static int do_test_dedup(unsigned int test_num) |
5883 | { | 5883 | { |
5884 | const struct btf_dedup_test *test = &dedup_tests[test_num - 1]; | 5884 | const struct btf_dedup_test *test = &dedup_tests[test_num - 1]; |
5885 | int err = 0, i; | 5885 | __u32 test_nr_types, expect_nr_types, test_btf_size, expect_btf_size; |
5886 | __u32 test_nr_types, expect_nr_types, test_str_len, expect_str_len; | 5886 | const struct btf_header *test_hdr, *expect_hdr; |
5887 | void *raw_btf; | ||
5888 | unsigned int raw_btf_size; | ||
5889 | struct btf *test_btf = NULL, *expect_btf = NULL; | 5887 | struct btf *test_btf = NULL, *expect_btf = NULL; |
5888 | const void *test_btf_data, *expect_btf_data; | ||
5890 | const char *ret_test_next_str, *ret_expect_next_str; | 5889 | const char *ret_test_next_str, *ret_expect_next_str; |
5891 | const char *test_strs, *expect_strs; | 5890 | const char *test_strs, *expect_strs; |
5892 | const char *test_str_cur, *test_str_end; | 5891 | const char *test_str_cur, *test_str_end; |
5893 | const char *expect_str_cur, *expect_str_end; | 5892 | const char *expect_str_cur, *expect_str_end; |
5893 | unsigned int raw_btf_size; | ||
5894 | void *raw_btf; | ||
5895 | int err = 0, i; | ||
5894 | 5896 | ||
5895 | fprintf(stderr, "BTF dedup test[%u] (%s):", test_num, test->descr); | 5897 | fprintf(stderr, "BTF dedup test[%u] (%s):", test_num, test->descr); |
5896 | 5898 | ||
@@ -5927,23 +5929,34 @@ static int do_test_dedup(unsigned int test_num) | |||
5927 | goto done; | 5929 | goto done; |
5928 | } | 5930 | } |
5929 | 5931 | ||
5930 | btf__get_strings(test_btf, &test_strs, &test_str_len); | 5932 | test_btf_data = btf__get_raw_data(test_btf, &test_btf_size); |
5931 | btf__get_strings(expect_btf, &expect_strs, &expect_str_len); | 5933 | expect_btf_data = btf__get_raw_data(expect_btf, &expect_btf_size); |
5932 | if (CHECK(test_str_len != expect_str_len, | 5934 | if (CHECK(test_btf_size != expect_btf_size, |
5933 | "test_str_len:%u != expect_str_len:%u", | 5935 | "test_btf_size:%u != expect_btf_size:%u", |
5934 | test_str_len, expect_str_len)) { | 5936 | test_btf_size, expect_btf_size)) { |
5937 | err = -1; | ||
5938 | goto done; | ||
5939 | } | ||
5940 | |||
5941 | test_hdr = test_btf_data; | ||
5942 | test_strs = test_btf_data + test_hdr->str_off; | ||
5943 | expect_hdr = expect_btf_data; | ||
5944 | expect_strs = expect_btf_data + expect_hdr->str_off; | ||
5945 | if (CHECK(test_hdr->str_len != expect_hdr->str_len, | ||
5946 | "test_hdr->str_len:%u != expect_hdr->str_len:%u", | ||
5947 | test_hdr->str_len, expect_hdr->str_len)) { | ||
5935 | fprintf(stderr, "\ntest strings:\n"); | 5948 | fprintf(stderr, "\ntest strings:\n"); |
5936 | dump_btf_strings(test_strs, test_str_len); | 5949 | dump_btf_strings(test_strs, test_hdr->str_len); |
5937 | fprintf(stderr, "\nexpected strings:\n"); | 5950 | fprintf(stderr, "\nexpected strings:\n"); |
5938 | dump_btf_strings(expect_strs, expect_str_len); | 5951 | dump_btf_strings(expect_strs, expect_hdr->str_len); |
5939 | err = -1; | 5952 | err = -1; |
5940 | goto done; | 5953 | goto done; |
5941 | } | 5954 | } |
5942 | 5955 | ||
5943 | test_str_cur = test_strs; | 5956 | test_str_cur = test_strs; |
5944 | test_str_end = test_strs + test_str_len; | 5957 | test_str_end = test_strs + test_hdr->str_len; |
5945 | expect_str_cur = expect_strs; | 5958 | expect_str_cur = expect_strs; |
5946 | expect_str_end = expect_strs + expect_str_len; | 5959 | expect_str_end = expect_strs + expect_hdr->str_len; |
5947 | while (test_str_cur < test_str_end && expect_str_cur < expect_str_end) { | 5960 | while (test_str_cur < test_str_end && expect_str_cur < expect_str_end) { |
5948 | size_t test_len, expect_len; | 5961 | size_t test_len, expect_len; |
5949 | 5962 | ||