Skip to contentSkip to conversation

selftests/bpf: merge most of test_btf into test_progs

PATCH Superseded Andrii Nakryiko 4 participants 5 messages Sep 15, 2020 – Sep 16, 2020

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selftests/bpf: merge most of test_btf into test_progs

Move almost 200 tests from test_btf into test_progs framework to be exercised regularly. Pretty-printing tests were left alone and renamed into test_btf_pprint because they are very slow and were not even executed by default with test_btf.

All the test_btf tests that were moved are modeled as proper sub-tests in test_progs framework for ease of debugging and reporting.

No functional or behavioral changes were intended, I tried to preserve original behavior as close to the original as possible. test_progs -v will activate "always_log" flag to emit BTF validation log.

---

v1->v2:
- pretty-print BTF tests were renamed test_btf -> test_btf_pprint, which allowed GIT to detect that majority of test_btf code was moved into prog_tests/btf.c; so diff is much-much smaller;

 tools/testing/selftests/bpf/.gitignore        |    2 +-
 .../bpf/{test_btf.c => prog_tests/btf.c}      | 1069 +----------------
 tools/testing/selftests/bpf/test_btf_pprint.c |  969 +++++++++++++++
 3 files changed, 1033 insertions(+), 1007 deletions(-)
 rename tools/testing/selftests/bpf/{test_btf.c => prog_tests/btf.c} (85%)
 create mode 100644 tools/testing/selftests/bpf/test_btf_pprint.c
tools/testing/selftests/bpf/.gitignore +1 -1
index 9a0946ddb705..160c413ee960 100644
@@ -15,7 +15,7 @@ test_sock
 test_sock_addr
 test_sock_fields
 urandom_read
-test_btf
+test_btf_pprint
 test_sockmap
 test_lirc_mode2_user
 get_cgroup_id_user
tools/testing/selftests/bpf/prog_tests/btf.c renamed from tools/testing/selftests/bpf/test_btf.c +63 -1006

1,296 lines not on this page · raw message

tools/testing/selftests/bpf/test_btf_pprint.c new file +969 -0

969 lines not on this page · raw message

Signature · 1 line
2.24.1
#1 lore raw
Quoted 21 lines · Andrii Nakryiko

Move almost 200 tests from test_btf into test_progs framework to be exercised regularly. Pretty-printing tests were left alone and renamed into test_btf_pprint because they are very slow and were not even executed by default with test_btf.

All the test_btf tests that were moved are modeled as proper sub-tests in test_progs framework for ease of debugging and reporting.

No functional or behavioral changes were intended, I tried to preserve original behavior as close to the original as possible. test_progs -v will activate "always_log" flag to emit BTF validation log.

---

v1->v2:
- pretty-print BTF tests were renamed test_btf -> test_btf_pprint, which allowed GIT to detect that majority of test_btf code was moved into prog_tests/btf.c; so diff is much-much smaller;

Quoted 6 lines
 tools/testing/selftests/bpf/.gitignore        |    2 +-
 .../bpf/{test_btf.c => prog_tests/btf.c}      | 1069 +----------------
 tools/testing/selftests/bpf/test_btf_pprint.c |  969 +++++++++++++++
 3 files changed, 1033 insertions(+), 1007 deletions(-)
 rename tools/testing/selftests/bpf/{test_btf.c => prog_tests/btf.c} (85%)
 create mode 100644 tools/testing/selftests/bpf/test_btf_pprint.c

Looks like I forgot to check in a trivial Makefile change (test_btf -> test_btf_pprint), but I'll hold off until we decided where pretty-print BTF tests should live.

[...]

#2 lore raw
In reply to Andrii Nakryiko
Quoted 4 lines · Andrii Nakryiko

Move almost 200 tests from test_btf into test_progs framework to be exercised regularly. Pretty-printing tests were left alone and renamed into test_btf_pprint because they are very slow and were not even executed by default with test_btf.

I think would be good to run them by default.
The following trivial tweak makes them fast:

tools/testing/selftests/bpf/test_btf.c +3 -3
index c75fc6447186..589afd4f0e47 100644
@@ -4428,7 +4428,7 @@ static struct btf_raw_test pprint_test_template[] = {
        .value_size = sizeof(struct pprint_mapv),
        .key_type_id = 3,       /* unsigned int */
        .value_type_id = 16,    /* struct pprint_mapv */
-       .max_entries = 128 * 1024,
+       .max_entries = 128,
 },
 
 {
@@ -4493,7 +4493,7 @@ static struct btf_raw_test pprint_test_template[] = {
        .value_size = sizeof(struct pprint_mapv),
        .key_type_id = 3,       /* unsigned int */
        .value_type_id = 16,    /* struct pprint_mapv */
-       .max_entries = 128 * 1024,
+       .max_entries = 128,
 },
 
 {
@@ -4564,7 +4564,7 @@ static struct btf_raw_test pprint_test_template[] = {
        .value_size = sizeof(struct pprint_mapv),
        .key_type_id = 3,       /* unsigned int */
        .value_type_id = 16,    /* struct pprint_mapv */
-       .max_entries = 128 * 1024,
+       .max_entries = 128,
 },
 

Martin,
do you remember why you picked such large numbers of entries
for the test?
If I read the code correctly smaller number doesn't reduce the test coverage.

Quoted 7 lines

All the test_btf tests that were moved are modeled as proper sub-tests in test_progs framework for ease of debugging and reporting.

No functional or behavioral changes were intended, I tried to preserve original behavior as close to the original as possible. test_progs -v will activate "always_log" flag to emit BTF validation log.

Quoted 7 lines

---

v1->v2:
- pretty-print BTF tests were renamed test_btf -> test_btf_pprint, which allowed GIT to detect that majority of test_btf code was moved into prog_tests/btf.c; so diff is much-much smaller;

Thanks. I hope with addition to pprint test the diff will be even smaller. I think it's worth to investigate why they're failing if moved to test_progs. I think they're the only tests that exercise seq_read logic. Clearly the bug:

[   25.960993] WARNING: CPU: 2 PID: 1995 at kernel/bpf/hashtab.c:717 htab_map_get_next_key+0x7fc/0xab0

is still there.
If pprint tests were part of test_progs we would have caught that earlier.

Yonghong,
please take a look at that issue.

#3 lore raw
Quoted 9 lines · Alexei Starovoitov
Quoted 4 lines · Andrii Nakryiko

Move almost 200 tests from test_btf into test_progs framework to be exercised regularly. Pretty-printing tests were left alone and renamed into test_btf_pprint because they are very slow and were not even executed by default with test_btf.

I think would be good to run them by default.
The following trivial tweak makes them fast:

Sounds good, I'll debug why it was failing now that I can run it reasonably.

Quoted 50 lines
tools/testing/selftests/bpf/test_btf.c +3 -3
index c75fc6447186..589afd4f0e47 100644
@@ -4428,7 +4428,7 @@ static struct btf_raw_test pprint_test_template[] = {
        .value_size = sizeof(struct pprint_mapv),
        .key_type_id = 3,       /* unsigned int */
        .value_type_id = 16,    /* struct pprint_mapv */
-       .max_entries = 128 * 1024,
+       .max_entries = 128,
 },
 
 {
@@ -4493,7 +4493,7 @@ static struct btf_raw_test pprint_test_template[] = {
        .value_size = sizeof(struct pprint_mapv),
        .key_type_id = 3,       /* unsigned int */
        .value_type_id = 16,    /* struct pprint_mapv */
-       .max_entries = 128 * 1024,
+       .max_entries = 128,
 },
 
 {
@@ -4564,7 +4564,7 @@ static struct btf_raw_test pprint_test_template[] = {
        .value_size = sizeof(struct pprint_mapv),
        .key_type_id = 3,       /* unsigned int */
        .value_type_id = 16,    /* struct pprint_mapv */
-       .max_entries = 128 * 1024,
+       .max_entries = 128,
 },
 
 Martin,

do you remember why you picked such large numbers of entries
for the test?
If I read the code correctly smaller number doesn't reduce the test coverage.

Quoted 7 lines

All the test_btf tests that were moved are modeled as proper sub-tests in test_progs framework for ease of debugging and reporting.

No functional or behavioral changes were intended, I tried to preserve original behavior as close to the original as possible. test_progs -v will activate "always_log" flag to emit BTF validation log.

Quoted 7 lines

---

v1->v2:
- pretty-print BTF tests were renamed test_btf -> test_btf_pprint, which allowed GIT to detect that majority of test_btf code was moved into prog_tests/btf.c; so diff is much-much smaller;

Quoted 7 lines

Thanks. I hope with addition to pprint test the diff will be even smaller. I think it's worth to investigate why they're failing if moved to test_progs. I think they're the only tests that exercise seq_read logic. Clearly the bug:

[   25.960993] WARNING: CPU: 2 PID: 1995 at kernel/bpf/hashtab.c:717 htab_map_get_next_key+0x7fc/0xab0

is still there.
If pprint tests were part of test_progs we would have caught that earlier.

yep, with pretty-printing tests in test_btf diff should be very small

Quoted 3 lines

Yonghong,
please take a look at that issue.

#4 lore raw
In reply to Alexei Starovoitov
Quoted 39 lines · Alexei Starovoitov
Quoted 4 lines · Andrii Nakryiko

Move almost 200 tests from test_btf into test_progs framework to be exercised regularly. Pretty-printing tests were left alone and renamed into test_btf_pprint because they are very slow and were not even executed by default with test_btf.

I think would be good to run them by default.
The following trivial tweak makes them fast:

tools/testing/selftests/bpf/test_btf.c +3 -3
index c75fc6447186..589afd4f0e47 100644
@@ -4428,7 +4428,7 @@ static struct btf_raw_test pprint_test_template[] = {
        .value_size = sizeof(struct pprint_mapv),
        .key_type_id = 3,       /* unsigned int */
        .value_type_id = 16,    /* struct pprint_mapv */
-       .max_entries = 128 * 1024,
+       .max_entries = 128,
 },
 
 {
@@ -4493,7 +4493,7 @@ static struct btf_raw_test pprint_test_template[] = {
        .value_size = sizeof(struct pprint_mapv),
        .key_type_id = 3,       /* unsigned int */
        .value_type_id = 16,    /* struct pprint_mapv */
-       .max_entries = 128 * 1024,
+       .max_entries = 128,
 },
 
 {
@@ -4564,7 +4564,7 @@ static struct btf_raw_test pprint_test_template[] = {
        .value_size = sizeof(struct pprint_mapv),
        .key_type_id = 3,       /* unsigned int */
        .value_type_id = 16,    /* struct pprint_mapv */
-       .max_entries = 128 * 1024,
+       .max_entries = 128,
 },
 
 Martin,
Quoted 2 lines

do you remember why you picked such large numbers of entries for the test?

It has been a while. iirc, I think there was no particular reason but there was only one pprint test and then a few had been added since then.

Quoted 1 line

If I read the code correctly smaller number doesn't reduce the test coverage.

Indeed. Please go ahead to reduce the max_entries. Sorry for the pain.

Quoted 26 lines
Quoted 8 lines

All the test_btf tests that were moved are modeled as proper sub-tests in test_progs framework for ease of debugging and reporting.

No functional or behavioral changes were intended, I tried to preserve original behavior as close to the original as possible. test_progs -v will activate "always_log" flag to emit BTF validation log.

Quoted 7 lines

---

v1->v2:
- pretty-print BTF tests were renamed test_btf -> test_btf_pprint, which allowed GIT to detect that majority of test_btf code was moved into prog_tests/btf.c; so diff is much-much smaller;

Thanks. I hope with addition to pprint test the diff will be even smaller. I think it's worth to investigate why they're failing if moved to test_progs. I think they're the only tests that exercise seq_read logic. Clearly the bug:

[   25.960993] WARNING: CPU: 2 PID: 1995 at kernel/bpf/hashtab.c:717 htab_map_get_next_key+0x7fc/0xab0

is still there.
If pprint tests were part of test_progs we would have caught that earlier.

Yonghong,
please take a look at that issue.