Skip to content

Commit

Permalink
runc --debug: more tests
Browse files Browse the repository at this point in the history
First, add runc --debug exec test cases, very similar to those in
debug.bats but for runc exec (rather than runc run). Do not include json
tests as it is already tested in debug.bats.

Second, add logrus debug to late stages of runc init, and amend the
integration tests to check for those messages. This serves two purposes:

 - demonstrate that runc init can be amended with debug logrus which is
   properly forwarded to and logged by the parent runc create/run/exec;

 - improve the chances to catch the race fixed by the previous commit.

Signed-off-by: Kir Kolyshkin <[email protected]>
  • Loading branch information
kolyshkin committed Mar 11, 2021
1 parent bcdc8f1 commit 897d121
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions libcontainer/setns_init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/opencontainers/runc/libcontainer/system"
"github.com/opencontainers/selinux/go-selinux"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)

Expand Down Expand Up @@ -87,6 +88,7 @@ func (l *linuxSetnsInit) Init() error {
return newSystemErrorWithCause(err, "init seccomp")
}
}
logrus.Debugf("setns_init: about to exec")
// Close the log pipe fd so the parent's ForwardLogs can exit.
if err := unix.Close(l.logFd); err != nil {
return newSystemErrorWithCause(err, "closing log pipe fd")
Expand Down
2 changes: 2 additions & 0 deletions libcontainer/standard_init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/selinux/go-selinux"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)

Expand Down Expand Up @@ -181,6 +182,7 @@ func (l *linuxStandardInit) Init() error {
return err
}
// Close the pipe to signal that we have completed our init.
logrus.Debugf("init: closing the pipe to signal completion")
l.pipe.Close()

// Close the log pipe fd so the parent's ForwardLogs can exit.
Expand Down
1 change: 1 addition & 0 deletions tests/integration/debug.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function teardown() {
function check_debug() {
[[ "$*" == *"nsexec started"* ]]
[[ "$*" == *"child process in init()"* ]]
[[ "$*" == *"init: closing the pipe to signal completion"* ]]
}

@test "global --debug" {
Expand Down
34 changes: 33 additions & 1 deletion tests/integration/exec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,38 @@ function teardown() {
echo hello >preserve-fds.test
# fd 3 is used by bats, so we use 4
exec 4<preserve-fds.test
output=$(__runc exec --preserve-fds=2 test_busybox cat /proc/self/fd/4)
runc exec --preserve-fds=2 test_busybox cat /proc/self/fd/4
[ "$status" -eq 0 ]
[[ "${output}" == "hello" ]]
}

function check_exec_debug() {
[[ "$*" == *"nsexec started"* ]]
[[ "$*" == *"child process in init()"* ]]
[[ "$*" == *"setns_init: about to exec"* ]]
}

@test "runc --debug exec" {
runc run -d --console-socket "$CONSOLE_SOCKET" test
[ "$status" -eq 0 ]

runc --debug exec test true
[ "$status" -eq 0 ]
[[ "${output}" == *"level=debug"* ]]
check_exec_debug "$output"
}

@test "runc --debug --log exec" {
runc run -d --console-socket "$CONSOLE_SOCKET" test
[ "$status" -eq 0 ]

runc --debug --log log.out exec test true
# check output does not include debug info
[[ "${output}" != *"level=debug"* ]]

cat log.out >&2
# check expected debug output was sent to log.out
output=$(cat log.out)
[[ "${output}" == *"level=debug"* ]]
check_exec_debug "$output"
}

0 comments on commit 897d121

Please sign in to comment.