Skip to content

Commit

Permalink
selftests/bpf: Add ASSERT_OK_FD macro
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Geliang Tang <[email protected]>
Link: https://lore.kernel.org/r/ded75be86ac630a3a5099739431854c1ec33f0ea.1720515893.git.tanggeliang@kylinos.cn
Signed-off-by: Martin KaFai Lau <[email protected]>
  • Loading branch information
Geliang Tang authored and Martin KaFai Lau committed Jul 10, 2024
1 parent a3016a2 commit 7046345
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tools/testing/selftests/bpf/test_progs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]; \
Expand Down

0 comments on commit 7046345

Please sign in to comment.