Skip to content

Commit 1302f93

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 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 <[email protected]> Reviewed-by: Benny Siegert <[email protected]> Trust: Michael Pratt <[email protected]> Run-TryBot: Michael Pratt <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Austin Clements <[email protected]>
1 parent e4a6b84 commit 1302f93

File tree

4 files changed

+67
-3
lines changed

4 files changed

+67
-3
lines changed

src/cmd/dist/metadata.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2021 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+
// Helper to print system metadata (CPU model, etc). This uses packages that
6+
// may not be available in the bootstrap toolchain. It only needs to be built
7+
// on the dist build using the final toolchain.
8+
9+
//go:build go1.18
10+
// +build go1.18
11+
12+
package main
13+
14+
import (
15+
"fmt"
16+
"internal/sysinfo"
17+
"runtime"
18+
)
19+
20+
func logMetadata() error {
21+
fmt.Printf("# GOARCH: %s\n", runtime.GOARCH)
22+
fmt.Printf("# CPU: %s\n", sysinfo.CPU.Name())
23+
return nil
24+
}

src/cmd/dist/metadata_bootstrap.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2021 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+
// No-op metadata implementation when building with an old bootstrap toolchain.
6+
7+
//go:build !go1.18
8+
// +build !go1.18
9+
10+
package main
11+
12+
import (
13+
"fmt"
14+
)
15+
16+
func logMetadata() error {
17+
// We don't return an error so we don't completely preclude running
18+
// tests with a bootstrap dist.
19+
fmt.Printf("# Metadata unavailable: bootstrap build\n")
20+
return nil
21+
}

src/cmd/dist/sys_windows.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ const (
3838
PROCESSOR_ARCHITECTURE_IA64 = 6
3939
)
4040

41-
var sysinfo systeminfo
41+
var winsysinfo systeminfo
4242

4343
func sysinit() {
44-
syscall.Syscall(procGetSystemInfo.Addr(), 1, uintptr(unsafe.Pointer(&sysinfo)), 0, 0)
45-
switch sysinfo.wProcessorArchitecture {
44+
syscall.Syscall(procGetSystemInfo.Addr(), 1, uintptr(unsafe.Pointer(&winsysinfo)), 0, 0)
45+
switch winsysinfo.wProcessorArchitecture {
4646
case PROCESSOR_ARCHITECTURE_AMD64:
4747
gohostarch = "amd64"
4848
case PROCESSOR_ARCHITECTURE_INTEL:

src/cmd/dist/test.go

+19
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,16 @@ 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+
return logMetadata()
288+
}
289+
271290
// short returns a -short flag value to use with 'go test'
272291
// or a test binary for tests intended to run in short mode.
273292
// It returns "true", unless the environment variable

0 commit comments

Comments
 (0)