Skip to content

Commit

Permalink
selftests/bpf: Use ASSERT_EQ instead ASSERT_OK for testing memcmp result
Browse files Browse the repository at this point in the history
In tcp_hdr_options test, it ensures the received tcp hdr option
and the sk local storage have the expected values. It uses memcmp
to check that. Testing the memcmp result with ASSERT_OK is confusing
because ASSERT_OK will print out the errno which is not set.
This patch uses ASSERT_EQ to check for 0 instead.

Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20230316000726.1016773-1-martin.lau@linux.dev
  • Loading branch information
Martin KaFai Lau authored and Daniel Borkmann committed Mar 16, 2023
1 parent 72fe61d commit ed01385
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static int check_hdr_opt(const struct bpf_test_option *exp,
const struct bpf_test_option *act,
const char *hdr_desc)
{
if (!ASSERT_OK(memcmp(exp, act, sizeof(*exp)), hdr_desc)) {
if (!ASSERT_EQ(memcmp(exp, act, sizeof(*exp)), 0, hdr_desc)) {
print_option(exp, "expected: ");
print_option(act, " actual: ");
return -1;
Expand All @@ -169,7 +169,7 @@ static int check_hdr_stg(const struct hdr_stg *exp, int fd,
"map_lookup(hdr_stg_map_fd)"))
return -1;

if (!ASSERT_OK(memcmp(exp, &act, sizeof(*exp)), stg_desc)) {
if (!ASSERT_EQ(memcmp(exp, &act, sizeof(*exp)), 0, stg_desc)) {
print_hdr_stg(exp, "expected: ");
print_hdr_stg(&act, " actual: ");
return -1;
Expand Down

0 comments on commit ed01385

Please sign in to comment.