2014-02-25 16:17:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2015-04-18 16:46:47 +00:00
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2014-02-25 16:17:48 +00:00
|
|
|
)
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTopMultipleArgs(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-20 06:44:22 +00:00
|
|
|
out, _ := dockerCmd(c, "run", "-i", "-d", "busybox", "top")
|
2014-08-31 12:53:05 +00:00
|
|
|
|
2015-04-06 13:21:18 +00:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2014-08-31 12:53:05 +00:00
|
|
|
|
2015-07-20 06:44:22 +00:00
|
|
|
out, _ = dockerCmd(c, "top", cleanedContainerID, "-o", "pid")
|
2014-08-31 12:53:05 +00:00
|
|
|
if !strings.Contains(out, "PID") {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("did not see PID after top -o pid: %s", out)
|
2014-08-31 12:53:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTopNonPrivileged(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-20 06:44:22 +00:00
|
|
|
out, _ := dockerCmd(c, "run", "-i", "-d", "busybox", "top")
|
2015-04-06 13:21:18 +00:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2014-02-25 16:17:48 +00:00
|
|
|
|
2015-07-20 06:44:22 +00:00
|
|
|
out1, _ := dockerCmd(c, "top", cleanedContainerID)
|
|
|
|
out2, _ := dockerCmd(c, "top", cleanedContainerID)
|
|
|
|
out, _ = dockerCmd(c, "kill", cleanedContainerID)
|
2014-02-25 16:17:48 +00:00
|
|
|
|
2015-04-08 23:32:45 +00:00
|
|
|
if !strings.Contains(out1, "top") && !strings.Contains(out2, "top") {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal("top should've listed `top` in the process list, but failed twice")
|
2015-04-08 23:32:45 +00:00
|
|
|
} else if !strings.Contains(out1, "top") {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal("top should've listed `top` in the process list, but failed the first time")
|
2015-04-08 23:32:45 +00:00
|
|
|
} else if !strings.Contains(out2, "top") {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal("top should've listed `top` in the process list, but failed the second itime")
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 11:43:19 +00:00
|
|
|
}
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTopPrivileged(c *check.C) {
|
2015-09-18 17:41:12 +00:00
|
|
|
testRequires(c, DaemonIsLinux, NotUserNamespace)
|
2015-07-20 06:44:22 +00:00
|
|
|
out, _ := dockerCmd(c, "run", "--privileged", "-i", "-d", "busybox", "top")
|
2015-04-06 13:21:18 +00:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2014-04-09 11:43:19 +00:00
|
|
|
|
2015-07-20 06:44:22 +00:00
|
|
|
out1, _ := dockerCmd(c, "top", cleanedContainerID)
|
|
|
|
out2, _ := dockerCmd(c, "top", cleanedContainerID)
|
|
|
|
out, _ = dockerCmd(c, "kill", cleanedContainerID)
|
2014-04-09 11:43:19 +00:00
|
|
|
|
2015-04-08 23:32:45 +00:00
|
|
|
if !strings.Contains(out1, "top") && !strings.Contains(out2, "top") {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal("top should've listed `top` in the process list, but failed twice")
|
2015-04-08 23:32:45 +00:00
|
|
|
} else if !strings.Contains(out1, "top") {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal("top should've listed `top` in the process list, but failed the first time")
|
2015-04-08 23:32:45 +00:00
|
|
|
} else if !strings.Contains(out2, "top") {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal("top should've listed `top` in the process list, but failed the second itime")
|
2014-04-09 11:43:19 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|