* [PATCH] selftests: net: fix warning when compiling selftest/net
@ 2022-03-16 11:50 Guo Zhengkui
2022-03-17 3:22 ` Jakub Kicinski
0 siblings, 1 reply; 8+ messages in thread
From: Guo Zhengkui @ 2022-03-16 11:50 UTC (permalink / raw)
To: David S. Miller, Jakub Kicinski, Shuah Khan,
open list:NETWORKING [GENERAL],
open list:KERNEL SELFTEST FRAMEWORK, open list
Cc: zhengkui_guo, Guo Zhengkui
When I compile tools/testing/selftests/net/ by
`make -C tools/testing/selftests/net` with gcc (Debian 8.3.0-6) 8.3.0,
it reports the following warnings:
txtimestamp.c: In function 'validate_timestamp':
txtimestamp.c:164:29: warning: format '%lu' expects argument of type
'long unsigned int', but argument 3 has type 'int64_t'
{aka 'long long int'} [-Wformat=]
fprintf(stderr, "ERROR: %lu us expected between %d and %d\n",
~~^
%llu
cur64 - start64, min_delay, max_delay);
~~~~~~~~~~~~~~~
txtimestamp.c: In function '__print_ts_delta_formatted':
txtimestamp.c:173:22: warning: format '%lu' expects argument of type
'long unsigned int', but argument 3 has type 'int64_t'
{aka 'long long int'} [-Wformat=]
fprintf(stderr, "%lu ns", ts_delta);
~~^ ~~~~~~~~
%llu
txtimestamp.c:175:22: warning: format '%lu' expects argument of type
'long unsigned int', but argument 3 has type 'int64_t'
{aka 'long long int'} [-Wformat=]
fprintf(stderr, "%lu us", ts_delta / NSEC_PER_USEC);
~~^
%llu
`int64_t` is the alias for `long long int`. '%lld' is more suitable.
Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>
---
tools/testing/selftests/net/txtimestamp.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/net/txtimestamp.c b/tools/testing/selftests/net/txtimestamp.c
index fabb1d555ee5..ab8d0181218f 100644
--- a/tools/testing/selftests/net/txtimestamp.c
+++ b/tools/testing/selftests/net/txtimestamp.c
@@ -161,7 +161,7 @@ static void validate_timestamp(struct timespec *cur, int min_delay)
max_delay = min_delay + cfg_delay_tolerance_usec;
if (cur64 < start64 + min_delay || cur64 > start64 + max_delay) {
- fprintf(stderr, "ERROR: %lu us expected between %d and %d\n",
+ fprintf(stderr, "ERROR: %lld us expected between %d and %d\n",
cur64 - start64, min_delay, max_delay);
test_failed = true;
}
@@ -170,9 +170,9 @@ static void validate_timestamp(struct timespec *cur, int min_delay)
static void __print_ts_delta_formatted(int64_t ts_delta)
{
if (cfg_print_nsec)
- fprintf(stderr, "%lu ns", ts_delta);
+ fprintf(stderr, "%lld ns", ts_delta);
else
- fprintf(stderr, "%lu us", ts_delta / NSEC_PER_USEC);
+ fprintf(stderr, "%lld us", ts_delta / NSEC_PER_USEC);
}
static void __print_timestamp(const char *name, struct timespec *cur,
--
2.20.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] selftests: net: fix warning when compiling selftest/net
2022-03-16 11:50 [PATCH] selftests: net: fix warning when compiling selftest/net Guo Zhengkui
@ 2022-03-17 3:22 ` Jakub Kicinski
2022-03-17 6:51 ` Guo Zhengkui
0 siblings, 1 reply; 8+ messages in thread
From: Jakub Kicinski @ 2022-03-17 3:22 UTC (permalink / raw)
To: Guo Zhengkui
Cc: David S. Miller, Shuah Khan, open list:NETWORKING [GENERAL],
open list:KERNEL SELFTEST FRAMEWORK, open list, zhengkui_guo
On Wed, 16 Mar 2022 19:50:40 +0800 Guo Zhengkui wrote:
> When I compile tools/testing/selftests/net/ by
> `make -C tools/testing/selftests/net` with gcc (Debian 8.3.0-6) 8.3.0,
> it reports the following warnings:
>
> txtimestamp.c: In function 'validate_timestamp':
> txtimestamp.c:164:29: warning: format '%lu' expects argument of type
> 'long unsigned int', but argument 3 has type 'int64_t'
> {aka 'long long int'} [-Wformat=]
> fprintf(stderr, "ERROR: %lu us expected between %d and %d\n",
> ~~^
> %llu
> cur64 - start64, min_delay, max_delay);
> ~~~~~~~~~~~~~~~
> txtimestamp.c: In function '__print_ts_delta_formatted':
> txtimestamp.c:173:22: warning: format '%lu' expects argument of type
> 'long unsigned int', but argument 3 has type 'int64_t'
> {aka 'long long int'} [-Wformat=]
> fprintf(stderr, "%lu ns", ts_delta);
> ~~^ ~~~~~~~~
> %llu
> txtimestamp.c:175:22: warning: format '%lu' expects argument of type
> 'long unsigned int', but argument 3 has type 'int64_t'
> {aka 'long long int'} [-Wformat=]
> fprintf(stderr, "%lu us", ts_delta / NSEC_PER_USEC);
> ~~^
> %llu
>
> `int64_t` is the alias for `long long int`. '%lld' is more suitable.
That's on 32bit machines, I think what you need to use is PRId64.
Or just cast the result / change variable types to long long.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] selftests: net: fix warning when compiling selftest/net
2022-03-17 3:22 ` Jakub Kicinski
@ 2022-03-17 6:51 ` Guo Zhengkui
2022-03-18 7:50 ` [PATCH linux-next v2] selftests: net: change fprintf format specifiers Guo Zhengkui
0 siblings, 1 reply; 8+ messages in thread
From: Guo Zhengkui @ 2022-03-17 6:51 UTC (permalink / raw)
To: Jakub Kicinski
Cc: David S. Miller, Shuah Khan, open list:NETWORKING [GENERAL],
open list:KERNEL SELFTEST FRAMEWORK, open list,
zhengkui_guo@outlook.com
On 2022/3/17 11:22, Jakub Kicinski wrote:
> On Wed, 16 Mar 2022 19:50:40 +0800 Guo Zhengkui wrote:
>> When I compile tools/testing/selftests/net/ by
>> `make -C tools/testing/selftests/net` with gcc (Debian 8.3.0-6) 8.3.0,
>> it reports the following warnings:
>>
>> txtimestamp.c: In function 'validate_timestamp':
>> txtimestamp.c:164:29: warning: format '%lu' expects argument of type
>> 'long unsigned int', but argument 3 has type 'int64_t'
>> {aka 'long long int'} [-Wformat=]
>> fprintf(stderr, "ERROR: %lu us expected between %d and %d\n",
>> ~~^
>> %llu
>> cur64 - start64, min_delay, max_delay);
>> ~~~~~~~~~~~~~~~
>> txtimestamp.c: In function '__print_ts_delta_formatted':
>> txtimestamp.c:173:22: warning: format '%lu' expects argument of type
>> 'long unsigned int', but argument 3 has type 'int64_t'
>> {aka 'long long int'} [-Wformat=]
>> fprintf(stderr, "%lu ns", ts_delta);
>> ~~^ ~~~~~~~~
>> %llu
>> txtimestamp.c:175:22: warning: format '%lu' expects argument of type
>> 'long unsigned int', but argument 3 has type 'int64_t'
>> {aka 'long long int'} [-Wformat=]
>> fprintf(stderr, "%lu us", ts_delta / NSEC_PER_USEC);
>> ~~^
>> %llu
>>
>> `int64_t` is the alias for `long long int`. '%lld' is more suitable.
>
> That's on 32bit machines, I think what you need to use is PRId64.
> Or just cast the result / change variable types to long long.
But it should be '%ld' instead of '%lu', right?
Zhengkui
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH linux-next v2] selftests: net: change fprintf format specifiers
2022-03-17 6:51 ` Guo Zhengkui
@ 2022-03-18 7:50 ` Guo Zhengkui
2022-03-18 16:33 ` Jakub Kicinski
0 siblings, 1 reply; 8+ messages in thread
From: Guo Zhengkui @ 2022-03-18 7:50 UTC (permalink / raw)
To: David S. Miller, Jakub Kicinski, Paolo Abeni, Shuah Khan,
open list:NETWORKING [GENERAL],
open list:KERNEL SELFTEST FRAMEWORK, open list
Cc: zhengkui_guo, Guo Zhengkui
`cur64`, `start64` and `ts_delta` are int64_t. Change
format specifiers in fprintf from '%lu' to '%ld'.
It has been tested with gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
on x86_64.
Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>
---
tools/testing/selftests/net/txtimestamp.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/net/txtimestamp.c b/tools/testing/selftests/net/txtimestamp.c
index fabb1d555ee5..b8a52995a635 100644
--- a/tools/testing/selftests/net/txtimestamp.c
+++ b/tools/testing/selftests/net/txtimestamp.c
@@ -161,7 +161,7 @@ static void validate_timestamp(struct timespec *cur, int min_delay)
max_delay = min_delay + cfg_delay_tolerance_usec;
if (cur64 < start64 + min_delay || cur64 > start64 + max_delay) {
- fprintf(stderr, "ERROR: %lu us expected between %d and %d\n",
+ fprintf(stderr, "ERROR: %ld us expected between %d and %d\n",
cur64 - start64, min_delay, max_delay);
test_failed = true;
}
@@ -170,9 +170,9 @@ static void validate_timestamp(struct timespec *cur, int min_delay)
static void __print_ts_delta_formatted(int64_t ts_delta)
{
if (cfg_print_nsec)
- fprintf(stderr, "%lu ns", ts_delta);
+ fprintf(stderr, "%ld ns", ts_delta);
else
- fprintf(stderr, "%lu us", ts_delta / NSEC_PER_USEC);
+ fprintf(stderr, "%ld us", ts_delta / NSEC_PER_USEC);
}
static void __print_timestamp(const char *name, struct timespec *cur,
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH linux-next v2] selftests: net: change fprintf format specifiers
2022-03-18 7:50 ` [PATCH linux-next v2] selftests: net: change fprintf format specifiers Guo Zhengkui
@ 2022-03-18 16:33 ` Jakub Kicinski
2022-03-19 7:09 ` Guo Zhengkui
2022-03-19 7:37 ` [PATCH linux-next v3] " Guo Zhengkui
0 siblings, 2 replies; 8+ messages in thread
From: Jakub Kicinski @ 2022-03-18 16:33 UTC (permalink / raw)
To: Guo Zhengkui
Cc: David S. Miller, Paolo Abeni, Shuah Khan,
open list:NETWORKING [GENERAL],
open list:KERNEL SELFTEST FRAMEWORK, open list, zhengkui_guo
On Fri, 18 Mar 2022 15:50:13 +0800 Guo Zhengkui wrote:
> `cur64`, `start64` and `ts_delta` are int64_t. Change
> format specifiers in fprintf from '%lu' to '%ld'.
>
> It has been tested with gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
> on x86_64.
No, not like that. Please read up on printing int64_t.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH linux-next v2] selftests: net: change fprintf format specifiers
2022-03-18 16:33 ` Jakub Kicinski
@ 2022-03-19 7:09 ` Guo Zhengkui
2022-03-19 7:37 ` [PATCH linux-next v3] " Guo Zhengkui
1 sibling, 0 replies; 8+ messages in thread
From: Guo Zhengkui @ 2022-03-19 7:09 UTC (permalink / raw)
To: Jakub Kicinski
Cc: David S. Miller, Paolo Abeni, Shuah Khan,
open list:NETWORKING [GENERAL],
open list:KERNEL SELFTEST FRAMEWORK, open list,
zhengkui_guo@outlook.com
On 2022/3/19 0:33, Jakub Kicinski wrote:
> On Fri, 18 Mar 2022 15:50:13 +0800 Guo Zhengkui wrote:
>> `cur64`, `start64` and `ts_delta` are int64_t. Change
>> format specifiers in fprintf from '%lu' to '%ld'.
>>
>> It has been tested with gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
>> on x86_64.
>
> No, not like that. Please read up on printing int64_t.
Sorry for misunderstanding. I wrongly thought that it's just for 64-bit.
So I should use `PRId64`.
Zhengkui
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH linux-next v3] selftests: net: change fprintf format specifiers
2022-03-18 16:33 ` Jakub Kicinski
2022-03-19 7:09 ` Guo Zhengkui
@ 2022-03-19 7:37 ` Guo Zhengkui
2022-03-22 0:00 ` patchwork-bot+netdevbpf
1 sibling, 1 reply; 8+ messages in thread
From: Guo Zhengkui @ 2022-03-19 7:37 UTC (permalink / raw)
To: David S. Miller, Jakub Kicinski, Paolo Abeni, Shuah Khan,
open list:NETWORKING [GENERAL],
open list:KERNEL SELFTEST FRAMEWORK, open list
Cc: zhengkui_guo, Guo Zhengkui
`cur64`, `start64` and `ts_delta` are int64_t. Change format
specifiers in fprintf from `"%lu"` to `"%" PRId64` to adapt
to 32-bit and 64-bit systems.
Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>
---
tools/testing/selftests/net/txtimestamp.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/net/txtimestamp.c b/tools/testing/selftests/net/txtimestamp.c
index fabb1d555ee5..10f2fde3686b 100644
--- a/tools/testing/selftests/net/txtimestamp.c
+++ b/tools/testing/selftests/net/txtimestamp.c
@@ -161,7 +161,7 @@ static void validate_timestamp(struct timespec *cur, int min_delay)
max_delay = min_delay + cfg_delay_tolerance_usec;
if (cur64 < start64 + min_delay || cur64 > start64 + max_delay) {
- fprintf(stderr, "ERROR: %lu us expected between %d and %d\n",
+ fprintf(stderr, "ERROR: %" PRId64 " us expected between %d and %d\n",
cur64 - start64, min_delay, max_delay);
test_failed = true;
}
@@ -170,9 +170,9 @@ static void validate_timestamp(struct timespec *cur, int min_delay)
static void __print_ts_delta_formatted(int64_t ts_delta)
{
if (cfg_print_nsec)
- fprintf(stderr, "%lu ns", ts_delta);
+ fprintf(stderr, "%" PRId64 " ns", ts_delta);
else
- fprintf(stderr, "%lu us", ts_delta / NSEC_PER_USEC);
+ fprintf(stderr, "%" PRId64 " us", ts_delta / NSEC_PER_USEC);
}
static void __print_timestamp(const char *name, struct timespec *cur,
--
2.20.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH linux-next v3] selftests: net: change fprintf format specifiers
2022-03-19 7:37 ` [PATCH linux-next v3] " Guo Zhengkui
@ 2022-03-22 0:00 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-03-22 0:00 UTC (permalink / raw)
To: Guo Zhengkui
Cc: davem, kuba, pabeni, shuah, netdev, linux-kselftest, linux-kernel,
zhengkui_guo
Hello:
This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:
On Sat, 19 Mar 2022 15:37:30 +0800 you wrote:
> `cur64`, `start64` and `ts_delta` are int64_t. Change format
> specifiers in fprintf from `"%lu"` to `"%" PRId64` to adapt
> to 32-bit and 64-bit systems.
>
> Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>
> ---
> tools/testing/selftests/net/txtimestamp.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
Here is the summary with links:
- [linux-next,v3] selftests: net: change fprintf format specifiers
https://git.kernel.org/netdev/net-next/c/94f19e1ec38f
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-03-22 0:01 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-16 11:50 [PATCH] selftests: net: fix warning when compiling selftest/net Guo Zhengkui
2022-03-17 3:22 ` Jakub Kicinski
2022-03-17 6:51 ` Guo Zhengkui
2022-03-18 7:50 ` [PATCH linux-next v2] selftests: net: change fprintf format specifiers Guo Zhengkui
2022-03-18 16:33 ` Jakub Kicinski
2022-03-19 7:09 ` Guo Zhengkui
2022-03-19 7:37 ` [PATCH linux-next v3] " Guo Zhengkui
2022-03-22 0:00 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).