github.com/FenixAra/go@v0.0.0-20170127160404-96ea0918e670/src/cmd/internal/obj/sizeof_test.go (about)

     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 obj
     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  		{Addr{}, 40, 64},
    26  		{LSym{}, 76, 128},
    27  		{Prog{}, 144, 224},
    28  	}
    29  
    30  	for _, tt := range tests {
    31  		want := tt._32bit
    32  		if _64bit {
    33  			want = tt._64bit
    34  		}
    35  		got := reflect.TypeOf(tt.val).Size()
    36  		if want != got {
    37  			t.Errorf("unsafe.Sizeof(%T) = %d, want %d", tt.val, got, want)
    38  		}
    39  	}
    40  }