6 "github.com/docker/docker/integration-cli/checker"
7 icmd "github.com/docker/docker/pkg/testutil/cmd"
8 "github.com/go-check/check"
11 func (s *DockerSuite) TestTopMultipleArgs(c *check.C) {
12 out := runSleepingContainer(c, "-d")
13 cleanedContainerID := strings.TrimSpace(out)
15 var expected icmd.Expected
16 switch testEnv.DaemonPlatform() {
18 expected = icmd.Expected{ExitCode: 1, Err: "Windows does not support arguments to top"}
20 expected = icmd.Expected{Out: "PID"}
22 result := dockerCmdWithResult("top", cleanedContainerID, "-o", "pid")
23 c.Assert(result, icmd.Matches, expected)
26 func (s *DockerSuite) TestTopNonPrivileged(c *check.C) {
27 out := runSleepingContainer(c, "-d")
28 cleanedContainerID := strings.TrimSpace(out)
30 out1, _ := dockerCmd(c, "top", cleanedContainerID)
31 out2, _ := dockerCmd(c, "top", cleanedContainerID)
32 dockerCmd(c, "kill", cleanedContainerID)
34 // Windows will list the name of the launched executable which in this case is busybox.exe, without the parameters.
35 // Linux will display the command executed in the container
37 if testEnv.DaemonPlatform() == "windows" {
38 lookingFor = "busybox.exe"
43 c.Assert(out1, checker.Contains, lookingFor, check.Commentf("top should've listed `%s` in the process list, but failed the first time", lookingFor))
44 c.Assert(out2, checker.Contains, lookingFor, check.Commentf("top should've listed `%s` in the process list, but failed the second time", lookingFor))
47 // TestTopWindowsCoreProcesses validates that there are lines for the critical
48 // processes which are found in a Windows container. Note Windows is architecturally
49 // very different to Linux in this regard.
50 func (s *DockerSuite) TestTopWindowsCoreProcesses(c *check.C) {
51 testRequires(c, DaemonIsWindows)
52 out := runSleepingContainer(c, "-d")
53 cleanedContainerID := strings.TrimSpace(out)
54 out1, _ := dockerCmd(c, "top", cleanedContainerID)
55 lookingFor := []string{"smss.exe", "csrss.exe", "wininit.exe", "services.exe", "lsass.exe", "CExecSvc.exe"}
56 for i, s := range lookingFor {
57 c.Assert(out1, checker.Contains, s, check.Commentf("top should've listed `%s` in the process list, but failed. Test case %d", s, i))
61 func (s *DockerSuite) TestTopPrivileged(c *check.C) {
62 // Windows does not support --privileged
63 testRequires(c, DaemonIsLinux, NotUserNamespace)
64 out, _ := dockerCmd(c, "run", "--privileged", "-i", "-d", "busybox", "top")
65 cleanedContainerID := strings.TrimSpace(out)
67 out1, _ := dockerCmd(c, "top", cleanedContainerID)
68 out2, _ := dockerCmd(c, "top", cleanedContainerID)
69 dockerCmd(c, "kill", cleanedContainerID)
71 c.Assert(out1, checker.Contains, "top", check.Commentf("top should've listed `top` in the process list, but failed the first time"))
72 c.Assert(out2, checker.Contains, "top", check.Commentf("top should've listed `top` in the process list, but failed the second time"))