public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH liburing v2] tests: add another timeout sequence test case
@ 2021-01-21 18:15 Marcelo Diop-Gonzalez
  2021-01-25  4:33 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Marcelo Diop-Gonzalez @ 2021-01-21 18:15 UTC (permalink / raw)
  To: axboe; +Cc: asml.silence, io-uring, Marcelo Diop-Gonzalez

This test case catches an issue where timeouts may not be flushed
if the number of new events is greater (not equal) to the number
of events requested in the timeout.

Signed-off-by: Marcelo Diop-Gonzalez <[email protected]>
---

v2: Don't assume the timeout should be last when nr < 2.

 test/timeout.c | 40 +++++++++++++++++++---------------------
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/test/timeout.c b/test/timeout.c
index 9c8211c..a28d599 100644
--- a/test/timeout.c
+++ b/test/timeout.c
@@ -112,7 +112,7 @@ err:
 /*
  * Test numbered trigger of timeout
  */
-static int test_single_timeout_nr(struct io_uring *ring)
+static int test_single_timeout_nr(struct io_uring *ring, int nr)
 {
 	struct io_uring_cqe *cqe;
 	struct io_uring_sqe *sqe;
@@ -126,7 +126,7 @@ static int test_single_timeout_nr(struct io_uring *ring)
 	}
 
 	msec_to_ts(&ts, TIMEOUT_MSEC);
-	io_uring_prep_timeout(sqe, &ts, 2, 0);
+	io_uring_prep_timeout(sqe, &ts, nr, 0);
 
 	sqe = io_uring_get_sqe(ring);
 	io_uring_prep_nop(sqe);
@@ -149,33 +149,26 @@ static int test_single_timeout_nr(struct io_uring *ring)
 			goto err;
 		}
 
+		ret = cqe->res;
+
 		/*
 		 * NOP commands have user_data as 1. Check that we get the
-		 * two NOPs first, then the successfully removed timout as
-		 * the last one.
+		 * at least 'nr' NOPs first, then the successfully removed timout.
 		 */
-		switch (i) {
-		case 0:
-		case 1:
-			if (io_uring_cqe_get_data(cqe) != (void *) 1) {
-				fprintf(stderr, "%s: nop not seen as 1 or 2\n", __FUNCTION__);
+		if (io_uring_cqe_get_data(cqe) == NULL) {
+			if (i < nr) {
+				fprintf(stderr, "%s: timeout received too early\n", __FUNCTION__);
 				goto err;
 			}
-			break;
-		case 2:
-			if (io_uring_cqe_get_data(cqe) != NULL) {
-				fprintf(stderr, "%s: timeout not last\n", __FUNCTION__);
+			if (ret) {
+				fprintf(stderr, "%s: timeout triggered by passage of"
+					" time, not by events completed\n", __FUNCTION__);
 				goto err;
 			}
-			break;
 		}
 
-		ret = cqe->res;
 		io_uring_cqe_seen(ring, cqe);
-		if (ret < 0) {
-			fprintf(stderr, "Timeout: %s\n", strerror(-ret));
-			goto err;
-		} else if (ret) {
+		if (ret) {
 			fprintf(stderr, "res: %d\n", ret);
 			goto err;
 		}
@@ -1224,9 +1217,14 @@ int main(int argc, char *argv[])
 		return ret;
 	}
 
-	ret = test_single_timeout_nr(&ring);
+	ret = test_single_timeout_nr(&ring, 1);
+	if (ret) {
+		fprintf(stderr, "test_single_timeout_nr(1) failed\n");
+		return ret;
+	}
+	ret = test_single_timeout_nr(&ring, 2);
 	if (ret) {
-		fprintf(stderr, "test_single_timeout_nr failed\n");
+		fprintf(stderr, "test_single_timeout_nr(2) failed\n");
 		return ret;
 	}
 
-- 
2.20.1


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

* Re: [PATCH liburing v2] tests: add another timeout sequence test case
  2021-01-21 18:15 [PATCH liburing v2] tests: add another timeout sequence test case Marcelo Diop-Gonzalez
@ 2021-01-25  4:33 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2021-01-25  4:33 UTC (permalink / raw)
  To: Marcelo Diop-Gonzalez; +Cc: asml.silence, io-uring

On 1/21/21 11:15 AM, Marcelo Diop-Gonzalez wrote:
> This test case catches an issue where timeouts may not be flushed
> if the number of new events is greater (not equal) to the number
> of events requested in the timeout.

Applied, thanks.

-- 
Jens Axboe


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

end of thread, other threads:[~2021-01-25  4:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-21 18:15 [PATCH liburing v2] tests: add another timeout sequence test case Marcelo Diop-Gonzalez
2021-01-25  4:33 ` Jens Axboe

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