Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH] Kselftest: msg_oob.c: Fix warning for Incorrect Specifier
@ 2024-08-13  5:59 David Hunter
  2024-08-13  6:12 ` Kuniyuki Iwashima
  0 siblings, 1 reply; 4+ messages in thread
From: David Hunter @ 2024-08-13  5:59 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, shuah, kuniyu, netdev,
	linux-kselftest, linux-kernel
  Cc: javier.carrasco.cruz, David Hunter

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 2417 bytes --]

Change specifier to %p to correctly substitute type 'const void *'. A
specifer involved with a macro is causing a misleading warning to occur:

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=]
  106 |                 fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
      |                                        ^~~~~~~~~~~~~
../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
  101 |                 __TH_LOG(fmt, ##__VA_ARGS__); \
      |                 ^~~~~~~~
msg_oob.c:235:17: note: in expansion of macro ‘TH_LOG’
  235 |                 TH_LOG("Expected:%s", expected_errno ? 
			strerror(expected_errno) : expected_buf);
      |                 ^~~~~~

A second set of these three warnings occur later for the incorrect
specifier at msg_oob.c:256. By tracing the various macros involved, the
correct specifier (in msg_oob.c) can be spotted and changed.

Signed-off-by: David Hunter <david.hunter.linux@gmail.com>
---
 tools/testing/selftests/net/af_unix/msg_oob.c | 4 ++--
 1 file changed, 2 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..87090ebda2a7 100644
--- a/tools/testing/selftests/net/af_unix/msg_oob.c
+++ b/tools/testing/selftests/net/af_unix/msg_oob.c
@@ -232,7 +232,7 @@ 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:%p", expected_errno ? strerror(expected_errno) : expected_buf);
 
 		ASSERT_EQ(ret[0], expected_len);
 		ASSERT_EQ(recv_errno[0], expected_errno);
@@ -256,7 +256,7 @@ 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:%p", expected_errno ? strerror(expected_errno) : expected_buf);
 
 			ASSERT_EQ(cmp, 0);
 		}
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Kselftest: msg_oob.c: Fix warning for Incorrect Specifier
  2024-08-13  5:59 [PATCH] Kselftest: msg_oob.c: Fix warning for Incorrect Specifier David Hunter
@ 2024-08-13  6:12 ` Kuniyuki Iwashima
  2024-08-13 19:19   ` [PATCH 1/1 V2] Kselftest: msg_oob.c: Fix Compiler Warning For " David Hunter
  0 siblings, 1 reply; 4+ messages in thread
From: Kuniyuki Iwashima @ 2024-08-13  6:12 UTC (permalink / raw)
  To: david.hunter.linux
  Cc: davem, edumazet, javier.carrasco.cruz, kuba, kuniyu, linux-kernel,
	linux-kselftest, netdev, pabeni, shuah

From: David Hunter <david.hunter.linux@gmail.com>
Date: Tue, 13 Aug 2024 01:59:57 -0400
> Change specifier to %p to correctly substitute type 'const void *'. A
> specifer involved with a macro is causing a misleading warning to occur:

You may want to run the test before/after the patch.

This is the 3rd patch posted for this warning, so it would be nice to
check lore before posting if the patch/issue is simple enough :)

And here's the correct fix.
https://lore.kernel.org/netdev/20240812191122.1092806-1-jain.abhinav177@gmail.com/

Thanks !

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/1 V2] Kselftest: msg_oob.c: Fix Compiler Warning For Incorrect Specifier
  2024-08-13  6:12 ` Kuniyuki Iwashima
@ 2024-08-13 19:19   ` David Hunter
  2024-08-13 19:38     ` Kuniyuki Iwashima
  0 siblings, 1 reply; 4+ messages in thread
From: David Hunter @ 2024-08-13 19:19 UTC (permalink / raw)
  To: kuniyu
  Cc: davem, david.hunter.linux, edumazet, javier.carrasco.cruz, kuba,
	linux-kernel, linux-kselftest, netdev, pabeni, shuah

Change declaration to 'char *'. A specifier involved with a macro is
causing a misleading warning to occur:

'''
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=]
  106 |                 fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
      |                                        ^~~~~~~~~~~~~
../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
  101 |                 __TH_LOG(fmt, ##__VA_ARGS__); \
      |                 ^~~~~~~~
msg_oob.c:235:17: note: in expansion of macro ‘TH_LOG’
  235 |                 TH_LOG("Expected:%s", expected_errno ?
			strerror(expected_errno) : expected_buf);
      |                 ^~~~~~
'''

I ran the tests using the following command:

'''
make kselftest TARGETS=net/af_unix
'''

I used a diff to examine the difference in output among the three
scenarios (1) before making the change, (2) after changing the
specifier, and (3) after changing the declaration. I saw no difference
in outputs among any of the tests; all three tests had the same exact
output.

For "net/af_unix: msg_oob", all 38 tests passed for msg_oob. I received
this result for all 3 scenarios. Should I have gotten a different
result?

Signed-off-by: David Hunter <david.hunter.linux@gmail.com>
---
Apologies for not looking ahead of time. I definitely need to remember
to check ahead of time. I understand that the other person was first; I
just wanted to get some practice sending patches. This is all still new
to me. 

V1 --> V2 
	- Changed the declaration instead of the specifier. 
	- Put number of patches for this bug fix. 
	- Put in tests performed. 

---
 tools/testing/selftests/net/af_unix/msg_oob.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1 V2] Kselftest: msg_oob.c: Fix Compiler Warning For Incorrect Specifier
  2024-08-13 19:19   ` [PATCH 1/1 V2] Kselftest: msg_oob.c: Fix Compiler Warning For " David Hunter
@ 2024-08-13 19:38     ` Kuniyuki Iwashima
  0 siblings, 0 replies; 4+ messages in thread
From: Kuniyuki Iwashima @ 2024-08-13 19:38 UTC (permalink / raw)
  To: david.hunter.linux
  Cc: davem, edumazet, javier.carrasco.cruz, kuba, kuniyu, linux-kernel,
	linux-kselftest, netdev, pabeni, shuah

From: David Hunter <david.hunter.linux@gmail.com>
Date: Tue, 13 Aug 2024 15:19:32 -0400
> Apologies for not looking ahead of time. I definitely need to remember
> to check ahead of time. I understand that the other person was first; I
> just wanted to get some practice sending patches. This is all still new
> to me.

I understand, but let's not respin an unnecessary patch just for practice
that waste community time...

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-08-13 19:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-13  5:59 [PATCH] Kselftest: msg_oob.c: Fix warning for Incorrect Specifier David Hunter
2024-08-13  6:12 ` Kuniyuki Iwashima
2024-08-13 19:19   ` [PATCH 1/1 V2] Kselftest: msg_oob.c: Fix Compiler Warning For " David Hunter
2024-08-13 19:38     ` Kuniyuki Iwashima

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox