Message ID | 20200722211223.1055107-14-jolsa@kernel.org |
---|---|
State | Changes Requested |
Delegated to: | BPF Maintainers |
Headers | show |
Series | bpf: Add d_path helper | expand |
On Wed, Jul 22, 2020 at 2:15 PM Jiri Olsa <jolsa@kernel.org> wrote: > > Adding test to for sets resolve_btfids. We're checking that > testing set gets properly resolved and sorted. > > Signed-off-by: Jiri Olsa <jolsa@kernel.org> > --- > .../selftests/bpf/prog_tests/resolve_btfids.c | 33 +++++++++++++++++++ > 1 file changed, 33 insertions(+) > > diff --git a/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c b/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c > index 101785b49f7e..cc90aa244285 100644 > --- a/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c > +++ b/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c > @@ -48,6 +48,15 @@ BTF_ID(struct, S) > BTF_ID(union, U) > BTF_ID(func, func) > > +BTF_SET_START(test_set) > +BTF_ID(typedef, S) > +BTF_ID(typedef, T) > +BTF_ID(typedef, U) > +BTF_ID(struct, S) > +BTF_ID(union, U) > +BTF_ID(func, func) > +BTF_SET_END(test_set) > + > static int > __resolve_symbol(struct btf *btf, int type_id) > { > @@ -126,5 +135,29 @@ int test_resolve_btfids(void) > } > } > > + /* Check BTF_SET_START(test_set) IDs */ > + for (i = 0; i < test_set.cnt && !ret; i++) { nit: usual we just do `goto err_out;` instead of complicating exit condition in a for loop > + bool found = false; > + > + for (j = 0; j < ARRAY_SIZE(test_symbols); j++) { > + if (test_symbols[j].id != test_set.ids[i]) > + continue; > + found = true; > + break; > + } > + > + ret = CHECK(!found, "id_check", > + "ID %d for %s not found in test_symbols\n", > + test_symbols[j].id, test_symbols[j].name); j == ARRAY_SIZE(test_symbols), you probably meant to get test_set.ids[i] instead of test_symbol name/id? > + if (ret) > + break; > + > + if (i > 0) { > + ret = CHECK(test_set.ids[i - 1] > test_set.ids[i], nit: >= would be the invalid condition > + "sort_check", > + "test_set is not sorted\n"); > + } > + } > + > return ret; > } > -- > 2.25.4 >
On Tue, Jul 28, 2020 at 12:56:02PM -0700, Andrii Nakryiko wrote: > On Wed, Jul 22, 2020 at 2:15 PM Jiri Olsa <jolsa@kernel.org> wrote: > > > > Adding test to for sets resolve_btfids. We're checking that > > testing set gets properly resolved and sorted. > > > > Signed-off-by: Jiri Olsa <jolsa@kernel.org> > > --- > > .../selftests/bpf/prog_tests/resolve_btfids.c | 33 +++++++++++++++++++ > > 1 file changed, 33 insertions(+) > > > > diff --git a/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c b/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c > > index 101785b49f7e..cc90aa244285 100644 > > --- a/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c > > +++ b/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c > > @@ -48,6 +48,15 @@ BTF_ID(struct, S) > > BTF_ID(union, U) > > BTF_ID(func, func) > > > > +BTF_SET_START(test_set) > > +BTF_ID(typedef, S) > > +BTF_ID(typedef, T) > > +BTF_ID(typedef, U) > > +BTF_ID(struct, S) > > +BTF_ID(union, U) > > +BTF_ID(func, func) > > +BTF_SET_END(test_set) > > + > > static int > > __resolve_symbol(struct btf *btf, int type_id) > > { > > @@ -126,5 +135,29 @@ int test_resolve_btfids(void) > > } > > } > > > > + /* Check BTF_SET_START(test_set) IDs */ > > + for (i = 0; i < test_set.cnt && !ret; i++) { > > nit: usual we just do `goto err_out;` instead of complicating exit > condition in a for loop ok > > > + bool found = false; > > + > > + for (j = 0; j < ARRAY_SIZE(test_symbols); j++) { > > + if (test_symbols[j].id != test_set.ids[i]) > > + continue; > > + found = true; > > + break; > > + } > > + > > + ret = CHECK(!found, "id_check", > > + "ID %d for %s not found in test_symbols\n", > > + test_symbols[j].id, test_symbols[j].name); > > j == ARRAY_SIZE(test_symbols), you probably meant to get > test_set.ids[i] instead of test_symbol name/id? oh yea.. test_set.ids[i] is not found in here > > > + if (ret) > > + break; > > + > > + if (i > 0) { > > + ret = CHECK(test_set.ids[i - 1] > test_set.ids[i], > > nit: >= would be the invalid condition yes, we actualy allow for same IDs to appear in the set thanks, jirka > > > + "sort_check", > > + "test_set is not sorted\n"); > > + } > > + } > > + > > return ret; > > } > > -- > > 2.25.4 > > >
diff --git a/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c b/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c index 101785b49f7e..cc90aa244285 100644 --- a/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c +++ b/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c @@ -48,6 +48,15 @@ BTF_ID(struct, S) BTF_ID(union, U) BTF_ID(func, func) +BTF_SET_START(test_set) +BTF_ID(typedef, S) +BTF_ID(typedef, T) +BTF_ID(typedef, U) +BTF_ID(struct, S) +BTF_ID(union, U) +BTF_ID(func, func) +BTF_SET_END(test_set) + static int __resolve_symbol(struct btf *btf, int type_id) { @@ -126,5 +135,29 @@ int test_resolve_btfids(void) } } + /* Check BTF_SET_START(test_set) IDs */ + for (i = 0; i < test_set.cnt && !ret; i++) { + bool found = false; + + for (j = 0; j < ARRAY_SIZE(test_symbols); j++) { + if (test_symbols[j].id != test_set.ids[i]) + continue; + found = true; + break; + } + + ret = CHECK(!found, "id_check", + "ID %d for %s not found in test_symbols\n", + test_symbols[j].id, test_symbols[j].name); + if (ret) + break; + + if (i > 0) { + ret = CHECK(test_set.ids[i - 1] > test_set.ids[i], + "sort_check", + "test_set is not sorted\n"); + } + } + return ret; }
Adding test to for sets resolve_btfids. We're checking that testing set gets properly resolved and sorted. Signed-off-by: Jiri Olsa <jolsa@kernel.org> --- .../selftests/bpf/prog_tests/resolve_btfids.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+)