2021-02-08 13:46:22 +00:00
|
|
|
package cgroup
|
|
|
|
|
2021-02-08 13:49:02 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
2021-02-08 13:46:22 +00:00
|
|
|
|
2021-02-08 13:49:02 +00:00
|
|
|
func TestGetHierarchicalMemoryLimitSuccess(t *testing.T) {
|
|
|
|
f := func(sysPath, cgroupPath string, want int64) {
|
2021-02-08 13:46:22 +00:00
|
|
|
t.Helper()
|
2021-02-08 13:49:02 +00:00
|
|
|
got, err := getHierarchicalMemoryLimit(sysPath, cgroupPath)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error: %s", err)
|
2021-02-08 13:46:22 +00:00
|
|
|
}
|
|
|
|
if got != want {
|
2021-02-08 13:49:02 +00:00
|
|
|
t.Fatalf("unexpected result, got: %d, want %d", got, want)
|
2021-02-08 13:46:22 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-08 13:49:02 +00:00
|
|
|
f("testdata/", "testdata/self/cgroup", 16)
|
|
|
|
f("testdata/cgroup", "testdata/self/cgroup", 120)
|
2021-02-08 13:46:22 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 13:49:02 +00:00
|
|
|
func TestGetHierarchicalMemoryLimitFailure(t *testing.T) {
|
|
|
|
f := func(sysPath, cgroupPath string) {
|
2021-02-08 13:46:22 +00:00
|
|
|
t.Helper()
|
|
|
|
got, err := getHierarchicalMemoryLimit(sysPath, cgroupPath)
|
2021-02-08 13:49:02 +00:00
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("expecting non-nil error")
|
2021-02-08 13:46:22 +00:00
|
|
|
}
|
2021-02-08 13:49:02 +00:00
|
|
|
if got != 0 {
|
|
|
|
t.Fatalf("unexpected result, got: %d, want 0", got)
|
2021-02-08 13:46:22 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-08 13:49:02 +00:00
|
|
|
f("testdata/", "testdata/none_existing_folder")
|
2021-02-08 13:46:22 +00:00
|
|
|
}
|