@@ -12,9 +12,11 @@ import (
1212const (
1313 memoryStatContents = `cache 512
1414rss 1024`
15- memoryUsageContents = "2048\n "
16- memoryMaxUsageContents = "4096\n "
17- memoryFailcnt = "100\n "
15+ memoryUsageContents = "2048\n "
16+ memoryMaxUsageContents = "4096\n "
17+ memoryFailcnt = "100\n "
18+ memoryOomControlContents = `oom_kill_disable 1
19+ under_oom 0`
1820)
1921
2022func TestMemorySetMemory (t * testing.T ) {
@@ -173,6 +175,8 @@ func TestMemoryStatsNoStatFile(t *testing.T) {
173175 helper .writeFileContents (map [string ]string {
174176 "memory.usage_in_bytes" : memoryUsageContents ,
175177 "memory.max_usage_in_bytes" : memoryMaxUsageContents ,
178+ "memory.failcnt" : memoryFailcnt ,
179+ "memory.oom_control" : memoryOomControlContents ,
176180 })
177181
178182 memory := & MemoryGroup {}
@@ -189,6 +193,8 @@ func TestMemoryStatsNoUsageFile(t *testing.T) {
189193 helper .writeFileContents (map [string ]string {
190194 "memory.stat" : memoryStatContents ,
191195 "memory.max_usage_in_bytes" : memoryMaxUsageContents ,
196+ "memory.failcnt" : memoryFailcnt ,
197+ "memory.oom_control" : memoryOomControlContents ,
192198 })
193199
194200 memory := & MemoryGroup {}
@@ -205,6 +211,8 @@ func TestMemoryStatsNoMaxUsageFile(t *testing.T) {
205211 helper .writeFileContents (map [string ]string {
206212 "memory.stat" : memoryStatContents ,
207213 "memory.usage_in_bytes" : memoryUsageContents ,
214+ "memory.failcnt" : memoryFailcnt ,
215+ "memory.oom_control" : memoryOomControlContents ,
208216 })
209217
210218 memory := & MemoryGroup {}
@@ -215,13 +223,51 @@ func TestMemoryStatsNoMaxUsageFile(t *testing.T) {
215223 }
216224}
217225
226+ func TestMemoryStatsNoFailcntFile (t * testing.T ) {
227+ helper := NewCgroupTestUtil ("memory" , t )
228+ defer helper .cleanup ()
229+ helper .writeFileContents (map [string ]string {
230+ "memory.stat" : memoryStatContents ,
231+ "memory.usage_in_bytes" : memoryUsageContents ,
232+ "memory.max_usage_in_bytes" : memoryMaxUsageContents ,
233+ "memory.oom_control" : memoryOomControlContents ,
234+ })
235+
236+ memory := & MemoryGroup {}
237+ actualStats := * cgroups .NewStats ()
238+ err := memory .GetStats (helper .CgroupPath , & actualStats )
239+ if err == nil {
240+ t .Fatal ("Expected failure" )
241+ }
242+ }
243+
244+ func TestMemoryStatsNoOomControlFile (t * testing.T ) {
245+ helper := NewCgroupTestUtil ("memory" , t )
246+ defer helper .cleanup ()
247+ helper .writeFileContents (map [string ]string {
248+ "memory.stat" : memoryStatContents ,
249+ "memory.usage_in_bytes" : memoryUsageContents ,
250+ "memory.max_usage_in_bytes" : memoryMaxUsageContents ,
251+ "memory.failcnt" : memoryFailcnt ,
252+ })
253+
254+ memory := & MemoryGroup {}
255+ actualStats := * cgroups .NewStats ()
256+ err := memory .GetStats (helper .CgroupPath , & actualStats )
257+ if err != nil {
258+ t .Fatal (err )
259+ }
260+ }
261+
218262func TestMemoryStatsBadStatFile (t * testing.T ) {
219263 helper := NewCgroupTestUtil ("memory" , t )
220264 defer helper .cleanup ()
221265 helper .writeFileContents (map [string ]string {
222266 "memory.stat" : "rss rss" ,
223267 "memory.usage_in_bytes" : memoryUsageContents ,
224268 "memory.max_usage_in_bytes" : memoryMaxUsageContents ,
269+ "memory.failcnt" : memoryFailcnt ,
270+ "memory.oom_control" : memoryOomControlContents ,
225271 })
226272
227273 memory := & MemoryGroup {}
@@ -239,6 +285,8 @@ func TestMemoryStatsBadUsageFile(t *testing.T) {
239285 "memory.stat" : memoryStatContents ,
240286 "memory.usage_in_bytes" : "bad" ,
241287 "memory.max_usage_in_bytes" : memoryMaxUsageContents ,
288+ "memory.failcnt" : memoryFailcnt ,
289+ "memory.oom_control" : memoryOomControlContents ,
242290 })
243291
244292 memory := & MemoryGroup {}
@@ -256,6 +304,46 @@ func TestMemoryStatsBadMaxUsageFile(t *testing.T) {
256304 "memory.stat" : memoryStatContents ,
257305 "memory.usage_in_bytes" : memoryUsageContents ,
258306 "memory.max_usage_in_bytes" : "bad" ,
307+ "memory.failcnt" : memoryFailcnt ,
308+ "memory.oom_control" : memoryOomControlContents ,
309+ })
310+
311+ memory := & MemoryGroup {}
312+ actualStats := * cgroups .NewStats ()
313+ err := memory .GetStats (helper .CgroupPath , & actualStats )
314+ if err == nil {
315+ t .Fatal ("Expected failure" )
316+ }
317+ }
318+
319+ func TestMemoryStatsBadFailcntFile (t * testing.T ) {
320+ helper := NewCgroupTestUtil ("memory" , t )
321+ defer helper .cleanup ()
322+ helper .writeFileContents (map [string ]string {
323+ "memory.stat" : memoryStatContents ,
324+ "memory.usage_in_bytes" : memoryUsageContents ,
325+ "memory.max_usage_in_bytes" : memoryMaxUsageContents ,
326+ "memory.failcnt" : "bad" ,
327+ "memory.oom_control" : memoryOomControlContents ,
328+ })
329+
330+ memory := & MemoryGroup {}
331+ actualStats := * cgroups .NewStats ()
332+ err := memory .GetStats (helper .CgroupPath , & actualStats )
333+ if err == nil {
334+ t .Fatal ("Expected failure" )
335+ }
336+ }
337+
338+ func TestMemoryStatsBadOomControlFile (t * testing.T ) {
339+ helper := NewCgroupTestUtil ("memory" , t )
340+ defer helper .cleanup ()
341+ helper .writeFileContents (map [string ]string {
342+ "memory.stat" : memoryStatContents ,
343+ "memory.usage_in_bytes" : memoryUsageContents ,
344+ "memory.max_usage_in_bytes" : memoryMaxUsageContents ,
345+ "memory.failcnt" : memoryFailcnt ,
346+ "memory.oom_control" : "bad bad" ,
259347 })
260348
261349 memory := & MemoryGroup {}
0 commit comments