Files
makronix/mobile/userland/tty/test.sh
T
lotherkandClaude Sonnet 5.5 73c9de51a6 licence: the CNCL line in every file Makronix wrote (tools, docs, www, mobile, top level)
consmirror.c: the BSD notice is replaced (Makronix's own file).  Files with
changes of other sessions pending are left for their commit.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 11:50:26 +00:00

56 lines
2.2 KiB
Bash

#!/bin/sh
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
#
# Test of the tty port. src/tests/usr.bin/tty does not exist, so there is no
# NetBSD test to translate; the cases are the ones tty(1) documents: the
# "not a tty" message with exit status 1, -s that writes no name and only
# affects the exit status, and an error exit (>1) for a bad option.
#
# The positive case -- standard input is a terminal, the name from ttyname(3)
# is written and the status is 0 -- cannot be reached here: both the qemu run
# and the phone run have no terminal on standard input (tools/
# userland-test.sh runs the test over a pipe). It is therefore not tested.
#
# Usage: test.sh TTY DATADIR
# TTY the command that runs the port (a path, or "qemu-aarch64 -L
# <sysroot> <path>"; tools/userland-test.sh passes it)
# DATADIR unused (src/tests/usr.bin/tty does not exist)
# Prints one line per case and exits non-zero if one failed.
[ $# -eq 2 ] || { echo "usage: $0 TTY DATADIR" >&2; exit 2; }
tty=$1 d=$2
fails=0
t=${TMPDIR:-/tmp}/tty-test.$$
mkdir -p "$t" || exit 1
trap 'rm -rf "$t"' EXIT
LC_ALL=C
export LC_ALL
ok() { echo "PASS $1"; }
no() { echo "FAIL $1"; fails=$((fails + 1)); }
same() { # NAME EXPECTED-FILE: compare $t/out with it
if cmp -s "$2" "$t/out"; then ok "$1"; else no "$1"; fi
}
# tty(1): "If the standard input is not a terminal, the message ``not a tty''
# is written", and "exits ... 1 if the standard input is not a terminal".
$tty < /dev/null > "$t/out" 2> "$t/err"
st=$?
printf 'not a tty\n' > "$t/exp"
if [ "$st" -eq 1 ]; then same not-a-tty "$t/exp"; else no not-a-tty; fi
# tty(1) -s: "Don't write the terminal name; only the exit status is
# affected" -- so nothing on standard output, still status 1.
$tty -s < /dev/null > "$t/out" 2> "$t/err"
st=$?
if [ "$st" -eq 1 ] && [ ! -s "$t/out" ]; then ok silent-flag; else no silent-flag; fi
# tty(1) EXIT STATUS: ">1 if an error occurs" -- an unknown option is such an
# error, and the usage goes to standard error.
$tty -q < /dev/null > "$t/out" 2> "$t/err"
st=$?
if [ "$st" -gt 1 ] && [ -s "$t/err" ]; then ok bad-option; else no bad-option; fi
echo "tty: $fails failed"
[ "$fails" -eq 0 ]