Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: PPC: unit: test sortTopology for expected output #1217

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/performanceprofile/profilecreator/profilecreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ func (ghwHandler GHWHandler) SortedTopology() (*topology.Info, error) {
if err != nil {
return nil, fmt.Errorf("can't obtain topology info from GHW snapshot: %v", err)
}
sortTopology(topologyInfo)
return topologyInfo, nil
}

func sortTopology(topologyInfo *topology.Info) {
sort.Slice(topologyInfo.Nodes, func(x, y int) bool {
return topologyInfo.Nodes[x].ID < topologyInfo.Nodes[y].ID
})
Expand All @@ -283,7 +288,6 @@ func (ghwHandler GHWHandler) SortedTopology() (*topology.Info, error) {
return node.Cores[i].LogicalProcessors[0] < node.Cores[j].LogicalProcessors[0]
})
}
return topologyInfo, nil
}

// topologyHTDisabled returns topologyinfo in case Hyperthreading needs to be disabled.
Expand Down
144 changes: 144 additions & 0 deletions pkg/performanceprofile/profilecreator/profilecreator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package profilecreator
import (
"fmt"
"path/filepath"
"reflect"
"sort"

"github.com/jaypipes/ghw/pkg/cpu"
Expand Down Expand Up @@ -1477,6 +1478,149 @@ var _ = Describe("PerformanceProfileCreator: Test Helper Function ensureSameTopo
})
})

var _ = Describe("PerformanceProfileCreator: Test Helper Function sortTopology", func() {
It("should sort node topologies as expected", func() {
unsorted := topology.Info{
Nodes: []*topology.Node{
{
ID: 2,
Cores: []*cpu.ProcessorCore{
{
ID: 0,
LogicalProcessors: []int{1, 0},
},
{
ID: 3,
LogicalProcessors: []int{6, 7},
},
{
ID: 2,
LogicalProcessors: []int{5, 4},
},
{
ID: 1,
LogicalProcessors: []int{3, 2},
},
},
},
{
ID: 1,
Cores: []*cpu.ProcessorCore{

{
ID: 2,
LogicalProcessors: []int{5, 4},
},
{
ID: 3,
LogicalProcessors: []int{7, 6},
},
{
ID: 0,
LogicalProcessors: []int{0, 1},
},
{
ID: 1,
LogicalProcessors: []int{2, 3},
},
},
},
{
ID: 0,
Cores: []*cpu.ProcessorCore{
{
ID: 1,
LogicalProcessors: []int{2, 3},
},
{
ID: 0,
LogicalProcessors: []int{1, 0},
},
{
ID: 3,
LogicalProcessors: []int{7, 6},
},
{
ID: 2,
LogicalProcessors: []int{4, 5},
},
},
},
},
}
expectedSorted := topology.Info{
Nodes: []*topology.Node{
{
ID: 0,
Cores: []*cpu.ProcessorCore{
{
ID: 0,
LogicalProcessors: []int{0, 1},
},
{
ID: 1,
LogicalProcessors: []int{2, 3},
},
{
ID: 2,
LogicalProcessors: []int{4, 5},
},
{
ID: 3,
LogicalProcessors: []int{6, 7},
},
},
},
{
ID: 1,
Cores: []*cpu.ProcessorCore{
{
ID: 0,
LogicalProcessors: []int{0, 1},
},
{
ID: 1,
LogicalProcessors: []int{2, 3},
},
{
ID: 2,
LogicalProcessors: []int{4, 5},
},
{
ID: 3,
LogicalProcessors: []int{6, 7},
},
},
},
{
ID: 2,
Cores: []*cpu.ProcessorCore{
{
ID: 0,
LogicalProcessors: []int{0, 1},
},
{
ID: 1,
LogicalProcessors: []int{2, 3},
},
{
ID: 2,
LogicalProcessors: []int{4, 5},
},
{
ID: 3,
LogicalProcessors: []int{6, 7},
},
},
},
},
}

sortTopology(&unsorted)
Expect(reflect.DeepEqual(unsorted, expectedSorted)).To(BeTrue(), "expected %+v, got %+v", expectedSorted, unsorted)
})
})

var _ = Describe("PerformanceProfileCreator: Test Helper Function GetAdditionalKernelArgs", func() {
var disableHT bool

Expand Down