Commit b8c50df0 authored by Jesper Dangaard Brouer's avatar Jesper Dangaard Brouer Committed by Daniel Borkmann

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: fd27b183 ("selftests/bpf: Reset process and thread affinity after each test/sub-test")
Fixes: 811d7e37 ("bpf: selftests: Restore netns after each test")
Signed-off-by: default avatarJesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/159410594499.1093222.11080787853132708654.stgit@firesoul
parent 3220fb66
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <execinfo.h> /* backtrace */ #include <execinfo.h> /* backtrace */
#define EXIT_NO_TEST 2 #define EXIT_NO_TEST 2
#define EXIT_ERR_SETUP_INFRA 3
/* defined in test_progs.h */ /* defined in test_progs.h */
struct test_env env = {}; struct test_env env = {};
...@@ -113,13 +114,13 @@ static void reset_affinity() { ...@@ -113,13 +114,13 @@ static void reset_affinity() {
if (err < 0) { if (err < 0) {
stdio_restore(); stdio_restore();
fprintf(stderr, "Failed to reset process affinity: %d!\n", err); fprintf(stderr, "Failed to reset process affinity: %d!\n", err);
exit(-1); exit(EXIT_ERR_SETUP_INFRA);
} }
err = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset); err = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
if (err < 0) { if (err < 0) {
stdio_restore(); stdio_restore();
fprintf(stderr, "Failed to reset thread affinity: %d!\n", err); fprintf(stderr, "Failed to reset thread affinity: %d!\n", err);
exit(-1); exit(EXIT_ERR_SETUP_INFRA);
} }
} }
...@@ -128,7 +129,7 @@ static void save_netns(void) ...@@ -128,7 +129,7 @@ static void save_netns(void)
env.saved_netns_fd = open("/proc/self/ns/net", O_RDONLY); env.saved_netns_fd = open("/proc/self/ns/net", O_RDONLY);
if (env.saved_netns_fd == -1) { if (env.saved_netns_fd == -1) {
perror("open(/proc/self/ns/net)"); perror("open(/proc/self/ns/net)");
exit(-1); exit(EXIT_ERR_SETUP_INFRA);
} }
} }
...@@ -137,7 +138,7 @@ static void restore_netns(void) ...@@ -137,7 +138,7 @@ static void restore_netns(void)
if (setns(env.saved_netns_fd, CLONE_NEWNET) == -1) { if (setns(env.saved_netns_fd, CLONE_NEWNET) == -1) {
stdio_restore(); stdio_restore();
perror("setns(CLONE_NEWNS)"); perror("setns(CLONE_NEWNS)");
exit(-1); exit(EXIT_ERR_SETUP_INFRA);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment