aboutsummaryrefslogtreecommitdiffstats
path: root/test/time.awk
diff options
context:
space:
mode:
authorAndrew J. Schorr <aschorr@telemetry-investments.com>2012-06-28 10:37:36 -0400
committerAndrew J. Schorr <aschorr@telemetry-investments.com>2012-06-28 10:37:36 -0400
commit47828911ae88038eda1051cfa2232f46eda95fd8 (patch)
treefbed9f28519113f2306e1865af0bb7b71348e2a1 /test/time.awk
parent2d0d82f7453b1c5ad5e1baa8c02c2f6d5e5ccb67 (diff)
downloadegawk-47828911ae88038eda1051cfa2232f46eda95fd8.tar.gz
egawk-47828911ae88038eda1051cfa2232f46eda95fd8.tar.bz2
egawk-47828911ae88038eda1051cfa2232f46eda95fd8.zip
Protect against race condition in test/time.awk.
Diffstat (limited to 'test/time.awk')
-rw-r--r--test/time.awk14
1 files changed, 12 insertions, 2 deletions
diff --git a/test/time.awk b/test/time.awk
index eeabc7bb..517377e2 100644
--- a/test/time.awk
+++ b/test/time.awk
@@ -1,10 +1,20 @@
@load "time"
+# make sure gettimeofday() is consistent with systime(). We must call
+# gettimeofday() before systime() to make sure the subtraction gives 0
+# without risk of rolling over to the next second.
+function timecheck(st,res) {
+ res = gettimeofday()
+ st = systime()
+ printf "gettimeofday - systime = %d\n", res-st
+ return res
+}
+
BEGIN {
delta = 1.3
- printf "gettimeofday - systime = %d\n", (t0 = gettimeofday())-systime()
+ t0 = timecheck()
printf "sleep(%s) = %s\n",delta,sleep(delta)
- printf "gettimeofday - systime = %d\n", (t1 = gettimeofday())-systime()
+ t1 = timecheck()
slept = t1-t0
if ((slept < 0.9*delta) || (slept > 1.3*delta))
printf "Warning: tried to sleep %.2f secs, but slept for %.2f secs\n",