Skip to content

Commit b4f7bf2

Browse files
committed
libct: rm TestGetContainerStats, mockIntelRdtManager
TestGetContainerStats test a function that is smaller than the test itself, and only calls a couple of other functions (which are represented by mocks). It does not make sense to have it. mockIntelRdtManager is only needed for TestGetContainerStats and TestGetContainerState, which basically tests that Path is called. Also, it does not make much sense to have it. Signed-off-by: Kir Kolyshkin <[email protected]> (cherry picked from commit 8593285) Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent b54e98e commit b4f7bf2

File tree

1 file changed

+4
-108
lines changed

1 file changed

+4
-108
lines changed

libcontainer/container_linux_test.go

Lines changed: 4 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,15 @@ import (
77

88
"github.com/opencontainers/runc/libcontainer/cgroups"
99
"github.com/opencontainers/runc/libcontainer/configs"
10-
"github.com/opencontainers/runc/libcontainer/intelrdt"
1110
"github.com/opencontainers/runc/libcontainer/system"
1211
)
1312

1413
type mockCgroupManager struct {
1514
pids []int
1615
allPids []int
17-
stats *cgroups.Stats
1816
paths map[string]string
1917
}
2018

21-
type mockIntelRdtManager struct {
22-
stats *intelrdt.Stats
23-
path string
24-
}
25-
2619
func (m *mockCgroupManager) GetPids() ([]int, error) {
2720
return m.pids, nil
2821
}
@@ -32,7 +25,7 @@ func (m *mockCgroupManager) GetAllPids() ([]int, error) {
3225
}
3326

3427
func (m *mockCgroupManager) GetStats() (*cgroups.Stats, error) {
35-
return m.stats, nil
28+
return nil, nil
3629
}
3730

3831
func (m *mockCgroupManager) Apply(pid int) error {
@@ -76,30 +69,6 @@ func (m *mockCgroupManager) GetFreezerState() (configs.FreezerState, error) {
7669
return configs.Thawed, nil
7770
}
7871

79-
func (m *mockIntelRdtManager) Apply(pid int) error {
80-
return nil
81-
}
82-
83-
func (m *mockIntelRdtManager) GetStats() (*intelrdt.Stats, error) {
84-
return m.stats, nil
85-
}
86-
87-
func (m *mockIntelRdtManager) Destroy() error {
88-
return nil
89-
}
90-
91-
func (m *mockIntelRdtManager) GetPath() string {
92-
return m.path
93-
}
94-
95-
func (m *mockIntelRdtManager) Set(container *configs.Config) error {
96-
return nil
97-
}
98-
99-
func (m *mockIntelRdtManager) GetCgroups() (*configs.Cgroup, error) {
100-
return nil, nil
101-
}
102-
10372
type mockProcess struct {
10473
_pid int
10574
started uint64
@@ -173,61 +142,11 @@ func TestGetContainerPids(t *testing.T) {
173142
}
174143
}
175144

176-
func TestGetContainerStats(t *testing.T) {
177-
container := &linuxContainer{
178-
id: "myid",
179-
config: &configs.Config{},
180-
cgroupManager: &mockCgroupManager{
181-
pids: []int{1, 2, 3},
182-
stats: &cgroups.Stats{
183-
MemoryStats: cgroups.MemoryStats{
184-
Usage: cgroups.MemoryData{
185-
Usage: 1024,
186-
},
187-
},
188-
},
189-
},
190-
intelRdtManager: &mockIntelRdtManager{
191-
stats: &intelrdt.Stats{
192-
L3CacheSchema: "L3:0=f;1=f0",
193-
MemBwSchema: "MB:0=20;1=70",
194-
},
195-
},
196-
}
197-
stats, err := container.Stats()
198-
if err != nil {
199-
t.Fatal(err)
200-
}
201-
if stats.CgroupStats == nil {
202-
t.Fatal("cgroup stats are nil")
203-
}
204-
if stats.CgroupStats.MemoryStats.Usage.Usage != 1024 {
205-
t.Fatalf("expected memory usage 1024 but received %d", stats.CgroupStats.MemoryStats.Usage.Usage)
206-
}
207-
if intelrdt.IsCATEnabled() {
208-
if stats.IntelRdtStats == nil {
209-
t.Fatal("intel rdt stats are nil")
210-
}
211-
if stats.IntelRdtStats.L3CacheSchema != "L3:0=f;1=f0" {
212-
t.Fatalf("expected L3CacheSchema L3:0=f;1=f0 but received %s", stats.IntelRdtStats.L3CacheSchema)
213-
}
214-
}
215-
if intelrdt.IsMBAEnabled() {
216-
if stats.IntelRdtStats == nil {
217-
t.Fatal("intel rdt stats are nil")
218-
}
219-
if stats.IntelRdtStats.MemBwSchema != "MB:0=20;1=70" {
220-
t.Fatalf("expected MemBwSchema MB:0=20;1=70 but received %s", stats.IntelRdtStats.MemBwSchema)
221-
}
222-
}
223-
}
224-
225145
func TestGetContainerState(t *testing.T) {
226146
var (
227-
pid = os.Getpid()
228-
expectedMemoryPath = "/sys/fs/cgroup/memory/myid"
229-
expectedNetworkPath = fmt.Sprintf("/proc/%d/ns/net", pid)
230-
expectedIntelRdtPath = "/sys/fs/resctrl/myid"
147+
pid = os.Getpid()
148+
expectedMemoryPath = "/sys/fs/cgroup/memory/myid"
149+
expectedNetworkPath = fmt.Sprintf("/proc/%d/ns/net", pid)
231150
)
232151
container := &linuxContainer{
233152
id: "myid",
@@ -248,24 +167,10 @@ func TestGetContainerState(t *testing.T) {
248167
},
249168
cgroupManager: &mockCgroupManager{
250169
pids: []int{1, 2, 3},
251-
stats: &cgroups.Stats{
252-
MemoryStats: cgroups.MemoryStats{
253-
Usage: cgroups.MemoryData{
254-
Usage: 1024,
255-
},
256-
},
257-
},
258170
paths: map[string]string{
259171
"memory": expectedMemoryPath,
260172
},
261173
},
262-
intelRdtManager: &mockIntelRdtManager{
263-
stats: &intelrdt.Stats{
264-
L3CacheSchema: "L3:0=f0;1=f",
265-
MemBwSchema: "MB:0=70;1=20",
266-
},
267-
path: expectedIntelRdtPath,
268-
},
269174
}
270175
container.state = &createdState{c: container}
271176
state, err := container.State()
@@ -285,15 +190,6 @@ func TestGetContainerState(t *testing.T) {
285190
if memPath := paths["memory"]; memPath != expectedMemoryPath {
286191
t.Fatalf("expected memory path %q but received %q", expectedMemoryPath, memPath)
287192
}
288-
if intelrdt.IsCATEnabled() || intelrdt.IsMBAEnabled() {
289-
intelRdtPath := state.IntelRdtPath
290-
if intelRdtPath == "" {
291-
t.Fatal("intel rdt path should not be empty")
292-
}
293-
if intelRdtPath != expectedIntelRdtPath {
294-
t.Fatalf("expected intel rdt path %q but received %q", expectedIntelRdtPath, intelRdtPath)
295-
}
296-
}
297193
for _, ns := range container.config.Namespaces {
298194
path := state.NamespacePaths[ns.Type]
299195
if path == "" {

0 commit comments

Comments
 (0)