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