]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: run debuglog tests when debuglog tag is *not* set
authorAustin Clements <austin@google.com>
Tue, 23 Jul 2024 21:28:09 +0000 (17:28 -0400)
committerAustin Clements <austin@google.com>
Tue, 30 Jul 2024 13:10:59 +0000 (13:10 +0000)
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>
src/runtime/debuglog.go
src/runtime/debuglog_test.go
src/runtime/export_debuglog_test.go

index a278dfabe741da6e9ecc319e13bfb4dde7ec1898..ad33ef8b0685b6171553db09f351210a780e30ed 100644 (file)
@@ -740,10 +740,12 @@ func (r *debugLogReader) printVal() bool {
 
 // printDebugLog prints the debug log.
 func printDebugLog() {
-       if !dlogEnabled {
-               return
+       if dlogEnabled {
+               printDebugLogImpl()
        }
+}
 
+func printDebugLogImpl() {
        // This function should not panic or throw since it is used in
        // the fatal panic path and this may deadlock.
 
index 18c54a81b93642a144fbca91ceeffff17570a690..6d484c462b99d1d7014902f499bb3e6155a7ac51 100644 (file)
@@ -34,8 +34,8 @@ import (
 )
 
 func skipDebugLog(t *testing.T) {
-       if !runtime.DlogEnabled {
-               t.Skip("debug log disabled (rebuild with -tags debuglog)")
+       if runtime.DlogEnabled {
+               t.Skip("debug log tests disabled to avoid collisions with real debug logs")
        }
 }
 
index a361c02299030701ba9d11d84268e0b07e67437b..fc55f73c1fb73c9054a21000a0387470c5fcae03 100644 (file)
@@ -31,7 +31,7 @@ func (l *dloggerImpl) PC(x uintptr) *dloggerImpl { return l.pc(x) }
 func DumpDebugLog() string {
        gp := getg()
        gp.writebuf = make([]byte, 0, 1<<20)
-       printDebugLog()
+       printDebugLogImpl()
        buf := gp.writebuf
        gp.writebuf = nil