From a0414ef0949eaf66c467abd5009790a6f339b164 Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Thu, 16 Jan 2014 10:51:30 -0500 Subject: Fix strftime test race condition. --- test/strftime.awk | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'test/strftime.awk') diff --git a/test/strftime.awk b/test/strftime.awk index 775cd4e5..a52957f0 100644 --- a/test/strftime.awk +++ b/test/strftime.awk @@ -2,18 +2,36 @@ # # input is the output of `date', see Makefile.in # -# The mucking about with $0 and $N is to avoid problems +# The mucking about with $0 and $NF is to avoid problems # on cygwin, where the timezone field is empty and there # are two consecutive blanks. -# Additional mucking about to lop off the seconds field; -# helps decrease chance of difference due to a second boundary +BEGIN { + maxtries = 10 + datecmd = "date" + fmt = "%a %b %d %H:%M:%S %Z %Y" -{ - $3 = sprintf("%02d", $3 + 0) - $4 = substr($4, 1, 5) - print > "strftime.ok" - $0 = strftime("%a %b %d %H:%M %Z %Y") + # loop until before equals after, thereby protecting + # against a race condition where the seconds field might have + # incremented between running date and strftime + i = 0 + while (1) { + if (++i > maxtries) { + printf "Warning: this system is so slow that after %d attempts, we could never get two sequential invocations of strftime to give the same result!\n", maxtries > "/dev/stderr" + break + } + before = strftime(fmt) + datecmd | getline sd + after = strftime(fmt) + close(datecmd) + if (before == after) { + if (i > 1) + printf "Notice: it took %d loops to get the before and after strftime values to match\n", i > "/dev/stderr" + break + } + } + print sd > "strftime.ok" + $0 = after $NF = $NF print > OUTPUT } -- cgit v1.2.3 From 6520f31b24575ce7308a8b42c8b617568db6c4d8 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Tue, 28 Jan 2014 18:55:11 +0200 Subject: Fix the test suite for the pc ports. test/strftime.awk: If DATECMD variable is non-empty, use it instead of the literal "date" as the 'date'-like command. pc/Makefile.tst (strftime): Pass the value of 'date' command through the DATECMD variable. (readdir): Adapt to changes in test/readdir0.awk. --- test/strftime.awk | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'test/strftime.awk') diff --git a/test/strftime.awk b/test/strftime.awk index a52957f0..73cdc698 100644 --- a/test/strftime.awk +++ b/test/strftime.awk @@ -8,7 +8,11 @@ BEGIN { maxtries = 10 - datecmd = "date" + # On DOS/Windows, DATECMD is set by the Makefile to point to + # Unix-like 'date' command. + datecmd = DATECMD + if (datecmd == "") + datecmd = "date" fmt = "%a %b %d %H:%M:%S %Z %Y" # loop until before equals after, thereby protecting -- cgit v1.2.3 From 5a1e957a2cda7d1f0062454a1c6caa4c835bd201 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Mon, 3 Feb 2014 21:04:18 +0200 Subject: Fix strftime test. --- test/strftime.awk | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'test/strftime.awk') diff --git a/test/strftime.awk b/test/strftime.awk index 73cdc698..f1276c15 100644 --- a/test/strftime.awk +++ b/test/strftime.awk @@ -1,10 +1,6 @@ # strftime.awk ; test the strftime code # # input is the output of `date', see Makefile.in -# -# The mucking about with $0 and $NF is to avoid problems -# on cygwin, where the timezone field is empty and there -# are two consecutive blanks. BEGIN { maxtries = 10 @@ -13,7 +9,7 @@ BEGIN { datecmd = DATECMD if (datecmd == "") datecmd = "date" - fmt = "%a %b %d %H:%M:%S %Z %Y" + fmt = "%a %b %e %H:%M:%S %Z %Y" # loop until before equals after, thereby protecting # against a race condition where the seconds field might have @@ -35,7 +31,5 @@ BEGIN { } } print sd > "strftime.ok" - $0 = after - $NF = $NF - print > OUTPUT + print after > OUTPUT } -- cgit v1.2.3