@@ -13,6 +13,8 @@ const (
1313	maxLimited    =  1024 
1414)
1515
16+ func  toPtr [T  any ](v  T ) * T  { return  & v  }
17+ 
1618func  TestPidsSetMax (t  * testing.T ) {
1719	path  :=  tempDir (t , "pids" )
1820
@@ -21,7 +23,7 @@ func TestPidsSetMax(t *testing.T) {
2123	})
2224
2325	r  :=  & cgroups.Resources {
24- 		PidsLimit : maxLimited ,
26+ 		PidsLimit : toPtr [ int64 ]( maxLimited ) ,
2527	}
2628	pids  :=  & PidsGroup {}
2729	if  err  :=  pids .Set (path , r ); err  !=  nil  {
@@ -37,6 +39,55 @@ func TestPidsSetMax(t *testing.T) {
3739	}
3840}
3941
42+ func  TestPidsSetZero (t  * testing.T ) {
43+ 	path  :=  tempDir (t , "pids" )
44+ 
45+ 	writeFileContents (t , path , map [string ]string {
46+ 		"pids.max" : "max" ,
47+ 	})
48+ 
49+ 	r  :=  & cgroups.Resources {
50+ 		PidsLimit : toPtr [int64 ](0 ),
51+ 	}
52+ 	pids  :=  & PidsGroup {}
53+ 	if  err  :=  pids .Set (path , r ); err  !=  nil  {
54+ 		t .Fatal (err )
55+ 	}
56+ 
57+ 	value , err  :=  fscommon .GetCgroupParamUint (path , "pids.max" )
58+ 	if  err  !=  nil  {
59+ 		t .Fatal (err )
60+ 	}
61+ 	// See comment in (*PidsGroup).Set for why we set to 1 here. 
62+ 	if  value  !=  1  {
63+ 		t .Fatalf ("Expected 1, got %d for setting pids.max = 0" , value )
64+ 	}
65+ }
66+ 
67+ func  TestPidsUnset (t  * testing.T ) {
68+ 	path  :=  tempDir (t , "pids" )
69+ 
70+ 	writeFileContents (t , path , map [string ]string {
71+ 		"pids.max" : "12345" ,
72+ 	})
73+ 
74+ 	r  :=  & cgroups.Resources {
75+ 		PidsLimit : nil ,
76+ 	}
77+ 	pids  :=  & PidsGroup {}
78+ 	if  err  :=  pids .Set (path , r ); err  !=  nil  {
79+ 		t .Fatal (err )
80+ 	}
81+ 
82+ 	value , err  :=  fscommon .GetCgroupParamUint (path , "pids.max" )
83+ 	if  err  !=  nil  {
84+ 		t .Fatal (err )
85+ 	}
86+ 	if  value  !=  12345  {
87+ 		t .Fatalf ("Expected 12345, got %d for not setting pids.max" , value )
88+ 	}
89+ }
90+ 
4091func  TestPidsSetUnlimited (t  * testing.T ) {
4192	path  :=  tempDir (t , "pids" )
4293
@@ -45,7 +96,7 @@ func TestPidsSetUnlimited(t *testing.T) {
4596	})
4697
4798	r  :=  & cgroups.Resources {
48- 		PidsLimit : maxUnlimited ,
99+ 		PidsLimit : toPtr [ int64 ]( maxUnlimited ) ,
49100	}
50101	pids  :=  & PidsGroup {}
51102	if  err  :=  pids .Set (path , r ); err  !=  nil  {
0 commit comments