integration: add test to check Pause and Resume operations

Signed-off-by: Andrey Vagin <avagin@openvz.org>
This commit is contained in:
Andrey Vagin 2015-01-19 17:12:00 +03:00
parent 02c1de6f11
commit 5138417f80
1 changed files with 77 additions and 0 deletions

View File

@ -204,6 +204,9 @@ func newTestRoot() (string, error) {
}
func TestEnter(t *testing.T) {
if testing.Short() {
return
}
root, err := newTestRoot()
if err != nil {
t.Fatal(err)
@ -300,3 +303,77 @@ func TestEnter(t *testing.T) {
t.Fatal("The second process isn't in the required pid namespace", pidns, pidns2)
}
}
func TestFreeze(t *testing.T) {
if testing.Short() {
return
}
root, err := newTestRoot()
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(root)
rootfs, err := newRootFs()
if err != nil {
t.Fatal(err)
}
defer remove(rootfs)
config := newTemplateConfig(rootfs)
factory, err := libcontainer.New(root, []string{os.Args[0], "init", "--"})
if err != nil {
t.Fatal(err)
}
container, err := factory.Create("test", config)
if err != nil {
t.Fatal(err)
}
defer container.Destroy()
stdinR, stdinW, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
pconfig := libcontainer.ProcessConfig{
Args: []string{"cat"},
Stdin: stdinR,
}
pid, err := container.StartProcess(&pconfig)
stdinR.Close()
defer stdinW.Close()
if err != nil {
t.Fatal(err)
}
process, err := os.FindProcess(pid)
if err != nil {
t.Fatal(err)
}
if err := container.Pause(); err != nil {
t.Fatal(err)
}
state, err := container.RunState()
if err != nil {
t.Fatal(err)
}
if state != configs.Paused {
t.Fatal("Unexpected state: ", state)
}
if err := container.Resume(); err != nil {
t.Fatal(err)
}
stdinW.Close()
s, err := process.Wait()
if err != nil {
t.Fatal(err)
}
if !s.Success() {
t.Fatal(s.String())
}
}