From c2ed4eda69e7f62900806e4cd6e45f0429f859fa Mon Sep 17 00:00:00 2001 From: Lynn Boger Date: Wed, 26 Sep 2018 11:31:15 -0400 Subject: [PATCH] unix: fix TestSchedSetaffinity for smt settings If a system has the ability to disable some cores, as on ppc64 with the ppc64_cpu command, then TestSchedSetaffinity will fail if the CPUset passed to Setaffinity includes one that has been disabled. This adds a check to use values from the oldMask, which are the valid cores returned from Getaffinity, to pass to Setaffinity. Fixes golang/go#27875 Change-Id: I9656f41867afc18e0eaedc4bdef5f75e137a1fcd Reviewed-on: https://go-review.googlesource.com/137675 Reviewed-by: Brad Fitzpatrick --- unix/syscall_linux_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/unix/syscall_linux_test.go b/unix/syscall_linux_test.go index b278493d..758efa66 100644 --- a/unix/syscall_linux_test.go +++ b/unix/syscall_linux_test.go @@ -273,6 +273,23 @@ func TestSchedSetaffinity(t *testing.T) { t.Skip("skipping setaffinity tests on android") } + // On a system like ppc64x where some cores can be disabled using ppc64_cpu, + // 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. + if !oldMask.IsSet(cpu) { + newMask.Zero() + for i := 0; i < len(oldMask); i++ { + if oldMask.IsSet(i) { + newMask.Set(i) + break + } + } + if newMask.Count() == 0 { + t.Skip("skipping setaffinity tests if CPU not available") + } + } + err = unix.SchedSetaffinity(0, &newMask) if err != nil { t.Fatalf("SchedSetaffinity: %v", err)