[PATCH 2/3] selftests/bpf: Add the ability to test for a log message on success

From: Ben Hutchings
Date: Fri Nov 23 2018 - 13:35:10 EST


This is needed to test that code is being patched when it should be.

Signed-off-by: Ben Hutchings <ben.hutchings@xxxxxxxxxxxxxxx>
---
tools/testing/selftests/bpf/test_verifier.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index 0f3f97a401c9..e71b7f2e5f17 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -76,6 +76,8 @@ struct bpf_test {
int fixup_percpu_cgroup_storage[MAX_FIXUPS];
const char *errstr;
const char *errstr_unpriv;
+ const char *infostr;
+ const char *infostr_unpriv;
uint32_t retval, retval_unpriv;
enum {
UNDEF,
@@ -14232,7 +14234,7 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
int prog_len, prog_type = test->prog_type;
struct bpf_insn *prog = test->insns;
int map_fds[MAX_NR_MAPS];
- const char *expected_err;
+ const char *expected_err, *expected_info;
uint32_t expected_val;
uint32_t retval;
int i, err;
@@ -14253,6 +14255,8 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
test->result_unpriv : test->result;
expected_err = unpriv && test->errstr_unpriv ?
test->errstr_unpriv : test->errstr;
+ expected_info = unpriv && test->infostr_unpriv ?
+ test->infostr_unpriv : test->infostr;
expected_val = unpriv && test->retval_unpriv ?
test->retval_unpriv : test->retval;

@@ -14272,6 +14276,11 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
strerror(errno));
goto fail_log;
}
+ if (expected_info && !strstr(bpf_vlog, expected_info)) {
+ printf("FAIL\nMissing expected info message!\n\tEXP: %s\n\tRES: %s\n",
+ expected_info, bpf_vlog);
+ goto fail_log;
+ }
} else {
if (fd_prog >= 0) {
printf("FAIL\nUnexpected success to load!\n");
--
Ben Hutchings, Software Developer Codethink Ltd
https://www.codethink.co.uk/ Dale House, 35 Dale Street
Manchester, M1 2HF, United Kingdom