From 3e1bda08fba871157c3c91a44437b7bd266371c1 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 23 Jul 2024 17:28:09 -0400 Subject: [PATCH] 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 Reviewed-by: Carlos Amedee --- src/runtime/debuglog.go | 6 ++++-- src/runtime/debuglog_test.go | 4 ++-- src/runtime/export_debuglog_test.go | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/runtime/debuglog.go b/src/runtime/debuglog.go index a278dfabe7..ad33ef8b06 100644 --- a/src/runtime/debuglog.go +++ b/src/runtime/debuglog.go @@ -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. diff --git a/src/runtime/debuglog_test.go b/src/runtime/debuglog_test.go index 18c54a81b9..6d484c462b 100644 --- a/src/runtime/debuglog_test.go +++ b/src/runtime/debuglog_test.go @@ -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") } } diff --git a/src/runtime/export_debuglog_test.go b/src/runtime/export_debuglog_test.go index a361c02299..fc55f73c1f 100644 --- a/src/runtime/export_debuglog_test.go +++ b/src/runtime/export_debuglog_test.go @@ -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 -- 2.48.1