~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to misc/cgo/test/callback.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 
13
13
import (
14
14
        "./backdoor"
 
15
        "path"
15
16
        "runtime"
 
17
        "strings"
16
18
        "testing"
17
19
        "unsafe"
18
20
)
110
112
func goFoo() {
111
113
        x := 1
112
114
        for i := 0; i < 10000; i++ {
113
 
                // variadic call mallocs + writes to 
 
115
                // variadic call mallocs + writes to
114
116
                variadic(x, x, x)
115
117
                if x != 1 {
116
118
                        panic("bad x")
136
138
                }
137
139
        })
138
140
}
 
141
 
 
142
// Test that the stack can be unwound through a call out and call back
 
143
// into Go.
 
144
func testCallbackCallers(t *testing.T) {
 
145
        if runtime.Compiler != "gc" {
 
146
                // The exact function names are not going to be the same.
 
147
                t.Skip("skipping for non-gc toolchain")
 
148
        }
 
149
        pc := make([]uintptr, 100)
 
150
        n := 0
 
151
        name := []string{
 
152
                "test.goCallback",
 
153
                "runtime.cgocallbackg",
 
154
                "runtime.cgocallback_gofunc",
 
155
                "return",
 
156
                "runtime.cgocall",
 
157
                "test._Cfunc_callback",
 
158
                "test.nestedCall",
 
159
                "test.testCallbackCallers",
 
160
                "test.TestCallbackCallers",
 
161
                "testing.tRunner",
 
162
                "runtime.goexit",
 
163
        }
 
164
        nestedCall(func() {
 
165
                n = runtime.Callers(2, pc)
 
166
        })
 
167
        if n != len(name) {
 
168
                t.Errorf("expected %d frames, got %d", len(name), n)
 
169
        }
 
170
        for i := 0; i < n; i++ {
 
171
                f := runtime.FuncForPC(pc[i])
 
172
                if f == nil {
 
173
                        t.Fatalf("expected non-nil Func for pc %p", pc[i])
 
174
                }
 
175
                fname := f.Name()
 
176
                // Remove the prepended pathname from automatically
 
177
                // generated cgo function names.
 
178
                if strings.HasPrefix(fname, "_") {
 
179
                        fname = path.Base(f.Name()[1:])
 
180
                }
 
181
                if fname != name[i] {
 
182
                        t.Errorf("expected function name %s, got %s", name[i], fname)
 
183
                }
 
184
        }
 
185
}