6db32fde |
package main
import (
"strings" |
e25352a4 |
"testing" |
dc944ea7 |
|
6345208b |
"gotest.tools/assert" |
38457285 |
"gotest.tools/icmd" |
6db32fde |
)
|
64a928a3 |
func (s *DockerSuite) TestTopMultipleArgs(c *testing.T) { |
a899aa67 |
out := runSleepingContainer(c, "-d") |
475c6531 |
cleanedContainerID := strings.TrimSpace(out) |
d7dd35bb |
|
52f04748 |
var expected icmd.Expected |
18a771a7 |
switch testEnv.OSType { |
52f04748 |
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") |
92427b3a |
result.Assert(c, expected) |
d7dd35bb |
}
|
64a928a3 |
func (s *DockerSuite) TestTopNonPrivileged(c *testing.T) { |
a899aa67 |
out := runSleepingContainer(c, "-d") |
475c6531 |
cleanedContainerID := strings.TrimSpace(out) |
6db32fde |
|
eef6eda7 |
out1, _ := dockerCmd(c, "top", cleanedContainerID)
out2, _ := dockerCmd(c, "top", cleanedContainerID) |
72269acf |
dockerCmd(c, "kill", cleanedContainerID) |
6db32fde |
|
52f04748 |
// 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 |
18a771a7 |
if testEnv.OSType == "windows" { |
52f04748 |
lookingFor = "busybox.exe"
} else {
lookingFor = "top"
}
|
6345208b |
assert.Assert(c, strings.Contains(out1, lookingFor), "top should've listed `%s` in the process list, but failed the first time", lookingFor)
assert.Assert(c, strings.Contains(out2, lookingFor), "top should've listed `%s` in the process list, but failed the second time", lookingFor) |
52f04748 |
}
// 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. |
64a928a3 |
func (s *DockerSuite) TestTopWindowsCoreProcesses(c *testing.T) { |
52f04748 |
testRequires(c, DaemonIsWindows) |
a899aa67 |
out := runSleepingContainer(c, "-d") |
52f04748 |
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 { |
6345208b |
assert.Assert(c, strings.Contains(out1, s), "top should've listed `%s` in the process list, but failed. Test case %d", s, i) |
52f04748 |
} |
031fcb31 |
}
|
64a928a3 |
func (s *DockerSuite) TestTopPrivileged(c *testing.T) { |
52f04748 |
// Windows does not support --privileged |
ea3afdad |
testRequires(c, DaemonIsLinux, NotUserNamespace) |
eef6eda7 |
out, _ := dockerCmd(c, "run", "--privileged", "-i", "-d", "busybox", "top") |
475c6531 |
cleanedContainerID := strings.TrimSpace(out) |
031fcb31 |
|
eef6eda7 |
out1, _ := dockerCmd(c, "top", cleanedContainerID)
out2, _ := dockerCmd(c, "top", cleanedContainerID) |
72269acf |
dockerCmd(c, "kill", cleanedContainerID) |
031fcb31 |
|
6345208b |
assert.Assert(c, strings.Contains(out1, "top"), "top should've listed `top` in the process list, but failed the first time")
assert.Assert(c, strings.Contains(out2, "top"), "top should've listed `top` in the process list, but failed the second time") |
6db32fde |
} |