]> Cypherpunks.ru repositories - gostls13.git/blob - test/stack.go
test for new string bug
[gostls13.git] / test / stack.go
1 // $G $D/$F.go && $L $F.$A && ./$A.out
2
3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6
7 // Try to tickle stack splitting bugs by doing
8 // go, defer, and closure calls at different stack depths.
9
10 package main
11
12 type T [20] int;
13
14 func g(c chan int, t T) {
15         s := 0;
16         for i := 0; i < len(t); i++ {
17                 s += t[i];
18         }
19         c <- s;
20 }
21
22 func d(t T) {
23         s := 0;
24         for i := 0; i < len(t); i++ {
25                 s += t[i];
26         }
27         if s != len(t) {
28                 panicln("bad defer", s);
29         }
30 }
31
32 var c = make(chan int);
33 var t T;
34 var b = []byte{1,2,3,4,5,6,7,8,9,10};
35
36 func recur(n int) {
37         ss := string(b);
38         if len(ss) != len(b) {
39                 panic("bad []byte -> string");
40         }
41         go g(c, t);
42         s := <-c;
43         if s != len(t) {
44                 panicln("bad go", s);
45         }
46         f := func(t T) int {
47                 s := 0;
48                 for i := 0; i < len(t); i++ {
49                         s += t[i];
50                 }
51                 s += n;
52                 return s;
53         };
54         s = f(t);
55         if s != len(t) + n {
56                 panicln("bad func", s, "at level", n);
57         }
58         if n > 0 {
59                 recur(n-1);
60         }
61         defer d(t);
62 }
63
64 func main() {
65         for i := 0; i < len(t); i++ {
66                 t[i] = 1;
67         }
68         recur(10000);
69 }