diff mbox series

[blktests] nvme/053: provide time extension alternative

Message ID 20241218111340.3912034-1-mcgrof@kernel.org (mailing list archive)
State New
Headers show
Series [blktests] nvme/053: provide time extension alternative | expand

Commit Message

Luis Chamberlain Dec. 18, 2024, 11:13 a.m. UTC
I get this failure when I run this test:

awk: ...rescan.awk:2: warning: The time extension is obsolete.
Use the timex extension from gawkextlib

I can't find this extension either, so just use systime() and
use system(sleep) for the sleep command.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 tests/nvme/053 | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Comments

Shinichiro Kawasaki Dec. 20, 2024, 11:37 a.m. UTC | #1
On Dec 18, 2024 / 03:13, Luis Chamberlain wrote:
> I get this failure when I run this test:
> 
> awk: ...rescan.awk:2: warning: The time extension is obsolete.
> Use the timex extension from gawkextlib

Hi Luis, thank you for catching this.

> I can't find this extension either, so just use systime() and
> use system(sleep) for the sleep command.

FYI, here I share the link to the past discussion that resulted in the awk
script in nvme/053 [1]. In that discussion, Martin noted that

   'But the fork-and-exec to "awk" is slow.'

So I wonder if this system(sleep) in the awk while loop could be slow also.

Assuming this system(sleep) approach is slow and not preferred, I suggest to go
back to the approach that the Martin's v1 patch took [2]. The while loop is
implemented with bash. The awk script was introduced for the float calculation
to get the random float number from 0.1 to 5.0. However, I think such
calculation can be done with bash as follows:

get_sleep_time() {
        local duration=$((RANDOM % 50 + 1))

	echo "$((duration / 10))"."$((duration % 10))"
}

With this, we should be able to drop the awk script form the test case.

Martin, what do you think?

[1] https://lore.kernel.org/linux-nvme/2cb6f86256803af00557f07e9573331c51111953.camel@suse.com/
[2] https://lore.kernel.org/linux-nvme/20240822193814.106111-3-mwilck@suse.com/
diff mbox series

Patch

diff --git a/tests/nvme/053 b/tests/nvme/053
index 3ade8d368be6..65a7b86519bc 100755
--- a/tests/nvme/053
+++ b/tests/nvme/053
@@ -27,13 +27,14 @@  rescan_controller() {
 
 create_rescan_script() {
 	cat >"$TMPDIR/rescan.awk" <<EOF
-@load "time"
-
 BEGIN {
     srand(seed);
-    finish = gettimeofday() + strtonum(timeout);
-    while (gettimeofday() < finish) {
-	sleep(0.1 + 5 * rand());
+    start_time = systime();
+    finish = start_time + strtonum(timeout);
+    while (systime() < finish) {
+	sleep_time = 0.1 + 5 * rand();
+        cmd = "sleep " sleep_time;
+        system(cmd);
 	printf("1\n") > path;
 	close(path);
     }