1
0
mirror of https://github.com/golang/go synced 2024-11-23 11:10:04 -07:00

runtime: fix FreeBSDNumCPU test

num cpu unit test fixes for FreeBSD.
cpuset -g can possibly output more
data than expected.

Fixes #25924

Change-Id: Iec45a919df68648759331da7cd1fa3b9f3ca4241
GitHub-Last-Rev: 4cc275b519
GitHub-Pull-Request: golang/go#25931
Reviewed-on: https://go-review.googlesource.com/119376
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
David Carlier 2018-06-17 17:27:13 +00:00 committed by Brad Fitzpatrick
parent 2036f16247
commit 65d55a13a9

View File

@ -9,12 +9,17 @@ import (
"fmt"
"os"
"os/exec"
"regexp"
"runtime"
"strconv"
"strings"
"syscall"
)
var (
cpuSetRE = regexp.MustCompile(`(\d,?)+`)
)
func init() {
register("FreeBSDNumCPU", FreeBSDNumCPU)
register("FreeBSDNumCPUHelper", FreeBSDNumCPUHelper)
@ -105,8 +110,12 @@ func checkNCPU(list []string) error {
return fmt.Errorf("could not check against an empty CPU list")
}
cListString := cpuSetRE.FindString(listString)
if len(cListString) == 0 {
return fmt.Errorf("invalid cpuset output '%s'", listString)
}
// Launch FreeBSDNumCPUHelper() with specified CPUs list.
cmd := exec.Command("cpuset", "-l", listString, os.Args[0], "FreeBSDNumCPUHelper")
cmd := exec.Command("cpuset", "-l", cListString, os.Args[0], "FreeBSDNumCPUHelper")
cmdline := strings.Join(cmd.Args, " ")
output, err := cmd.CombinedOutput()
if err != nil {
@ -120,7 +129,7 @@ func checkNCPU(list []string) error {
return fmt.Errorf("fail to parse output from child '%s', error: %s, output: %s", cmdline, err, output)
}
if n != len(list) {
return fmt.Errorf("runtime.NumCPU() expected to %d, got %d when run with CPU list %s", len(list), n, listString)
return fmt.Errorf("runtime.NumCPU() expected to %d, got %d when run with CPU list %s", len(list), n, cListString)
}
return nil
}