1
0
mirror of https://github.com/golang/go synced 2024-11-06 15:46:19 -07:00

runtime: fix FreeBSDNumCPU test

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

Fixes #25924
This commit is contained in:
David Carlier 2018-06-16 12:40:04 +01:00
parent cdffe9b1e3
commit 4cc275b519

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
}