1// Copyright 2018 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// +build !nacl 6 7package runtime_test 8 9import ( 10 "reflect" 11 "runtime" 12 "testing" 13 "unsafe" 14) 15 16// Assert that the size of important structures do not change unexpectedly. 17 18func TestSizeof(t *testing.T) { 19 if runtime.Compiler != "gc" { 20 t.Skip("skipping size test; specific to gc compiler") 21 } 22 23 const _64bit = unsafe.Sizeof(uintptr(0)) == 8 24 25 var tests = []struct { 26 val interface{} // type as a value 27 _32bit uintptr // size on 32bit platforms 28 _64bit uintptr // size on 64bit platforms 29 }{ 30 {runtime.G{}, 216, 376}, // g, but exported for testing 31 } 32 33 for _, tt := range tests { 34 want := tt._32bit 35 if _64bit { 36 want = tt._64bit 37 } 38 got := reflect.TypeOf(tt.val).Size() 39 if want != got { 40 t.Errorf("unsafe.Sizeof(%T) = %d, want %d", tt.val, got, want) 41 } 42 } 43} 44