• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2016 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 obj
6
7import (
8	"reflect"
9	"testing"
10	"unsafe"
11)
12
13// Assert that the size of important structures do not change unexpectedly.
14
15func TestSizeof(t *testing.T) {
16	const _64bit = unsafe.Sizeof(uintptr(0)) == 8
17
18	var tests = []struct {
19		val    interface{} // type as a value
20		_32bit uintptr     // size on 32bit platforms
21		_64bit uintptr     // size on 64bit platforms
22	}{
23		{Addr{}, 32, 48},
24		{LSym{}, 72, 120},
25		{Prog{}, 132, 200},
26	}
27
28	for _, tt := range tests {
29		want := tt._32bit
30		if _64bit {
31			want = tt._64bit
32		}
33		got := reflect.TypeOf(tt.val).Size()
34		if want != got {
35			t.Errorf("unsafe.Sizeof(%T) = %d, want %d", tt.val, got, want)
36		}
37	}
38}
39