-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libct/cg: add Resources=nil unit test
Cgroup controllers should never panic, and yet sometimes they do. Add a unit test to check that controllers never panic when called with nil arguments and/or resources, and fix a few found cases. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
- Loading branch information
Showing
4 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package manager | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/opencontainers/runc/libcontainer/configs" | ||
) | ||
|
||
// TestNilResources checks that a cgroup manager do not panic when | ||
// config.Resources is nil. While it does not make sense to use a | ||
// manager with no resources, it should not result in a panic. | ||
// | ||
// This tests either v1 or v2 managers (both fs and systemd), | ||
// depending on what cgroup version is available on the host. | ||
func TestNilResources(t *testing.T) { | ||
for _, sd := range []bool{false, true} { | ||
cg := &configs.Cgroup{} // .Resources is nil | ||
cg.Systemd = sd | ||
mgr, err := New(cg) | ||
if err != nil { | ||
// Some managers require non-nil Resources during | ||
// instantiation -- provide and retry. In such case | ||
// we're mostly testing Set(nil) below. | ||
cg.Resources = &configs.Resources{} | ||
mgr, err = New(cg) | ||
if err != nil { | ||
t.Error(err) | ||
continue | ||
} | ||
} | ||
_ = mgr.Apply(-1) | ||
_ = mgr.Set(nil) | ||
_ = mgr.Freeze(configs.Thawed) | ||
_ = mgr.Exists() | ||
_, _ = mgr.GetAllPids() | ||
_, _ = mgr.GetCgroups() | ||
_, _ = mgr.GetFreezerState() | ||
_ = mgr.Path("") | ||
_ = mgr.GetPaths() | ||
_, _ = mgr.GetStats() | ||
_, _ = mgr.OOMKillCount() | ||
_ = mgr.Destroy() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters