aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types/sizeof_test.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2017-04-06 20:13:04 -0700
committerRobert Griesemer <gri@golang.org>2017-04-07 03:43:34 +0000
commit5c850cc207a8916073415bf406d002ef12173e3a (patch)
tree73c6d297e01e0bc42a1ba22de245da2eed511d0a /src/cmd/compile/internal/types/sizeof_test.go
parentf68f292820a3dc545aba0ee64a372635a64d5040 (diff)
downloadgo-5c850cc207a8916073415bf406d002ef12173e3a.tar.gz
go-5c850cc207a8916073415bf406d002ef12173e3a.zip
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>
Diffstat (limited to 'src/cmd/compile/internal/types/sizeof_test.go')
-rw-r--r--src/cmd/compile/internal/types/sizeof_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/types/sizeof_test.go b/src/cmd/compile/internal/types/sizeof_test.go
new file mode 100644
index 0000000000..a073f9b1a7
--- /dev/null
+++ b/src/cmd/compile/internal/types/sizeof_test.go
@@ -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)
+ }
+ }
+}