Dmitriy Vyukov | 91f0f18 | 2011-07-29 13:47:24 -0400 | [diff] [blame] | 1 | // Copyright 2009 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 | package runtime_test |
| 6 | |
| 7 | import ( |
| 8 | "runtime" |
| 9 | "strings" |
| 10 | "testing" |
| 11 | ) |
| 12 | |
| 13 | func TestCaller(t *testing.T) { |
| 14 | procs := runtime.GOMAXPROCS(-1) |
| 15 | c := make(chan bool, procs) |
| 16 | for p := 0; p < procs; p++ { |
| 17 | go func() { |
| 18 | for i := 0; i < 1000; i++ { |
| 19 | testCallerFoo(t) |
| 20 | } |
| 21 | c <- true |
| 22 | }() |
| 23 | defer func() { |
| 24 | <-c |
| 25 | }() |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | func testCallerFoo(t *testing.T) { |
| 30 | testCallerBar(t) |
| 31 | } |
| 32 | |
| 33 | func testCallerBar(t *testing.T) { |
| 34 | for i := 0; i < 2; i++ { |
| 35 | pc, file, line, ok := runtime.Caller(i) |
| 36 | f := runtime.FuncForPC(pc) |
| 37 | if !ok || |
| 38 | !strings.HasSuffix(file, "symtab_test.go") || |
| 39 | (i == 0 && !strings.HasSuffix(f.Name(), "testCallerBar")) || |
| 40 | (i == 1 && !strings.HasSuffix(f.Name(), "testCallerFoo")) || |
| 41 | line < 5 || line > 1000 || |
| 42 | f.Entry() >= pc { |
| 43 | t.Errorf("incorrect symbol info %d: %t %d %d %s %s %d", |
| 44 | i, ok, f.Entry(), pc, f.Name(), file, line) |
| 45 | } |
| 46 | } |
| 47 | } |