2014-02-25 16:17:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2015-04-18 16:46:47 +00:00
|
|
|
|
2016-12-30 17:23:00 +00:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
|
|
|
icmd "github.com/docker/docker/pkg/testutil/cmd"
|
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) {
|
2017-04-16 21:39:30 +00:00
|
|
|
out := runSleepingContainer(c, "-d")
|
2015-04-06 13:21:18 +00:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2014-08-31 12:53:05 +00:00
|
|
|
|
2016-08-17 22:46:28 +00:00
|
|
|
var expected icmd.Expected
|
2017-01-13 16:23:28 +00:00
|
|
|
switch testEnv.DaemonPlatform() {
|
2016-08-17 22:46:28 +00:00
|
|
|
case "windows":
|
|
|
|
expected = icmd.Expected{ExitCode: 1, Err: "Windows does not support arguments to top"}
|
|
|
|
default:
|
|
|
|
expected = icmd.Expected{Out: "PID"}
|
|
|
|
}
|
|
|
|
result := dockerCmdWithResult("top", cleanedContainerID, "-o", "pid")
|
|
|
|
c.Assert(result, icmd.Matches, expected)
|
2014-08-31 12:53:05 +00:00
|
|
|
}
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTopNonPrivileged(c *check.C) {
|
2017-04-16 21:39:30 +00:00
|
|
|
out := runSleepingContainer(c, "-d")
|
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)
|
2015-10-08 19:42:41 +00:00
|
|
|
dockerCmd(c, "kill", cleanedContainerID)
|
2014-02-25 16:17:48 +00:00
|
|
|
|
2016-08-17 22:46:28 +00:00
|
|
|
// Windows will list the name of the launched executable which in this case is busybox.exe, without the parameters.
|
|
|
|
// Linux will display the command executed in the container
|
|
|
|
var lookingFor string
|
2017-01-13 16:23:28 +00:00
|
|
|
if testEnv.DaemonPlatform() == "windows" {
|
2016-08-17 22:46:28 +00:00
|
|
|
lookingFor = "busybox.exe"
|
|
|
|
} else {
|
|
|
|
lookingFor = "top"
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Assert(out1, checker.Contains, lookingFor, check.Commentf("top should've listed `%s` in the process list, but failed the first time", lookingFor))
|
|
|
|
c.Assert(out2, checker.Contains, lookingFor, check.Commentf("top should've listed `%s` in the process list, but failed the second time", lookingFor))
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestTopWindowsCoreProcesses validates that there are lines for the critical
|
|
|
|
// processes which are found in a Windows container. Note Windows is architecturally
|
|
|
|
// very different to Linux in this regard.
|
|
|
|
func (s *DockerSuite) TestTopWindowsCoreProcesses(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsWindows)
|
2017-04-16 21:39:30 +00:00
|
|
|
out := runSleepingContainer(c, "-d")
|
2016-08-17 22:46:28 +00:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
|
out1, _ := dockerCmd(c, "top", cleanedContainerID)
|
|
|
|
lookingFor := []string{"smss.exe", "csrss.exe", "wininit.exe", "services.exe", "lsass.exe", "CExecSvc.exe"}
|
|
|
|
for i, s := range lookingFor {
|
|
|
|
c.Assert(out1, checker.Contains, s, check.Commentf("top should've listed `%s` in the process list, but failed. Test case %d", s, i))
|
|
|
|
}
|
2014-04-09 11:43:19 +00:00
|
|
|
}
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTopPrivileged(c *check.C) {
|
2016-08-17 22:46:28 +00:00
|
|
|
// Windows does not support --privileged
|
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)
|
2015-10-08 19:42:41 +00:00
|
|
|
dockerCmd(c, "kill", cleanedContainerID)
|
2014-04-09 11:43:19 +00:00
|
|
|
|
2015-10-08 19:42:41 +00:00
|
|
|
c.Assert(out1, checker.Contains, "top", check.Commentf("top should've listed `top` in the process list, but failed the first time"))
|
|
|
|
c.Assert(out2, checker.Contains, "top", check.Commentf("top should've listed `top` in the process list, but failed the second time"))
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|