Source file
src/runtime/runtime_linux_test.go
1
2
3
4
5 package runtime_test
6
7 import (
8 . "runtime"
9 "syscall"
10 "testing"
11 "time"
12 "unsafe"
13 )
14
15 var pid, tid int
16
17 func init() {
18
19
20
21
22
23 pid, tid = syscall.Getpid(), syscall.Gettid()
24 LockOSThread()
25
26 sysNanosleep = func(d time.Duration) {
27
28
29 ts := syscall.NsecToTimespec(d.Nanoseconds())
30 for {
31 if err := syscall.Nanosleep(&ts, &ts); err != syscall.EINTR {
32 return
33 }
34 }
35 }
36 }
37
38 func TestLockOSThread(t *testing.T) {
39 if pid != tid {
40 t.Fatalf("pid=%d but tid=%d", pid, tid)
41 }
42 }
43
44
45
46 func TestMincoreErrorSign(t *testing.T) {
47 var dst byte
48 v := Mincore(Add(unsafe.Pointer(new(int32)), 1), 1, &dst)
49
50 const EINVAL = 0x16
51 if v != -EINVAL {
52 t.Errorf("mincore = %v, want %v", v, -EINVAL)
53 }
54 }
55
56 func TestEpollctlErrorSign(t *testing.T) {
57 v := Epollctl(-1, 1, -1, unsafe.Pointer(&EpollEvent{}))
58
59 const EBADF = 0x09
60 if v != -EBADF {
61 t.Errorf("epollctl = %v, want %v", v, -EBADF)
62 }
63 }
64
65 func TestKernelStructSize(t *testing.T) {
66
67
68 if have, want := unsafe.Sizeof(Siginfo{}), uintptr(SiginfoMaxSize); have != want {
69 t.Errorf("Go's siginfo struct is %d bytes long; kernel expects %d", have, want)
70 }
71 if have, want := unsafe.Sizeof(Sigevent{}), uintptr(SigeventMaxSize); have != want {
72 t.Errorf("Go's sigevent struct is %d bytes long; kernel expects %d", have, want)
73 }
74 }
75
View as plain text