Skip to content

Commit 67f1a43

Browse files
committed
cmd/dist: log CPU model when testing
Knowing whether test failures are correlated with specific CPU models on has proven useful on several issues. Log it for prior to testing so it is always available. internal/sysinfo provides the CPU model, but it is not available in the bootstrap toolchain, so we can't access this in cmd/dist. Instead use a separate binary which cmd/dist will only build once testing begins. The addition of new data to the beginning of cmd/dist output will break x/build/cmd/coordinator's banner parsing, leaving extra lines in the log output, though information will not be lost. https://golang.org/cl/372538 fixes up the coordinator and should be submitted and deployed before this CL is submitted. This is a redo of CL 371474. It switches back to the original approach of using a separate binary, as the bootstap toolchain won't allow cmd/dist to import internal packages. For #46272. For #49209. For #50146. Change-Id: I906bbda987902a2120c5183290a4e89a2440de58 Reviewed-on: https://go-review.googlesource.com/c/go/+/378589 Reviewed-by: Austin Clements <[email protected]> Trust: Michael Pratt <[email protected]> Run-TryBot: Michael Pratt <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent bd77d6e commit 67f1a43

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/cmd/dist/test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@ func (t *tester) run() {
218218
}
219219
}
220220

221+
if err := t.maybeLogMetadata(); err != nil {
222+
t.failed = true
223+
if t.keepGoing {
224+
log.Printf("Failed logging metadata: %v", err)
225+
} else {
226+
fatalf("Failed logging metadata: %v", err)
227+
}
228+
}
229+
221230
for _, dt := range t.tests {
222231
if !t.shouldRunTest(dt.name) {
223232
t.partial = true
@@ -268,6 +277,22 @@ func (t *tester) shouldRunTest(name string) bool {
268277
return false
269278
}
270279

280+
func (t *tester) maybeLogMetadata() error {
281+
if t.compileOnly {
282+
// We need to run a subprocess to log metadata. Don't do that
283+
// on compile-only runs.
284+
return nil
285+
}
286+
t.out("Test execution environment.")
287+
// Helper binary to print system metadata (CPU model, etc). This is a
288+
// separate binary from dist so it need not build with the bootstrap
289+
// toolchain.
290+
//
291+
// TODO(prattmic): If we split dist bootstrap and dist test then this
292+
// could be simplified to directly use internal/sysinfo here.
293+
return t.dirCmd(filepath.Join(goroot, "src/cmd/internal/metadata"), "go", []string{"run", "."}).Run()
294+
}
295+
271296
// short returns a -short flag value to use with 'go test'
272297
// or a test binary for tests intended to run in short mode.
273298
// It returns "true", unless the environment variable

src/cmd/internal/metadata/main.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// Metadata prints basic system metadata to include in test logs. This is
6+
// separate from cmd/dist so it does not need to build with the bootstrap
7+
// toolchain.
8+
package main
9+
10+
import (
11+
"fmt"
12+
"internal/sysinfo"
13+
"runtime"
14+
)
15+
16+
func main() {
17+
fmt.Printf("# GOARCH: %s\n", runtime.GOARCH)
18+
fmt.Printf("# CPU: %s\n", sysinfo.CPU.Name())
19+
}

0 commit comments

Comments
 (0)