1
0
mirror of https://github.com/golang/go synced 2024-10-04 16:11:21 -06:00
Commit Graph

172 Commits

Author SHA1 Message Date
Russ Cox
21e75b3251 testing: write profiles on failure
Fixes #7901.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/90930044
2014-05-09 12:18:50 -04:00
Dmitriy Vyukov
cd13a57b0a testing: fix bogus benchmark
Fatal must not be called from secondary goroutines.
Fixes #7401.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/67820047
2014-02-24 21:12:44 +04:00
Dmitriy Vyukov
5b6aaba1ce testing: improve diagnosis of a potential misuse of RunParallel
LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/68230045
2014-02-24 21:08:37 +04:00
Dmitriy Vyukov
1163127def testing: diagnose a potential misuse of RunParallel
LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/68030043
2014-02-24 20:32:28 +04:00
Rob Pike
f1e4184db6 testing: improve introduction to package comment
Fixes #7361.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/66910045
2014-02-21 14:35:54 -08:00
Dmitriy Vyukov
c3922f0a63 testing: ease writing parallel benchmarks
Add b.RunParallel function that captures parallel benchmark boilerplate:
creates worker goroutines, joins worker goroutines, distributes work
among them in an efficient way, auto-tunes grain size.
Fixes #7090.

R=bradfitz, iant, josharian, tracey.brendan, r, rsc, gobot
CC=golang-codereviews
https://golang.org/cl/57270043
2014-02-17 06:29:56 +04:00
Russ Cox
91fbf6f159 testing: fix SkipNow and FailNow to avoid panic(nil) check
Sorry, too many windows in which to run all.bash.
Fixes build.

TBR=r
CC=golang-codereviews
https://golang.org/cl/55790043
2014-01-22 16:34:02 -05:00
Russ Cox
ae56210708 testing: diagnose buggy tests that panic(nil)
Fixes #6546.

LGTM=dave, bradfitz, r
R=r, dave, bradfitz
CC=golang-codereviews
https://golang.org/cl/55780043
2014-01-22 16:04:50 -05:00
Shenghou Ma
9847c065f4 testing: document that ResetTimer also zeros the allocation counters.
Fixes #6998.

R=golang-codereviews, gobot, r
CC=golang-codereviews
https://golang.org/cl/44880044
2014-01-09 15:21:24 -05:00
Olivier Duperray
8f10c76471 cmd/godoc: document package-level examples
Fixes  issue  5807 .

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/23940043
2013-11-11 12:09:24 +11:00
Rob Pike
6fb9cc1f63 testing: don't start timing a Parallel test until it's actually starting
Fixes #5285.

R=golang-dev, dvyukov
CC=golang-dev
https://golang.org/cl/13045044
2013-08-19 10:15:30 +10:00
Brad Fitzpatrick
35d8bb39bd testing: add TB, an interface common to T and B
R=golang-dev, kevlar, rsc, adg, r
CC=golang-dev
https://golang.org/cl/12962043
2013-08-14 23:21:32 -07:00
Russ Cox
337407d847 testing: make parsing of -cpu more lenient
Also add \n to error message.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/12261044
2013-08-02 13:51:45 -04:00
Dmitriy Vyukov
bd0a14fe40 testing: say what was the timeout if it fires
It looks reasonable here and may be useful.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/12252043
2013-08-01 17:24:24 +04:00
Russ Cox
ccc4553491 cmd/go, testing: streamline direct use of test binaries
Before:

        $ go test -c -cover fmt
        $ ./fmt.test -test.covermode=set
        PASS
        coverage: 65.1% of statements in strconv
        $

After:

        $ go test -c -cover fmt
        $ ./fmt.test
        PASS
        coverage: 65.1% of statements in strconv
        $

In addition to being cumbersome, the old flag didn't make sense:
the cover mode cannot be changed after the binary has been built.

Another useful effect of this CL is that if you happen to do

        $ go test -c -covermode=atomic fmt

and then forget you did that and run benchmarks,
the final line of the output (the coverage summary) reminds you
that you are benchmarking with coverage enabled, which might
not be what you want.

        $ ./fmt.test -test.bench .
        PASS
        BenchmarkSprintfEmpty	10000000	       217 ns/op
        BenchmarkSprintfString	 2000000	       755 ns/op
        BenchmarkSprintfInt	 2000000	       774 ns/op
        BenchmarkSprintfIntInt	 1000000	      1363 ns/op
        BenchmarkSprintfPrefixedInt	 1000000	      1501 ns/op
        BenchmarkSprintfFloat	 1000000	      1257 ns/op
        BenchmarkManyArgs	  500000	      5346 ns/op
        BenchmarkScanInts	    1000	   2562402 ns/op
        BenchmarkScanRecursiveInt	     500	   3189457 ns/op
        coverage: 91.4% of statements
        $

As part of passing the new mode setting in via _testmain.go, merge
the two registration mechanisms into one extensible mechanism
(a struct).

R=r
CC=golang-dev
https://golang.org/cl/11219043
2013-07-12 20:40:30 -04:00
Russ Cox
56cd47b295 cmd/go, testing: remove redundant "for pkg" in coverage message
This is a transcript before this change. I've capitalized the text being removed.
Note that it is always near another line that already says fmt, marked with <<<

$ cd $GOROOT/src/pkg/fmt

$ go test -cover
PASS
coverage FOR FMT: 91.3% of statements
ok  	fmt	0.040s <<<

$ go test -coverpkg strconv
PASS
coverage FOR FMT: 64.9% of statements in strconv
ok  	fmt	0.039s <<<

$ go test -cover -c
$ ./fmt.test -test.covermode=set <<<
PASS
coverage FOR FMT: 91.3% of statements

$ go test -coverpkg strconv -c
$ ./fmt.test -test.covermode=set <<<
PASS
coverage FOR FMT: 64.9% of statements in strconv

That the summary printed by 'go test [options] fmt' is unchanged:

$ go test -cover fmt
ok  	fmt	0.040s	coverage: 91.3% of statements

$ go test -coverpkg strconv fmt
ok  	fmt	0.038s	coverage: 64.9% of statements in strconv

R=r
CC=gobot, golang-dev
https://golang.org/cl/10932045
2013-07-12 07:34:16 -04:00
Rob Pike
6d86c14efa cmd/go: fix a couple of bugs in coverage tooling
Merging a couple of CLs into one, since they collided in my client
and I'm lazy.

1) Fix up output in "go test -cover" case.
We need to tell the testing package the name of the package being tested
and the name of the package being covered. It can then sort out the report.

2) Filter out the _test.go files from coverage processing. We want to measure
what the tests cover, not what's covered in the tests,
The coverage for encoding/gob goes from 82.2% to 88.4%.
There may be a cleaner way to do this - suggestions welcome - but ça suffit.

Fixes #5810.

R=rsc
CC=golang-dev
https://golang.org/cl/10868047
2013-07-10 09:52:36 +10:00
Rob Pike
279c48444a testing: include cover mode in cover profile
R=adg, rsc
CC=golang-dev
https://golang.org/cl/10392049
2013-06-21 14:19:08 -07:00
Rob Pike
27cca31ee1 cmd/go: simplify flags for coverage
The single flag -cover provides the default simplest behavior.
The other flags, -covermode and -coverprofile, provide more
control. The three flags interconnect to work well.

R=rsc, adg
CC=golang-dev
https://golang.org/cl/10364044
2013-06-18 17:15:26 -07:00
Rob Pike
8e8b8b85c2 cmd/go: write coverage to file, add percentage statistic
Move the data dumper to the testing package, where it has access
to file I/O.
Print a percentage value at the end of the run.

R=rsc, adg
CC=golang-dev
https://golang.org/cl/10264045
2013-06-18 14:18:25 -07:00
Dan Peterson
563d09cd14 testing: use -bench flag and fix flags doc link
R=golang-dev, r, kr
CC=golang-dev
https://golang.org/cl/10263043
2013-06-17 07:32:28 -07:00
Rob Pike
28a1c36d62 testing: add -outputdir flag so "go test" controls where the files are written
Obscure misfeature now fixed: When run from "go test", profiles were always
written in the package's source directory. This change puts them in the directory
where "go test" is run.
Also fix a couple of problems causing errors in testing.after to go unreported
unless -v was set.

R=rsc, minux.ma, iant, alex.brainman
CC=golang-dev
https://golang.org/cl/10234044
2013-06-12 18:13:34 -07:00
Dave Cheney
a28609d66f testing: fix rounding error in roundDown10
Fixes #5599.

Thanks to minux.ma for the suggested fix.

As we now have a harness to test testing internal functions I added some coverage for testing.roundUp, as it is the main consumer of roundDown10.

R=minux.ma, kr, r
CC=golang-dev
https://golang.org/cl/9926043
2013-06-02 09:13:12 +10:00
Dave Cheney
787976c739 testing: add test for issue 5599
Update #5599

R=golang-dev, r, minux.ma
CC=golang-dev
https://golang.org/cl/9738052
2013-05-31 23:03:22 +10:00
Rob Pike
cf5dd6ad64 testing: quantize AllocsPerRun
As the code now says:

We are forced to return a float64 because the API is silly, but do
the division as integers so we can ask if AllocsPerRun()==1
instead of AllocsPerRun()<2.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/9837049
2013-05-30 11:28:08 -04:00
Jonathan Hseu
c691ae6764 testing/quick: fix for aliased types, delete duplicate uint8 test, and fix randFloat64() to give random numbers from (-math.MaxFloat64, math.MaxFloat64).
R=r, agl
CC=agl, bradfitz, golang-dev
https://golang.org/cl/9296046
2013-05-14 17:14:59 -07:00
Alexei Sholik
d4d063580f testing/iotest: rephrase DataErrReader's description
R=r
CC=golang-dev
https://golang.org/cl/8650044
2013-04-12 16:08:56 -07:00
Volker Dobler
03048ae454 testing: structure package documentation
Makes finding the relevant information much easier.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/8353045
2013-04-05 13:43:18 +11:00
Rob Pike
144dd2b21c testing: document that Log and Logf do not usually produce output
The text is printed only if the test fails or -test.v is set.
Document this behavior in the testing package and 'go help test'.
Also put a 'go install' into mkdoc.sh so I don't get tricked by the
process of updating the documentation ever again.

Fixes #5174.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/8118047
2013-04-01 15:17:00 -07:00
Ewan Chou
174a17e3c6 testing: report test as failed if the test panics.
Fixes #5149.

R=golang-dev, dave, minux.ma
CC=golang-dev
https://golang.org/cl/8136043
2013-04-01 22:36:41 +11:00
Russ Cox
f6d0adedb6 build: remove dead code
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/7877045
2013-03-22 17:28:22 -04:00
Dave Cheney
d31dd089e6 testing: move Skip into *common
Move Skip and friends into *common so benchmarks can also be skipped.

R=golang-dev, gustav.paul, rsc
CC=golang-dev
https://golang.org/cl/7379046
2013-02-23 11:57:51 +11:00
Olivier Duperray
2482ef7233 testing: document that example output must use line comments
Fixes #4812.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7396051
2013-02-22 12:23:19 +11:00
Robert Dinu
782cbb4f90 testing: fix output formatting
Revision 5e7fd762f356 has changed the output formatting in a way that
is no longer in line with the format described by the revision
ff0ade0b937b which has introduced this functionality.
When decorating the first line, instead of indenting the whole line,
the current implementation adds indentation right after the "decorate"
part and  before the "log" message.
The fix addresses this issue.

R=golang-dev, iant, minux.ma, r, rsc, remyoudompheng
CC=golang-dev
https://golang.org/cl/7304094
2013-02-21 14:17:43 -08:00
Russ Cox
6600092527 testing: be explicit about use of b.N
R=golang-dev, minux.ma
CC=golang-dev
https://golang.org/cl/7314071
2013-02-09 13:43:15 -05:00
Russ Cox
89a2a8c8df cmd/go, testing: revise docs for test flags
In cmd/go's 'go help testflag':
* Rewrite list of flags to drop test. prefix on every name.
* Sort list of flags.
* Add example of using -bench to match all benchmarks.

In testing:
* Remove mention of undefined 'CPU group' concept.

Fixes #4488.
Fixes #4508.

R=adg
CC=golang-dev
https://golang.org/cl/7288053
2013-02-03 23:47:03 -05:00
Kyle Lemons
9bfd3c3937 testing: add AllocsPerRun
This CL also replaces similar loops in other stdlib
package tests with calls to AllocsPerRun.

Fixes #4461.

R=minux.ma, rsc
CC=golang-dev
https://golang.org/cl/7002055
2013-02-02 22:52:29 -05:00
Russ Cox
2cb8dcea5c testing: SkipNow, FailNow must be called from test goroutine
Impossible for us to check (without sleazily reaching into the
runtime) but at least document it.

Fixes #3800.

R=golang-dev, bradfitz, dave
CC=golang-dev
https://golang.org/cl/7268043
2013-02-01 21:01:32 -05:00
Dave Cheney
f7ea900a7b testing: add Skip/Skipf
This proposal adds two methods to *testing.T, Skip(string) and Skipf(format, args...). The intent is to replace the existing log and return idiom which currently has 97 cases in the standard library. A simple example of Skip would be:

func TestSomethingLong(t *testing.T) {
        if testing.Short() {
                t.Skip("skipping test in short mode.")
                // not reached
        }
        ... time consuming work
}

Additionally tests can be skipped anywhere a *testing.T is present. An example adapted from the go.crypto/ssh/test package would be:

// setup performs some before test action and returns a func()
// which should be defered by the caller for cleanup.
func setup(t *testing.T) func() {
        ...
        cmd := exec.Command("sshd", "-f", configfile, "-i")
        if err := cmd.Run(); err != nil {
                t.Skipf("could not execute mock ssh server: %v", err)
        }
        ...
        return func() {
                // stop subprocess and cleanup
        }
}

func TestDialMockServer(t *testing.T) {
        cleanup := setup(t)
        defer cleanup()
        ...
}

In verbose mode tests that are skipped are now reported as a SKIP, rather than PASS.

Link to discussion: https://groups.google.com/d/topic/golang-nuts/BqorNARzt4U/discussion

R=adg, rsc, r, n13m3y3r
CC=golang-dev, minux.ma
https://golang.org/cl/6501094
2013-01-23 10:22:33 +11:00
Andrew Gerrand
e19cdc651c testing: allow examples to pass (fix build)
R=golang-dev
CC=golang-dev
https://golang.org/cl/7132050
2013-01-18 12:25:41 +11:00
Andrew Gerrand
5bd5ed2b57 testing: catch panicking example and report, just like tests
Fixes #4670.

R=rsc
CC=golang-dev
https://golang.org/cl/7148043
2013-01-18 10:28:18 +11:00
Shenghou Ma
1e095b7622 testing: introduce (*B).ReportAllocs()
Calling it will show memory allocation statistics for that
single benchmark (if -test.benchmem is not provided)

R=golang-dev, rsc, kevlar, bradfitz
CC=golang-dev
https://golang.org/cl/7027046
2013-01-17 18:45:49 +08:00
Caleb Spare
b78f5f0e3a testing: document whitespace trimming of example expected/actual output.
Fixes #4642.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7090044
2013-01-12 11:18:15 +11:00
Emil Hessman
4b7c2dfcea testing: fix example test fd leak
Close the read side of the pipe.
Fixes #4551.

R=rsc
CC=golang-dev
https://golang.org/cl/6962049
2012-12-22 13:41:01 -05:00
Andrew Gerrand
ff5d47ebba testing: only capture stdout when running examples
Fixes #4550.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/6973048
2012-12-20 10:48:33 +11:00
Robert Griesemer
465b9c35e5 gofmt: apply gofmt -w src misc
Remove trailing whitespace in comments.
No other changes.

R=r
CC=golang-dev
https://golang.org/cl/6815053
2012-10-30 13:38:01 -07:00
David Symonds
f8b5838123 testing: change -test.benchtime to a flag.Duration.
Fixes #3902.

R=golang-dev, minux.ma, rsc, r
CC=golang-dev
https://golang.org/cl/6611059
2012-10-09 08:57:29 +11:00
Shenghou Ma
51310d8320 testing: fix extra tabs when t.Log("string")
t.Log("line 1\nline 2\nline 3")

Old output:
=== RUN TestLine3
--- PASS: TestLine3 (0.00 seconds)
testing_test.go:25: 	line 1
		line 2
		line 3
		PASS

New output:
=== RUN TestLine3
--- PASS: TestLine3 (0.00 seconds)
testing_test.go:24: 	line 1
		line 2
		line 3
PASS

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6613069
2012-10-08 00:21:53 +08:00
Dmitriy Vyukov
4cc7bf326a pprof: add goroutine blocking profiling
The profiler collects goroutine blocking information similar to Google Perf Tools.
You may see an example of the profile (converted to svg) attached to
http://code.google.com/p/go/issues/detail?id=3946
The public API changes are:
+pkg runtime, func BlockProfile([]BlockProfileRecord) (int, bool)
+pkg runtime, func SetBlockProfileRate(int)
+pkg runtime, method (*BlockProfileRecord) Stack() []uintptr
+pkg runtime, type BlockProfileRecord struct
+pkg runtime, type BlockProfileRecord struct, Count int64
+pkg runtime, type BlockProfileRecord struct, Cycles int64
+pkg runtime, type BlockProfileRecord struct, embedded StackRecord

R=rsc, dave, minux.ma, r
CC=gobot, golang-dev, r, remyoudompheng
https://golang.org/cl/6443115
2012-10-06 12:56:04 +04:00
Shenghou Ma
727e5ce95f testing: update package docs to use ResetTimer() instead of StopTimer/StartTimer()
R=golang-dev, rsc, r
CC=golang-dev
https://golang.org/cl/6591051
2012-10-03 11:41:18 +08:00