1
0
mirror of https://github.com/golang/go synced 2024-11-26 08:27:56 -07:00

runtime: run debuglog tests when debuglog tag is *not* set

Currently, the debuglog tests only run when the debuglog build tag is
set because, until the last few CLs, all of debuglog was compiled away
without that build tag. This causes two annoying problems:

1. The tests basically never run, because we don't regularly test this
configuration.

2. If you do turn on the debuglog build tag, it's probably because
you're adding debuglogs into the runtime, which are very likely to
mess up these tests, so you wind up disabling the tests and they,
again, don't get coverage.

Now we've set things up so the debuglog implementation is always
accessible, if you ask nicely enough. So we can switch these tests to
run when the tag is *not* set, and turn off when the tag *is* set (and
you're probably adding actual log statements).

Change-Id: Ib68d7a5022d4f5db96e9c7c8010cbef21d11fe11
Reviewed-on: https://go-review.googlesource.com/c/go/+/600697
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
This commit is contained in:
Austin Clements 2024-07-23 17:28:09 -04:00
parent 548158c4a5
commit 3e1bda08fb
3 changed files with 7 additions and 5 deletions

View File

@ -740,10 +740,12 @@ func (r *debugLogReader) printVal() bool {
// printDebugLog prints the debug log. // printDebugLog prints the debug log.
func printDebugLog() { func printDebugLog() {
if !dlogEnabled { if dlogEnabled {
return printDebugLogImpl()
}
} }
func printDebugLogImpl() {
// This function should not panic or throw since it is used in // This function should not panic or throw since it is used in
// the fatal panic path and this may deadlock. // the fatal panic path and this may deadlock.

View File

@ -34,8 +34,8 @@ import (
) )
func skipDebugLog(t *testing.T) { func skipDebugLog(t *testing.T) {
if !runtime.DlogEnabled { if runtime.DlogEnabled {
t.Skip("debug log disabled (rebuild with -tags debuglog)") t.Skip("debug log tests disabled to avoid collisions with real debug logs")
} }
} }

View File

@ -31,7 +31,7 @@ func (l *dloggerImpl) PC(x uintptr) *dloggerImpl { return l.pc(x) }
func DumpDebugLog() string { func DumpDebugLog() string {
gp := getg() gp := getg()
gp.writebuf = make([]byte, 0, 1<<20) gp.writebuf = make([]byte, 0, 1<<20)
printDebugLog() printDebugLogImpl()
buf := gp.writebuf buf := gp.writebuf
gp.writebuf = nil gp.writebuf = nil