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

26 Commits

Author SHA1 Message Date
Caleb Spare
a150c4ff24 testing: pause the test timer while waiting in T.Parallel
Before, we reset the timer at the end of T.Parallel, which is okay
assuming that T.Parallel is the first thing in the test.

Snapshot the elapsed time at the beginning of Parallel and include it in
the total duration so that any time spent in the test before calling
Parallel is reported in the test duration as well.

Updates #12243.

Change-Id: Ieca553e1f801e16b9b6416463fa8f7fa65425185
Reviewed-on: https://go-review.googlesource.com/16989
Reviewed-by: Russ Cox <rsc@golang.org>
2015-11-24 17:07:45 +00:00
Alberto Bertogli
ab196aeff2 testing: only call flag.Parse if it has not been called before
Calling flag.Parse twice can be problematic if other goroutines called
flag.Parsed in between: the race detector complains due to the
write after read from a different goroutine.

This can happen if TestMain calls flag.Parse and launches goroutines
that call flag.Parsed, for example if it initializes a server which
checks flags.

This patch makes testing.M.Run only parse the flags if they have not
been parsed already.

Change-Id: Id9f8c31c5f90614e3f34c63d1a32cf7e9055d68e
Reviewed-on: https://go-review.googlesource.com/16739
Reviewed-by: Russ Cox <rsc@golang.org>
2015-11-12 19:48:06 +00:00
Håvard Haugen
74245b0353 testing/quick: terminate for arbitrary recursive types
Recursive types R containing slices of R's did not terminate despite the
effort in CL 10821.

For recursive types there was a competition between slice expansion by a
factor 'complexSize', and termination with probability '1/complexSize'
which lead to stack overflow as soon as a recursive struct had slices
pointing to its own type.

Fix this by shrinking the size hint as a function of recursion depth.
This has the dual effect of reducing the number of elements generated
per slice and also increasing the probability for termination.

Fixes #11148.

Change-Id: Ib61155b4f2e2de3873d508d63a1f4be759426d67
Reviewed-on: https://go-review.googlesource.com/13830
Reviewed-by: Adam Langley <agl@golang.org>
2015-08-29 19:23:37 +00:00
Dmitry Vyukov
ae1ea2aa94 runtime/trace: add new package
Move tracing functions from runtime/pprof to the new runtime/trace package.

Fixes #9710

Change-Id: I718bcb2ae3e5959d9f72cab5e6708289e5c8ebd5
Reviewed-on: https://go-review.googlesource.com/12511
Reviewed-by: Russ Cox <rsc@golang.org>
2015-07-22 15:47:16 +00:00
Brad Fitzpatrick
2ae77376f7 all: link to https instead of http
The one in misc/makerelease/makerelease.go is particularly bad and
probably warrants rotating our keys.

I didn't update old weekly notes, and reverted some changes involving
test code for now, since we're late in the Go 1.5 freeze. Otherwise,
the rest are all auto-generated changes, and all manually reviewed.

Change-Id: Ia2753576ab5d64826a167d259f48a2f50508792d
Reviewed-on: https://go-review.googlesource.com/12048
Reviewed-by: Rob Pike <r@golang.org>
2015-07-11 14:36:33 +00:00
Matt T. Proud
e6ad56c711 testing/quick: improve function signature error.
This commit fixes a cosmetic defect whereby quick.Check reports that
the provided function returns too many values when it may, in fact,
return too few:

  func f() {}

  func TestFoo(t *testing.T) {
    if err := quick.Check(f, nil); err != nil {
      t.Fatal(err)
    }
  }
  // yields
  // $ go test -v foo_test.go
  // === RUN TestFoo
  // --- FAIL: TestFoo (0.00s)
  // 	foo_test.go:76: function returns more than one value.

Change-Id: Ia209ff5b57375b30f8db425454e80798908e8ff4
Reviewed-on: https://go-review.googlesource.com/11281
Reviewed-by: Russ Cox <rsc@golang.org>
2015-06-26 18:03:32 +00:00
Rob Pike
1f9026c0bd testing: don't print CPU count for tests, only benchmarks
The number of CPUs is of value when benchmarking but mostly
noise when testing. The recent change to default to the number
of CPUs available has made the tests noisier and confusing.

Fixes #11200

Change-Id: Ifc87d9ccb4177d73e304fb7ffcef4367bd163c9e
Reviewed-on: https://go-review.googlesource.com/11121
Reviewed-by: Russ Cox <rsc@golang.org>
2015-06-15 18:11:06 +00:00
Håvard Haugen
7089ea4e47 testing/quick: probabilistically generate nil pointers
The documentation for quick.Value says that it "returns an arbitrary
value of the given type." In spite of this, nil values for pointers were
never generated, which seems more like an oversight than an intentional
choice.

The lack of nil values meant that testing recursive type like

  type Node struct {
  	Next *Node
  }

with testing/quick would lead to a stack overflow since the data
structure would never terminate.

This change may break tests that don't check for nil with pointers
returned from quick.Value. Two such instances were found in the standard
library, one of which was in the testing/quick package itself.

Fixes #8818.

Change-Id: Id390dcce649d12fbbaa801ce6f58f5defed77e60
Reviewed-on: https://go-review.googlesource.com/10821
Reviewed-by: Adam Langley <agl@golang.org>
Run-TryBot: Adam Langley <agl@golang.org>
2015-06-08 21:19:13 +00:00
Russ Cox
fddc3ca11c testing: add -test.count flag to run tests and benchmarks multiple times
The flag is available from the go test command as -count:

% go test -run XXX -bench . -count 3
PASS
BenchmarkSprintfEmpty      	30000000	        54.0 ns/op
BenchmarkSprintfEmpty      	30000000	        51.9 ns/op
BenchmarkSprintfEmpty      	30000000	        53.8 ns/op
BenchmarkSprintfString     	10000000	       238 ns/op
BenchmarkSprintfString     	10000000	       239 ns/op
BenchmarkSprintfString     	10000000	       234 ns/op
BenchmarkSprintfInt        	10000000	       232 ns/op
BenchmarkSprintfInt        	10000000	       226 ns/op
BenchmarkSprintfInt        	10000000	       225 ns/op
...

If -cpu is set, each test is run n times for each cpu value.

Original by r (CL 10663).

Change-Id: If3dfbdf21698952daac9249b5dbca66f5301e91b
Reviewed-on: https://go-review.googlesource.com/10669
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-05 04:31:10 +00:00
Shenghou Ma
c06b856555 testing: fix typo
Fixes #10794.

Change-Id: Id91485394ddbadc28c800e1d0c3ec281ba6cd098
Reviewed-on: https://go-review.googlesource.com/9990
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-05-12 23:39:00 +00:00
Rob Pike
2b833666f1 testing: make the output of -v more uniform and aligned when using fixed-width fonts
Delete the colon from RUN: for examples, since it's not there for tests.
Add spaces to line up RUN and PASS: lines.

Before:
=== RUN TestCount
--- PASS: TestCount (0.00s)
=== RUN: ExampleFields
--- PASS: ExampleFields (0.00s)

After:
=== RUN   TestCount
--- PASS: TestCount (0.00s)
=== RUN   ExampleFields
--- PASS: ExampleFields (0.00s)

Fixes #10594.

Change-Id: I189c80a5d99101ee72d8c9c3a4639c07e640cbd8
Reviewed-on: https://go-review.googlesource.com/9846
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-05-08 18:38:25 +00:00
Rob Pike
e9827f6201 testing: document that Log and Logf always print in benchmarks
Fixes #10713.

Change-Id: Ifdafc340ae3bba751236f0482246c568346a569c
Reviewed-on: https://go-review.googlesource.com/9763
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-05-06 20:59:36 +00:00
Matt T. Proud
b6a0450bec testing/quick: align tests with reflect.Kind.
This commit is largely cosmetic in the sense that it is the remnants
of a change proposal I had prepared for testing/quick, until I
discovered that 3e9ed27 already implemented the feature I was looking
for: quick.Value() for reflect.Kind Array.  What you see is a merger
and manual cleanup; the cosmetic cleanups are as follows:

(1.) Keeping the TestCheckEqual and its associated input functions
in the same order as type kinds defined in reflect.Kind.  Since
3e9ed27 was committed, the test case began to diverge from the
constant's ordering.

(2.) The `Intptr` derivatives existed to exercise quick.Value with
reflect.Kind's `Ptr` constant.  All `Intptr` (unrelated to `uintptr`)
in the test have been migrated to ensure the parallelism of the
listings and to convey that `Intptr` is not special.

(3.) Correct a misspelling (transposition) of "alias", whereby it is
named as "Alais".

Change-Id: I441450db16b8bb1272c52b0abcda3794dcd0599d
Reviewed-on: https://go-review.googlesource.com/8804
Reviewed-by: Russ Cox <rsc@golang.org>
2015-04-26 02:40:40 +00:00
Dmitry Vyukov
6b85090139 testing/quick: fix comment
There is no top-level Values function.

Change-Id: I3ea2eea0b5f77f3e1a3f75d1a6472507ef2888bb
Reviewed-on: https://go-review.googlesource.com/8196
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-03-27 13:00:53 +00:00
Shenghou Ma
f63678ae91 testing: document that flag.Parse is not called when TestMain runs
Fixes #9825.

Change-Id: Id7eeaa14c26201db34db0820371c92a63af485b0
Reviewed-on: https://go-review.googlesource.com/7604
Reviewed-by: Rob Pike <r@golang.org>
2015-03-20 04:40:08 +00:00
Håvard Haugen
3d56fe6d94 testing: pad benchmark names to align results
Fixes #8780

Change-Id: I09cf01ff9722eed49086992a12774f2de81d16f2
Reviewed-on: https://go-review.googlesource.com/2840
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-02-07 21:52:25 +00:00
Chris Kastorff
3e9ed273a2 testing/quick: support generation of array types in Value
Generating array types like [4]int would fail even though the int type
is generatable. Allow generating values of array types when the inner
type is generatable.

Change-Id: I7d71b3c18edb3737e2fec1ddf5e36c9dc8401971
Reviewed-on: https://go-review.googlesource.com/3865
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-02-04 16:17:07 +00:00
Dmitry Vyukov
20004ba889 testing: add tracing support
testing part of tracing functionality:
https://docs.google.com/document/u/1/d/1FP5apqzBgr7ahCCgFO-yoVhk4YZrNIDNf9RybngBc14/pub
Full change:
https://codereview.appspot.com/146920043

Change-Id: Ia3c2c4417106937d5775b0e7064db92c1fc36679
Reviewed-on: https://go-review.googlesource.com/1461
Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-28 16:43:00 +00:00
Robert Griesemer
c85a2bf9c2 testing/iotest: fix copy/paste error in comment
Reported via unsupported GitHub pull request:
https://github.com/golang/go/pull/9436/

Change-Id: I12b00e8ccac700bb36b200196e2867fcc863fdf1
Reviewed-on: https://go-review.googlesource.com/2139
Reviewed-by: Alan Donovan <adonovan@google.com>
2014-12-29 19:05:37 +00:00
Ian Lance Taylor
1e65616e1a testing: style change: omit unnecessary new
This was brought to my attention because a user thought that because
the file was named "example.go" it served as an example of good coding
practice.  It's not an example, of course, but may as well use a more
idiomatic style anyhow.

Change-Id: I7aa720f603f09f7d597fb7536dbf46ef09144e28
Reviewed-on: https://go-review.googlesource.com/1902
Reviewed-by: Minux Ma <minux@golang.org>
2014-12-20 01:40:11 +00:00
Dmitriy Vyukov
8f47c837fd runtime: fix memory profiler
There are 3 issues:
1. Skip argument of callers is off by 3,
so that all allocations are deep inside of memory profiler.
2. Memory profiling statistics are not updated after runtime.GC.
3. Testing package does not update memory profiling statistics
before capturing the profile.
Also add an end-to-end test.
Fixes #8867.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/148710043
2014-10-16 22:11:26 +04:00
Robert Griesemer
5edff32704 testing: clearer comment
Fixes #8797.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/146680043
2014-10-01 13:19:40 -07:00
Russ Cox
182d1316dd cmd/go, testing: add TestMain support
Fixes #8202.

LGTM=r, bradfitz
R=r, josharian, bradfitz
CC=golang-codereviews
https://golang.org/cl/148770043
2014-09-19 13:51:06 -04:00
Russ Cox
e19d8a47d1 runtime: account for tiny allocs, for testing.AllocsPerRun
Fixes #8734.

LGTM=r, bradfitz, dvyukov
R=bradfitz, r, dvyukov
CC=golang-codereviews, iant, khr
https://golang.org/cl/143150043
2014-09-17 14:49:32 -04:00
Rob Pike
d33ee0c5e5 testing: read coverage counters atomically
For -mode=atomic, we need to read the counters
using an atomic load to avoid a race. Not worth worrying
about when -mode=atomic is set during generation
of the profile, so we use atomic loads always.

Fixes #8630.

LGTM=rsc
R=dvyukov, rsc
CC=golang-codereviews
https://golang.org/cl/141800043
2014-09-09 12:31:07 -07:00
Russ Cox
c007ce824d build: move package sources from src/pkg to src
Preparation was in CL 134570043.
This CL contains only the effect of 'hg mv src/pkg/* src'.
For more about the move, see golang.org/s/go14nopkg.
2014-09-08 00:08:51 -04:00