...

Source file src/github.com/opencontainers/runc/libcontainer/cgroups/manager/manager_test.go

Documentation: github.com/opencontainers/runc/libcontainer/cgroups/manager

     1  package manager
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/opencontainers/runc/libcontainer/cgroups/systemd"
     7  	"github.com/opencontainers/runc/libcontainer/configs"
     8  )
     9  
    10  // TestNilResources checks that a cgroup manager do not panic when
    11  // config.Resources is nil. While it does not make sense to use a
    12  // manager with no resources, it should not result in a panic.
    13  //
    14  // This tests either v1 or v2 fs cgroup manager, depending on which
    15  // cgroup version is available.
    16  func TestNilResources(t *testing.T) {
    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)
    39  		if err != nil {
    40  			t.Fatal(err)
    41  		}
    42  	}
    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()
    55  }
    56  

View as plain text