selftests/tcp_ao: Fix printing format for uint64_t
authorMohammad Nassiri <mnassiri@ciena.com>
Fri, 23 Aug 2024 22:04:56 +0000 (23:04 +0100)
committerJakub Kicinski <kuba@kernel.org>
Tue, 27 Aug 2024 21:11:27 +0000 (14:11 -0700)
It's not safe to use '%zu' specifier for printing uint64_t on 32-bit
systems. For uint64_t, we should use the 'PRIu64' macro from
the inttypes.h library. This ensures that the uint64_t is printed
correctly from the selftests regardless of the system architecture.

Signed-off-by: Mohammad Nassiri <mnassiri@ciena.com>
[Added missing spaces in fail/ok messages and uint64_t cast in
 setsockopt-closed, as otherwise it was giving warnings on 64bit.
 And carried it to netdev ml]
Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>
Link: https://patch.msgid.link/20240823-tcp-ao-selftests-upd-6-12-v4-6-05623636fe8c@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/tcp_ao/connect-deny.c
tools/testing/selftests/net/tcp_ao/connect.c
tools/testing/selftests/net/tcp_ao/restore.c
tools/testing/selftests/net/tcp_ao/self-connect.c
tools/testing/selftests/net/tcp_ao/seq-ext.c
tools/testing/selftests/net/tcp_ao/setsockopt-closed.c
tools/testing/selftests/net/tcp_ao/unsigned-md5.c

index 185a2f6..5691f3d 100644 (file)
@@ -84,10 +84,10 @@ static void try_accept(const char *tst_name, unsigned int port, const char *pwd,
        after_cnt = netstat_get_one(cnt_name, NULL);
 
        if (after_cnt <= before_cnt) {
-               test_fail("%s: %s counter did not increase: %zu <= %zu",
+               test_fail("%s: %s counter did not increase: %" PRIu64 " <= %" PRIu64,
                                tst_name, cnt_name, after_cnt, before_cnt);
        } else {
-               test_ok("%s: counter %s increased %zu => %zu",
+               test_ok("%s: counter %s increased %" PRIu64  " => %" PRIu64,
                        tst_name, cnt_name, before_cnt, after_cnt);
        }
 
index 81653b4..9eecc4a 100644 (file)
@@ -67,14 +67,14 @@ static void *client_fn(void *arg)
        netstat_free(ns_after);
 
        if (nr_packets > (after_aogood - before_aogood)) {
-               test_fail("TCPAOGood counter mismatch: %zu > (%zu - %zu)",
+               test_fail("TCPAOGood counter mismatch: %zu > (%" PRIu64 " - %" PRIu64 ")",
                                nr_packets, after_aogood, before_aogood);
                return NULL;
        }
        if (test_tcp_ao_counters_cmp("connect", &ao1, &ao2, TEST_CNT_GOOD))
                return NULL;
 
-       test_ok("connect TCPAOGood %" PRIu64 "/%" PRIu64 "/%" PRIu64 " => %" PRIu64 "/%" PRIu64 "/%" PRIu64 ", sent %" PRIu64,
+       test_ok("connect TCPAOGood %" PRIu64 "/%" PRIu64 "/%" PRIu64 " => %" PRIu64 "/%" PRIu64 "/%" PRIu64 ", sent %zu",
                        before_aogood, ao1.ao_info_pkt_good,
                        ao1.key_cnts[0].pkt_good,
                        after_aogood, ao2.ao_info_pkt_good,
index 8fdc808..7b91d7f 100644 (file)
@@ -71,10 +71,10 @@ static void try_server_run(const char *tst_name, unsigned int port,
        test_tcp_ao_counters_cmp(tst_name, &ao1, &ao2, cnt_expected);
 
        if (after_cnt <= before_cnt) {
-               test_fail("%s: %s counter did not increase: %zu <= %zu",
+               test_fail("%s: %s counter did not increase: %" PRIu64 " <= %" PRIu64,
                                tst_name, cnt_name, after_cnt, before_cnt);
        } else {
-               test_ok("%s: counter %s increased %zu => %zu",
+               test_ok("%s: counter %s increased %" PRIu64 " => %" PRIu64,
                        tst_name, cnt_name, before_cnt, after_cnt);
        }
 
@@ -183,10 +183,10 @@ static void test_sk_restore(const char *tst_name, unsigned int server_port,
        test_tcp_ao_counters_cmp(tst_name, &ao1, &ao2, cnt_expected);
 
        if (after_cnt <= before_cnt) {
-               test_fail("%s: %s counter did not increase: %zu <= %zu",
+               test_fail("%s: %s counter did not increase: %" PRIu64 " <= %" PRIu64,
                                tst_name, cnt_name, after_cnt, before_cnt);
        } else {
-               test_ok("%s: counter %s increased %zu => %zu",
+               test_ok("%s: counter %s increased %" PRIu64 " => %" PRIu64,
                        tst_name, cnt_name, before_cnt, after_cnt);
        }
        synchronize_threads(); /* 3: verified => closed */
index a5698b0..e56931d 100644 (file)
@@ -87,7 +87,7 @@ static void tcp_self_connect(const char *tst, unsigned int port,
        netstat_free(ns_after);
 
        if (after_aogood <= before_aogood) {
-               test_fail("%s: TCPAOGood counter mismatch: %zu <= %zu",
+               test_fail("%s: TCPAOGood counter mismatch: %" PRIu64 " <= %" PRIu64,
                          tst, after_aogood, before_aogood);
                close(sk);
                return;
@@ -148,7 +148,7 @@ static void tcp_self_connect(const char *tst, unsigned int port,
        netstat_free(ns_after);
        close(sk);
        if (after_aogood <= before_aogood) {
-               test_fail("%s: TCPAOGood counter mismatch: %zu <= %zu",
+               test_fail("%s: TCPAOGood counter mismatch: %" PRIu64 " <= %" PRIu64,
                          tst, after_aogood, before_aogood);
                return;
        }
index ad4e77d..9c7dde7 100644 (file)
@@ -134,15 +134,15 @@ static void *server_fn(void *arg)
        test_tcp_ao_counters_cmp(NULL, &ao1, &ao2, TEST_CNT_GOOD);
 
        if (after_good <= before_good) {
-               test_fail("TCPAOGood counter did not increase: %zu <= %zu",
+               test_fail("TCPAOGood counter did not increase: %" PRIu64 " <= %" PRIu64,
                          after_good, before_good);
        } else {
-               test_ok("TCPAOGood counter increased %zu => %zu",
+               test_ok("TCPAOGood counter increased %" PRIu64 " => %" PRIu64,
                        before_good, after_good);
        }
        after_bad = netstat_get_one("TCPAOBad", NULL);
        if (after_bad)
-               test_fail("TCPAOBad counter is non-zero: %zu", after_bad);
+               test_fail("TCPAOBad counter is non-zero: %" PRIu64, after_bad);
        else
                test_ok("TCPAOBad counter didn't increase");
        test_enable_repair(sk);
@@ -219,15 +219,15 @@ static void *client_fn(void *arg)
        test_tcp_ao_counters_cmp(NULL, &ao1, &ao2, TEST_CNT_GOOD);
 
        if (after_good <= before_good) {
-               test_fail("TCPAOGood counter did not increase: %zu <= %zu",
+               test_fail("TCPAOGood counter did not increase: %" PRIu64 " <= %" PRIu64,
                          after_good, before_good);
        } else {
-               test_ok("TCPAOGood counter increased %zu => %zu",
+               test_ok("TCPAOGood counter increased %" PRIu64 " => %" PRIu64,
                        before_good, after_good);
        }
        after_bad = netstat_get_one("TCPAOBad", NULL);
        if (after_bad)
-               test_fail("TCPAOBad counter is non-zero: %zu", after_bad);
+               test_fail("TCPAOBad counter is non-zero: %" PRIu64, after_bad);
        else
                test_ok("TCPAOBad counter didn't increase");
 
index 517930f..5eee826 100644 (file)
@@ -30,8 +30,8 @@ static void test_vefify_ao_info(int sk, struct tcp_ao_info_opt *info,
 #define __cmp_ao(member)                                                       \
 do {                                                                           \
        if (info->member != tmp.member) {                                       \
-               test_fail("%s: getsockopt(): " __stringify(member) " %zu != %zu",       \
-                         tst, (size_t)info->member, (size_t)tmp.member);       \
+               test_fail("%s: getsockopt(): " __stringify(member) " %" PRIu64 " != %" PRIu64,  \
+                         tst, (uint64_t)info->member, (uint64_t)tmp.member);   \
                return;                                                         \
        }                                                                       \
 } while(0)
index 6b59a65..ec28480 100644 (file)
@@ -100,10 +100,10 @@ static void try_accept(const char *tst_name, unsigned int port,
        after_cnt = netstat_get_one(cnt_name, NULL);
 
        if (after_cnt <= before_cnt) {
-               test_fail("%s: %s counter did not increase: %zu <= %zu",
+               test_fail("%s: %s counter did not increase: %" PRIu64 " <= %" PRIu64,
                                tst_name, cnt_name, after_cnt, before_cnt);
        } else {
-               test_ok("%s: counter %s increased %zu => %zu",
+               test_ok("%s: counter %s increased %" PRIu64 " => %" PRIu64,
                        tst_name, cnt_name, before_cnt, after_cnt);
        }
        if (ao_addr)