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 main
6
7import (
8	"fmt"
9	"os"
10	"sync"
11	"unsafe"
12
13	"./a"
14)
15
16func F1() int {
17	var buf [1024]int
18	a.F1(uintptr(unsafe.Pointer(&buf[0])))
19	return buf[0]
20}
21
22func F2() int {
23	var buf [1024]int
24	a.F2(uintptr(unsafe.Pointer(&buf[0])))
25	return buf[0]
26}
27
28var t = a.GetT()
29
30func M1() int {
31	var buf [1024]int
32	t.M1(uintptr(unsafe.Pointer(&buf[0])))
33	return buf[0]
34}
35
36func M2() int {
37	var buf [1024]int
38	t.M2(uintptr(unsafe.Pointer(&buf[0])))
39	return buf[0]
40}
41
42func main() {
43	// Use different goroutines to force stack growth.
44	var wg sync.WaitGroup
45	wg.Add(4)
46	c := make(chan bool, 4)
47
48	go func() {
49		defer wg.Done()
50		b := F1()
51		if b != 42 {
52			fmt.Printf("F1: got %d, expected 42\n", b)
53			c <- false
54		}
55	}()
56
57	go func() {
58		defer wg.Done()
59		b := F2()
60		if b != 42 {
61			fmt.Printf("F2: got %d, expected 42\n", b)
62			c <- false
63		}
64	}()
65
66	go func() {
67		defer wg.Done()
68		b := M1()
69		if b != 42 {
70			fmt.Printf("M1: got %d, expected 42\n", b)
71			c <- false
72		}
73	}()
74
75	go func() {
76		defer wg.Done()
77		b := M2()
78		if b != 42 {
79			fmt.Printf("M2: got %d, expected 42\n", b)
80			c <- false
81		}
82	}()
83
84	wg.Wait()
85
86	select {
87	case <-c:
88		os.Exit(1)
89	default:
90	}
91}
92