mirror of
https://github.com/opencontainers/runc.git
synced 2025-10-13 03:03:56 +08:00

Signed-off-by: Michael Crosby <crosbymichael@gmail.com> Conflicts: MAINTAINERS cgroups/cgroups.go cgroups/fs/apply_raw.go cgroups/fs/notify_linux.go cgroups/fs/notify_linux_test.go cgroups/systemd/apply_systemd.go config.go configs/config_test.go console/console.go integration/exec_test.go integration/init_test.go integration/template_test.go integration/utils_test.go linux_notify.go linux_notify_test.go mount/init.go mount/mount_config.go mount/pivotroot.go mount/ptmx.go namespaces/create.go namespaces/exec.go namespaces/execin.go namespaces/init.go namespaces/nsenter/nsenter.c namespaces/nsenter/nsenter.go namespaces/utils.go network/network.go network/types.go network/veth.go notify_linux.go notify_linux_test.go nsinit/exec.go nsinit/main.go nsinit/nsenter.go nsinit/oom.go sample_configs/host-pid.json sample_configs/userns.json security/capabilities/capabilities.go update-vendor.sh
133 lines
2.7 KiB
Go
133 lines
2.7 KiB
Go
package integration
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"syscall"
|
|
"testing"
|
|
|
|
"github.com/docker/libcontainer"
|
|
)
|
|
|
|
func TestExecIn(t *testing.T) {
|
|
if testing.Short() {
|
|
return
|
|
}
|
|
rootfs, err := newRootfs()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer remove(rootfs)
|
|
config := newTemplateConfig(rootfs)
|
|
container, err := newContainer(config)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer container.Destroy()
|
|
buffers := newStdBuffers()
|
|
process := &libcontainer.Process{
|
|
Args: []string{"sleep", "10"},
|
|
Env: standardEnvironment,
|
|
Stdin: buffers.Stdin,
|
|
Stdout: buffers.Stdout,
|
|
Stderr: buffers.Stderr,
|
|
}
|
|
pid1, err := container.Start(process)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
buffers = newStdBuffers()
|
|
psPid, err := container.Start(&libcontainer.Process{
|
|
Args: []string{"ps"},
|
|
Env: standardEnvironment,
|
|
Stdin: buffers.Stdin,
|
|
Stdout: buffers.Stdout,
|
|
Stderr: buffers.Stderr,
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ps, err := os.FindProcess(psPid)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := ps.Wait(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p, err := os.FindProcess(pid1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := p.Signal(syscall.SIGKILL); err != nil {
|
|
t.Log(err)
|
|
}
|
|
if _, err := p.Wait(); err != nil {
|
|
t.Log(err)
|
|
}
|
|
out := buffers.Stdout.String()
|
|
if !strings.Contains(out, "sleep 10") || !strings.Contains(out, "ps") {
|
|
t.Fatalf("unexpected running process, output %q", out)
|
|
}
|
|
}
|
|
|
|
func TestExecInRlimit(t *testing.T) {
|
|
if testing.Short() {
|
|
return
|
|
}
|
|
rootfs, err := newRootfs()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer remove(rootfs)
|
|
config := newTemplateConfig(rootfs)
|
|
container, err := newContainer(config)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer container.Destroy()
|
|
buffers := newStdBuffers()
|
|
process := &libcontainer.Process{
|
|
Args: []string{"sleep", "10"},
|
|
Env: standardEnvironment,
|
|
Stdin: buffers.Stdin,
|
|
Stdout: buffers.Stdout,
|
|
Stderr: buffers.Stderr,
|
|
}
|
|
pid1, err := container.Start(process)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
buffers = newStdBuffers()
|
|
psPid, err := container.Start(&libcontainer.Process{
|
|
Args: []string{"/bin/sh", "-c", "ulimit -n"},
|
|
Env: standardEnvironment,
|
|
Stdin: buffers.Stdin,
|
|
Stdout: buffers.Stdout,
|
|
Stderr: buffers.Stderr,
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ps, err := os.FindProcess(psPid)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := ps.Wait(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p, err := os.FindProcess(pid1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := p.Signal(syscall.SIGKILL); err != nil {
|
|
t.Log(err)
|
|
}
|
|
if _, err := p.Wait(); err != nil {
|
|
t.Log(err)
|
|
}
|
|
out := buffers.Stdout.String()
|
|
if limit := strings.TrimSpace(out); limit != "1024" {
|
|
t.Fatalf("expected rlimit to be 1024, got %s", limit)
|
|
}
|
|
}
|