@@ -3,42 +3,53 @@ package manager
33import  (
44	"testing" 
55
6+ 	"github.com/opencontainers/runc/libcontainer/cgroups/systemd" 
67	"github.com/opencontainers/runc/libcontainer/configs" 
78)
89
910// TestNilResources checks that a cgroup manager do not panic when 
1011// config.Resources is nil. While it does not make sense to use a 
1112// manager with no resources, it should not result in a panic. 
1213// 
13- // This tests either v1 or v2 managers (both  fs and systemd),  
14- // depending on what  cgroup version is available on the host . 
14+ // This tests either v1 or v2 fs cgroup manager, depending on which  
15+ // cgroup version is available. 
1516func  TestNilResources (t  * testing.T ) {
16- 	for  _ , sd  :=  range  []bool {false , true } {
17- 		cg  :=  & configs.Cgroup {} // .Resources is nil 
18- 		cg .Systemd  =  sd 
19- 		mgr , err  :=  New (cg )
17+ 	testNilResources (t , false )
18+ }
19+ 
20+ // TestNilResourcesSystemd is the same as TestNilResources, 
21+ // only checking the systemd cgroup manager. 
22+ func  TestNilResourcesSystemd (t  * testing.T ) {
23+ 	if  ! systemd .IsRunningSystemd () {
24+ 		t .Skip ("requires systemd" )
25+ 	}
26+ 	testNilResources (t , true )
27+ }
28+ 
29+ func  testNilResources (t  * testing.T , systemd  bool ) {
30+ 	cg  :=  & configs.Cgroup {} // .Resources is nil 
31+ 	cg .Systemd  =  systemd 
32+ 	mgr , err  :=  New (cg )
33+ 	if  err  !=  nil  {
34+ 		// Some managers require non-nil Resources during 
35+ 		// instantiation -- provide and retry. In such case 
36+ 		// we're mostly testing Set(nil) below. 
37+ 		cg .Resources  =  & configs.Resources {}
38+ 		mgr , err  =  New (cg )
2039		if  err  !=  nil  {
21- 			// Some managers require non-nil Resources during 
22- 			// instantiation -- provide and retry. In such case 
23- 			// we're mostly testing Set(nil) below. 
24- 			cg .Resources  =  & configs.Resources {}
25- 			mgr , err  =  New (cg )
26- 			if  err  !=  nil  {
27- 				t .Error (err )
28- 				continue 
29- 			}
40+ 			t .Fatal (err )
3041		}
31- 		_  =  mgr .Apply (- 1 )
32- 		_  =  mgr .Set (nil )
33- 		_  =  mgr .Freeze (configs .Thawed )
34- 		_  =  mgr .Exists ()
35- 		_ , _  =  mgr .GetAllPids ()
36- 		_ , _  =  mgr .GetCgroups ()
37- 		_ , _  =  mgr .GetFreezerState ()
38- 		_  =  mgr .Path ("" )
39- 		_  =  mgr .GetPaths ()
40- 		_ , _  =  mgr .GetStats ()
41- 		_ , _  =  mgr .OOMKillCount ()
42- 		_  =  mgr .Destroy ()
4342	}
43+ 	_  =  mgr .Apply (- 1 )
44+ 	_  =  mgr .Set (nil )
45+ 	_  =  mgr .Freeze (configs .Thawed )
46+ 	_  =  mgr .Exists ()
47+ 	_ , _  =  mgr .GetAllPids ()
48+ 	_ , _  =  mgr .GetCgroups ()
49+ 	_ , _  =  mgr .GetFreezerState ()
50+ 	_  =  mgr .Path ("" )
51+ 	_  =  mgr .GetPaths ()
52+ 	_ , _  =  mgr .GetStats ()
53+ 	_ , _  =  mgr .OOMKillCount ()
54+ 	_  =  mgr .Destroy ()
4455}
0 commit comments