3
# tests of podman commands that require an interactive pty
8
###############################################################################
11
# Each test runs with its own PTY, managed by socat.
12
PODMAN_TEST_PTY=$(mktemp -u --tmpdir=${BATS_TMPDIR:-/tmp} podman_pty.XXXXXX)
13
PODMAN_DUMMY=$(mktemp -u --tmpdir=${BATS_TMPDIR:-/tmp} podman_dummy.XXXXXX)
19
# Create a pty. Run under 'timeout' because BATS reaps child processes
20
# and if we exit before killing socat, bats will hang forever.
22
PTY,link=$PODMAN_TEST_PTY,raw,echo=0 \
23
PTY,link=$PODMAN_DUMMY,raw,echo=0 &
28
while [[ ! -e $PODMAN_TEST_PTY ]]; do
29
retries=$(( retries - 1 ))
30
assert $retries -gt 0 "Timed out waiting for $PODMAN_TEST_PTY"
36
if [[ -n $PODMAN_SOCAT_PID ]]; then
37
kill $PODMAN_SOCAT_PID
40
rm -f $PODMAN_TEST_PTY $PODMAN_DUMMY_PTY
46
###############################################################################
49
@test "podman detects correct tty size" {
50
# Set the pty to a random size. Make rows/columns odd/even, to guarantee
51
# that they can never be the same
52
rows=$(( 15 + RANDOM % 60 | 1 ))
53
cols=$(( 15 + RANDOM % 60 & 126 ))
54
stty rows $rows cols $cols <$PODMAN_TEST_PTY
58
# ...and make sure stty under podman reads that.
59
# This flakes often ("stty: standard input"), so, retry.
60
run_podman run -it --name mystty $IMAGE stty size <$PODMAN_TEST_PTY
61
if [[ "$output" =~ stty ]]; then
62
echo "# stty flaked, retrying: $output" >&3
63
run_podman rm -f mystty
65
run_podman run -it --name mystty $IMAGE stty size <$PODMAN_TEST_PTY
67
is "$output" "$rows $cols$CR" "stty under podman run reads the correct dimensions"
69
run_podman rm -t 0 -f mystty
71
# FIXME: the checks below are flaking a lot (see #10710).
73
# check that the same works for podman exec
74
# run_podman run -d --name mystty $IMAGE top
75
# run_podman exec -it mystty stty size <$PODMAN_TEST_PTY
76
# is "$output" "$rows $cols" "stty under podman exec reads the correct dimensions"
78
# run_podman rm -t 0 -f mystty
82
@test "podman load - will not read from tty" {
83
run_podman 125 load <$PODMAN_TEST_PTY
85
"Error: cannot read from terminal, use command-line redirection or the --input flag" \
86
"Diagnostic from 'podman load' without redirection or -i"
90
@test "podman run --tty -i failure with no tty" {
91
run_podman 0+w run --tty -i --rm $IMAGE echo hello < /dev/null
92
require_warning "The input device is not a TTY.*" "-it _without_ a tty"
95
run_podman run --tty -i --rm $IMAGE echo hello <$PODMAN_TEST_PTY
96
is "$output" "hello$CR" "-it _with_ a pty"
98
run_podman run --tty=false -i --rm $IMAGE echo hello < /dev/null
99
is "$output" "hello" "-tty=false: no warning"
101
run_podman run --tty -i=false --rm $IMAGE echo hello < /dev/null
102
is "$output" "hello$CR" "-i=false: no warning"
106
@test "podman run -l passthrough-tty" {
109
# Requires conmon 2.1.10 or greater
111
run_podman info --format '{{.Host.Conmon.Path}}'
112
conmon_path="$output"
113
conmon_version=$($conmon_path --version | sed -ne 's/^.* version //p')
114
if ! printf "%s\n%s\n" "$want" "$conmon_version" | sort --check=quiet --version-sort; then
115
skip "need conmon >= $want; have $conmon_version"
118
run tty <$PODMAN_TEST_PTY
119
expected_tty="$output"
121
run_podman run -v/dev:/dev --log-driver=passthrough-tty $IMAGE tty <$PODMAN_TEST_PTY
122
is "$output" "$expected_tty" "passthrough-tty: tty matches"