git: 0c0146c30904 - main - tests/sendfile: test operation on unix/stream socket

From: Gleb Smirnoff <glebius_at_FreeBSD.org>
Date: Fri, 03 May 2024 14:45:23 UTC
The branch main has been updated by glebius:

URL: https://cgit.FreeBSD.org/src/commit/?id=0c0146c30904c1766695b141222542ea50608363

commit 0c0146c30904c1766695b141222542ea50608363
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2024-05-03 14:45:07 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2024-05-03 14:45:07 +0000

    tests/sendfile: test operation on unix/stream socket
    
    Although there are already multiple tests in the tests collection
    that utilize sendfile(2) support over unix/stream socket, they all
    don't exercise the asynchronous part of the operation.  This test
    framework, however, uses a trick to toggle true async operation and
    guarantee that pr_ready method of unix/stream is also tested.
    
    Reviewed by:            chs
    Differential Revision:  https://reviews.freebsd.org/D45055
---
 tests/sys/kern/sendfile_helper.c | 39 ++++++++++++++++++++++++++++++---------
 tests/sys/kern/sendfile_test.sh  | 24 ++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/tests/sys/kern/sendfile_helper.c b/tests/sys/kern/sendfile_helper.c
index 6a3b4a1ac880..703b04fdea6c 100644
--- a/tests/sys/kern/sendfile_helper.c
+++ b/tests/sys/kern/sendfile_helper.c
@@ -121,26 +121,47 @@ receiver(void *arg)
 	return NULL;
 }
 
+static void
+usage(void)
+{
+	errx(1, "usage: %s [-u] <file> <start> <len> <flags>", getprogname());
+}
+
 int
 main(int argc, char **argv)
 {
 	pthread_t pt;
 	off_t start;
-	int fd, ss[2], flags, error;
+	int ch, fd, ss[2], flags, error;
+	bool pf_unix = false;
+
+	while ((ch = getopt(argc, argv, "u")) != -1)
+		switch (ch) {
+		case 'u':
+			pf_unix = true;
+			break;
+		default:
+			usage();
+		}
+	argc -= optind;
+	argv += optind;
 
-	if (argc != 5)
-		errx(1, "usage: %s <file> <start> <len> <flags>",
-		    getprogname());
+	if (argc != 4)
+		usage();
 
-	start = strtoull(argv[2], NULL, 0);
-	readlen = strtoull(argv[3], NULL, 0);
-	flags = strtoul(argv[4], NULL, 0);
+	start = strtoull(argv[1], NULL, 0);
+	readlen = strtoull(argv[2], NULL, 0);
+	flags = strtoul(argv[3], NULL, 0);
 
-	fd = open(argv[1], O_RDONLY);
+	fd = open(argv[0], O_RDONLY);
 	if (fd < 0)
 		err(1, "open");
 
-	tcp_socketpair(ss);
+	if (pf_unix) {
+		if (socketpair(PF_LOCAL, SOCK_STREAM, 0, ss) != 0)
+			err(1, "socketpair");
+	} else
+		tcp_socketpair(ss);
 
 	error = pthread_create(&pt, NULL, receiver, &ss[1]);
 	if (error)
diff --git a/tests/sys/kern/sendfile_test.sh b/tests/sys/kern/sendfile_test.sh
index 03d87292f3a3..7e549eec610a 100755
--- a/tests/sys/kern/sendfile_test.sh
+++ b/tests/sys/kern/sendfile_test.sh
@@ -112,12 +112,36 @@ io_fail_async_cleanup()
 	common_cleanup
 }
 
+atf_test_case unix_success cleanup
+unix_success_head()
+{
+	atf_set "descr" "sendfile via unix(4) where all disk I/O succeeds"
+	atf_set "require.user" "root"
+	atf_set "timeout" 15
+}
+unix_success_body()
+{
+	if [ "$(atf_config_get qemu false)" = "true" ]; then
+	    atf_skip "Sendfile(4) unimplemented. https://github.com/qemu-bsd-user/qemu-bsd-user/issues/25"
+	fi
+
+	alloc_md md
+	common_body_setup $md
+
+	atf_check $HELPER -u $FILE 0 0x10000 0x10000
+}
+unix_success_cleanup()
+{
+	common_cleanup
+}
+
 
 atf_init_test_cases()
 {
 	atf_add_test_case io_success
 	atf_add_test_case io_fail_sync
 	atf_add_test_case io_fail_async
+	atf_add_test_case unix_success
 }
 
 alloc_md()