Skip to content

Commit

Permalink
Add comments and unit tests for GetHugePagesInfo()
Browse files Browse the repository at this point in the history
Signed-off-by: sewon.oh <[email protected]>
  • Loading branch information
ohsewon committed Oct 7, 2019
1 parent 95453fe commit 255729d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ func getNodeIdFromCpuBus(cpuBusPath string, threadId int) (int, error) {
}

// GetHugePagesInfo returns information about pre-allocated huge pages
// hugepagesDirectory should be top directory of hugepages
// Such as: /sys/kernel/mm/hugepages/
func GetHugePagesInfo(hugepagesDirectory string) ([]info.HugePagesInfo, error) {
var hugePagesInfo []info.HugePagesInfo
files, err := ioutil.ReadDir(hugepagesDirectory)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
1 change: 1 addition & 0 deletions machine/testdata/hugepages/hugepages-2048kB/nr_hugepages
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2
23 changes: 23 additions & 0 deletions machine/topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,26 @@ func TestTopologyNodeId(t *testing.T) {
t.Errorf("Expected core 1234 , found %d", val)
}
}

func TestGetHugePagesInfo(t *testing.T) {
testPath := "./testdata/hugepages/"
expected := []info.HugePagesInfo{
{
NumPages: 1,
PageSize: 1048576,
},
{
NumPages: 2,
PageSize: 2048,
},
}

val, err := GetHugePagesInfo(testPath)
if err != nil {
t.Errorf("Failed to GetHugePagesInfo() for sample path %s: %v", testPath, err)
}

if !reflect.DeepEqual(expected, val) {
t.Errorf("Expected HugePagesInfo %+v, got %+v", expected, val)
}
}

0 comments on commit 255729d

Please sign in to comment.