All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lucas De Marchi <lucas.de.marchi@gmail.com>
To: linux-modules@vger.kernel.org
Cc: Lucas De Marchi <lucas.de.marchi@gmail.com>
Subject: [PATCH 7/8] testsuite: Add tests for sleep calculation
Date: Fri,  3 Jun 2022 14:50:46 -0700	[thread overview]
Message-ID: <20220603215047.9607-8-lucas.de.marchi@gmail.com> (raw)
In-Reply-To: <20220603215047.9607-1-lucas.de.marchi@gmail.com>

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
---
 testsuite/test-util.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/testsuite/test-util.c b/testsuite/test-util.c
index 621446b..fb8c9ef 100644
--- a/testsuite/test-util.c
+++ b/testsuite/test-util.c
@@ -229,4 +229,45 @@ DEFINE_TEST(test_addu64_overflow,
 	);
 
 
+static int test_backoff_time(const struct test *t)
+{
+	unsigned long long delta;
+
+	/* Check exponential increments */
+	get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta);
+	assert_return(delta == 1, EXIT_FAILURE);
+	get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta);
+	assert_return(delta == 2, EXIT_FAILURE);
+	get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta);
+	assert_return(delta == 4, EXIT_FAILURE);
+	get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta);
+	assert_return(delta == 8, EXIT_FAILURE);
+
+	{
+		unsigned long long t0, tend;
+
+		/* Check tail */
+		delta = 4;
+		tend = now_msec() + 3;
+		t0 = tend - 10;
+		get_backoff_delta_msec(t0, tend, &delta);
+		assert_return(delta == 2, EXIT_FAILURE);
+		tend = now_msec() + 1;
+		t0 = tend - 9;
+		get_backoff_delta_msec(t0, tend, &delta);
+		assert_return(delta == 1, EXIT_FAILURE);
+		tend = now_msec();
+		t0 = tend - 10;
+		get_backoff_delta_msec(t0, tend, &delta);
+		assert_return(delta == 0, EXIT_FAILURE);
+	}
+
+	return EXIT_SUCCESS;
+}
+DEFINE_TEST(test_backoff_time,
+	.description = "check implementation of get_backoff_delta_msec()",
+	.need_spawn = false,
+	);
+
+
 TESTSUITE_MAIN();
-- 
2.36.1


  parent reply	other threads:[~2022-06-03 21:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-03 21:50 [PATCH 0/8] Add --wait to modprobe -r Lucas De Marchi
2022-06-03 21:50 ` [PATCH 1/8] modprobe: Move -R to "Query options" Lucas De Marchi
2022-06-03 21:50 ` [PATCH 2/8] libkmod: Allow to ignore log message on module removal Lucas De Marchi
2022-06-03 21:50 ` [PATCH 3/8] module-playground: Add debugfs entry in mod-simple Lucas De Marchi
2022-06-03 21:50 ` [PATCH 4/8] util: Add time-related functions from testsuite Lucas De Marchi
2022-06-03 21:50 ` [PATCH 5/8] util: Add msec variants for time-related functions Lucas De Marchi
2022-06-03 21:50 ` [PATCH 6/8] util: Add exponential backoff sleep Lucas De Marchi
2022-06-03 21:50 ` Lucas De Marchi [this message]
2022-06-03 21:50 ` [PATCH 8/8] modprobe: Add --wait Lucas De Marchi
2022-06-15 16:31 ` [PATCH 0/8] Add --wait to modprobe -r Lucas De Marchi
2022-06-27 16:46   ` Lucas De Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220603215047.9607-8-lucas.de.marchi@gmail.com \
    --to=lucas.de.marchi@gmail.com \
    --cc=linux-modules@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.