2016-03-06 13:04:52 +11:00
|
|
|
// Copyright 2016 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
// +build !nacl
|
|
|
|
|
|
|
|
|
|
package gc
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"reflect"
|
|
|
|
|
"testing"
|
|
|
|
|
"unsafe"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Assert that the size of important structures do not change unexpectedly.
|
|
|
|
|
|
|
|
|
|
func TestSizeof(t *testing.T) {
|
|
|
|
|
const _64bit = unsafe.Sizeof(uintptr(0)) == 8
|
|
|
|
|
|
|
|
|
|
var tests = []struct {
|
|
|
|
|
val interface{} // type as a value
|
|
|
|
|
_32bit uintptr // size on 32bit platforms
|
|
|
|
|
_64bit uintptr // size on 64bit platforms
|
|
|
|
|
}{
|
2017-04-07 19:50:31 +00:00
|
|
|
{Func{}, 96, 160},
|
2017-02-27 19:56:38 +02:00
|
|
|
{Name{}, 36, 56},
|
2016-10-28 11:42:40 -07:00
|
|
|
{Param{}, 28, 56},
|
2017-02-27 19:56:38 +02:00
|
|
|
{Node{}, 84, 136},
|
2016-03-06 13:04:52 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
want := tt._32bit
|
|
|
|
|
if _64bit {
|
|
|
|
|
want = tt._64bit
|
|
|
|
|
}
|
|
|
|
|
got := reflect.TypeOf(tt.val).Size()
|
|
|
|
|
if want != got {
|
2016-03-06 18:05:41 -08:00
|
|
|
t.Errorf("unsafe.Sizeof(%T) = %d, want %d", tt.val, got, want)
|
2016-03-06 13:04:52 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|