diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2014-01-16 19:19:14 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2014-01-16 19:19:14 +0200 |
commit | 133196310e68de01021a3da02536b67eba7ef3e5 (patch) | |
tree | 8c4e33fe4590490509e7316fd33cc32139aa5347 /test | |
parent | 00db6f0be4e51725ab07db0e34164246bba57d16 (diff) | |
parent | a0414ef0949eaf66c467abd5009790a6f339b164 (diff) | |
download | egawk-133196310e68de01021a3da02536b67eba7ef3e5.tar.gz egawk-133196310e68de01021a3da02536b67eba7ef3e5.tar.bz2 egawk-133196310e68de01021a3da02536b67eba7ef3e5.zip |
Merge branch 'gawk-4.1-stable'
Diffstat (limited to 'test')
-rw-r--r-- | test/ChangeLog | 10 | ||||
-rw-r--r-- | test/Makefile.am | 4 | ||||
-rw-r--r-- | test/Makefile.in | 4 | ||||
-rw-r--r-- | test/strftime.awk | 34 |
4 files changed, 38 insertions, 14 deletions
diff --git a/test/ChangeLog b/test/ChangeLog index 52eade27..90e34c8b 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,13 @@ +2014-01-16 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * Makefile.am (strftime): Remove comment about the race condition, since + this should be fixed. And gawk now calls date inside the script. + * strftime.awk: Based on an idea from Pat Ranking, fix the race + condition by looping repeatedly over strftime/date/strftime until + the before and after strftime results match. That should fix + the race condition where the seconds field might increment between + invocations. + 2014-01-14 Arnold D. Robbins <arnold@skeeve.com> * Makefile.am (split_after_fpat): New test. diff --git a/test/Makefile.am b/test/Makefile.am index 56547d11..82492c41 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1254,12 +1254,10 @@ nonl:: @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ strftime:: - @echo This test could fail on slow machines or on a minute boundary, - @echo so if it does, double check the actual results: @echo $@ @GAWKLOCALE=C; export GAWKLOCALE; \ TZ=GMT0; export TZ; \ - (LC_ALL=C date) | $(AWK) -v OUTPUT=_$@ -f "$(srcdir)"/strftime.awk + $(AWK) -v OUTPUT=_$@ -f "$(srcdir)"/strftime.awk @-$(CMP) strftime.ok _$@ && rm -f _$@ strftime.ok || exit 0 litoct:: diff --git a/test/Makefile.in b/test/Makefile.in index 216dde28..3b088b7f 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -1678,12 +1678,10 @@ nonl:: @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ strftime:: - @echo This test could fail on slow machines or on a minute boundary, - @echo so if it does, double check the actual results: @echo $@ @GAWKLOCALE=C; export GAWKLOCALE; \ TZ=GMT0; export TZ; \ - (LC_ALL=C date) | $(AWK) -v OUTPUT=_$@ -f "$(srcdir)"/strftime.awk + $(AWK) -v OUTPUT=_$@ -f "$(srcdir)"/strftime.awk @-$(CMP) strftime.ok _$@ && rm -f _$@ strftime.ok || exit 0 litoct:: 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 } |