Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: test_progs avoid minus shell exit codes

There are a number of places in test_progs that use minus-1 as the argument
to exit(). This is confusing as a process exit status is masked to be a
number between 0 and 255 as defined in man exit(3). Thus, users will see
status 255 instead of minus-1.

This patch use positive exit code 3 instead of minus-1. These cases are put
in the same group of infrastructure setup errors.

Fixes: fd27b1835e70 ("selftests/bpf: Reset process and thread affinity after each test/sub-test")
Fixes: 811d7e375d08 ("bpf: selftests: Restore netns after each test")
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/159410594499.1093222.11080787853132708654.stgit@firesoul

authored by

Jesper Dangaard Brouer and committed by
Daniel Borkmann
b8c50df0 3220fb66

+5 -4
+5 -4
tools/testing/selftests/bpf/test_progs.c
··· 13 13 #include <execinfo.h> /* backtrace */ 14 14 15 15 #define EXIT_NO_TEST 2 16 + #define EXIT_ERR_SETUP_INFRA 3 16 17 17 18 /* defined in test_progs.h */ 18 19 struct test_env env = {}; ··· 114 113 if (err < 0) { 115 114 stdio_restore(); 116 115 fprintf(stderr, "Failed to reset process affinity: %d!\n", err); 117 - exit(-1); 116 + exit(EXIT_ERR_SETUP_INFRA); 118 117 } 119 118 err = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset); 120 119 if (err < 0) { 121 120 stdio_restore(); 122 121 fprintf(stderr, "Failed to reset thread affinity: %d!\n", err); 123 - exit(-1); 122 + exit(EXIT_ERR_SETUP_INFRA); 124 123 } 125 124 } 126 125 ··· 129 128 env.saved_netns_fd = open("/proc/self/ns/net", O_RDONLY); 130 129 if (env.saved_netns_fd == -1) { 131 130 perror("open(/proc/self/ns/net)"); 132 - exit(-1); 131 + exit(EXIT_ERR_SETUP_INFRA); 133 132 } 134 133 } 135 134 ··· 138 137 if (setns(env.saved_netns_fd, CLONE_NEWNET) == -1) { 139 138 stdio_restore(); 140 139 perror("setns(CLONE_NEWNS)"); 141 - exit(-1); 140 + exit(EXIT_ERR_SETUP_INFRA); 142 141 } 143 142 } 144 143