OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [time/] [tick_test.go] - Blame information for rev 833

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2009 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
 
5
package time_test
6
 
7
import (
8
        "testing"
9
        . "time"
10
)
11
 
12
func TestTicker(t *testing.T) {
13
        const (
14
                Delta = 100 * Millisecond
15
                Count = 10
16
        )
17
        ticker := NewTicker(Delta)
18
        t0 := Now()
19
        for i := 0; i < Count; i++ {
20
                <-ticker.C
21
        }
22
        ticker.Stop()
23
        t1 := Now()
24
        dt := t1.Sub(t0)
25
        target := Delta * Count
26
        slop := target * 2 / 10
27
        if dt < target-slop || dt > target+slop {
28
                t.Fatalf("%d %s ticks took %s, expected [%s,%s]", Count, Delta, dt, target-slop, target+slop)
29
        }
30
        // Now test that the ticker stopped
31
        Sleep(2 * Delta)
32
        select {
33
        case <-ticker.C:
34
                t.Fatal("Ticker did not shut down")
35
        default:
36
                // ok
37
        }
38
}
39
 
40
// Test that a bug tearing down a ticker has been fixed.  This routine should not deadlock.
41
func TestTeardown(t *testing.T) {
42
        for i := 0; i < 3; i++ {
43
                ticker := NewTicker(1e8)
44
                <-ticker.C
45
                ticker.Stop()
46
        }
47
}
48
 
49
func BenchmarkTicker(b *testing.B) {
50
        ticker := NewTicker(1)
51
        b.ResetTimer()
52
        b.StartTimer()
53
        for i := 0; i < b.N; i++ {
54
                <-ticker.C
55
        }
56
        b.StopTimer()
57
        ticker.Stop()
58
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.