Commit 1fe42210 authored by Dmitry Safonov's avatar Dmitry Safonov Committed by Jakub Kicinski
Browse files

selftests/net: Provide tcp-ao counters comparison helper



Rename __test_tcp_ao_counters_cmp() into test_assert_counters_ao() and
test_tcp_ao_key_counters_cmp() into test_assert_counters_key() as they
are asserts, rather than just compare functions.

Provide test_cmp_counters() helper, that's going to be used to compare
ao_info and netns counters as a stop condition for polling the sockets.

Signed-off-by: default avatarDmitry Safonov <0x7f454c46@gmail.com>
Link: https://patch.msgid.link/20250319-tcp-ao-selftests-polling-v2-2-da48040153d1@gmail.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 65ffdf31
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ static void try_accept(const char *tst_name, unsigned int port, const char *pwd,
	close(lsk);

	if (pwd)
		test_tcp_ao_counters_cmp(tst_name, &ao_cnt1, &ao_cnt2, cnt_expected);
		test_assert_counters(tst_name, &ao_cnt1, &ao_cnt2, cnt_expected);

	if (!cnt_name)
		goto out;
@@ -204,7 +204,7 @@ static void try_connect(const char *tst_name, unsigned int port,
	if (pwd && ret > 0) {
		if (test_get_tcp_ao_counters(sk, &ao_cnt2))
			test_error("test_get_tcp_ao_counters()");
		test_tcp_ao_counters_cmp(tst_name, &ao_cnt1, &ao_cnt2, cnt_expected);
		test_assert_counters(tst_name, &ao_cnt1, &ao_cnt2, cnt_expected);
	}
out:
	synchronize_threads(); /* close() */
+1 −1
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ static void *client_fn(void *arg)
				nr_packets, after_aogood, before_aogood);
		return NULL;
	}
	if (test_tcp_ao_counters_cmp("connect", &ao1, &ao2, TEST_CNT_GOOD))
	if (test_assert_counters("connect", &ao1, &ao2, TEST_CNT_GOOD))
		return NULL;

	test_ok("connect TCPAOGood %" PRIu64 "/%" PRIu64 "/%" PRIu64 " => %" PRIu64 "/%" PRIu64 "/%" PRIu64 ", sent %zu",
+2 −2
Original line number Diff line number Diff line
@@ -91,9 +91,9 @@ static void serve_interfered(int sk)
		return;
	}
#ifdef TEST_ICMPS_ACCEPT
	test_tcp_ao_counters_cmp(NULL, &ao_cnt1, &ao_cnt2, TEST_CNT_GOOD);
	test_assert_counters(NULL, &ao_cnt1, &ao_cnt2, TEST_CNT_GOOD);
#else
	test_tcp_ao_counters_cmp(NULL, &ao_cnt1, &ao_cnt2, TEST_CNT_GOOD | TEST_CNT_AO_DROPPED_ICMP);
	test_assert_counters(NULL, &ao_cnt1, &ao_cnt2, TEST_CNT_GOOD | TEST_CNT_AO_DROPPED_ICMP);
#endif
	if (icmp_ignored_a >= icmp_ignored_b) {
		test_icmps_fail("%s counter didn't change: %" PRIu64 " >= %" PRIu64,
+4 −4
Original line number Diff line number Diff line
@@ -633,7 +633,7 @@ static void verify_counters(const char *tst_name, bool is_listen_sk, bool server
{
	unsigned int i;

	__test_tcp_ao_counters_cmp(tst_name, a, b, TEST_CNT_GOOD);
	test_assert_counters_ao(tst_name, a, b, TEST_CNT_GOOD);

	for (i = 0; i < collection.nr_keys; i++) {
		struct test_key *key = &collection.keys[i];
@@ -652,7 +652,7 @@ static void verify_counters(const char *tst_name, bool is_listen_sk, bool server
			rx_cnt_expected = key->used_on_server_tx;
		}

		test_tcp_ao_key_counters_cmp(tst_name, a, b,
		test_assert_counters_key(tst_name, a, b,
					 rx_cnt_expected ? TEST_CNT_KEY_GOOD : 0,
					 sndid, rcvid);
	}
+24 −9
Original line number Diff line number Diff line
@@ -528,6 +528,22 @@ extern int test_get_tcp_ao_counters(int sk, struct tcp_ao_counters *out);
#define TEST_CNT_NS_DROPPED_ICMP	BIT(11)
typedef uint16_t test_cnt;

#define _for_each_counter(f)						\
do {									\
	/* per-netns */							\
	f(netns_ao_good,		TEST_CNT_NS_GOOD);		\
	f(netns_ao_bad,			TEST_CNT_NS_BAD);		\
	f(netns_ao_key_not_found,	TEST_CNT_NS_KEY_NOT_FOUND);	\
	f(netns_ao_required,		TEST_CNT_NS_AO_REQUIRED);	\
	f(netns_ao_dropped_icmp,	TEST_CNT_NS_DROPPED_ICMP);	\
	/* per-socket */						\
	f(ao_info_pkt_good,		TEST_CNT_SOCK_GOOD);		\
	f(ao_info_pkt_bad,		TEST_CNT_SOCK_BAD);		\
	f(ao_info_pkt_key_not_found,	TEST_CNT_SOCK_KEY_NOT_FOUND);	\
	f(ao_info_pkt_ao_required,	TEST_CNT_SOCK_AO_REQUIRED);	\
	f(ao_info_pkt_dropped_icmp,	TEST_CNT_SOCK_DROPPED_ICMP);	\
} while (0)

#define TEST_CNT_AO_GOOD		(TEST_CNT_SOCK_GOOD | TEST_CNT_NS_GOOD)
#define TEST_CNT_AO_BAD			(TEST_CNT_SOCK_BAD | TEST_CNT_NS_BAD)
#define TEST_CNT_AO_KEY_NOT_FOUND	(TEST_CNT_SOCK_KEY_NOT_FOUND | \
@@ -539,10 +555,10 @@ typedef uint16_t test_cnt;
#define TEST_CNT_GOOD			(TEST_CNT_KEY_GOOD | TEST_CNT_AO_GOOD)
#define TEST_CNT_BAD			(TEST_CNT_KEY_BAD | TEST_CNT_AO_BAD)

extern int __test_tcp_ao_counters_cmp(const char *tst_name,
extern int test_assert_counters_ao(const char *tst_name,
		struct tcp_ao_counters *before, struct tcp_ao_counters *after,
		test_cnt expected);
extern int test_tcp_ao_key_counters_cmp(const char *tst_name,
extern int test_assert_counters_key(const char *tst_name,
		struct tcp_ao_counters *before, struct tcp_ao_counters *after,
		test_cnt expected, int sndid, int rcvid);
extern void test_tcp_ao_counters_free(struct tcp_ao_counters *cnts);
@@ -552,18 +568,17 @@ extern void test_tcp_ao_counters_free(struct tcp_ao_counters *cnts);
 * to test_get_tcp_ao_counters(). Check key counters manually if they
 * may change.
 */
static inline int test_tcp_ao_counters_cmp(const char *tst_name,
static inline int test_assert_counters(const char *tst_name,
				       struct tcp_ao_counters *before,
				       struct tcp_ao_counters *after,
				       test_cnt expected)
{
	int ret;

	ret = __test_tcp_ao_counters_cmp(tst_name, before, after, expected);
	ret = test_assert_counters_ao(tst_name, before, after, expected);
	if (ret)
		goto out;
	ret = test_tcp_ao_key_counters_cmp(tst_name, before, after,
					   expected, -1, -1);
	ret = test_assert_counters_key(tst_name, before, after, expected, -1, -1);
out:
	test_tcp_ao_counters_free(before);
	test_tcp_ao_counters_free(after);
Loading