diff options
author | Russ Cox <rsc@golang.org> | 2016-01-26 22:58:59 -0500 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2016-01-27 04:55:59 +0000 |
commit | 313fd1cb1343e46b563b6b8acfef7e58604b5b8f (patch) | |
tree | 25afafd92b7625d2fe0df3503454cdfb91a7a48a /src/runtime/runtime_test.go | |
parent | 4ec2fd3e6ac4f869d39348bf48016687b731d910 (diff) | |
download | go-313fd1cb1343e46b563b6b8acfef7e58604b5b8f.tar.gz go-313fd1cb1343e46b563b6b8acfef7e58604b5b8f.zip |
runtime: fix crash in GoroutineProfile
It was just completely broken if you gave it the number
of records it asked for. Make it impossible for that particular
inconsistency to happen again.
Also make it exclude system goroutines, to match both
NumGoroutine and Stack.
Fixes #14046.
Change-Id: Ic238c6b89934ba7b47cccd3440dd347ed11e4c3d
Reviewed-on: https://go-review.googlesource.com/18976
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/runtime_test.go')
-rw-r--r-- | src/runtime/runtime_test.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/runtime/runtime_test.go b/src/runtime/runtime_test.go index 664c1180c4..581f52bcb0 100644 --- a/src/runtime/runtime_test.go +++ b/src/runtime/runtime_test.go @@ -308,3 +308,15 @@ func TestAppendSliceGrowth(t *testing.T) { } } } + +func TestGoroutineProfileTrivial(t *testing.T) { + n1, ok := GoroutineProfile(nil) // should fail, there's at least 1 goroutine + if n1 < 1 || ok { + t.Fatalf("GoroutineProfile(nil) = %d, %v, want >0, false", n1, ok) + } + + n2, ok := GoroutineProfile(make([]StackRecord, n1)) + if n2 != n1 || !ok { + t.Fatalf("GoroutineProfile(%d) = %d, %v, want %d, true", n1, n2, ok, n1) + } +} |