Skip to content

Commit

Permalink
test: add ut case
Browse files Browse the repository at this point in the history
Signed-off-by: linzhecheng <linzhecheng@bytedance.com>
  • Loading branch information
cheney-lin committed Sep 12, 2024
1 parent 1c50599 commit da71043
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pkg/util/cgroup/manager/cgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ import (
"math"
"os"
"path/filepath"
"runtime"
"testing"

"bou.ke/monkey"
"github.com/opencontainers/runc/libcontainer/cgroups"
"github.com/stretchr/testify/assert"

"github.com/kubewharf/katalyst-core/pkg/util/bitmask"
"github.com/kubewharf/katalyst-core/pkg/util/cgroup/common"
v1 "github.com/kubewharf/katalyst-core/pkg/util/cgroup/manager/v1"
v2 "github.com/kubewharf/katalyst-core/pkg/util/cgroup/manager/v2"
"github.com/kubewharf/katalyst-core/pkg/util/machine"
)

func TestManager(t *testing.T) {
Expand Down Expand Up @@ -231,3 +234,36 @@ func testMemPressureV1(t *testing.T) {
assert.Equal(t, "0", fmt.Sprint(some.Avg60))
assert.Equal(t, "0", fmt.Sprint(some.Avg300))
}

func TestMemoryPolicy(t *testing.T) {
t.Parallel()

runtime.LockOSThread()
defer runtime.UnlockOSThread()

mode, mask, err := GetMemPolicy(nil, 0)
assert.NoError(t, err)

assert.Equal(t, MPOL_DEFAULT, mode)

t.Logf("mask: %v", mask)

mems := machine.NewCPUSet(0)
newMask := bitmask.NewEmptyBitMask()
newMask.Add(mems.ToSliceInt()...)

err = SetMemPolicy(MPOL_BIND, newMask)
assert.NoError(t, err)

mode, mask, err = GetMemPolicy(nil, 0)
assert.NoError(t, err)

assert.Equal(t, MPOL_BIND, mode)

expectMask, err := bitmask.NewBitMask(0)
assert.NoError(t, err)

assert.Equal(t, expectMask, mask)

t.Logf("mask: %v", mask)
}

0 comments on commit da71043

Please sign in to comment.