diff mbox series

[bpf-next,v4,6/6] selftest/bpf: Fix error usage of ASSERT_OK in xdp_adjust_tail.c

Message ID 20221011120108.782373-7-xukuohai@huaweicloud.com (mailing list archive)
State Accepted
Commit cbc1c998da59687e8bbc4667154a72eead2daf2d
Headers show
Series Fix bugs found by ASAN when running selftests | expand

Commit Message

Xu Kuohai Oct. 11, 2022, 12:01 p.m. UTC
From: Xu Kuohai <xukuohai@huawei.com>

xdp_adjust_tail.c calls ASSERT_OK() to check the return value of
bpf_prog_test_load(), but the condition is not correct. Fix it.

Fixes: 791cad025051 ("bpf: selftests: Get rid of CHECK macro in xdp_adjust_tail.c")
Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
---
 tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Martin KaFai Lau Oct. 12, 2022, 11:26 p.m. UTC | #1
On 10/11/22 5:01 AM, Xu Kuohai wrote:
> From: Xu Kuohai <xukuohai@huawei.com>
> 
> xdp_adjust_tail.c calls ASSERT_OK() to check the return value of
> bpf_prog_test_load(), but the condition is not correct. Fix it.
> 
> Fixes: 791cad025051 ("bpf: selftests: Get rid of CHECK macro in xdp_adjust_tail.c")
> Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
> ---
>   tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
> index 009ee37607df..39973ea1ce43 100644
> --- a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
> +++ b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
> @@ -18,7 +18,7 @@ static void test_xdp_adjust_tail_shrink(void)
>   	);
>   
>   	err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
> -	if (ASSERT_OK(err, "test_xdp_adjust_tail_shrink"))
> +	if (!ASSERT_OK(err, "test_xdp_adjust_tail_shrink"))
>   		return;
>   
>   	err = bpf_prog_test_run_opts(prog_fd, &topts);
> @@ -53,7 +53,7 @@ static void test_xdp_adjust_tail_grow(void)
>   	);
>   
>   	err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
> -	if (ASSERT_OK(err, "test_xdp_adjust_tail_grow"))
> +	if (!ASSERT_OK(err, "test_xdp_adjust_tail_grow"))

Ouch... ic.  It is why this test has been passing.


>   		return;
>   
>   	err = bpf_prog_test_run_opts(prog_fd, &topts);
> @@ -90,7 +90,7 @@ static void test_xdp_adjust_tail_grow2(void)
>   	);
>   
>   	err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
> -	if (ASSERT_OK(err, "test_xdp_adjust_tail_grow"))
> +	if (!ASSERT_OK(err, "test_xdp_adjust_tail_grow"))
>   		return;
>   
>   	/* Test case-64 */
Xu Kuohai Oct. 13, 2022, 1:36 a.m. UTC | #2
On 10/13/2022 7:26 AM, Martin KaFai Lau wrote:
> On 10/11/22 5:01 AM, Xu Kuohai wrote:
>> From: Xu Kuohai <xukuohai@huawei.com>
>>
>> xdp_adjust_tail.c calls ASSERT_OK() to check the return value of
>> bpf_prog_test_load(), but the condition is not correct. Fix it.
>>
>> Fixes: 791cad025051 ("bpf: selftests: Get rid of CHECK macro in xdp_adjust_tail.c")
>> Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
>> ---
>>   tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
>> index 009ee37607df..39973ea1ce43 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
>> @@ -18,7 +18,7 @@ static void test_xdp_adjust_tail_shrink(void)
>>       );
>>       err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
>> -    if (ASSERT_OK(err, "test_xdp_adjust_tail_shrink"))
>> +    if (!ASSERT_OK(err, "test_xdp_adjust_tail_shrink"))
>>           return;
>>       err = bpf_prog_test_run_opts(prog_fd, &topts);
>> @@ -53,7 +53,7 @@ static void test_xdp_adjust_tail_grow(void)
>>       );
>>       err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
>> -    if (ASSERT_OK(err, "test_xdp_adjust_tail_grow"))
>> +    if (!ASSERT_OK(err, "test_xdp_adjust_tail_grow"))
> 
> Ouch... ic.  It is why this test has been passing.
> 

Well, it's because the value of err is zero, so ASSERT_OK passed.

> 
>>           return;
>>       err = bpf_prog_test_run_opts(prog_fd, &topts);
>> @@ -90,7 +90,7 @@ static void test_xdp_adjust_tail_grow2(void)
>>       );
>>       err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
>> -    if (ASSERT_OK(err, "test_xdp_adjust_tail_grow"))
>> +    if (!ASSERT_OK(err, "test_xdp_adjust_tail_grow"))
>>           return;
>>       /* Test case-64 */
> 
> .
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
index 009ee37607df..39973ea1ce43 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
@@ -18,7 +18,7 @@  static void test_xdp_adjust_tail_shrink(void)
 	);
 
 	err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
-	if (ASSERT_OK(err, "test_xdp_adjust_tail_shrink"))
+	if (!ASSERT_OK(err, "test_xdp_adjust_tail_shrink"))
 		return;
 
 	err = bpf_prog_test_run_opts(prog_fd, &topts);
@@ -53,7 +53,7 @@  static void test_xdp_adjust_tail_grow(void)
 	);
 
 	err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
-	if (ASSERT_OK(err, "test_xdp_adjust_tail_grow"))
+	if (!ASSERT_OK(err, "test_xdp_adjust_tail_grow"))
 		return;
 
 	err = bpf_prog_test_run_opts(prog_fd, &topts);
@@ -90,7 +90,7 @@  static void test_xdp_adjust_tail_grow2(void)
 	);
 
 	err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
-	if (ASSERT_OK(err, "test_xdp_adjust_tail_grow"))
+	if (!ASSERT_OK(err, "test_xdp_adjust_tail_grow"))
 		return;
 
 	/* Test case-64 */