]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use first line of cpuset output on FreeBSD
authorSteven Hartland <steven.hartland@multiplay.co.uk>
Thu, 7 May 2020 22:34:25 +0000 (22:34 +0000)
committerIan Lance Taylor <iant@golang.org>
Fri, 8 May 2020 20:24:33 +0000 (20:24 +0000)
Fix TestFreeBSDNumCPU on newer versions of FreeBSD which have multi line
output from cpuset e.g.

cpuset -g -p 4141
pid 4141 mask: 0, 1, 2, 3, 4, 5, 6, 7, 8
pid 4141 domain policy: first-touch mask: 0, 1

The test now uses just the first line of output.

Fixes #38937
Fixes #25924

Change-Id: If082ee6b82120ebde4dc437e58343b3dad69c65f
Reviewed-on: https://go-review.googlesource.com/c/go/+/232801
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/runtime/testdata/testprog/numcpu_freebsd.go

index 42ee15488306db8f85224452a50d3fa2c8b3701b..aff36ec702b0660ce2b5d4597cea9c093f13fc50 100644 (file)
@@ -85,7 +85,13 @@ func getList() ([]string, error) {
        if err != nil {
                return nil, fmt.Errorf("fail to execute '%s': %s", cmdline, err)
        }
-       pos := bytes.IndexRune(output, ':')
+       pos := bytes.IndexRune(output, '\n')
+       if pos == -1 {
+               return nil, fmt.Errorf("invalid output from '%s', '\\n' not found: %s", cmdline, output)
+       }
+       output = output[0:pos]
+
+       pos = bytes.IndexRune(output, ':')
        if pos == -1 {
                return nil, fmt.Errorf("invalid output from '%s', ':' not found: %s", cmdline, output)
        }