github.com/runcom/containerd@v0.0.0-20160708090337-9bff9f934c0d/integration-test/exec_test.go (about) 1 package main 2 3 import ( 4 "path/filepath" 5 "syscall" 6 7 "github.com/docker/containerd/api/grpc/types" 8 "github.com/docker/docker/pkg/integration/checker" 9 "github.com/go-check/check" 10 ) 11 12 func (cs *ContainerdSuite) TestBusyboxTopExecEcho(t *check.C) { 13 bundleName := "busybox-top" 14 if err := CreateBusyboxBundle(bundleName, []string{"top"}); err != nil { 15 t.Fatal(err) 16 } 17 18 var ( 19 err error 20 initp *ContainerProcess 21 echop *ContainerProcess 22 ) 23 24 containerID := "top" 25 initp, err = cs.StartContainer(containerID, bundleName) 26 t.Assert(err, checker.Equals, nil) 27 28 echop, err = cs.AddProcessToContainer(initp, "echo", "/", []string{"PATH=/bin"}, []string{"sh", "-c", "echo -n Ay Caramba! ; exit 1"}, 0, 0) 29 t.Assert(err, checker.Equals, nil) 30 31 for _, evt := range []types.Event{ 32 { 33 Type: "start-container", 34 Id: containerID, 35 Status: 0, 36 Pid: "", 37 }, 38 { 39 Type: "start-process", 40 Id: containerID, 41 Status: 0, 42 Pid: "echo", 43 }, 44 { 45 Type: "exit", 46 Id: containerID, 47 Status: 1, 48 Pid: "echo", 49 }, 50 } { 51 ch := initp.GetEventsChannel() 52 e := <-ch 53 evt.Timestamp = e.Timestamp 54 55 t.Assert(*e, checker.Equals, evt) 56 } 57 58 t.Assert(echop.io.stdoutBuffer.String(), checker.Equals, "Ay Caramba!") 59 } 60 61 func (cs *ContainerdSuite) TestBusyboxTopExecTop(t *check.C) { 62 bundleName := "busybox-top" 63 if err := CreateBusyboxBundle(bundleName, []string{"top"}); err != nil { 64 t.Fatal(err) 65 } 66 67 var ( 68 err error 69 initp *ContainerProcess 70 ) 71 72 containerID := "top" 73 initp, err = cs.StartContainer(containerID, bundleName) 74 t.Assert(err, checker.Equals, nil) 75 76 execID := "top1" 77 _, err = cs.AddProcessToContainer(initp, execID, "/", []string{"PATH=/usr/bin"}, []string{"top"}, 0, 0) 78 t.Assert(err, checker.Equals, nil) 79 80 for idx, evt := range []types.Event{ 81 { 82 Type: "start-container", 83 Id: containerID, 84 Status: 0, 85 Pid: "", 86 }, 87 { 88 Type: "start-process", 89 Id: containerID, 90 Status: 0, 91 Pid: execID, 92 }, 93 { 94 Type: "exit", 95 Id: containerID, 96 Status: 137, 97 Pid: execID, 98 }, 99 } { 100 ch := initp.GetEventsChannel() 101 e := <-ch 102 evt.Timestamp = e.Timestamp 103 t.Assert(*e, checker.Equals, evt) 104 if idx == 1 { 105 // Process Started, kill it 106 cs.SignalContainerProcess(containerID, "top1", uint32(syscall.SIGKILL)) 107 } 108 } 109 110 // Container should still be running 111 containers, err := cs.ListRunningContainers() 112 if err != nil { 113 t.Fatal(err) 114 } 115 t.Assert(len(containers), checker.Equals, 1) 116 t.Assert(containers[0].Id, checker.Equals, "top") 117 t.Assert(containers[0].Status, checker.Equals, "running") 118 t.Assert(containers[0].BundlePath, check.Equals, filepath.Join(cs.cwd, GetBundle(bundleName).Path)) 119 } 120 121 func (cs *ContainerdSuite) TestBusyboxTopExecTopKillInit(t *check.C) { 122 bundleName := "busybox-top" 123 if err := CreateBusyboxBundle(bundleName, []string{"top"}); err != nil { 124 t.Fatal(err) 125 } 126 127 var ( 128 err error 129 initp *ContainerProcess 130 ) 131 132 containerID := "top" 133 initp, err = cs.StartContainer(containerID, bundleName) 134 t.Assert(err, checker.Equals, nil) 135 136 execID := "top1" 137 _, err = cs.AddProcessToContainer(initp, execID, "/", []string{"PATH=/usr/bin"}, []string{"top"}, 0, 0) 138 t.Assert(err, checker.Equals, nil) 139 140 for idx, evt := range []types.Event{ 141 { 142 Type: "start-container", 143 Id: containerID, 144 Status: 0, 145 Pid: "", 146 }, 147 { 148 Type: "start-process", 149 Id: containerID, 150 Status: 0, 151 Pid: execID, 152 }, 153 { 154 Type: "exit", 155 Id: containerID, 156 Status: 137, 157 Pid: execID, 158 }, 159 { 160 Type: "exit", 161 Id: containerID, 162 Status: 143, 163 Pid: "init", 164 }, 165 } { 166 ch := initp.GetEventsChannel() 167 e := <-ch 168 evt.Timestamp = e.Timestamp 169 t.Assert(*e, checker.Equals, evt) 170 if idx == 1 { 171 // Process Started, kill it 172 cs.SignalContainerProcess(containerID, "init", uint32(syscall.SIGTERM)) 173 } 174 } 175 }