summaryrefslogtreecommitdiffstats
path: root/tests/clock.test
diff options
context:
space:
mode:
authorsebres <sebres@users.sourceforge.net>2019-01-10 14:43:25 (GMT)
committersebres <sebres@users.sourceforge.net>2019-01-10 14:43:25 (GMT)
commit66865f387ea4608111a688745f457a3e1323880b (patch)
treeacdb998d03febe07d1fc4328c15c9a032f28a454 /tests/clock.test
parent2aee61ea3055c9d7212040a402680c89b8df2a9e (diff)
parent4693981b235565c28349466192503fb764e5e55e (diff)
downloadtcl-66865f387ea4608111a688745f457a3e1323880b.zip
tcl-66865f387ea4608111a688745f457a3e1323880b.tar.gz
tcl-66865f387ea4608111a688745f457a3e1323880b.tar.bz2
merge 8.6
Diffstat (limited to 'tests/clock.test')
-rw-r--r--tests/clock.test80
1 files changed, 44 insertions, 36 deletions
diff --git a/tests/clock.test b/tests/clock.test
index 2b8c757..0e143ec 100644
--- a/tests/clock.test
+++ b/tests/clock.test
@@ -270,6 +270,18 @@ proc ::testClock::registry { cmd path key } {
return [dict get $reg $path $key]
}
+proc timeWithinDuration {duration start end} {
+ regexp {([\d.]+)(s|ms|us)} $duration -> duration unit
+ if {[llength $start] > 1} { set start [expr "([join $start +])/[llength $start]"] }
+ if {[llength $end] > 1} { set end [expr "([join $end +])/[llength $end]"] }
+ set delta [expr {$end - $start}]
+ expr {
+ ($delta > 0) && ($delta <= $duration) ?
+ "ok" :
+ "test should have taken 0-$duration $unit, actually took $delta"}
+}
+
+
# Base test cases:
test clock-0.1 "initial: auto-loading of ensemble and stubs on demand" no_tclclockmod {
@@ -35730,7 +35742,7 @@ test clock-33.2 {clock clicks tests} {
set start [clock clicks]
after 10
set end [clock clicks]
- expr "$end > $start"
+ expr {$end > $start}
} {1}
test clock-33.3 {clock clicks tests} {
list [catch {clock clicks foo} msg] $msg
@@ -35744,28 +35756,22 @@ test clock-33.4a {clock milliseconds} {
concat {}
} {}
test clock-33.5 {clock clicks tests, millisecond timing test} {
- # This test can fail on a system that is so heavily loaded that
- # the test takes >60 ms to run.
- set start [clock clicks -milli]
- after 10
- set end [clock clicks -milli]
- # 60 msecs seems to be the max time slice under Windows 95/98
- expr {
- ($end > $start) && (($end - $start) <= 60) ?
- "ok" :
- "test should have taken 0-60 ms, actually took [expr $end - $start]"}
+ set start [set end {}]
+ lassign [time {
+ lappend start [clock clicks -milli]
+ after 1 {lappend end [clock clicks -milli]}
+ vwait end
+ } 5] tm
+ timeWithinDuration [expr {int($tm/1000 + 1)}]ms $start $end
} {ok}
test clock-33.5a {clock tests, millisecond timing test} {
- # This test can fail on a system that is so heavily loaded that
- # the test takes >60 ms to run.
- set start [clock milliseconds]
- after 10
- set end [clock milliseconds]
- # 60 msecs seems to be the max time slice under Windows 95/98
- expr {
- ($end > $start) && (($end - $start) <= 60) ?
- "ok" :
- "test should have taken 0-60 ms, actually took [expr $end - $start]"}
+ set start [set end {}]
+ lassign [time {
+ lappend start [clock milliseconds]
+ after 1 {lappend end [clock milliseconds]}
+ vwait end
+ } 5] tm
+ timeWithinDuration [expr {int($tm/1000 + 1)}]ms $start $end
} {ok}
test clock-33.6 {clock clicks, milli with too much abbreviation} {
list [catch { clock clicks ? } msg] $msg
@@ -35775,21 +35781,23 @@ test clock-33.7 {clock clicks, milli with too much abbreviation} {
} {1 {ambiguous option "-": must be -milliseconds or -microseconds}}
test clock-33.8 {clock clicks test, microsecond timing test} {
- # This test can fail on a system that is so heavily loaded that
- # the test takes >60 ms to run.
- set start [clock clicks -micro]
- after 10
- set end [clock clicks -micro]
- expr {($end > $start) && (($end - $start) <= 60000)}
-} {1}
+ set start [set end {}]
+ lassign [time {
+ lappend start [clock clicks -micro]
+ after 1 {lappend end [clock clicks -micro]}
+ vwait end
+ } 5] tm
+ timeWithinDuration [expr {int($tm + 10)}]us $start $end
+} {ok}
test clock-33.8a {clock test, microsecond timing test} {
- # This test can fail on a system that is so heavily loaded that
- # the test takes >60 ms to run.
- set start [clock microseconds]
- after 10
- set end [clock microseconds]
- expr {($end > $start) && (($end - $start) <= 60000)}
-} {1}
+ set start [set end {}]
+ lassign [time {
+ lappend start [clock microseconds]
+ after 1 {lappend end [clock microseconds]}
+ vwait end
+ } 5] tm
+ timeWithinDuration [expr {int($tm + 10)}]us $start $end
+} {ok}
test clock-33.9 {clock clicks test, millis align with seconds} {
set t1 [clock seconds]
@@ -36342,7 +36350,7 @@ test clock-35.3 {clock seconds tests} {
set start [clock seconds]
after 2000
set end [clock seconds]
- expr "$end > $start"
+ expr {$end > $start}
} {1}