aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/coverage/testsupport.go
AgeCommit message (Collapse)Author
2024-05-21runtime/coverage: remove uses of //go:linknameRuss Cox
Move code to internal/coverage/cfile, making it possible to access directly from testing/internal/testdeps, so that we can avoid needing //go:linkname hacks. For #67401. Change-Id: I10b23a9970164afd2165e718ef3b2d9e86783883 Reviewed-on: https://go-review.googlesource.com/c/go/+/585820 Auto-Submit: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-05-15cmd/link: disallow pull-only linknamesCherry Mui
As mentioned in CL 584598, linkname is a mechanism that, when abused, can break API integrity and even safety of Go programs. CL 584598 is a first step to restrict the use of linknames, by implementing a blocklist. This CL takes a step further, tightening up the restriction by allowing linkname references ("pull") only when the definition side explicitly opts into it, by having a linkname on the definition (possibly to itself). This way, it is at least clear on the definition side that the symbol, despite being unexported, is accessed outside of the package. Unexported symbols without linkname can now be actually private. This is similar to the symbol visibility rule used by gccgo for years (which defines unexported non-linknamed symbols as C static symbols). As there can be pull-only linknames in the wild that may be broken by this change, we currently only enforce this rule for symbols defined in the standard library. Push linknames are added in the standard library to allow things build. Linkname references to external (non-Go) symbols are still allowed, as their visibility is controlled by the C symbol visibility rules and enforced by the C (static or dynamic) linker. Assembly symbols are treated similar to linknamed symbols. This is controlled by -checklinkname linker flag, currently not enabled by default. A follow-up CL will enable it by default. Change-Id: I07344f5c7a02124dbbef0fbc8fec3b666a4b2b0e Reviewed-on: https://go-review.googlesource.com/c/go/+/585358 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Russ Cox <rsc@golang.org>
2024-03-26all: fix a large number of commentscui fliter
Partial typo corrections, following https://go.dev/wiki/Spelling Change-Id: I2357906ff2ea04305c6357418e4e9556e20375d1 Reviewed-on: https://go-review.googlesource.com/c/go/+/573776 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: shuang cui <imcusg@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-03-25runtime: migrate internal/atomic to internal/runtimeAndy Pan
For #65355 Change-Id: I65dd090fb99de9b231af2112c5ccb0eb635db2be Reviewed-on: https://go-review.googlesource.com/c/go/+/560155 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ibrahim Bazoka <ibrahimbazoka729@gmail.com> Auto-Submit: Emmanuel Odeke <emmanuel@orijtech.com>
2023-05-23runtime/coverage: add support for "auxiliary" meta-data filesThan McIntosh
Enhance the functions called by _testmain.go during "go test -cover" test binary runs to allow for injection of extra or "auxiliary" meta-data files when reporting coverage statistics. There are unit tests for this functionality, but it is not yet wired up to be used by the Go command yet, that will appear in a subsequent patch. Change-Id: I10b79ca003fd7a875727dc1a86f23f58d6bf630c Reviewed-on: https://go-review.googlesource.com/c/go/+/495451 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
2023-05-23runtime/coverage: add coverage snapshot helper routineThan McIntosh
Add a new function runtime/coverage.snapshot(), which samples the current values of coverage counters in a running "go test -cover" binary and returns percentage of statements executed so far. This function is intended to be used by the function testing.Coverage(). Updates #59590. Change-Id: I861393701c0cef47b4980aec14331168a9e64e8e Reviewed-on: https://go-review.googlesource.com/c/go/+/495449 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-05-23internal/coverage/cformat: add aggregation option to EmitPercentThan McIntosh
Add a flag to EmitPercent indicating to emit a single line percent summary across all packages as opposed to a line per package. We need to set this flag when reporting as part of a "go test -cover" run, but false when reporting as part of a "go tool covdata percent" run. Change-Id: Iba6a81b9ae27e3a5aaf9d0e46c0023c0e7ceae16 Reviewed-on: https://go-review.googlesource.com/c/go/+/495448 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-01-20runtime/coverage: avoid non-test coverage profiles in test report helperThan McIntosh
When walking through the set of coverage data files generated from a "go test -cover" run, it's possible to encounter pods (clumps of data files) that were generated by a run from an instrumented Go tool (for example, cmd/compile). Add a guard to the test reporting code to ensure that it only processes files created by the currently running test. Fixes #57924. Change-Id: I1bb7dce88305e1088162e3cb1df628486ecee1c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/462756 Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Than McIntosh <thanm@google.com>
2022-12-21runtime/coverage: add missing file close in test support helperThan McIntosh
The processPod() helper (invoked by processCoverTestDir, which is in turn called by _testmain.go) was opening and reading counter data files, but never closing them. Add a call to close the files after they have been read. Fixes #57407. Change-Id: If9a489f92e4bab72c5b2df8697e14420a6f7b8f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/458835 Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-29runtime/coverage: improve unit testsThan McIntosh
Add a testpoint to cover support routines used to help implement "go test -cover". Change-Id: Ic28bf884a4e0d2c0a6d8fd04fc29c0c949227f21 Reviewed-on: https://go-review.googlesource.com/c/go/+/432315 Reviewed-by: Bryan Mills <bcmills@google.com>
2022-09-28runtime/coverage: runtime routines to emit coverage dataThan McIntosh
This patch fleshes out the runtime support for emitting coverage data at the end of a run of an instrumented binary. Data is emitted in the form of a pair of files, a meta-out-file and counter-data-outfile, each written to the dir GOCOVERDIR. The meta-out-file is emitted only if required; no need to emit again if an existing meta-data file with the same hash and length is present. Updates #51430. Change-Id: I59d20a4b8c05910c933ee29527972f8e401b1685 Reviewed-on: https://go-review.googlesource.com/c/go/+/355451 Reviewed-by: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Than McIntosh <thanm@google.com>