From: Michael Pratt Date: Mon, 13 Dec 2021 22:32:07 +0000 (-0500) Subject: cmd/dist: log CPU model when testing X-Git-Tag: go1.19beta1~1121 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=67f1a436b9c4055e02d9d031c6c2e9d6c9456bf0;p=gostls13.git 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 Trust: Michael Pratt Run-TryBot: Michael Pratt TryBot-Result: Gopher Robot --- diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go index ab30089881..cd3c26ab3a 100644 --- a/src/cmd/dist/test.go +++ b/src/cmd/dist/test.go @@ -218,6 +218,15 @@ func (t *tester) run() { } } + if err := t.maybeLogMetadata(); err != nil { + t.failed = true + if t.keepGoing { + log.Printf("Failed logging metadata: %v", err) + } else { + fatalf("Failed logging metadata: %v", err) + } + } + for _, dt := range t.tests { if !t.shouldRunTest(dt.name) { t.partial = true @@ -268,6 +277,22 @@ func (t *tester) shouldRunTest(name string) bool { return false } +func (t *tester) maybeLogMetadata() error { + if t.compileOnly { + // We need to run a subprocess to log metadata. Don't do that + // on compile-only runs. + return nil + } + t.out("Test execution environment.") + // Helper binary to print system metadata (CPU model, etc). This is a + // separate binary from dist so it need not build with the bootstrap + // toolchain. + // + // TODO(prattmic): If we split dist bootstrap and dist test then this + // could be simplified to directly use internal/sysinfo here. + return t.dirCmd(filepath.Join(goroot, "src/cmd/internal/metadata"), "go", []string{"run", "."}).Run() +} + // short returns a -short flag value to use with 'go test' // or a test binary for tests intended to run in short mode. // It returns "true", unless the environment variable diff --git a/src/cmd/internal/metadata/main.go b/src/cmd/internal/metadata/main.go new file mode 100644 index 0000000000..2df048fad6 --- /dev/null +++ b/src/cmd/internal/metadata/main.go @@ -0,0 +1,19 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Metadata prints basic system metadata to include in test logs. This is +// separate from cmd/dist so it does not need to build with the bootstrap +// toolchain. +package main + +import ( + "fmt" + "internal/sysinfo" + "runtime" +) + +func main() { + fmt.Printf("# GOARCH: %s\n", runtime.GOARCH) + fmt.Printf("# CPU: %s\n", sysinfo.CPU.Name()) +}