...
Source file
src/runtime/sizeof_test.go
Documentation: runtime
1
2
3
4
5 package runtime_test
6
7 import (
8 "internal/goexperiment"
9 "reflect"
10 "runtime"
11 "testing"
12 "unsafe"
13 )
14
15
16
17 func TestSizeof(t *testing.T) {
18 const _64bit = unsafe.Sizeof(uintptr(0)) == 8
19
20 g32bit := uintptr(256)
21 if goexperiment.ExecTracer2 {
22 g32bit = uintptr(260)
23 }
24
25 var tests = []struct {
26 val any
27 _32bit uintptr
28 _64bit uintptr
29 }{
30 {runtime.G{}, g32bit, 424},
31 {runtime.Sudog{}, 56, 88},
32 }
33
34 for _, tt := range tests {
35 want := tt._32bit
36 if _64bit {
37 want = tt._64bit
38 }
39 got := reflect.TypeOf(tt.val).Size()
40 if want != got {
41 t.Errorf("unsafe.Sizeof(%T) = %d, want %d", tt.val, got, want)
42 }
43 }
44 }
45
View as plain text