-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: jason yang <[email protected]>
- Loading branch information
1 parent
0579353
commit 0e65f98
Showing
16 changed files
with
201 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package cgroup_test | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/apptainer/apptheus/internal/cgroup" | ||
"github.com/opencontainers/runc/libcontainer/cgroups" | ||
"github.com/opencontainers/runc/libcontainer/configs" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type MockCgroupManager struct { | ||
mock.Mock | ||
} | ||
|
||
func (m *MockCgroupManager) Apply(_ int) error { | ||
return nil | ||
} | ||
|
||
func (m *MockCgroupManager) GetPids() ([]int, error) { | ||
return []int{}, nil | ||
} | ||
|
||
func (m *MockCgroupManager) GetAllPids() ([]int, error) { | ||
return []int{}, nil | ||
} | ||
|
||
func (m *MockCgroupManager) GetStats() (*cgroups.Stats, error) { | ||
return cgroups.NewStats(), nil | ||
} | ||
|
||
func (m *MockCgroupManager) Freeze(_ configs.FreezerState) error { | ||
return nil | ||
} | ||
|
||
func (m *MockCgroupManager) Destroy() error { | ||
return nil | ||
} | ||
|
||
func (m *MockCgroupManager) Path(path string) string { | ||
return path | ||
} | ||
|
||
func (m *MockCgroupManager) Set(_ *configs.Resources) error { | ||
return nil | ||
} | ||
|
||
func (m *MockCgroupManager) GetPaths() map[string]string { | ||
return map[string]string{} | ||
} | ||
|
||
func (m *MockCgroupManager) GetCgroups() (*configs.Cgroup, error) { | ||
return nil, nil | ||
} | ||
|
||
func (m *MockCgroupManager) GetFreezerState() (configs.FreezerState, error) { | ||
return "", nil | ||
} | ||
|
||
func (m *MockCgroupManager) Exists() bool { | ||
return true | ||
} | ||
|
||
func (m *MockCgroupManager) OOMKillCount() (uint64, error) { | ||
return 0, nil | ||
} | ||
|
||
func TestCgroup(t *testing.T) { | ||
cgroup := &cgroup.CGroup{ | ||
Manager: &MockCgroupManager{}, | ||
} | ||
|
||
has, err := cgroup.HasProcess() | ||
require.NoError(t, err) | ||
require.False(t, has) | ||
|
||
funcs, err := cgroup.CreateStats() | ||
require.NoError(t, err) | ||
require.NotEmpty(t, funcs) | ||
require.Len(t, funcs, 4) | ||
|
||
var buffer bytes.Buffer | ||
_, err = cgroup.Marshal(&buffer) | ||
require.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package parser_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/apptainer/apptheus/internal/cgroup/parser" | ||
"github.com/opencontainers/runc/libcontainer/cgroups" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestParser(t *testing.T) { | ||
stats := cgroups.NewStats() | ||
mgr := &parser.StatManager{ | ||
Stats: stats, | ||
} | ||
|
||
require.NotNil(t, mgr) | ||
allFuncs := mgr.WithCPU().WithMemory().WithMemorySwap().WithPid().All() | ||
require.Len(t, allFuncs, 4) | ||
|
||
_, usage := allFuncs[0]() | ||
require.Equal(t, 0.0, usage) | ||
|
||
_, usage = allFuncs[1]() | ||
require.Equal(t, 0.0, usage) | ||
|
||
_, usage = allFuncs[2]() | ||
require.Equal(t, 0.0, usage) | ||
|
||
_, usage = allFuncs[3]() | ||
require.Equal(t, 0.0, usage) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.