Skip to content

Commit a67c481

Browse files
committed
cmd/link/internal/sym: add sizeof tests
CL 121916 showed that sym.Symbol matters for linker performance. Prevent accidental regression. Change-Id: I5fd998c91fdeef9e721bc3f6e30f775b81103e95 Reviewed-on: https://go-review.googlesource.com/122716 Run-TryBot: Josh Bleecher Snyder <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 3d5703b commit a67c481

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
5+
// +build !nacl
6+
7+
package sym
8+
9+
import (
10+
"reflect"
11+
"testing"
12+
"unsafe"
13+
)
14+
15+
// Assert that the size of important structures do not change unexpectedly.
16+
17+
func TestSizeof(t *testing.T) {
18+
const nbit = unsafe.Sizeof(uintptr(0)) * 8
19+
const _64bit = nbit == 64
20+
21+
var tests = []struct {
22+
val interface{} // type as a value
23+
_32bit uintptr // size on 32bit platforms
24+
_64bit uintptr // size on 64bit platforms
25+
}{
26+
{Symbol{}, 132, 216},
27+
}
28+
29+
for _, tt := range tests {
30+
want := tt._32bit
31+
if _64bit {
32+
want = tt._64bit
33+
}
34+
got := reflect.TypeOf(tt.val).Size()
35+
if want != got {
36+
t.Errorf("%d bit unsafe.Sizeof(%T) = %d, want %d", nbit, tt.val, got, want)
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)