mirror of
https://github.com/torvalds/linux.git
synced 2024-11-23 12:42:02 +00:00
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: Martin KaFai Lau <martin.lau@kernel.org> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn> Link: https://lore.kernel.org/r/ded75be86ac630a3a5099739431854c1ec33f0ea.1720515893.git.tanggeliang@kylinos.cn Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
This commit is contained in:
parent
a3016a27ce
commit
7046345d48
@ -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]; \
|
||||
|
Loading…
Reference in New Issue
Block a user