Tizen_4.0 base
[platform/upstream/docker-engine.git] / integration-cli / docker_cli_top_test.go
1 package main
2
3 import (
4         "strings"
5
6         "github.com/docker/docker/integration-cli/checker"
7         icmd "github.com/docker/docker/pkg/testutil/cmd"
8         "github.com/go-check/check"
9 )
10
11 func (s *DockerSuite) TestTopMultipleArgs(c *check.C) {
12         out := runSleepingContainer(c, "-d")
13         cleanedContainerID := strings.TrimSpace(out)
14
15         var expected icmd.Expected
16         switch testEnv.DaemonPlatform() {
17         case "windows":
18                 expected = icmd.Expected{ExitCode: 1, Err: "Windows does not support arguments to top"}
19         default:
20                 expected = icmd.Expected{Out: "PID"}
21         }
22         result := dockerCmdWithResult("top", cleanedContainerID, "-o", "pid")
23         c.Assert(result, icmd.Matches, expected)
24 }
25
26 func (s *DockerSuite) TestTopNonPrivileged(c *check.C) {
27         out := runSleepingContainer(c, "-d")
28         cleanedContainerID := strings.TrimSpace(out)
29
30         out1, _ := dockerCmd(c, "top", cleanedContainerID)
31         out2, _ := dockerCmd(c, "top", cleanedContainerID)
32         dockerCmd(c, "kill", cleanedContainerID)
33
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
36         var lookingFor string
37         if testEnv.DaemonPlatform() == "windows" {
38                 lookingFor = "busybox.exe"
39         } else {
40                 lookingFor = "top"
41         }
42
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))
45 }
46
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))
58         }
59 }
60
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)
66
67         out1, _ := dockerCmd(c, "top", cleanedContainerID)
68         out2, _ := dockerCmd(c, "top", cleanedContainerID)
69         dockerCmd(c, "kill", cleanedContainerID)
70
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"))
73 }