Add comments and unit tests for GetHugePagesInfo()

Signed-off-by: sewon.oh <sewon.oh@samsung.com>
This commit is contained in:
sewon.oh 2019-10-04 16:27:14 +09:00
parent 95453fe0aa
commit 255729d1ae
No known key found for this signature in database
GPG Key ID: 86535333CDB2A648
4 changed files with 27 additions and 0 deletions

View File

@ -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)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
2

View File

@ -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)
}
}