Skip to content

Commit efe5f9c

Browse files
netoptimizerdavem330
authored andcommitted
selftests/bpf: make correct use of exit codes in bpf selftests
The selftests depend on using the shell exit code as a mean of detecting the success or failure of test-binary executed. The appropiate output "[PASS]" or "[FAIL]" in generated by tools/testing/selftests/lib.mk. Notice that the exit code is masked with 255. Thus, be careful if using the number of errors as the exit code, as 256 errors would be seen as a success. There are two standard defined exit(3) codes: /usr/include/stdlib.h #define EXIT_FAILURE 1 /* Failing exit status. */ #define EXIT_SUCCESS 0 /* Successful exit status. */ Fix test_verifier.c to not use the negative value of variable "results", but instead return EXIT_FAILURE. Fix test_align.c and test_progs.c to actually use exit codes, before they were always indicating success regardless of results. Signed-off-by: Jesper Dangaard Brouer <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Reviewed-by: Fengguang Wu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent fb34a36 commit efe5f9c

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

tools/testing/selftests/bpf/test_align.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ static int do_test(unsigned int from, unsigned int to)
428428
}
429429
printf("Results: %d pass %d fail\n",
430430
all_pass, all_fail);
431-
return 0;
431+
return all_fail ? EXIT_FAILURE : EXIT_SUCCESS;
432432
}
433433

434434
int main(int argc, char **argv)

tools/testing/selftests/bpf/test_progs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,5 +497,5 @@ int main(void)
497497
test_bpf_obj_id();
498498

499499
printf("Summary: %d PASSED, %d FAILED\n", pass_cnt, error_cnt);
500-
return 0;
500+
return error_cnt ? EXIT_FAILURE : EXIT_SUCCESS;
501501
}

tools/testing/selftests/bpf/test_verifier.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5418,7 +5418,7 @@ static int do_test(bool unpriv, unsigned int from, unsigned int to)
54185418
}
54195419

54205420
printf("Summary: %d PASSED, %d FAILED\n", passes, errors);
5421-
return errors ? -errors : 0;
5421+
return errors ? EXIT_FAILURE : EXIT_SUCCESS;
54225422
}
54235423

54245424
int main(int argc, char **argv)

0 commit comments

Comments
 (0)