diff mbox series

[linux-next,v2] selftests: net: change fprintf format specifiers

Message ID 20220318075013.48964-1-guozhengkui@vivo.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [linux-next,v2] selftests: net: change fprintf format specifiers | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning + fprintf(stderr, "ERROR: %ld us expected between %d and %d\n", CHECK: Alignment should match open parenthesis
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Guo Zhengkui March 18, 2022, 7:50 a.m. UTC
`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(-)

Comments

Jakub Kicinski March 18, 2022, 4:33 p.m. UTC | #1
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.
Guo Zhengkui March 19, 2022, 7:09 a.m. UTC | #2
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
diff mbox series

Patch

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,