From 4c7a9d0fe056d9d1de37e1409ca8a5c17accb46a Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 13 Nov 2019 17:21:06 +0100 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Bryan C. Mills --- unix/syscall_linux_test.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/unix/syscall_linux_test.go b/unix/syscall_linux_test.go index d3f2bc3e..8f4f1254 100644 --- a/unix/syscall_linux_test.go +++ b/unix/syscall_linux_test.go @@ -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++ {