selftests/run_kselftest.sh: Use readlink if realpath is not available
PATCH 1/1 selftests/run_kselftest.sh: Use readlink if realpath is not available
'realpath' is not always available, fallback to 'readlink -f' if is not available. They seem to work equally well in this context.
--- tools/testing/selftests/run_kselftest.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
tools/testing/selftests/run_kselftest.sh +8 -1
@@ -3,7 +3,14 @@ # # Run installed kselftest tests. # -BASE_DIR=$(realpath $(dirname $0)) + +# Fallback to readlink if realpath is not available +if which realpath > /dev/null; then + BASE_DIR=$(realpath $(dirname $0)) +else + BASE_DIR=$(readlink -f $(dirname $0)) +fi + cd $BASE_DIR TESTS="$BASE_DIR"/kselftest-list.txt if [ ! -r "$TESTS" ] ; then
Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog
Shuah Khan
maintainerQuoted 2 lines · Yosry Ahmed
'realpath' is not always available, fallback to 'readlink -f' if is not available. They seem to work equally well in this context.
Can you add more specifics on "realpath" is not always available,"
No issues with the patch itself. I would like to know the cases where "realpath" command is missing.
Quoted 16 lines
Signed-off-by Yosry Ahmed <[email protected]>--- tools/testing/selftests/run_kselftest.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)tools/testing/selftests/run_kselftest.sh +1
-1@@ -3,7 +3,14 @@ # # Run installed kselftest tests. # -BASE_DIR=$(realpath $(dirname $0)) +
tools/testing/selftests/run_kselftest.sh line 16
Quoted 10 lines
tools/testing/selftests/run_kselftest.sh +7
-0+# Fallback to readlink if realpath is not available +if which realpath > /dev/null; then + BASE_DIR=$(realpath $(dirname $0)) +else + BASE_DIR=$(readlink -f $(dirname $0)) +fi + cd $BASE_DIR TESTS="$BASE_DIR"/kselftest-list.txt if [ ! -r "$TESTS" ] ; then
thanks,
-- Shuah
Quoted 9 lines · Shuah Khan
Quoted 2 lines · Yosry Ahmed
'realpath' is not always available, fallback to 'readlink -f' if is not
available. They seem to work equally well in this context.Can you add more specifics on "realpath" is not always available," No issues with the patch itself. I would like to know the cases where "realpath" command is missing.
Not all distros have realpath. In my case, it was an internal distro we use on some test machines, so I can't really share much details about it.
Thanks.
Quoted 30 lines
Quoted 17 lines
Signed-off-by Yosry Ahmed <[email protected]>---
tools/testing/selftests/run_kselftest.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)diff --git
a/tools/testing/selftests/run_kselftest.shb/tools/testing/selftests/run_kselftest.shindex50e03eefe7ac7..0443beacf3621100755
---a/tools/testing/selftests/run_kselftest.sh
+++b/tools/testing/selftests/run_kselftest.sh
@@ -3,7 +3,14 @@
#
# Run installed kselftest tests.
#
-BASE_DIR=$(realpath $(dirname $0))
+
+# Fallback to readlink if realpath is not available
+if which realpath >/dev/null; thenQuoted 8 lines
+ BASE_DIR=$(realpath $(dirname $0))
+else
+ BASE_DIR=$(readlink -f $(dirname $0))
+fi
+
cd $BASE_DIR
TESTS="$BASE_DIR"/kselftest-list.txt
if [ ! -r "$TESTS" ] ; thenthanks,
-- Shuah
Quoted 8 lines · Shuah Khan
Quoted 2 lines · Yosry Ahmed
'realpath' is not always available, fallback to 'readlink -f' if is not available. They seem to work equally well in this context.
Can you add more specifics on "realpath" is not always available,"
No issues with the patch itself. I would like to know the cases where "realpath" command is missing.
I think I already responded but I can't find my response, anyway:
Not all distros have realpath. In my case, it was an internal distro we use on some test machines, so I can't really share much details about it.
Are there any other questions that I can help answer about this patch?
Quoted 32 lines
Quoted 18 lines
Signed-off-by Yosry Ahmed <[email protected]>--- tools/testing/selftests/run_kselftest.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)tools/testing/selftests/run_kselftest.sh +1
-1@@ -3,7 +3,14 @@ # # Run installed kselftest tests. # -BASE_DIR=$(realpath $(dirname $0)) +tools/testing/selftests/run_kselftest.sh line 16
Quoted 10 lines
tools/testing/selftests/run_kselftest.sh +7
-0+# Fallback to readlink if realpath is not available +if which realpath > /dev/null; then + BASE_DIR=$(realpath $(dirname $0)) +else + BASE_DIR=$(readlink -f $(dirname $0)) +fi + cd $BASE_DIR TESTS="$BASE_DIR"/kselftest-list.txt if [ ! -r "$TESTS" ] ; thenthanks,
-- Shuah