diff mbox series

[net] selftest: af_unix: Fix kselftest compilation warnings

Message ID 20240810134037.669765-1-jain.abhinav177@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net] selftest: af_unix: Fix kselftest compilation warnings | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present fail Series targets non-next tree, but doesn't contain any Fixes tags
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 7 this patch: 7
netdev/build_tools success Errors and warnings before: 9 this patch: 9
netdev/cc_maintainers warning 1 maintainers not CCed: kuniyu@amazon.com
netdev/build_clang success Errors and warnings before: 7 this patch: 7
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch warning CHECK: Alignment should match open parenthesis WARNING: line length of 87 exceeds 80 columns WARNING: line length of 98 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-08-10--18-00 (tests: 707)

Commit Message

Abhinav Jain Aug. 10, 2024, 1:40 p.m. UTC
Add proper type cast (char *) to the buffer being passed to TH_LOG
macro in __recvpair function.

This change fixes the below warnings during test compilation:

```
In file included from msg_oob.c:14:
msg_oob.c: In function ‘__recvpair’:

../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument
of type ‘char *’,but argument 6 has type ‘const void *’ [-Wformat=]

../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
msg_oob.c:235:17: note: in expansion of macro ‘TH_LOG’

../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument
of type ‘char *’,but argument 6 has type ‘const void *’ [-Wformat=]

../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
msg_oob.c:259:25: note: in expansion of macro ‘TH_LOG’
```

Signed-off-by: Abhinav Jain <jain.abhinav177@gmail.com>
---
 tools/testing/selftests/net/af_unix/msg_oob.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Kuniyuki Iwashima Aug. 12, 2024, 6:39 p.m. UTC | #1
From: Abhinav Jain <jain.abhinav177@gmail.com>
Date: Sat, 10 Aug 2024 19:10:37 +0530
> Add proper type cast (char *) to the buffer being passed to TH_LOG
> macro in __recvpair function.
> 
> This change fixes the below warnings during test compilation:
> 
> ```
> In file included from msg_oob.c:14:
> msg_oob.c: In function ‘__recvpair’:
> 
> ../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument
> of type ‘char *’,but argument 6 has type ‘const void *’ [-Wformat=]
> 
> ../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
> msg_oob.c:235:17: note: in expansion of macro ‘TH_LOG’
> 
> ../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument
> of type ‘char *’,but argument 6 has type ‘const void *’ [-Wformat=]
> 
> ../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
> msg_oob.c:259:25: note: in expansion of macro ‘TH_LOG’
> ```
>

Fixes: tag is needed here (no space between SOB tag)

> Signed-off-by: Abhinav Jain <jain.abhinav177@gmail.com>
> ---
>  tools/testing/selftests/net/af_unix/msg_oob.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/net/af_unix/msg_oob.c b/tools/testing/selftests/net/af_unix/msg_oob.c
> index 16d0c172eaeb..66d76ab38251 100644
> --- a/tools/testing/selftests/net/af_unix/msg_oob.c
> +++ b/tools/testing/selftests/net/af_unix/msg_oob.c
> @@ -232,7 +232,8 @@ static void __recvpair(struct __test_metadata *_metadata,
>  
>  	if (ret[0] != expected_len || recv_errno[0] != expected_errno) {
>  		TH_LOG("AF_UNIX :%s", ret[0] < 0 ? strerror(recv_errno[0]) : recv_buf[0]);
> -		TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
> +		TH_LOG("Expected:%s",
> +				expected_errno ? strerror(expected_errno) : (char *)expected_buf);
>  
>  		ASSERT_EQ(ret[0], expected_len);
>  		ASSERT_EQ(recv_errno[0], expected_errno);

I don't remember why I defined expected_buf as (void *), but more simple
fix would be the following ?

---8<---
diff --git a/tools/testing/selftests/net/af_unix/msg_oob.c b/tools/testing/selftests/net/af_unix/msg_oob.c
index 16d0c172eaeb..535eb2c3d7d1 100644
--- a/tools/testing/selftests/net/af_unix/msg_oob.c
+++ b/tools/testing/selftests/net/af_unix/msg_oob.c
@@ -209,7 +209,7 @@ static void __sendpair(struct __test_metadata *_metadata,
 
 static void __recvpair(struct __test_metadata *_metadata,
 		       FIXTURE_DATA(msg_oob) *self,
-		       const void *expected_buf, int expected_len,
+		       const char *expected_buf, int expected_len,
 		       int buf_len, int flags)
 {
 	int i, ret[2], recv_errno[2], expected_errno = 0;
---8<---

Thanks!
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/af_unix/msg_oob.c b/tools/testing/selftests/net/af_unix/msg_oob.c
index 16d0c172eaeb..66d76ab38251 100644
--- a/tools/testing/selftests/net/af_unix/msg_oob.c
+++ b/tools/testing/selftests/net/af_unix/msg_oob.c
@@ -232,7 +232,8 @@  static void __recvpair(struct __test_metadata *_metadata,
 
 	if (ret[0] != expected_len || recv_errno[0] != expected_errno) {
 		TH_LOG("AF_UNIX :%s", ret[0] < 0 ? strerror(recv_errno[0]) : recv_buf[0]);
-		TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
+		TH_LOG("Expected:%s",
+				expected_errno ? strerror(expected_errno) : (char *)expected_buf);
 
 		ASSERT_EQ(ret[0], expected_len);
 		ASSERT_EQ(recv_errno[0], expected_errno);
@@ -256,7 +257,8 @@  static void __recvpair(struct __test_metadata *_metadata,
 		cmp = strncmp(expected_buf, recv_buf[0], expected_len);
 		if (cmp) {
 			TH_LOG("AF_UNIX :%s", ret[0] < 0 ? strerror(recv_errno[0]) : recv_buf[0]);
-			TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
+			TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno)
+					: (char *)expected_buf);
 
 			ASSERT_EQ(cmp, 0);
 		}