1// Copyright 2018 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
5package runtime_test
6
7import (
8	"reflect"
9	"runtime"
10	"testing"
11	"unsafe"
12)
13
14// Assert that the size of important structures do not change unexpectedly.
15
16func TestSizeof(t *testing.T) {
17	if runtime.Compiler != "gc" {
18		t.Skip("skipping size test; specific to gc compiler")
19	}
20
21	const _64bit = unsafe.Sizeof(uintptr(0)) == 8
22
23	var tests = []struct {
24		val    interface{} // type as a value
25		_32bit uintptr     // size on 32bit platforms
26		_64bit uintptr     // size on 64bit platforms
27	}{
28		{runtime.G{}, 216, 376}, // g, but exported for testing
29	}
30
31	for _, tt := range tests {
32		want := tt._32bit
33		if _64bit {
34			want = tt._64bit
35		}
36		got := reflect.TypeOf(tt.val).Size()
37		if want != got {
38			t.Errorf("unsafe.Sizeof(%T) = %d, want %d", tt.val, got, want)
39		}
40	}
41}
42