summaryrefslogtreecommitdiff
path: root/lib/test_bpf.c
diff options
context:
space:
mode:
authorJohan Almbladh <johan.almbladh@anyfinetworks.com>2021-07-21 12:38:22 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-09-22 12:26:29 +0200
commit9dff06c505728bd19f57d3cc89cf901a6b0aa162 (patch)
tree69aa00d186324b97d4215d8bd7d15ab3117c01e1 /lib/test_bpf.c
parent58831317c9b1823a4c7bb4574aaa54c6d155a42c (diff)
bpf/tests: Do not PASS tests without actually testing the result
[ Upstream commit 2b7e9f25e590726cca76700ebdb10e92a7a72ca1 ] Each test case can have a set of sub-tests, where each sub-test can run the cBPF/eBPF test snippet with its own data_size and expected result. Before, the end of the sub-test array was indicated by both data_size and result being zero. However, most or all of the internal eBPF tests has a data_size of zero already. When such a test also had an expected value of zero, the test was never run but reported as PASS anyway. Now the test runner always runs the first sub-test, regardless of the data_size and result values. The sub-test array zero-termination only applies for any additional sub-tests. There are other ways fix it of course, but this solution at least removes the surprise of eBPF tests with a zero result always succeeding. Signed-off-by: Johan Almbladh <johan.almbladh@anyfinetworks.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20210721103822.3755111-1-johan.almbladh@anyfinetworks.com Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'lib/test_bpf.c')
-rw-r--r--lib/test_bpf.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index 5e985ed68b2a..3ae002ced4c7 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -6684,7 +6684,14 @@ static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
u64 duration;
u32 ret;
- if (test->test[i].data_size == 0 &&
+ /*
+ * NOTE: Several sub-tests may be present, in which case
+ * a zero {data_size, result} tuple indicates the end of
+ * the sub-test array. The first test is always run,
+ * even if both data_size and result happen to be zero.
+ */
+ if (i > 0 &&
+ test->test[i].data_size == 0 &&
test->test[i].result == 0)
break;