]> Cypherpunks repositories - gostls13.git/commitdiff
test/chan: avoid wrap-around in memstats comparison
authorCarl Shapiro <cshapiro@google.com>
Sat, 21 Sep 2013 00:27:56 +0000 (17:27 -0700)
committerCarl Shapiro <cshapiro@google.com>
Sat, 21 Sep 2013 00:27:56 +0000 (17:27 -0700)
The select2.go test assumed that the memory allocated between
its two samplings of runtime.ReadMemStats is strictly
increasing.  To avoid failing the tests when this is not true,
a greater-than check is introduced before computing the
difference in allocated memory.

R=golang-dev, r, cshapiro
CC=golang-dev
https://golang.org/cl/13701046

test/chan/select2.go

index 4a08139126192f87e72a39fed7ceb41a6ab90112..ccf9dab81bc2aab83c599ee173ed3123dcf31f34 100644 (file)
@@ -47,7 +47,8 @@ func main() {
        runtime.GC()
        runtime.ReadMemStats(memstats)
 
-       if memstats.Alloc-alloc > 1.1e5 {
+       // Be careful to avoid wraparound.
+       if memstats.Alloc > alloc && memstats.Alloc-alloc > 1.1e5 {
                println("BUG: too much memory for 100,000 selects:", memstats.Alloc-alloc)
        }
 }