Commit 5c850cc2 authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile: move sizeof tests for types structs to package types

Change-Id: I04cd4dd0ed55b88247a056b429fc496539cd0985
Reviewed-on: https://go-review.googlesource.com/39910
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
parent f68f2928
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
package gc package gc
import ( import (
"cmd/compile/internal/types"
"reflect" "reflect"
"testing" "testing"
"unsafe" "unsafe"
...@@ -27,21 +26,6 @@ func TestSizeof(t *testing.T) { ...@@ -27,21 +26,6 @@ func TestSizeof(t *testing.T) {
{Name{}, 36, 56}, {Name{}, 36, 56},
{Param{}, 28, 56}, {Param{}, 28, 56},
{Node{}, 84, 136}, {Node{}, 84, 136},
// TODO(gri) test the ones below in the types package
{types.Sym{}, 60, 104},
{types.Type{}, 52, 88},
{types.MapType{}, 20, 40},
{types.ForwardType{}, 20, 32},
{types.FuncType{}, 28, 48},
{types.StructType{}, 12, 24},
{types.InterType{}, 4, 8},
{types.ChanType{}, 8, 16},
{types.ArrayType{}, 12, 16},
{types.DDDFieldType{}, 4, 8},
{types.FuncArgsType{}, 4, 8},
{types.ChanArgsType{}, 4, 8},
{types.PtrType{}, 4, 8},
{types.SliceType{}, 4, 8},
} }
for _, tt := range tests { for _, tt := range tests {
......
// Copyright 2017 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 types
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
}{
{Sym{}, 60, 104},
{Type{}, 52, 88},
{MapType{}, 20, 40},
{ForwardType{}, 20, 32},
{FuncType{}, 28, 48},
{StructType{}, 12, 24},
{InterType{}, 4, 8},
{ChanType{}, 8, 16},
{ArrayType{}, 12, 16},
{DDDFieldType{}, 4, 8},
{FuncArgsType{}, 4, 8},
{ChanArgsType{}, 4, 8},
{PtrType{}, 4, 8},
{SliceType{}, 4, 8},
}
for _, tt := range tests {
want := tt._32bit
if _64bit {
want = tt._64bit
}
got := reflect.TypeOf(tt.val).Size()
if want != got {
t.Errorf("unsafe.Sizeof(%T) = %d, want %d", tt.val, got, want)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment