mirror of
https://github.com/golang/go
synced 2024-11-17 19:04:47 -07:00
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: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
f68f292820
commit
5c850cc207
@ -7,7 +7,6 @@
|
||||
package gc
|
||||
|
||||
import (
|
||||
"cmd/compile/internal/types"
|
||||
"reflect"
|
||||
"testing"
|
||||
"unsafe"
|
||||
@ -27,21 +26,6 @@ func TestSizeof(t *testing.T) {
|
||||
{Name{}, 36, 56},
|
||||
{Param{}, 28, 56},
|
||||
{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 {
|
||||
|
51
src/cmd/compile/internal/types/sizeof_test.go
Normal file
51
src/cmd/compile/internal/types/sizeof_test.go
Normal file
@ -0,0 +1,51 @@
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user