1
2
3
4
5 package main
6
7 import (
8 "testshared/globallib"
9 )
10
11
12 func testLoop() {
13 for i, s := range globallib.Data {
14 if s != int64(i) {
15 panic("testLoop: mismatch")
16 }
17 }
18 }
19
20
21 func ptrData() *[1<<20 + 10]int64 {
22 return &globallib.Data
23 }
24
25
26 func testMediumOffset() {
27 for i, s := range globallib.Data[1<<16-2:] {
28 if s != int64(i)+1<<16-2 {
29 panic("testMediumOffset: index mismatch")
30 }
31 }
32
33 x := globallib.Data[1<<16-1]
34 if x != 1<<16-1 {
35 panic("testMediumOffset: direct mismatch")
36 }
37
38 y := &globallib.Data[1<<16-3]
39 if y != &ptrData()[1<<16-3] {
40 panic("testMediumOffset: address mismatch")
41 }
42 }
43
44
45 func testLargeOffset() {
46 for i, s := range globallib.Data[1<<20:] {
47 if s != int64(i)+1<<20 {
48 panic("testLargeOffset: index mismatch")
49 }
50 }
51
52 x := globallib.Data[1<<20+1]
53 if x != 1<<20+1 {
54 panic("testLargeOffset: direct mismatch")
55 }
56
57 y := &globallib.Data[1<<20+2]
58 if y != &ptrData()[1<<20+2] {
59 panic("testLargeOffset: address mismatch")
60 }
61 }
62
63 func main() {
64 testLoop()
65
66
67
68
69 testMediumOffset()
70 testLargeOffset()
71 }
72
View as plain text