Use __builtin_memmove for trivially copyable types
[official-gcc.git] / libgo / go / time / internal_test.go
blobe3f458fad09563f42529d3dc0a00c406e7724b7e
1 // Copyright 2011 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.
5 package time
7 import "runtime"
9 func init() {
10 // force US/Pacific for time zone tests
11 ForceUSPacificForTesting()
14 func initTestingZone() {
15 z, err := loadLocation("America/Los_Angeles", zoneSources[len(zoneSources)-1:])
16 if runtime.Compiler == "gccgo" && err != nil {
17 z, err = loadLocation("America/Los_Angeles", zoneSources)
19 if err != nil {
20 panic("cannot load America/Los_Angeles for testing: " + err.Error())
22 z.name = "Local"
23 localLoc = *z
26 var OrigZoneSources = zoneSources
28 func forceZipFileForTesting(zipOnly bool) {
29 zoneSources = make([]string, len(OrigZoneSources))
30 copy(zoneSources, OrigZoneSources)
31 if zipOnly {
32 zoneSources = zoneSources[len(zoneSources)-1:]
36 var Interrupt = interrupt
37 var DaysIn = daysIn
39 func empty(arg interface{}, seq uintptr) {}
41 // Test that a runtimeTimer with a duration so large it overflows
42 // does not cause other timers to hang.
44 // This test has to be in internal_test.go since it fiddles with
45 // unexported data structures.
46 func CheckRuntimeTimerOverflow() {
47 // We manually create a runtimeTimer to bypass the overflow
48 // detection logic in NewTimer: we're testing the underlying
49 // runtime.addtimer function.
50 r := &runtimeTimer{
51 when: runtimeNano() + (1<<63 - 1),
52 f: empty,
53 arg: nil,
55 startTimer(r)
57 // Start a goroutine that should send on t.C right away.
58 t := NewTimer(1)
60 defer func() {
61 // Subsequent tests won't work correctly if we don't stop the
62 // overflow timer and kick the timer proc back into service.
64 // The timer proc is now sleeping and can only be awoken by
65 // adding a timer to the *beginning* of the heap. We can't
66 // wake it up by calling NewTimer since other tests may have
67 // left timers running that should have expired before ours.
68 // Instead we zero the overflow timer duration and start it
69 // once more.
70 stopTimer(r)
71 t.Stop()
72 r.when = 0
73 startTimer(r)
74 }()
76 // If the test fails, we will hang here until the timeout in the testing package
77 // fires, which is 10 minutes. It would be nice to catch the problem sooner,
78 // but there is no reliable way to guarantee that timerproc schedules without
79 // doing something involving timerproc itself. Previous failed attempts have
80 // tried calling runtime.Gosched and runtime.GC, but neither is reliable.
81 // So we fall back to hope: We hope we don't hang here.
82 <-t.C