selftests/bpf: make correct use of exit codes in bpf selftests
Subsystems (5)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 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 exits 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.
--- tools/testing/selftests/bpf/test_align.c | 2 +- tools/testing/selftests/bpf/test_progs.c | 2 +- tools/testing/selftests/bpf/test_verifier.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/test_align.c +1 -1
@@ -428,7 +428,7 @@ static int do_test(unsigned int from, unsigned int to) }printf ("Results: %d pass %d fail\n" , all_pass, all_fail); -return 0 ; +return all_fail ?EXIT_FAILURE :EXIT_SUCCESS ; }int main (int argc,char **argv)
tools/testing/selftests/bpf/test_progs.c +1 -1
@@ -497,5 +497,5 @@ int main(void)test_bpf_obj_id ();printf ("Summary: %d PASSED, %d FAILED\n" , pass_cnt, error_cnt); -return 0 ; +return error_cnt ?EXIT_FAILURE :EXIT_SUCCESS ; }
tools/testing/selftests/bpf/test_verifier.c +1 -1
@@ -5418,7 +5418,7 @@ static int do_test(bool unpriv, unsigned int from, unsigned int to) }printf ("Summary: %d PASSED, %d FAILED\n" , passes, errors); -return errors ? -errors :0 ; +return errors ?EXIT_FAILURE :EXIT_SUCCESS ; }int main (int argc,char **argv)
Quoted 14 lines · Jesper Dangaard Brouer
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 exits 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. */
Quoted 7 lines
Fix
test_verifier.cto not use the negative value of variable "results", but instead returnEXIT_FAILURE.Fix
test_align.candtest_progs.cto actually use exit codes, before they were always indicating success regardless of results.Signed-off-by Jesper Dangaard Brouer <[email protected]>
Quoted 7 lines · Jesper Dangaard Brouer
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 exits code, as 256 errors would be
nit pick:
s/exits/exit/
tools/testing/selftests/bpf/test_verifier.c static int do_test(bool unpriv, unsigned int from, unsigned int to) · line 5421
Quoted 3 lines
printf("Summary: %d PASSED, %d FAILED\n", passes, errors);tools/testing/selftests/bpf/test_verifier.c +1
-1-return errors ? -errors :0 ; +return errors ?EXIT_FAILURE :EXIT_SUCCESS ;
Thanks,
Fengguang
David Miller
maintainerFrom: Jesper Dangaard Brouer <[email protected]>
Date: Tue, 13 Jun 2017 15:17:19 +0200
Quoted 14 lines
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 exits 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. */
Quoted 7 lines
Fix
test_verifier.cto not use the negative value of variable "results", but instead returnEXIT_FAILURE.Fix
test_align.candtest_progs.cto actually use exit codes, before they were always indicating success regardless of results.Signed-off-by Jesper Dangaard Brouer <[email protected]>
Applied with commit log message corrected, thanks.