tests: provide a cmd_exe helper to find a program binary

init.cfg (cmd_exe): Provide a function to find the command under test,
whether in the $PATH or in the standard build directory.
* tests/env/env0-from.sh: Use it instead of `command -v`.
* tests/misc/coreutils.sh: Likewise.
* tests/nproc/nproc-quota.sh: Likewise.
* tests/env/env.sh: Likewise.  Also remove non robust use of sed.
This commit is contained in:
Pádraig Brady committed 2026-08-26 15:18:08 +01:00
1 parent f1a5961c12
commit ff91f242fd
5 files changed
+18 -4

No files matched your search

+14
View File
@@ -350,6 +350,20 @@ require_built_()
test $skip_ = yes && skip_ "required program(s) not built"
}
# Return the file for a command.
# Warn and fail if not found.
cmd_exe()
{
# Give precedence to $PATH to allow overriding command under test
local found_cmd=$(command -v "$1$EXEEXT") # May be a builtin
local found_dir=$(dirname "$(command -v "env$EXEEXT")") # Assume env is not
local built_cmd="$abs_top_builddir/src/$1$EXEEXT"
{ test -x "$found_cmd" && printf '%s\n' "$found_cmd"; } ||
{ test -x "$found_dir/$1" && printf '%s\n' "$found_dir/$1"; } ||
{ test -x "$built_cmd" && printf '%s\n' "$built_cmd"; } ||
{ warn_ "unable to find $1 command"; return 1; }
}
require_file_system_bytes_free_()
{
local req=$1
+1 -1
View File
@@ -21,7 +21,7 @@
print_ver_ env pwd nice
# A simple shebang program to call "echo" from symlinks like "./-u" or "./--".
echo '#!'"$(command -v env | sed 's|/env|/echo|')"' foo' > show_args \
echo '#!'"$(cmd_exe echo)"' foo' > show_args \
|| framework_failure_
chmod a+x show_args || framework_failure_
+1 -1
View File
@@ -20,7 +20,7 @@
print_ver_ env
# reference the env(1) to test before $PATH is adjusted
envexe=$(command -v "env$EXEEXT") || framework_failure_
envexe=$(cmd_exe 'env') || framework_failure_
CU_ENV0_FROM_PARENT=parent
CU_ENV0_FROM_REPLACE=parent
+1 -1
View File
@@ -20,7 +20,7 @@
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ coreutils
cp -s "$(command -v coreutils)" blah || skip_ 'multicall binary is disabled'
cp -s "$(cmd_exe coreutils)" blah || skip_ 'multicall binary is disabled'
# Yes outputs all its params so is good to verify argv manipulations
echo 'y' > exp &&
+1 -1
View File
@@ -44,7 +44,7 @@ ROOT=cgroup
echo 'max 100000' > $ROOT/sys/fs/cgroup/foo/cpu.max # ignored
} || framework_failure_
nproc=$(command -v nproc)
nproc=$(cmd_exe 'nproc')
cp --parents $(ldd "$nproc" | grep -o '/[^ ]*') $ROOT ||
skip_ 'Failed to copy nproc libs to chroot'
cp "$nproc" $ROOT || framework_failure_