]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: log CPU model when testing
authorMichael Pratt <mpratt@google.com>
Mon, 13 Dec 2021 22:32:07 +0000 (17:32 -0500)
committerMichael Pratt <mpratt@google.com>
Tue, 8 Mar 2022 21:35:32 +0000 (21:35 +0000)
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 <austin@google.com>
Trust: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/dist/test.go
src/cmd/internal/metadata/main.go [new file with mode: 0644]

index ab30089881d498e9f554bb52afc526467bbbd18d..cd3c26ab3a334a6cf3fe21dcc7366f23002cf748 100644 (file)
@@ -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 (file)
index 0000000..2df048f
--- /dev/null
@@ -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())
+}