From: Florian Lehner <dev@der-flo.net>
To: bpf@vger.kernel.org
Cc: netdev@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, john.fastabend@gmail.com,
Florian Lehner <dev@der-flo.net>,
Krzesimir Nowak <krzesimir@kinvolk.io>
Subject: [PATCH 2/2] selftests/bpf: Avoid errno clobbering
Date: Wed, 2 Dec 2020 20:45:32 +0100 [thread overview]
Message-ID: <20201202194532.12879-3-dev@der-flo.net> (raw)
In-Reply-To: <20201202194532.12879-1-dev@der-flo.net>
Print a message when the returned error is about a program type being
not supported or because of permission problems.
These messages are expected if the program to test was actually
executed.
Cc: Krzesimir Nowak <krzesimir@kinvolk.io>
Signed-off-by: Florian Lehner <dev@der-flo.net>
---
tools/testing/selftests/bpf/test_verifier.c | 26 +++++++++++++++++----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index ceea9409639e..86ef28dd9919 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -875,19 +875,35 @@ static int do_prog_test_run(int fd_prog, bool unpriv, uint32_t expected_val,
__u8 tmp[TEST_DATA_LEN << 2];
__u32 size_tmp = sizeof(tmp);
uint32_t retval;
- int err;
+ int err, saved_errno;
if (unpriv)
set_admin(true);
err = bpf_prog_test_run(fd_prog, 1, data, size_data,
tmp, &size_tmp, &retval, NULL);
+ saved_errno = errno;
+
if (unpriv)
set_admin(false);
- if (err && errno != 524/*ENOTSUPP*/ && errno != EPERM) {
- printf("Unexpected bpf_prog_test_run error ");
- return err;
+
+ if (err) {
+ switch (saved_errno) {
+ case 524/*ENOTSUPP*/:
+ printf("Did not run the program (not supported) ");
+ return 0;
+ case EPERM:
+ if (unpriv) {
+ printf("Did not run the program (no permission) ");
+ return 0;
+ }
+ default:
+ printf("FAIL: Unexpected bpf_prog_test_run error (%s) ",
+ strerror(saved_errno));
+ return err;
+ }
}
- if (!err && retval != expected_val &&
+
+ if (retval != expected_val &&
expected_val != POINTER_VALUE) {
printf("FAIL retval %d != %d ", retval, expected_val);
return 1;
--
2.28.0
next prev parent reply other threads:[~2020-12-02 19:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-02 19:45 [PATCH 0/2 v2] Improve error handling of verifier tests Florian Lehner
2020-12-02 19:45 ` [PATCH 1/2] selftests/bpf: Print reason when a tester could not run a program Florian Lehner
2020-12-02 19:45 ` Florian Lehner [this message]
2020-12-03 21:13 ` [PATCH 2/2] selftests/bpf: Avoid errno clobbering Andrii Nakryiko
-- strict thread matches above, loose matches on Subject: below --
2020-12-04 18:18 [PATCH 0/2 v3] Improve error handling of verifier tests Florian Lehner
2020-12-04 18:18 ` [PATCH 2/2] selftests/bpf: Avoid errno clobbering Florian Lehner
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=20201202194532.12879-3-dev@der-flo.net \
--to=dev@der-flo.net \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=krzesimir@kinvolk.io \
--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).