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

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

Issue 6443115: code review 6443115: pprof: add contention profiling (Closed)
Left Patch Set: diff -r 248e11862ed5 https://go.googlecode.com/hg/ Created 11 years, 6 months ago
Right Patch Set: diff -r 2aef5548a9cf https://go.googlecode.com/hg/ Created 11 years, 5 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/pkg/runtime/signal_linux_arm.c ('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 // Package testing provides support for automated testing of Go packages. 5 // Package testing provides support for automated testing of Go packages.
6 // It is intended to be used in concert with the ``go test'' command, which auto mates 6 // It is intended to be used in concert with the ``go test'' command, which auto mates
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.
11 // These TestXxx routines should be declared within the package they are testing . 11 // These TestXxx routines should be declared within the package they are testing .
12 // 12 //
13 // Functions of the form 13 // Functions of the form
14 // func BenchmarkXxx(*testing.B) 14 // func BenchmarkXxx(*testing.B)
15 // are considered benchmarks, and are executed by the "go test" command when 15 // are considered benchmarks, and are executed by the "go test" command when
16 // the -test.bench flag is provided. 16 // the -test.bench flag is provided. Benchmarks are run sequentially.
17 //·
18 // For a description of the testing flags, see
19 // http://golang.org/cmd/go/#Description_of_testing_flags.
17 // 20 //
18 // A sample benchmark function looks like this: 21 // A sample benchmark function looks like this:
19 // func BenchmarkHello(b *testing.B) { 22 // func BenchmarkHello(b *testing.B) {
20 // for i := 0; i < b.N; i++ { 23 // for i := 0; i < b.N; i++ {
21 // fmt.Sprintf("hello") 24 // fmt.Sprintf("hello")
22 // } 25 // }
23 // } 26 // }
24 // 27 //
25 // The benchmark package will vary b.N until the benchmark function lasts 28 // The benchmark package will vary b.N until the benchmark function lasts
26 // long enough to be timed reliably. The output 29 // long enough to be timed reliably. The output
27 // testing.BenchmarkHello 10000000 282 ns/op 30 // BenchmarkHello 10000000 282 ns/op
28 // means that the loop ran 10000000 times at a speed of 282 ns per loop. 31 // means that the loop ran 10000000 times at a speed of 282 ns per loop.
29 // 32 //
30 // If a benchmark needs some expensive setup before running, the timer 33 // If a benchmark needs some expensive setup before running, the timer
31 // may be stopped: 34 // may be reset:
32 // func BenchmarkBigLen(b *testing.B) { 35 // func BenchmarkBigLen(b *testing.B) {
33 // b.StopTimer()
34 // big := NewBig() 36 // big := NewBig()
35 // b.StartTimer() 37 // b.ResetTimer()
36 // for i := 0; i < b.N; i++ { 38 // for i := 0; i < b.N; i++ {
37 // big.Len() 39 // big.Len()
38 // } 40 // }
39 // } 41 // }
40 // 42 //
41 // The package also runs and verifies example code. Example functions may 43 // The package also runs and verifies example code. Example functions may
42 // include a concluding comment that begins with "Output:" and is compared with 44 // include a concluding comment that begins with "Output:" and is compared with
43 // the standard output of the function when the tests are run, as in these 45 // the standard output of the function when the tests are run, as in these
44 // examples of an example: 46 // examples of an example:
45 // 47 //
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 // full test of the package. 101 // full test of the package.
100 short = flag.Bool("test.short", false, "run smaller test suite to save t ime") 102 short = flag.Bool("test.short", false, "run smaller test suite to save t ime")
101 103
102 // Report as tests are run; default is silent for success. 104 // Report as tests are run; default is silent for success.
103 chatty = flag.Bool("test.v", false, "verbose: print additional output") 105 chatty = flag.Bool("test.v", false, "verbose: print additional output")
104 match = flag.String("test.run", "", "regular expression to se lect tests and examples to run") 106 match = flag.String("test.run", "", "regular expression to se lect tests and examples to run")
105 memProfile = flag.String("test.memprofile", "", "write a memory pr ofile to the named file after execution") 107 memProfile = flag.String("test.memprofile", "", "write a memory pr ofile to the named file after execution")
106 memProfileRate = flag.Int("test.memprofilerate", 0, "if >=0, sets runt ime.MemProfileRate") 108 memProfileRate = flag.Int("test.memprofilerate", 0, "if >=0, sets runt ime.MemProfileRate")
107 cpuProfile = flag.String("test.cpuprofile", "", "write a cpu profi le to the named file during execution") 109 cpuProfile = flag.String("test.cpuprofile", "", "write a cpu profi le to the named file during execution")
108 blockProfile = flag.String("test.blockprofile", "", "write a gorouti ne blocking profile to the named file after execution") 110 blockProfile = flag.String("test.blockprofile", "", "write a gorouti ne blocking profile to the named file after execution")
109 » blockProfileRate = flag.Int("test.blockprofilerate", 1, "if >= 0, sets r untime.BlockProfileRate") 111 » blockProfileRate = flag.Int("test.blockprofilerate", 1, "if >= 0, calls runtime.SetBlockProfileRate()")
110 timeout = flag.Duration("test.timeout", 0, "if positive, sets a n aggregate time limit for all tests") 112 timeout = flag.Duration("test.timeout", 0, "if positive, sets a n aggregate time limit for all tests")
111 cpuListStr = flag.String("test.cpu", "", "comma-separated list of number of CPUs to use for each test") 113 cpuListStr = flag.String("test.cpu", "", "comma-separated list of number of CPUs to use for each test")
112 parallel = flag.Int("test.parallel", runtime.GOMAXPROCS(0), "max imum test parallelism") 114 parallel = flag.Int("test.parallel", runtime.GOMAXPROCS(0), "max imum test parallelism")
113 115
114 haveExamples bool // are there examples? 116 haveExamples bool // are there examples?
115 117
116 cpuList []int 118 cpuList []int
117 ) 119 )
118 120
119 // common holds the elements common between T and B and 121 // common holds the elements common between T and B and
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 return 416 return
415 } 417 }
416 if err := pprof.StartCPUProfile(f); err != nil { 418 if err := pprof.StartCPUProfile(f); err != nil {
417 fmt.Fprintf(os.Stderr, "testing: can't start cpu profile : %s", err) 419 fmt.Fprintf(os.Stderr, "testing: can't start cpu profile : %s", err)
418 f.Close() 420 f.Close()
419 return 421 return
420 } 422 }
421 // Could save f so after can call f.Close; not worth the effort. 423 // Could save f so after can call f.Close; not worth the effort.
422 } 424 }
423 if *blockProfile != "" && *blockProfileRate >= 0 { 425 if *blockProfile != "" && *blockProfileRate >= 0 {
424 » » runtime.BlockProfileRate = *blockProfileRate 426 » » runtime.SetBlockProfileRate(*blockProfileRate)
425 } 427 }
426 } 428 }
427 429
428 // after runs after all testing. 430 // after runs after all testing.
429 func after() { 431 func after() {
430 if *cpuProfile != "" { 432 if *cpuProfile != "" {
431 pprof.StopCPUProfile() // flushes profile to disk 433 pprof.StopCPUProfile() // flushes profile to disk
432 } 434 }
433 if *memProfile != "" { 435 if *memProfile != "" {
434 f, err := os.Create(*memProfile) 436 f, err := os.Create(*memProfile)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 for _, val := range strings.Split(*cpuListStr, ",") { 484 for _, val := range strings.Split(*cpuListStr, ",") {
483 cpu, err := strconv.Atoi(val) 485 cpu, err := strconv.Atoi(val)
484 if err != nil || cpu <= 0 { 486 if err != nil || cpu <= 0 {
485 fmt.Fprintf(os.Stderr, "testing: invalid value % q for -test.cpu", val) 487 fmt.Fprintf(os.Stderr, "testing: invalid value % q for -test.cpu", val)
486 os.Exit(1) 488 os.Exit(1)
487 } 489 }
488 cpuList = append(cpuList, cpu) 490 cpuList = append(cpuList, cpu)
489 } 491 }
490 } 492 }
491 } 493 }
LEFTRIGHT

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