2014-02-25 11:17:48 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2019-09-09 17:06:12 -04:00
|
|
|
"testing"
|
2015-04-18 12:46:47 -04:00
|
|
|
|
2019-04-04 09:23:19 -04:00
|
|
|
"gotest.tools/assert"
|
2018-06-11 09:32:11 -04:00
|
|
|
"gotest.tools/icmd"
|
2014-02-25 11:17:48 -05:00
|
|
|
)
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerSuite) TestTopMultipleArgs(c *testing.T) {
|
2017-04-16 17:39:30 -04:00
|
|
|
out := runSleepingContainer(c, "-d")
|
2015-04-06 09:21:18 -04:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2014-08-31 08:53:05 -04:00
|
|
|
|
2016-08-17 18:46:28 -04:00
|
|
|
var expected icmd.Expected
|
2018-01-15 09:32:06 -05:00
|
|
|
switch testEnv.OSType {
|
2016-08-17 18:46:28 -04: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")
|
2017-08-23 17:01:29 -04:00
|
|
|
result.Assert(c, expected)
|
2014-08-31 08:53:05 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerSuite) TestTopNonPrivileged(c *testing.T) {
|
2017-04-16 17:39:30 -04:00
|
|
|
out := runSleepingContainer(c, "-d")
|
2015-04-06 09:21:18 -04:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2014-02-25 11:17:48 -05:00
|
|
|
|
2015-07-20 02:44:22 -04:00
|
|
|
out1, _ := dockerCmd(c, "top", cleanedContainerID)
|
|
|
|
out2, _ := dockerCmd(c, "top", cleanedContainerID)
|
2015-10-08 15:42:41 -04:00
|
|
|
dockerCmd(c, "kill", cleanedContainerID)
|
2014-02-25 11:17:48 -05:00
|
|
|
|
2016-08-17 18:46:28 -04: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
|
2018-01-15 09:32:06 -05:00
|
|
|
if testEnv.OSType == "windows" {
|
2016-08-17 18:46:28 -04:00
|
|
|
lookingFor = "busybox.exe"
|
|
|
|
} else {
|
|
|
|
lookingFor = "top"
|
|
|
|
}
|
|
|
|
|
2019-04-04 09:23:19 -04:00
|
|
|
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)
|
2016-08-17 18:46:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerSuite) TestTopWindowsCoreProcesses(c *testing.T) {
|
2016-08-17 18:46:28 -04:00
|
|
|
testRequires(c, DaemonIsWindows)
|
2017-04-16 17:39:30 -04:00
|
|
|
out := runSleepingContainer(c, "-d")
|
2016-08-17 18:46:28 -04: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 {
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.Assert(c, strings.Contains(out1, s), "top should've listed `%s` in the process list, but failed. Test case %d", s, i)
|
2016-08-17 18:46:28 -04:00
|
|
|
}
|
2014-04-09 07:43:19 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerSuite) TestTopPrivileged(c *testing.T) {
|
2016-08-17 18:46:28 -04:00
|
|
|
// Windows does not support --privileged
|
2015-09-18 13:41:12 -04:00
|
|
|
testRequires(c, DaemonIsLinux, NotUserNamespace)
|
2015-07-20 02:44:22 -04:00
|
|
|
out, _ := dockerCmd(c, "run", "--privileged", "-i", "-d", "busybox", "top")
|
2015-04-06 09:21:18 -04:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2014-04-09 07:43:19 -04:00
|
|
|
|
2015-07-20 02:44:22 -04:00
|
|
|
out1, _ := dockerCmd(c, "top", cleanedContainerID)
|
|
|
|
out2, _ := dockerCmd(c, "top", cleanedContainerID)
|
2015-10-08 15:42:41 -04:00
|
|
|
dockerCmd(c, "kill", cleanedContainerID)
|
2014-04-09 07:43:19 -04:00
|
|
|
|
2019-04-04 09:23:19 -04:00
|
|
|
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")
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|