Skip to content

Commit

Permalink
selftests/bpf: Add ASSERT_STRNEQ() variant for test_progs
Browse files Browse the repository at this point in the history
It will support strncmp()-style string comparisons.

Suggested-by: Andrii Nakryiko <[email protected]>
Signed-off-by: Alan Maguire <[email protected]>
Signed-off-by: Andrii Nakryiko <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
alan-maguire authored and anakryiko committed Jul 16, 2021
1 parent 920d16a commit 1728333
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tools/testing/selftests/bpf/test_progs.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@ extern int test__join_cgroup(const char *path);
___ok; \
})

#define ASSERT_STRNEQ(actual, expected, len, name) ({ \
static int duration = 0; \
const char *___act = actual; \
const char *___exp = expected; \
int ___len = len; \
bool ___ok = strncmp(___act, ___exp, ___len) == 0; \
CHECK(!___ok, (name), \
"unexpected %s: actual '%.*s' != expected '%.*s'\n", \
(name), ___len, ___act, ___len, ___exp); \
___ok; \
})

#define ASSERT_OK(res, name) ({ \
static int duration = 0; \
long long ___res = (res); \
Expand Down

0 comments on commit 1728333

Please sign in to comment.