Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(143)

Delta Between Two Patch Sets: src/pkg/testing/testing.go

Issue 4272066: code review 4272066: testing: add -cpu.profile flag (Closed)
Left Patch Set: diff -r 1ca16d1788ba https://go.googlecode.com/hg Created 13 years, 11 months ago
Right Patch Set: diff -r b5c246d30318 https://go.googlecode.com/hg Created 13 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/cmd/prof/gopprof ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // The testing package provides support for automated testing of Go packages. 5 // The testing package provides support for automated testing of Go packages.
6 // It is intended to be used in concert with the ``gotest'' utility, which autom ates 6 // It is intended to be used in concert with the ``gotest'' utility, which autom ates
7 // execution of any function of the form 7 // execution of any function of the form
8 // func TestXxx(*testing.T) 8 // func TestXxx(*testing.T)
9 // where Xxx can be any alphanumeric string (but the first letter must not be in 9 // where Xxx can be any alphanumeric string (but the first letter must not be in
10 // [a-z]) and serves to identify the test routine. 10 // [a-z]) and serves to identify the test routine.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 "runtime/pprof" 46 "runtime/pprof"
47 "time" 47 "time"
48 ) 48 )
49 49
50 var ( 50 var (
51 // Report as tests are run; default is silent for success. 51 // Report as tests are run; default is silent for success.
52 chatty = flag.Bool("test.v", false, "verbose: print additional o utput") 52 chatty = flag.Bool("test.v", false, "verbose: print additional o utput")
53 match = flag.String("test.run", "", "regular expression to sele ct tests to run") 53 match = flag.String("test.run", "", "regular expression to sele ct tests to run")
54 memProfile = flag.String("test.memprofile", "", "write a memory prof ile to the named file after execution") 54 memProfile = flag.String("test.memprofile", "", "write a memory prof ile to the named file after execution")
55 memProfileRate = flag.Int("test.memprofilerate", 0, "if >=0, sets runtim e.MemProfileRate") 55 memProfileRate = flag.Int("test.memprofilerate", 0, "if >=0, sets runtim e.MemProfileRate")
56 cpuProfile = flag.String("test.cpuprofile", "", "write a cpu profile to the named file during execution") 56 cpuProfile = flag.String("test.cpuprofile", "", "write a cpu profile to the named file during execution")
r 2011/03/23 19:39:16 the CL says -cpu.profile. please update the CL des
57 ) 57 )
58 58
59 59
60 // Insert final newline if needed and tabs after internal newlines. 60 // Insert final newline if needed and tabs after internal newlines.
61 func tabify(s string) string { 61 func tabify(s string) string {
62 n := len(s) 62 n := len(s)
63 if n > 0 && s[n-1] != '\n' { 63 if n > 0 && s[n-1] != '\n' {
64 s += "\n" 64 s += "\n"
65 n++ 65 n++
66 } 66 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 test.F(t) 139 test.F(t)
140 t.ch <- t 140 t.ch <- t
141 } 141 }
142 142
143 // An internal function but exported because it is cross-package; part of the im plementation 143 // An internal function but exported because it is cross-package; part of the im plementation
144 // of gotest. 144 // of gotest.
145 func Main(matchString func(pat, str string) (bool, os.Error), tests []InternalTe st, benchmarks []InternalBenchmark) { 145 func Main(matchString func(pat, str string) (bool, os.Error), tests []InternalTe st, benchmarks []InternalBenchmark) {
146 flag.Parse() 146 flag.Parse()
147 147
148 before() 148 before()
149 RunTests(matchString, tests)
150 RunBenchmarks(matchString, benchmarks)
151 after()
152 }
153
154 func RunTests(matchString func(pat, str string) (bool, os.Error), tests []Intern alTest) {
149 ok := true 155 ok := true
150 if len(tests) == 0 { 156 if len(tests) == 0 {
r 2011/03/23 19:39:16 it's just cosmetic but at this point i'd refactor
151 println("testing: warning: no tests to run") 157 println("testing: warning: no tests to run")
152 } 158 }
153 for i := 0; i < len(tests); i++ { 159 for i := 0; i < len(tests); i++ {
154 matched, err := matchString(*match, tests[i].Name) 160 matched, err := matchString(*match, tests[i].Name)
155 if err != nil { 161 if err != nil {
156 println("invalid regexp for -test.run:", err.String()) 162 println("invalid regexp for -test.run:", err.String())
157 os.Exit(1) 163 os.Exit(1)
158 } 164 }
159 if !matched { 165 if !matched {
160 continue 166 continue
(...skipping 15 matching lines...) Expand all
176 } else if *chatty { 182 } else if *chatty {
177 println("--- PASS:", tests[i].Name, tstr) 183 println("--- PASS:", tests[i].Name, tstr)
178 print(t.errors) 184 print(t.errors)
179 } 185 }
180 } 186 }
181 if !ok { 187 if !ok {
182 println("FAIL") 188 println("FAIL")
183 os.Exit(1) 189 os.Exit(1)
184 } 190 }
185 println("PASS") 191 println("PASS")
186 RunBenchmarks(matchString, benchmarks)
187 after()
188 } 192 }
189 193
190 // before runs before all testing. 194 // before runs before all testing.
191 func before() { 195 func before() {
192 if *memProfileRate > 0 { 196 if *memProfileRate > 0 {
193 runtime.MemProfileRate = *memProfileRate 197 runtime.MemProfileRate = *memProfileRate
194 } 198 }
195 if *cpuProfile != "" { 199 if *cpuProfile != "" {
196 f, err := os.Open(*cpuProfile, os.O_WRONLY|os.O_CREAT|os.O_TRUNC , 0666) 200 f, err := os.Open(*cpuProfile, os.O_WRONLY|os.O_CREAT|os.O_TRUNC , 0666)
197 if err != nil { 201 if err != nil {
(...skipping 20 matching lines...) Expand all
218 if err != nil { 222 if err != nil {
219 fmt.Fprintf(os.Stderr, "testing: %s", err) 223 fmt.Fprintf(os.Stderr, "testing: %s", err)
220 return 224 return
221 } 225 }
222 if err = pprof.WriteHeapProfile(f); err != nil { 226 if err = pprof.WriteHeapProfile(f); err != nil {
223 fmt.Fprintf(os.Stderr, "testing: can't write %s: %s", *m emProfile, err) 227 fmt.Fprintf(os.Stderr, "testing: can't write %s: %s", *m emProfile, err)
224 } 228 }
225 f.Close() 229 f.Close()
226 } 230 }
227 } 231 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b