Commit 7046345d authored by Geliang Tang's avatar Geliang Tang Committed by Martin KaFai Lau

selftests/bpf: Add ASSERT_OK_FD macro

Add a new dedicated ASSERT macro ASSERT_OK_FD to test whether a socket
FD is valid or not. It can be used to replace macros ASSERT_GT(fd, 0, ""),
ASSERT_NEQ(fd, -1, "") or statements (fd < 0), (fd != -1).
Suggested-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
Link: https://lore.kernel.org/r/ded75be86ac630a3a5099739431854c1ec33f0ea.1720515893.git.tanggeliang@kylinos.cnSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
parent a3016a27
......@@ -377,6 +377,15 @@ int test__join_cgroup(const char *path);
___ok; \
})
#define ASSERT_OK_FD(fd, name) ({ \
static int duration = 0; \
int ___fd = (fd); \
bool ___ok = ___fd >= 0; \
CHECK(!___ok, (name), "unexpected fd: %d (errno %d)\n", \
___fd, errno); \
___ok; \
})
#define SYS(goto_label, fmt, ...) \
({ \
char cmd[1024]; \
......
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