linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ben Hutchings <ben.hutchings@codethink.co.uk>
To: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] selftests/bpf: Add the ability to test for a log message on success
Date: Fri, 23 Nov 2018 18:35:03 +0000	[thread overview]
Message-ID: <20181123183503.v3gl42innv4zbilw@xylophone.i.decadent.org.uk> (raw)
In-Reply-To: <20181123183356.5q4bu47zpj5wdufb@xylophone.i.decadent.org.uk>

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

Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
---
 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



  parent reply	other threads:[~2018-11-23 18:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-23 18:33 [PATCH 0/3] bpf: Test defence against SSB exploitation Ben Hutchings
2018-11-23 18:34 ` [PATCH 1/3] bpf/verifier: Log instruction patching when verbose logging is enabled Ben Hutchings
2018-11-23 20:10   ` Daniel Borkmann
2018-11-29 15:55     ` Ben Hutchings
2018-11-23 18:35 ` Ben Hutchings [this message]
2018-11-23 18:35 ` [PATCH 3/3] selftests/bpf: Add test case for defence against SSB exploitation Ben Hutchings

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181123183503.v3gl42innv4zbilw@xylophone.i.decadent.org.uk \
    --to=ben.hutchings@codethink.co.uk \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).