diff options
Diffstat (limited to 'tests/stty')
-rwxr-xr-x | tests/stty/stty-invalid.sh | 60 | ||||
-rwxr-xr-x | tests/stty/stty-pairs.sh | 65 | ||||
-rwxr-xr-x | tests/stty/stty-row-col.sh | 91 | ||||
-rwxr-xr-x | tests/stty/stty.sh | 98 |
4 files changed, 314 insertions, 0 deletions
diff --git a/tests/stty/stty-invalid.sh b/tests/stty/stty-invalid.sh new file mode 100755 index 0000000..7b65d0c --- /dev/null +++ b/tests/stty/stty-invalid.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# Ensure that stty diagnoses invalid inputs, rather than silently misbehaving. + +# Copyright (C) 2007-2023 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ stty +require_controlling_input_terminal_ +require_trap_signame_ + +trap '' TTOU # Ignore SIGTTOU + + +saved_state=$(stty -g) || fail=1 +stty $saved_state || fail=1 + +# Before coreutils-6.9.90, if stty were given an argument with 35 colons +# separating 36 hexadecimal strings, stty would fail to diagnose as invalid +# any number that was out of range as long as sscanf happened to +# overflow/wrap it back into the range of the corresponding type (either +# tcflag_t or cc_t). + +# For each of the following, with coreutils-6.9 and earlier, +# stty would fail to diagnose the error on at least Solaris 10. +hex_2_64=10000000000000000 +returns_ 1 stty $(echo $saved_state |sed 's/^[^:]*:/'$hex_2_64:/) \ + 2>/dev/null || fail=1 +returns_ 1 stty $(echo $saved_state |sed 's/:[0-9a-f]*$/:'$hex_2_64/) \ + 2>/dev/null || fail=1 + +# From coreutils 5.3.0 to 8.28, the following would crash +# due to incorrect argument handling. +if tty -s </dev/tty; then + returns_ 1 stty eol -F /dev/tty || fail=1 + returns_ 1 stty -F /dev/tty eol || fail=1 + returns_ 1 stty -F/dev/tty eol || fail=1 + returns_ 1 stty eol -F/dev/tty eol || fail=1 +fi + +# coreutils <= 9.1 would not validate speeds to ispeed or ospeed +returns_ 1 stty ispeed 420 || fail=1 + +# Just in case either of the above mistakenly succeeds (and changes +# the state of our tty), try to restore the initial state. +stty $saved_state || fail=1 + +Exit $fail diff --git a/tests/stty/stty-pairs.sh b/tests/stty/stty-pairs.sh new file mode 100755 index 0000000..fd32ba2 --- /dev/null +++ b/tests/stty/stty-pairs.sh @@ -0,0 +1,65 @@ +#!/bin/sh +# Make sure stty can parse most of its options - in pairs [expensive]. + +# Copyright (C) 1998-2023 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ stty + +expensive_ + +# Make sure there's a tty on stdin. +require_controlling_input_terminal_ +require_trap_signame_ + +trap '' TTOU # Ignore SIGTTOU + +# Get the reversible settings from stty.c. +stty_reversible_init_ + +saved_state=.saved-state +stty --save > $saved_state || fail=1 +stty $(cat $saved_state) || fail=1 + +# Build a list of all boolean options stty accepts on this system. +# Don't depend on terminal width. Put each option on its own line, +# remove all non-boolean ones, remove 'parenb' and 'cread' explicitly, +# then remove any leading hyphens. +sed_del='/^speed/d;/^rows/d;/^columns/d;/ = /d;s/parenb//;s/cread//' +options=$(stty -a | tr -s ';' '\n' | sed "s/^ //;$sed_del;s/-//g") + +# Take them in pairs, with and without the leading '-'. +for opt1 in $options; do + for opt2 in $options; do + + stty $opt1 $opt2 || fail=1 + + if stty_reversible_query_ "$opt1" ; then + stty -$opt1 $opt2 || fail=1 + fi + if stty_reversible_query_ "$opt2" ; then + stty $opt1 -$opt2 || fail=1 + fi + if stty_reversible_query_ "$opt1" \ + && stty_reversible_query_ "$opt2" ; then + stty -$opt1 -$opt2 || fail=1 + fi + done +done + +stty $(cat $saved_state) + +Exit $fail diff --git a/tests/stty/stty-row-col.sh b/tests/stty/stty-row-col.sh new file mode 100755 index 0000000..2b336e5 --- /dev/null +++ b/tests/stty/stty-row-col.sh @@ -0,0 +1,91 @@ +#!/bin/sh +# Test "stty" with rows and columns. + +# Copyright (C) 1998-2023 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +# Setting this envvar to a very small value used to cause e.g., 'stty size' +# to generate slightly different output on certain systems. +COLUMNS=80 +export COLUMNS + +# Make sure we get English-language behavior. +# See the report about a possibly-related Solaris problem by Alexandre Peshansky +# <https://lists.gnu.org/r/bug-coreutils/2004-10/msg00035.html>. +# Currently stty isn't localized, but it might be in the future. +LC_ALL=C +export LC_ALL + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ stty + +require_controlling_input_terminal_ +require_trap_signame_ + +trap '' TTOU # Ignore SIGTTOU + +# Versions of GNU stty from shellutils-1.9.2c and earlier failed +# tests #2 and #4 when run on SunOS 4.1.3. + +tests=' +1 rows_40_columns_80 40_80 +2 rows_1_columns_1 1_1 +3 rows_40_columns_80 40_80 +4 rows_1 1_80 +5 columns_1 1_1 +6 rows_40 40_1 +7 rows_1 1_1 +8 columns_80 1_80 +9 rows_30 30_80 +10 rows_0x1E 30_80 +11 rows_036 30_80 +NA LAST NA +' +set $tests + +saved_size=$(stty size) && test -n "$saved_size" \ + || skip_ "can't get window size" + +# Linux virtual consoles issue an error if you +# try to increase their size. So skip in that case. +if test "x$saved_size" != "x0 0"; then + srow=$(echo $saved_size | cut -d ' ' -f1) + scol=$(echo $saved_size | cut -d ' ' -f2) + stty rows $(expr $srow + 1) cols $(expr $scol + 1) || + skip_ "can't increase window size" +fi + +while :; do + test_name=$1 + args=$2 + expected_result="$(echo $3|tr _ ' ')" + test "$args" = empty && args='' + test "x$args" = xLAST && break + args=$(echo x$args|tr _ ' '|sed 's/^x//') + if test "$VERBOSE" = yes; then + # echo "testing \$(stty $args; stty size\) = $expected_result ..." + echo "test $test_name... " | tr -d '\n' + fi + stty $args || exit 1 + test x"$(stty size 2> /dev/null)" = "x$expected_result" \ + && ok=ok || ok=FAIL fail=1 + test "$VERBOSE" = yes && echo $ok + shift; shift; shift +done + +set x $saved_size +stty rows $2 columns $3 || exit 1 + +Exit $fail diff --git a/tests/stty/stty.sh b/tests/stty/stty.sh new file mode 100755 index 0000000..6254ab8 --- /dev/null +++ b/tests/stty/stty.sh @@ -0,0 +1,98 @@ +#!/bin/sh +# Make sure stty can parse most of its options. + +# Copyright (C) 1998-2023 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +# Make sure there's a tty on stdin. +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ stty + +require_controlling_input_terminal_ +require_trap_signame_ +require_strace_ ioctl + +trap '' TTOU # Ignore SIGTTOU + +# Get the reversible settings from stty.c. +stty_reversible_init_ + +saved_state=.saved-state +stty --save > $saved_state || fail=1 +stty $(cat $saved_state) || fail=1 + +# This would segfault prior to sh-utils-2.0j. +stty erase - || fail=1 + +# Ensure "immediate" and "wait" mode supported, with and without settings +for mode in '-drain' 'drain'; do + for opt in 'echo' ''; do + stty "$mode" $opt || fail=1 + done +done + +# These would improperly ignore invalid options through coreutils 5.2.1. +returns_ 1 stty -F 2>/dev/null || fail=1 +returns_ 1 stty -raw -F no/such/file 2>/dev/null || fail=1 +returns_ 1 stty -raw -a 2>/dev/null || fail=1 + +# Build a list of all boolean options stty accepts on this system. +# Don't depend on terminal width. Put each option on its own line, +# remove all non-boolean ones, then remove any leading hyphens. +sed_del='/^speed/d;/^rows/d;/^columns/d;/ = /d' +options=$(stty -a | tr -s ';' '\n' | sed "s/^ //;$sed_del;s/-//g") + +# Take them one at a time, with and without the leading '-'. +for opt in $options; do + # 'stty parenb' and 'stty -parenb' fail with this message + # stty: standard input: unable to perform all requested operations + # on Linux 2.2.0-pre4 kernels. Also since around Linux 2.6.30 + # other serial control settings give the same error. So skip them. + # Also on ppc*|sparc* glibc platforms 'icanon' gives the same error. + # See: https://bugs.gnu.org/7228#14 + case $opt in + parenb|parodd|cmspar) continue;; + cstopb|crtscts|cdtrdsr|icanon) continue;; + esac + + # This is listed as supported on FreeBSD + # but the ioctl returns ENOTTY. + test $opt = extproc && continue + + stty $opt || fail=1 + + # Likewise, 'stty -cread' would fail, so skip that, too. + test $opt = cread && continue + if stty_reversible_query_ "$opt" ; then + stty -$opt || { fail=1; echo -$opt; } + fi +done + +stty $(cat $saved_state) + +# Ensure we validate options before accessing the device +strace -o log1 -e ioctl stty --version || fail=1 +n_ioctl1=$(wc -l < log1) || framework_failure_ +returns_ 1 strace -o log2 -e ioctl stty -blahblah || fail=1 +n_ioctl2=$(wc -l < log2) || framework_failure_ +test "$n_ioctl1" = "$n_ioctl2" || fail=1 + +# Ensure we wrap output appropriately +for W in $(seq 80 90); do + output_width=$(COLUMNS="$W" stty -a | wc -L) + test "$output_width" -le "$W" || fail=1 +done + +Exit $fail |