selftests/bpf: Add ASSERT_STRNEQ() variant for test_progs
authorAlan Maguire <alan.maguire@oracle.com>
Thu, 15 Jul 2021 15:15:25 +0000 (16:15 +0100)
committerAndrii Nakryiko <andrii@kernel.org>
Fri, 16 Jul 2021 20:46:59 +0000 (13:46 -0700)
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
tools/testing/selftests/bpf/test_progs.h

index 8ef7f334e71527cea4d5f9771b786ebbb9b85ea6..c8c2bf878f67cc9cde33657ca1df3fb207648d88 100644 (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);                                       \