selftests/bpf: Add ASSERT_STRNEQ() variant for test_progs

It will support strncmp()-style string comparisons.

Suggested-by: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/1626362126-27775-3-git-send-email-alan.maguire@oracle.com
This commit is contained in:
Alan Maguire 2021-07-15 16:15:25 +01:00 committed by Andrii Nakryiko
parent 920d16af9b
commit 17283337ff

View File

@ -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); \