Skip to content

Commit

Permalink
cmd/dist: log CPU model when testing
Browse files Browse the repository at this point in the history
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 unconditionally in
cmd/dist. Instead use a build-tagged file, as the final version of
cmd/dist will use the final toolchain.

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.

For #46272.
For #49209.
For #50146.

Change-Id: I515d2ec58e4c0034b76bf624ecaab38f16146074
Reviewed-on: https://go-review.googlesource.com/c/go/+/371474
Trust: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Trust: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
  • Loading branch information
prattmic committed Jan 14, 2022
1 parent e4a6b84 commit 1302f93
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
24 changes: 24 additions & 0 deletions src/cmd/dist/metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2021 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.

// Helper to print system metadata (CPU model, etc). This uses packages that
// may not be available in the bootstrap toolchain. It only needs to be built
// on the dist build using the final toolchain.

//go:build go1.18
// +build go1.18

package main

import (
"fmt"
"internal/sysinfo"
"runtime"
)

func logMetadata() error {
fmt.Printf("# GOARCH: %s\n", runtime.GOARCH)
fmt.Printf("# CPU: %s\n", sysinfo.CPU.Name())
return nil
}
21 changes: 21 additions & 0 deletions src/cmd/dist/metadata_bootstrap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2021 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.

// No-op metadata implementation when building with an old bootstrap toolchain.

//go:build !go1.18
// +build !go1.18

package main

import (
"fmt"
)

func logMetadata() error {
// We don't return an error so we don't completely preclude running
// tests with a bootstrap dist.
fmt.Printf("# Metadata unavailable: bootstrap build\n")
return nil
}
6 changes: 3 additions & 3 deletions src/cmd/dist/sys_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ const (
PROCESSOR_ARCHITECTURE_IA64 = 6
)

var sysinfo systeminfo
var winsysinfo systeminfo

func sysinit() {
syscall.Syscall(procGetSystemInfo.Addr(), 1, uintptr(unsafe.Pointer(&sysinfo)), 0, 0)
switch sysinfo.wProcessorArchitecture {
syscall.Syscall(procGetSystemInfo.Addr(), 1, uintptr(unsafe.Pointer(&winsysinfo)), 0, 0)
switch winsysinfo.wProcessorArchitecture {
case PROCESSOR_ARCHITECTURE_AMD64:
gohostarch = "amd64"
case PROCESSOR_ARCHITECTURE_INTEL:
Expand Down
19 changes: 19 additions & 0 deletions src/cmd/dist/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -268,6 +277,16 @@ 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.")
return logMetadata()
}

// 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
Expand Down

0 comments on commit 1302f93

Please sign in to comment.