tools: add checkusage.sh
Just some simple generic tests for our UL commands, regarding
options --help, --version and --unknownopt.
The script looks still a bit weired but could be polished to
be used in tests/. It would be the first time testing at least
"something" for *all* built binaries (currently 109! commands).
For the record here are the current candidates with possible
problems:
$ make checkusage
agetty: --unknownopt, stderr too long: 45
blockdev: --unknownopt, stderr too long: 28
flock: --help, no stdout
flock: --help, non-empty stderr
getopt: --help, returns error
kill: --unknownopt, stderr too short: 1
lsipc: --unknownopt, stderr too long: 77
pg: --unknownopt, stderr too long: 23
renice: --unknownopt, stderr too long: 18
rtcwake: --unknownopt, non-empty stdout
rtcwake: --unknownopt, stderr too long: 21
sulogin: --unknownopt, stderr too long: 17
write: --unknownopt, stderr too long: 12
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-18 08:19:39 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
## This script is potentially dangerous! Don't run it on
|
|
|
|
## arbitrary commands.
|
|
|
|
|
|
|
|
export LC_ALL=C
|
|
|
|
|
|
|
|
if [ "$#" -lt 1 ]; then
|
|
|
|
echo "usage: $0 program..." >&2
|
|
|
|
echo " or try 'make checkusage' to check all built programs" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
builddir="."
|
|
|
|
cmds=$(echo $@ | tr ' ' '\n' | sort)
|
|
|
|
|
2017-06-27 01:25:22 -05:00
|
|
|
# set env to dump all output to files
|
|
|
|
test -z "$CU_DUMP" || rm -f /tmp/checkusage--{help,version,unknownopt}
|
|
|
|
|
tools: add checkusage.sh
Just some simple generic tests for our UL commands, regarding
options --help, --version and --unknownopt.
The script looks still a bit weired but could be polished to
be used in tests/. It would be the first time testing at least
"something" for *all* built binaries (currently 109! commands).
For the record here are the current candidates with possible
problems:
$ make checkusage
agetty: --unknownopt, stderr too long: 45
blockdev: --unknownopt, stderr too long: 28
flock: --help, no stdout
flock: --help, non-empty stderr
getopt: --help, returns error
kill: --unknownopt, stderr too short: 1
lsipc: --unknownopt, stderr too long: 77
pg: --unknownopt, stderr too long: 23
renice: --unknownopt, stderr too long: 18
rtcwake: --unknownopt, non-empty stdout
rtcwake: --unknownopt, stderr too long: 21
sulogin: --unknownopt, stderr too long: 17
write: --unknownopt, stderr too long: 12
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-18 08:19:39 -05:00
|
|
|
## Set alternative options for --help, --version
|
|
|
|
## or --unknownopt. "x" means "not implemented".
|
|
|
|
##
|
|
|
|
## Examples:
|
|
|
|
## alt_whereis__help="-h" # in past whereis(1) had no longopt for --help
|
|
|
|
## alt_more__help="x" # more(1) had neither --help nor -h
|
|
|
|
|
2017-06-27 01:25:10 -05:00
|
|
|
alt_fsck__unknownopt="x" # fsck passes unknown opts to fsck.ext4, etc.
|
|
|
|
alt_mkfs__unknownopt="x" # dito
|
|
|
|
alt_kill__unknownopt="inval pids" # trick, kill does not use errtryhelp()
|
|
|
|
if [ $(id -ru) -eq 0 ]; then
|
|
|
|
alt_sulogin__unknownopt="x" # would hang at pwd prompt
|
|
|
|
fi
|
tools: add checkusage.sh
Just some simple generic tests for our UL commands, regarding
options --help, --version and --unknownopt.
The script looks still a bit weired but could be polished to
be used in tests/. It would be the first time testing at least
"something" for *all* built binaries (currently 109! commands).
For the record here are the current candidates with possible
problems:
$ make checkusage
agetty: --unknownopt, stderr too long: 45
blockdev: --unknownopt, stderr too long: 28
flock: --help, no stdout
flock: --help, non-empty stderr
getopt: --help, returns error
kill: --unknownopt, stderr too short: 1
lsipc: --unknownopt, stderr too long: 77
pg: --unknownopt, stderr too long: 23
renice: --unknownopt, stderr too long: 18
rtcwake: --unknownopt, non-empty stdout
rtcwake: --unknownopt, stderr too long: 21
sulogin: --unknownopt, stderr too long: 17
write: --unknownopt, stderr too long: 12
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-18 08:19:39 -05:00
|
|
|
|
|
|
|
function exec_option {
|
|
|
|
local cmdb=$1
|
|
|
|
local cmd=$2
|
|
|
|
opt=$3
|
2017-06-27 01:25:22 -05:00
|
|
|
local tofile="/tmp/checkusage$opt"
|
tools: add checkusage.sh
Just some simple generic tests for our UL commands, regarding
options --help, --version and --unknownopt.
The script looks still a bit weired but could be polished to
be used in tests/. It would be the first time testing at least
"something" for *all* built binaries (currently 109! commands).
For the record here are the current candidates with possible
problems:
$ make checkusage
agetty: --unknownopt, stderr too long: 45
blockdev: --unknownopt, stderr too long: 28
flock: --help, no stdout
flock: --help, non-empty stderr
getopt: --help, returns error
kill: --unknownopt, stderr too short: 1
lsipc: --unknownopt, stderr too long: 77
pg: --unknownopt, stderr too long: 23
renice: --unknownopt, stderr too long: 18
rtcwake: --unknownopt, non-empty stdout
rtcwake: --unknownopt, stderr too long: 21
sulogin: --unknownopt, stderr too long: 17
write: --unknownopt, stderr too long: 12
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-18 08:19:39 -05:00
|
|
|
|
|
|
|
local alt="alt_${cmdb}${opt}"
|
|
|
|
alt=${alt//-/_}
|
|
|
|
alt=${alt//./_}
|
|
|
|
alt=$(eval printf -- \"\$${alt}\")
|
|
|
|
if test -n "$alt"; then
|
|
|
|
if test "$alt" = "x"; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
opt=$alt
|
|
|
|
fi
|
|
|
|
|
2017-06-27 01:25:22 -05:00
|
|
|
test -z "$CU_DUMP" || {
|
|
|
|
echo "##########################################################"
|
|
|
|
echo "#### $cmdb"
|
|
|
|
$cmd $opt
|
|
|
|
} >> "$tofile" 2>&1
|
|
|
|
|
2017-06-27 01:25:10 -05:00
|
|
|
out=$("$cmd" $opt 2>/dev/null)
|
|
|
|
err=$("$cmd" $opt 2>&1 >/dev/null)
|
tools: add checkusage.sh
Just some simple generic tests for our UL commands, regarding
options --help, --version and --unknownopt.
The script looks still a bit weired but could be polished to
be used in tests/. It would be the first time testing at least
"something" for *all* built binaries (currently 109! commands).
For the record here are the current candidates with possible
problems:
$ make checkusage
agetty: --unknownopt, stderr too long: 45
blockdev: --unknownopt, stderr too long: 28
flock: --help, no stdout
flock: --help, non-empty stderr
getopt: --help, returns error
kill: --unknownopt, stderr too short: 1
lsipc: --unknownopt, stderr too long: 77
pg: --unknownopt, stderr too long: 23
renice: --unknownopt, stderr too long: 18
rtcwake: --unknownopt, non-empty stdout
rtcwake: --unknownopt, stderr too long: 21
sulogin: --unknownopt, stderr too long: 17
write: --unknownopt, stderr too long: 12
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-18 08:19:39 -05:00
|
|
|
ret=$?
|
|
|
|
|
|
|
|
# hardcoded ... nologin should always return false
|
|
|
|
if test "$cmdb" = "nologin" &&
|
|
|
|
test "$opt" = "--help" -o "$opt" = "--version"; then
|
2017-06-27 13:34:29 -05:00
|
|
|
if test "$ret" -eq 0 -o "$ret" -ge 128; then
|
|
|
|
echo "$cmdb, $opt, should return false: $ret"
|
tools: add checkusage.sh
Just some simple generic tests for our UL commands, regarding
options --help, --version and --unknownopt.
The script looks still a bit weired but could be polished to
be used in tests/. It would be the first time testing at least
"something" for *all* built binaries (currently 109! commands).
For the record here are the current candidates with possible
problems:
$ make checkusage
agetty: --unknownopt, stderr too long: 45
blockdev: --unknownopt, stderr too long: 28
flock: --help, no stdout
flock: --help, non-empty stderr
getopt: --help, returns error
kill: --unknownopt, stderr too short: 1
lsipc: --unknownopt, stderr too long: 77
pg: --unknownopt, stderr too long: 23
renice: --unknownopt, stderr too long: 18
rtcwake: --unknownopt, non-empty stdout
rtcwake: --unknownopt, stderr too long: 21
sulogin: --unknownopt, stderr too long: 17
write: --unknownopt, stderr too long: 12
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-18 08:19:39 -05:00
|
|
|
fi
|
|
|
|
ret=0
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function check_help {
|
|
|
|
local cb=$1
|
|
|
|
local c=$2
|
|
|
|
|
|
|
|
if ! exec_option "$cb" "$c" --help; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test $ret != 0; then
|
|
|
|
echo "$cb: $opt, returns error"
|
|
|
|
else
|
|
|
|
if test -z "$out"; then
|
|
|
|
echo "$cb: $opt, no stdout"
|
|
|
|
fi
|
|
|
|
if test -n "$err"; then
|
|
|
|
echo "$cb: $opt, non-empty stderr"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_version {
|
|
|
|
local cb=$1
|
|
|
|
local c=$2
|
|
|
|
|
|
|
|
if ! exec_option "$cb" "$c" --version; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test $ret != 0; then
|
|
|
|
echo "$cb: $opt, returns error"
|
|
|
|
else
|
|
|
|
if test -z "$out"; then
|
|
|
|
echo "$cb: $opt, no stdout"
|
|
|
|
fi
|
|
|
|
if test -n "$err"; then
|
|
|
|
echo "$cb: $opt, non-empty stderr"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_unknownopt {
|
|
|
|
local cb=$1
|
|
|
|
local c=$2
|
|
|
|
local nohelp=$3
|
|
|
|
|
|
|
|
if ! exec_option "$cb" "$c" --unknownopt; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test $ret = 0; then
|
|
|
|
echo "$cb: $opt, returns no error"
|
2017-06-27 13:34:29 -05:00
|
|
|
elif test $ret -ge 128; then
|
|
|
|
echo "$cb: $opt, abnormal exit: $ret"
|
tools: add checkusage.sh
Just some simple generic tests for our UL commands, regarding
options --help, --version and --unknownopt.
The script looks still a bit weired but could be polished to
be used in tests/. It would be the first time testing at least
"something" for *all* built binaries (currently 109! commands).
For the record here are the current candidates with possible
problems:
$ make checkusage
agetty: --unknownopt, stderr too long: 45
blockdev: --unknownopt, stderr too long: 28
flock: --help, no stdout
flock: --help, non-empty stderr
getopt: --help, returns error
kill: --unknownopt, stderr too short: 1
lsipc: --unknownopt, stderr too long: 77
pg: --unknownopt, stderr too long: 23
renice: --unknownopt, stderr too long: 18
rtcwake: --unknownopt, non-empty stdout
rtcwake: --unknownopt, stderr too long: 21
sulogin: --unknownopt, stderr too long: 17
write: --unknownopt, stderr too long: 12
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-18 08:19:39 -05:00
|
|
|
fi
|
|
|
|
if test -n "$out"; then
|
|
|
|
echo "$cb: $opt, non-empty stdout"
|
|
|
|
fi
|
|
|
|
if test -z "$err"; then
|
|
|
|
echo "$cb: $opt, no stderr"
|
|
|
|
elif test -z "$nohelp" -o "$nohelp" != "yes"; then
|
|
|
|
out_len=$(echo "$out" | wc -l)
|
|
|
|
err_len=$(echo "$err" | wc -l)
|
|
|
|
if test "$err_len" -gt 2; then
|
2017-06-27 01:25:10 -05:00
|
|
|
echo "$cb: $opt, stderr too long: $err_len"
|
tools: add checkusage.sh
Just some simple generic tests for our UL commands, regarding
options --help, --version and --unknownopt.
The script looks still a bit weired but could be polished to
be used in tests/. It would be the first time testing at least
"something" for *all* built binaries (currently 109! commands).
For the record here are the current candidates with possible
problems:
$ make checkusage
agetty: --unknownopt, stderr too long: 45
blockdev: --unknownopt, stderr too long: 28
flock: --help, no stdout
flock: --help, non-empty stderr
getopt: --help, returns error
kill: --unknownopt, stderr too short: 1
lsipc: --unknownopt, stderr too long: 77
pg: --unknownopt, stderr too long: 23
renice: --unknownopt, stderr too long: 18
rtcwake: --unknownopt, non-empty stdout
rtcwake: --unknownopt, stderr too long: 21
sulogin: --unknownopt, stderr too long: 17
write: --unknownopt, stderr too long: 12
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-18 08:19:39 -05:00
|
|
|
elif test "$err_len" -lt 2; then
|
|
|
|
echo "$cb: $opt, stderr too short: $err_len"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
for cb in $cmds; do
|
|
|
|
c="$builddir/$cb"
|
|
|
|
if ! type "$c" &>/dev/null; then
|
|
|
|
echo "$cb: does not exist"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
nohelp="no"
|
|
|
|
if ! check_help "$cb" "$c"; then
|
|
|
|
nohelp="yes"
|
|
|
|
fi
|
|
|
|
check_version "$cb" "$c"
|
|
|
|
check_unknownopt "$cb" "$c" "$nohelp"
|
|
|
|
done
|
|
|
|
|