Skip to content

Commit b8c50df

Browse files
netoptimizerborkmann
authored andcommitted
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: fd27b18 ("selftests/bpf: Reset process and thread affinity after each test/sub-test") Fixes: 811d7e3 ("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
1 parent 3220fb6 commit b8c50df

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎tools/testing/selftests/bpf/test_progs.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <execinfo.h> /* backtrace */
1414

1515
#define EXIT_NO_TEST 2
16+
#define EXIT_ERR_SETUP_INFRA 3
1617

1718
/* defined in test_progs.h */
1819
struct test_env env = {};
@@ -113,13 +114,13 @@ static void reset_affinity() {
113114
if (err < 0) {
114115
stdio_restore();
115116
fprintf(stderr, "Failed to reset process affinity: %d!\n", err);
116-
exit(-1);
117+
exit(EXIT_ERR_SETUP_INFRA);
117118
}
118119
err = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
119120
if (err < 0) {
120121
stdio_restore();
121122
fprintf(stderr, "Failed to reset thread affinity: %d!\n", err);
122-
exit(-1);
123+
exit(EXIT_ERR_SETUP_INFRA);
123124
}
124125
}
125126

@@ -128,7 +129,7 @@ static void save_netns(void)
128129
env.saved_netns_fd = open("/proc/self/ns/net", O_RDONLY);
129130
if (env.saved_netns_fd == -1) {
130131
perror("open(/proc/self/ns/net)");
131-
exit(-1);
132+
exit(EXIT_ERR_SETUP_INFRA);
132133
}
133134
}
134135

@@ -137,7 +138,7 @@ static void restore_netns(void)
137138
if (setns(env.saved_netns_fd, CLONE_NEWNET) == -1) {
138139
stdio_restore();
139140
perror("setns(CLONE_NEWNS)");
140-
exit(-1);
141+
exit(EXIT_ERR_SETUP_INFRA);
141142
}
142143
}
143144

0 commit comments

Comments
 (0)