@@ -9,9 +9,10 @@ import (
99	"github.com/opencontainers/runc/libcontainer/configs" 
1010)
1111
12- const  (
13- 	maxUnlimited  =  - 1 
14- 	maxLimited    =  1024 
12+ var  (
13+ 	maxUnlimited  int64  =  - 1 
14+ 	maxZero       int64  =  0 
15+ 	maxLimited    int64  =  1024 
1516)
1617
1718func  TestPidsSetMax (t  * testing.T ) {
@@ -22,7 +23,7 @@ func TestPidsSetMax(t *testing.T) {
2223	})
2324
2425	r  :=  & configs.Resources {
25- 		PidsLimit : maxLimited ,
26+ 		PidsLimit : & maxLimited ,
2627	}
2728	pids  :=  & PidsGroup {}
2829	if  err  :=  pids .Set (path , r ); err  !=  nil  {
@@ -33,20 +34,45 @@ func TestPidsSetMax(t *testing.T) {
3334	if  err  !=  nil  {
3435		t .Fatal (err )
3536	}
36- 	if  value  !=  maxLimited  {
37+ 	// Only done for comparison 
38+ 	if  value  !=  uint64 (maxLimited ) {
3739		t .Fatalf ("Expected %d, got %d for setting pids.max - limited" , maxLimited , value )
3840	}
3941}
4042
43+ func  TestPidsSetUnlimitedWhenZero (t  * testing.T ) {
44+ 	path  :=  tempDir (t , "pids" )
45+ 
46+ 	writeFileContents (t , path , map [string ]string {
47+ 		"pids.max" : "max" ,
48+ 	})
49+ 
50+ 	r  :=  & configs.Resources {
51+ 		PidsLimit : & maxZero ,
52+ 	}
53+ 	pids  :=  & PidsGroup {}
54+ 	if  err  :=  pids .Set (path , r ); err  !=  nil  {
55+ 		t .Fatal (err )
56+ 	}
57+ 
58+ 	value , err  :=  fscommon .GetCgroupParamString (path , "pids.max" )
59+ 	if  err  !=  nil  {
60+ 		t .Fatal (err )
61+ 	}
62+ 	if  value  !=  "max"  {
63+ 		t .Fatalf ("Expected %s, got %s for setting pids.max - unlimited" , "max" , value )
64+ 	}
65+ }
66+ 
4167func  TestPidsSetUnlimited (t  * testing.T ) {
4268	path  :=  tempDir (t , "pids" )
4369
4470	writeFileContents (t , path , map [string ]string {
45- 		"pids.max" : strconv .Itoa (maxLimited ),
71+ 		"pids.max" : strconv .FormatInt (maxLimited ,  10 ),
4672	})
4773
4874	r  :=  & configs.Resources {
49- 		PidsLimit : maxUnlimited ,
75+ 		PidsLimit : & maxUnlimited ,
5076	}
5177	pids  :=  & PidsGroup {}
5278	if  err  :=  pids .Set (path , r ); err  !=  nil  {
@@ -67,7 +93,7 @@ func TestPidsStats(t *testing.T) {
6793
6894	writeFileContents (t , path , map [string ]string {
6995		"pids.current" : strconv .Itoa (1337 ),
70- 		"pids.max" :     strconv .Itoa (maxLimited ),
96+ 		"pids.max" :     strconv .FormatInt (maxLimited ,  10 ),
7197	})
7298
7399	pids  :=  & PidsGroup {}
@@ -80,7 +106,7 @@ func TestPidsStats(t *testing.T) {
80106		t .Fatalf ("Expected %d, got %d for pids.current" , 1337 , stats .PidsStats .Current )
81107	}
82108
83- 	if  stats .PidsStats .Limit  !=  maxLimited  {
109+ 	if  stats .PidsStats .Limit  !=  uint64 ( maxLimited )  {
84110		t .Fatalf ("Expected %d, got %d for pids.max" , maxLimited , stats .PidsStats .Limit )
85111	}
86112}
0 commit comments