Skip to content

Commit 26434e1

Browse files
florianlkernel-patches-bot
authored andcommitted
selftests/bpf: Avoid errno clobbering
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>
1 parent ad1155c commit 26434e1

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

tools/testing/selftests/bpf/test_verifier.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -875,19 +875,35 @@ static int do_prog_test_run(int fd_prog, bool unpriv, uint32_t expected_val,
875875
__u8 tmp[TEST_DATA_LEN << 2];
876876
__u32 size_tmp = sizeof(tmp);
877877
uint32_t retval;
878-
int err;
878+
int err, saved_errno;
879879

880880
if (unpriv)
881881
set_admin(true);
882882
err = bpf_prog_test_run(fd_prog, 1, data, size_data,
883883
tmp, &size_tmp, &retval, NULL);
884+
saved_errno = errno;
885+
884886
if (unpriv)
885887
set_admin(false);
886-
if (err && errno != 524/*ENOTSUPP*/ && errno != EPERM) {
887-
printf("Unexpected bpf_prog_test_run error ");
888-
return err;
888+
889+
if (err) {
890+
switch (saved_errno) {
891+
case 524/*ENOTSUPP*/:
892+
printf("Did not run the program (not supported) ");
893+
return 0;
894+
case EPERM:
895+
if (unpriv) {
896+
printf("Did not run the program (no permission) ");
897+
return 0;
898+
}
899+
default:
900+
printf("FAIL: Unexpected bpf_prog_test_run error (%s) ",
901+
strerror(saved_errno));
902+
return err;
903+
}
889904
}
890-
if (!err && retval != expected_val &&
905+
906+
if (retval != expected_val &&
891907
expected_val != POINTER_VALUE) {
892908
printf("FAIL retval %d != %d ", retval, expected_val);
893909
return 1;

0 commit comments

Comments
 (0)