public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH liburing 0/3] extra tests
@ 2022-04-17  9:09 Pavel Begunkov
  2022-04-17  9:09 ` [PATCH liburing 1/3] tests: reduce multicqe_drain waiting time Pavel Begunkov
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Pavel Begunkov @ 2022-04-17  9:09 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe, asml.silence

2 and 3 add extra tests that were useful during the SCM patching and
rsrc refactoring. 1/3 tames the multicqe_drain's execution time.

Pavel Begunkov (3):
  tests: reduce multicqe_drain waiting time
  tests: extend scm cycle breaking tests
  tests: add more file registration tests

 test/file-register.c   | 95 ++++++++++++++++++++++++++++++++++++++++++
 test/multicqes_drain.c |  4 +-
 test/ring-leak.c       | 84 +++++++++++++++++++++++++++++++++++++
 3 files changed, 181 insertions(+), 2 deletions(-)

-- 
2.35.2


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH liburing 1/3] tests: reduce multicqe_drain waiting time
  2022-04-17  9:09 [PATCH liburing 0/3] extra tests Pavel Begunkov
@ 2022-04-17  9:09 ` Pavel Begunkov
  2022-04-17  9:09 ` [PATCH liburing 2/3] tests: extend scm cycle breaking tests Pavel Begunkov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2022-04-17  9:09 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe, asml.silence

sleep(4) is too long and not needed, wait just for one second, should be
good enough.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 test/multicqes_drain.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/test/multicqes_drain.c b/test/multicqes_drain.c
index ff6fa7d..b16dc52 100644
--- a/test/multicqes_drain.c
+++ b/test/multicqes_drain.c
@@ -224,7 +224,7 @@ static int test_generic_drain(struct io_uring *ring)
 		goto err;
 	}
 
-	sleep(4);
+	sleep(1);
 	// TODO: randomize event triggerring order
 	for (i = 0; i < max_entry; i++) {
 		if (si[i].op != multi && si[i].op != single)
@@ -233,7 +233,7 @@ static int test_generic_drain(struct io_uring *ring)
 		if (trigger_event(pipes[i]))
 			goto err;
 	}
-	sleep(5);
+	sleep(1);
 	i = 0;
 	while (!io_uring_peek_cqe(ring, &cqe)) {
 		cqe_data[i] = cqe->user_data;
-- 
2.35.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH liburing 2/3] tests: extend scm cycle breaking tests
  2022-04-17  9:09 [PATCH liburing 0/3] extra tests Pavel Begunkov
  2022-04-17  9:09 ` [PATCH liburing 1/3] tests: reduce multicqe_drain waiting time Pavel Begunkov
@ 2022-04-17  9:09 ` Pavel Begunkov
  2022-04-17  9:09 ` [PATCH liburing 3/3] tests: add more file registration tests Pavel Begunkov
  2022-04-17 13:01 ` (subset) [PATCH liburing 0/3] extra tests Jens Axboe
  3 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2022-04-17  9:09 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe, asml.silence

Add a test with file ref dependency, which is actually checks that the
files are removed and put.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 test/ring-leak.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff --git a/test/ring-leak.c b/test/ring-leak.c
index f8f043c..5b739ad 100644
--- a/test/ring-leak.c
+++ b/test/ring-leak.c
@@ -131,12 +131,84 @@ static int test_iowq_request_cancel(void)
 	ret = read(fds[0], buffer, 10);
 	if (ret < 0)
 		perror("read");
+	close(fds[0]);
+	return 0;
+}
+
+static int test_scm_cycles(bool update)
+{
+	char buffer[128];
+	struct io_uring ring;
+	int i, ret;
+	int sp[2], fds[2], reg_fds[4];
+
+	if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sp) != 0) {
+		perror("Failed to create Unix-domain socket pair\n");
+		return 1;
+	}
+	ret = io_uring_queue_init(8, &ring, 0);
+	if (ret < 0) {
+		fprintf(stderr, "failed to init io_uring: %s\n", strerror(-ret));
+		return ret;
+	}
+	if (pipe(fds)) {
+		perror("pipe");
+		return -1;
+	}
+	send_fd(sp[0], ring.ring_fd);
+
+	/* register an empty set for updates */
+	if (update) {
+		for (i = 0; i < 4; i++)
+			reg_fds[i] = -1;
+		ret = io_uring_register_files(&ring, reg_fds, 4);
+		if (ret) {
+			fprintf(stderr, "file_register: %d\n", ret);
+			return ret;
+		}
+	}
+
+	reg_fds[0] = fds[0];
+	reg_fds[1] = fds[1];
+	reg_fds[2] = sp[0];
+	reg_fds[3] = sp[1];
+	if (update) {
+		ret = io_uring_register_files_update(&ring, 0, reg_fds, 4);
+		if (ret != 4) {
+			fprintf(stderr, "file_register: %d\n", ret);
+			return ret;
+		}
+	} else {
+		ret = io_uring_register_files(&ring, reg_fds, 4);
+		if (ret) {
+			fprintf(stderr, "file_register: %d\n", ret);
+			return ret;
+		}
+	}
+
+	close(fds[1]);
+	close(sp[0]);
+	close(sp[1]);
+
+	/* should unregister files and close the write fd */
+	io_uring_queue_exit(&ring);
+
+	/*
+	 * We're trying to wait for the ring to "really" exit, that will be
+	 * done async. For that rely on the registered write end to be closed
+	 * after ring quiesce, so failing read from the other pipe end.
+	 */
+	ret = read(fds[0], buffer, 10);
+	if (ret < 0)
+		perror("read");
+	close(fds[0]);
 	return 0;
 }
 
 int main(int argc, char *argv[])
 {
 	int sp[2], pid, ring_fd, ret;
+	int i;
 
 	if (argc > 1)
 		return 0;
@@ -147,6 +219,18 @@ int main(int argc, char *argv[])
 		return 1;
 	}
 
+	for (i = 0; i < 2; i++) {
+		bool update = !!(i & 1);
+
+		ret = test_scm_cycles(update);
+		if (ret) {
+			fprintf(stderr, "test_scm_cycles() failed %i\n",
+				update);
+			return 1;
+		}
+		break;
+	}
+
 	if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sp) != 0) {
 		perror("Failed to create Unix-domain socket pair\n");
 		return 1;
-- 
2.35.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH liburing 3/3] tests: add more file registration tests
  2022-04-17  9:09 [PATCH liburing 0/3] extra tests Pavel Begunkov
  2022-04-17  9:09 ` [PATCH liburing 1/3] tests: reduce multicqe_drain waiting time Pavel Begunkov
  2022-04-17  9:09 ` [PATCH liburing 2/3] tests: extend scm cycle breaking tests Pavel Begunkov
@ 2022-04-17  9:09 ` Pavel Begunkov
  2022-04-17 13:00   ` Jens Axboe
  2022-04-17 13:01 ` (subset) [PATCH liburing 0/3] extra tests Jens Axboe
  3 siblings, 1 reply; 7+ messages in thread
From: Pavel Begunkov @ 2022-04-17  9:09 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe, asml.silence

Add tests for file registration failing in the middle of the fd set, and
mixing files that need and don't SCM accounting + checking for
underflows.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 test/file-register.c | 95 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)

diff --git a/test/file-register.c b/test/file-register.c
index bd15408..ee2fdcd 100644
--- a/test/file-register.c
+++ b/test/file-register.c
@@ -745,7 +745,90 @@ static int test_fixed_removal_ordering(void)
 	return 0;
 }
 
+/* mix files requiring SCM-accounting and not in a single register */
+static int test_mixed_af_unix(void)
+{
+	struct io_uring ring;
+	int i, ret, fds[2];
+	int reg_fds[32];
+	int sp[2];
+
+	ret = io_uring_queue_init(8, &ring, 0);
+	if (ret < 0) {
+		fprintf(stderr, "failed to init io_uring: %s\n", strerror(-ret));
+		return ret;
+	}
+	if (pipe(fds)) {
+		perror("pipe");
+		return -1;
+	}
+	if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sp) != 0) {
+		perror("Failed to create Unix-domain socket pair\n");
+		return 1;
+	}
+
+	for (i = 0; i < 16; i++) {
+		reg_fds[i * 2] = fds[0];
+		reg_fds[i * 2 + 1] = sp[0];
+	}
 
+	ret = io_uring_register_files(&ring, reg_fds, 32);
+	if (!ret) {
+		fprintf(stderr, "file_register: %d\n", ret);
+		return ret;
+	}
+
+	close(fds[0]);
+	close(fds[1]);
+	close(sp[0]);
+	close(sp[1]);
+	io_uring_queue_exit(&ring);
+	return 0;
+}
+
+static int test_partial_register_fail(void)
+{
+	char buffer[128];
+	struct io_uring ring;
+	int ret, fds[2];
+	int reg_fds[5];
+
+	ret = io_uring_queue_init(8, &ring, 0);
+	if (ret < 0) {
+		fprintf(stderr, "failed to init io_uring: %s\n", strerror(-ret));
+		return ret;
+	}
+	if (pipe(fds)) {
+		perror("pipe");
+		return -1;
+	}
+
+	/*
+	 * Expect register to fail as it doesn't support io_uring fds, shouldn't
+	 * leave any fds referenced afterwards.
+	 */
+	reg_fds[0] = fds[0];
+	reg_fds[1] = fds[1];
+	reg_fds[2] = -1;
+	reg_fds[3] = ring.ring_fd;
+	reg_fds[4] = -1;
+	ret = io_uring_register_files(&ring, reg_fds, 5);
+	if (!ret) {
+		fprintf(stderr, "file_register: %d\n", ret);
+		return ret;
+	}
+
+	/* ring should have fds referenced, can close them */
+	close(fds[1]);
+
+	/* confirm that fds[1] is actually close and to ref'ed by io_uring */
+	ret = read(fds[0], buffer, 10);
+	if (ret < 0)
+		perror("read");
+	close(fds[0]);
+	io_uring_queue_exit(&ring);
+	return 0;
+}
 
 int main(int argc, char *argv[])
 {
@@ -854,5 +937,17 @@ int main(int argc, char *argv[])
 		return 1;
 	}
 
+	ret = test_mixed_af_unix();
+	if (ret) {
+		printf("test_mixed_af_unix failed\n");
+		return 1;
+	}
+
+	ret = test_partial_register_fail();
+	if (ret) {
+		printf("test_partial_register_fail failed\n");
+		return ret;
+	}
+
 	return 0;
 }
-- 
2.35.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH liburing 3/3] tests: add more file registration tests
  2022-04-17  9:09 ` [PATCH liburing 3/3] tests: add more file registration tests Pavel Begunkov
@ 2022-04-17 13:00   ` Jens Axboe
  2022-04-17 14:28     ` Pavel Begunkov
  0 siblings, 1 reply; 7+ messages in thread
From: Jens Axboe @ 2022-04-17 13:00 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring

On 4/17/22 3:09 AM, Pavel Begunkov wrote:
> diff --git a/test/file-register.c b/test/file-register.c
> index bd15408..ee2fdcd 100644
> --- a/test/file-register.c
> +++ b/test/file-register.c
> @@ -745,7 +745,90 @@ static int test_fixed_removal_ordering(void)
>  	return 0;
>  }
>  
> +/* mix files requiring SCM-accounting and not in a single register */
> +static int test_mixed_af_unix(void)
> +{
> +	struct io_uring ring;
> +	int i, ret, fds[2];
> +	int reg_fds[32];
> +	int sp[2];
> +
> +	ret = io_uring_queue_init(8, &ring, 0);
> +	if (ret < 0) {
> +		fprintf(stderr, "failed to init io_uring: %s\n", strerror(-ret));
> +		return ret;
> +	}
> +	if (pipe(fds)) {
> +		perror("pipe");
> +		return -1;
> +	}
> +	if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sp) != 0) {
> +		perror("Failed to create Unix-domain socket pair\n");
> +		return 1;
> +	}
> +
> +	for (i = 0; i < 16; i++) {
> +		reg_fds[i * 2] = fds[0];
> +		reg_fds[i * 2 + 1] = sp[0];
> +	}
>  
> +	ret = io_uring_register_files(&ring, reg_fds, 32);
> +	if (!ret) {
> +		fprintf(stderr, "file_register: %d\n", ret);
> +		return ret;
> +	}

This check looks wrong.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: (subset) [PATCH liburing 0/3] extra tests
  2022-04-17  9:09 [PATCH liburing 0/3] extra tests Pavel Begunkov
                   ` (2 preceding siblings ...)
  2022-04-17  9:09 ` [PATCH liburing 3/3] tests: add more file registration tests Pavel Begunkov
@ 2022-04-17 13:01 ` Jens Axboe
  3 siblings, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2022-04-17 13:01 UTC (permalink / raw)
  To: asml.silence, io-uring

On Sun, 17 Apr 2022 10:09:22 +0100, Pavel Begunkov wrote:
> 2 and 3 add extra tests that were useful during the SCM patching and
> rsrc refactoring. 1/3 tames the multicqe_drain's execution time.
> 
> Pavel Begunkov (3):
>   tests: reduce multicqe_drain waiting time
>   tests: extend scm cycle breaking tests
>   tests: add more file registration tests
> 
> [...]

Applied, thanks!

[1/3] tests: reduce multicqe_drain waiting time
      commit: e0aa6fceed8e9a36325ae3d6d83b0dfb73aea2ca
[2/3] tests: extend scm cycle breaking tests
      commit: c1459b2c99f0bb2554d181d9bf55388814add1a5

Best regards,
-- 
Jens Axboe



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH liburing 3/3] tests: add more file registration tests
  2022-04-17 13:00   ` Jens Axboe
@ 2022-04-17 14:28     ` Pavel Begunkov
  0 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2022-04-17 14:28 UTC (permalink / raw)
  To: Jens Axboe, io-uring

On 4/17/22 14:00, Jens Axboe wrote:
> On 4/17/22 3:09 AM, Pavel Begunkov wrote:
>> diff --git a/test/file-register.c b/test/file-register.c
>> index bd15408..ee2fdcd 100644
>> --- a/test/file-register.c
>> +++ b/test/file-register.c
>> @@ -745,7 +745,90 @@ static int test_fixed_removal_ordering(void)
>>   	return 0;
>>   }
>>   
>> +/* mix files requiring SCM-accounting and not in a single register */
>> +static int test_mixed_af_unix(void)
>> +{
>> +	struct io_uring ring;
>> +	int i, ret, fds[2];
>> +	int reg_fds[32];
>> +	int sp[2];
>> +
>> +	ret = io_uring_queue_init(8, &ring, 0);
>> +	if (ret < 0) {
>> +		fprintf(stderr, "failed to init io_uring: %s\n", strerror(-ret));
>> +		return ret;
>> +	}
>> +	if (pipe(fds)) {
>> +		perror("pipe");
>> +		return -1;
>> +	}
>> +	if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sp) != 0) {
>> +		perror("Failed to create Unix-domain socket pair\n");
>> +		return 1;
>> +	}
>> +
>> +	for (i = 0; i < 16; i++) {
>> +		reg_fds[i * 2] = fds[0];
>> +		reg_fds[i * 2 + 1] = sp[0];
>> +	}
>>   
>> +	ret = io_uring_register_files(&ring, reg_fds, 32);
>> +	if (!ret) {
>> +		fprintf(stderr, "file_register: %d\n", ret);
>> +		return ret;
>> +	}
> 
> This check looks wrong.

Agree, resending it

-- 
Pavel Begunkov

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-04-17 14:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-17  9:09 [PATCH liburing 0/3] extra tests Pavel Begunkov
2022-04-17  9:09 ` [PATCH liburing 1/3] tests: reduce multicqe_drain waiting time Pavel Begunkov
2022-04-17  9:09 ` [PATCH liburing 2/3] tests: extend scm cycle breaking tests Pavel Begunkov
2022-04-17  9:09 ` [PATCH liburing 3/3] tests: add more file registration tests Pavel Begunkov
2022-04-17 13:00   ` Jens Axboe
2022-04-17 14:28     ` Pavel Begunkov
2022-04-17 13:01 ` (subset) [PATCH liburing 0/3] extra tests Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox