unix: check correct CPU for being enabled in old mask in TestSchedSetaffinity

When checking the old affinity mask with the fix introduced in CL
137675, the wrong CPU (5 instead of 1) is checked. Correct this and also
move the call to SchedGetaffinity closer to the SchedSetaffinity call in
order to reduce the time window for CPUs to go offline.

Updates golang/go#27875
Fixes golang/go#35184

Change-Id: Ie50320c82d1334aa26764281253dc9dde066a730
Reviewed-on: https://go-review.googlesource.com/c/sys/+/206863
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
Tobias Klauser
2019-11-13 17:21:06 +01:00
committed by Tobias Klauser
parent 344fec8e55
commit 4c7a9d0fe0

View File

@@ -309,15 +309,6 @@ func TestPselect(t *testing.T) {
}
func TestSchedSetaffinity(t *testing.T) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var oldMask unix.CPUSet
err := unix.SchedGetaffinity(0, &oldMask)
if err != nil {
t.Fatalf("SchedGetaffinity: %v", err)
}
var newMask unix.CPUSet
newMask.Zero()
if newMask.Count() != 0 {
@@ -338,6 +329,15 @@ func TestSchedSetaffinity(t *testing.T) {
t.Errorf("CpuClr: didn't clear CPU %d in set: %v", cpu, newMask)
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var oldMask unix.CPUSet
err := unix.SchedGetaffinity(0, &oldMask)
if err != nil {
t.Fatalf("SchedGetaffinity: %v", err)
}
if runtime.NumCPU() < 2 {
t.Skip("skipping setaffinity tests on single CPU system")
}
@@ -349,6 +349,7 @@ func TestSchedSetaffinity(t *testing.T) {
// setaffinity should only be called with enabled cores. The valid cores
// are found from the oldMask, but if none are found then the setaffinity
// tests are skipped. Issue #27875.
cpu = 1
if !oldMask.IsSet(cpu) {
newMask.Zero()
for i := 0; i < len(oldMask); i++ {