Home | History | Annotate | Download | only in gc
      1 // Copyright 2016 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 
      7 package gc
      8 
      9 import (
     10 	"reflect"
     11 	"testing"
     12 	"unsafe"
     13 )
     14 
     15 // Assert that the size of important structures do not change unexpectedly.
     16 
     17 func TestSizeof(t *testing.T) {
     18 	const _64bit = unsafe.Sizeof(uintptr(0)) == 8
     19 
     20 	var tests = []struct {
     21 		val    interface{} // type as a value
     22 		_32bit uintptr     // size on 32bit platforms
     23 		_64bit uintptr     // size on 64bit platforms
     24 	}{
     25 		{Func{}, 92, 160},
     26 		{Name{}, 44, 72},
     27 		{Param{}, 24, 48},
     28 		{Node{}, 92, 144},
     29 		{Sym{}, 60, 112},
     30 		{Type{}, 60, 96},
     31 		{MapType{}, 20, 40},
     32 		{ForwardType{}, 16, 32},
     33 		{FuncType{}, 28, 48},
     34 		{StructType{}, 12, 24},
     35 		{InterType{}, 4, 8},
     36 		{ChanType{}, 8, 16},
     37 		{ArrayType{}, 16, 24},
     38 		{InterMethType{}, 4, 8},
     39 		{DDDFieldType{}, 4, 8},
     40 		{FuncArgsType{}, 4, 8},
     41 		{ChanArgsType{}, 4, 8},
     42 		{PtrType{}, 4, 8},
     43 		{SliceType{}, 4, 8},
     44 	}
     45 
     46 	for _, tt := range tests {
     47 		want := tt._32bit
     48 		if _64bit {
     49 			want = tt._64bit
     50 		}
     51 		got := reflect.TypeOf(tt.val).Size()
     52 		if want != got {
     53 			t.Errorf("unsafe.Sizeof(%T) = %d, want %d", tt.val, got, want)
     54 		}
     55 	}
     56 }
     57