]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgo/go/time/sleep_test.go
Add Go frontend, libgo library, and Go testsuite.
[thirdparty/gcc.git] / libgo / go / time / sleep_test.go
1 // 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 "os"
9 "syscall"
10 "testing"
11 . "time"
12 )
13
14 func TestSleep(t *testing.T) {
15 const delay = int64(100e6)
16 go func() {
17 Sleep(delay / 2)
18 syscall.Kill(os.Getpid(), syscall.SIGCHLD)
19 }()
20 start := Nanoseconds()
21 Sleep(delay)
22 duration := Nanoseconds() - start
23 if duration < delay {
24 t.Fatalf("Sleep(%d) slept for only %d ns", delay, duration)
25 }
26 }
27
28 func TestAfter(t *testing.T) {
29 const delay = int64(100e6)
30 start := Nanoseconds()
31 end := <-After(delay)
32 if duration := Nanoseconds() - start; duration < delay {
33 t.Fatalf("After(%d) slept for only %d ns", delay, duration)
34 }
35 if min := start + delay; end < min {
36 t.Fatalf("After(%d) expect >= %d, got %d", delay, min, end)
37 }
38 }