git: 2c1052053340 - main - ktls_test: Add a helper function to close sockets.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Tue, 14 Jun 2022 17:35:32 UTC
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=2c1052053340af562e3121a41545419fa71e65f7

commit 2c1052053340af562e3121a41545419fa71e65f7
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-06-14 17:34:38 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-06-14 17:34:38 +0000

    ktls_test: Add a helper function to close sockets.
    
    Reviewed by:    markj
    Sponsored by:   Chelsio Communications
    Differential Revision:  https://reviews.freebsd.org/D35425
---
 tests/sys/kern/ktls_test.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/tests/sys/kern/ktls_test.c b/tests/sys/kern/ktls_test.c
index 759a23455f25..d5cbc727734a 100644
--- a/tests/sys/kern/ktls_test.c
+++ b/tests/sys/kern/ktls_test.c
@@ -88,7 +88,7 @@ alloc_buffer(size_t len)
 }
 
 static bool
-socketpair_tcp(int *sv)
+socketpair_tcp(int sv[2])
 {
 	struct pollfd pfd;
 	struct sockaddr_in sin;
@@ -161,6 +161,13 @@ socketpair_tcp(int *sv)
 	return (true);
 }
 
+static void
+close_sockets(int sv[2])
+{
+	ATF_REQUIRE(close(sv[1]) == 0);
+	ATF_REQUIRE(close(sv[0]) == 0);
+}
+
 static void
 fd_set_blocking(int fd)
 {
@@ -993,8 +1000,7 @@ test_ktls_transmit_app_data(struct tls_enable *en, uint64_t seqno, size_t len)
 	free(decrypted);
 	free(plaintext);
 
-	ATF_REQUIRE(close(sockets[1]) == 0);
-	ATF_REQUIRE(close(sockets[0]) == 0);
+	close_sockets(sockets);
 	ATF_REQUIRE(close(kq) == 0);
 }
 
@@ -1079,8 +1085,7 @@ test_ktls_transmit_control(struct tls_enable *en, uint64_t seqno, uint8_t type,
 	free(decrypted);
 	free(plaintext);
 
-	ATF_REQUIRE(close(sockets[1]) == 0);
-	ATF_REQUIRE(close(sockets[0]) == 0);
+	close_sockets(sockets);
 }
 
 static void
@@ -1142,8 +1147,7 @@ test_ktls_transmit_empty_fragment(struct tls_enable *en, uint64_t seqno)
 out:
 	free(outbuf);
 
-	ATF_REQUIRE(close(sockets[1]) == 0);
-	ATF_REQUIRE(close(sockets[0]) == 0);
+	close_sockets(sockets);
 }
 
 static size_t
@@ -1282,8 +1286,7 @@ test_ktls_receive_app_data(struct tls_enable *en, uint64_t seqno, size_t len,
 	free(received);
 	free(plaintext);
 
-	ATF_REQUIRE(close(sockets[1]) == 0);
-	ATF_REQUIRE(close(sockets[0]) == 0);
+	close_sockets(sockets);
 	ATF_REQUIRE(close(kq) == 0);
 }
 
@@ -1532,8 +1535,7 @@ test_ktls_invalid_transmit_cipher_suite(struct tls_enable *en)
 	    sizeof(*en)) == -1);
 	ATF_REQUIRE(errno == EINVAL);
 
-	ATF_REQUIRE(close(sockets[1]) == 0);
-	ATF_REQUIRE(close(sockets[0]) == 0);
+	close_sockets(sockets);
 }
 
 #define GEN_INVALID_TRANSMIT_TEST(name, cipher_alg, key_size, auth_alg,	\
@@ -1665,8 +1667,7 @@ test_ktls_invalid_receive_cipher_suite(struct tls_enable *en)
 	    sizeof(*en)) == -1);
 	ATF_REQUIRE(errno == EINVAL);
 
-	ATF_REQUIRE(close(sockets[1]) == 0);
-	ATF_REQUIRE(close(sockets[0]) == 0);
+	close_sockets(sockets);
 }
 
 #define GEN_INVALID_RECEIVE_TEST(name, cipher_alg, key_size, auth_alg,	\
@@ -1705,8 +1706,7 @@ test_ktls_unsupported_receive_cipher_suite(struct tls_enable *en)
 	    sizeof(*en)) == -1);
 	ATF_REQUIRE(errno == EPROTONOSUPPORT);
 
-	ATF_REQUIRE(close(sockets[1]) == 0);
-	ATF_REQUIRE(close(sockets[0]) == 0);
+	close_sockets(sockets);
 }
 
 #define GEN_UNSUPPORTED_RECEIVE_TEST(name, cipher_alg, key_size,	\