...
1
2
3
4
5 package unix_test
6
7 import (
8 "internal/goarch"
9 "internal/syscall/unix"
10 "runtime"
11 "strings"
12 "testing"
13 "unsafe"
14 )
15
16
17
18 func TestSiginfoChildLayout(t *testing.T) {
19 var si unix.SiginfoChild
20
21 const host64bit = goarch.PtrSize == 8
22
23 if v := unsafe.Sizeof(si); v != 128 {
24 t.Fatalf("sizeof: got %d, want 128", v)
25 }
26
27 ofSigno := 0
28 ofErrno := 4
29 ofCode := 8
30 if strings.HasPrefix(runtime.GOARCH, "mips") {
31
32 ofErrno, ofCode = ofCode, ofErrno
33 }
34 ofPid := 12
35 if host64bit {
36 ofPid = 16
37 }
38 ofUid := ofPid + 4
39 ofStatus := ofPid + 8
40
41 offsets := []struct {
42 name string
43 got uintptr
44 want int
45 }{
46 {"Signo", unsafe.Offsetof(si.Signo), ofSigno},
47 {"Errno", unsafe.Offsetof(si.Errno), ofErrno},
48 {"Code", unsafe.Offsetof(si.Code), ofCode},
49 {"Pid", unsafe.Offsetof(si.Pid), ofPid},
50 {"Uid", unsafe.Offsetof(si.Uid), ofUid},
51 {"Status", unsafe.Offsetof(si.Status), ofStatus},
52 }
53
54 for _, tc := range offsets {
55 if int(tc.got) != tc.want {
56 t.Errorf("offsetof %s: got %d, want %d", tc.name, tc.got, tc.want)
57 }
58 }
59 }
60
View as plain text