[LTP] [PATCH] testcases:Fix the failure of shell script to get path

曾浩
2023-04-04T03:33:39Z

From 9f372d2d4c9a9df9cda1a7afceddaa2acca27f03 Mon Sep 17 00:00:00 2001
From: Hao Zeng <zenghao@kylinos.cn>
Date: Fri, 31 Mar 2023 17:04:07 +0800
Subject: [LTP] [PATCH] testcases:Fix the failure of shell script to get path

For example, in the file testcases/kernel/controllers/cpuset/cpuset_funcs.sh, if the path is obtained by
find "$CPUSET" -type d | sort | sed -n '2,$p' | tac | while read subdir, the escaped characters will be lost,
and by adding the -r option, the escaped characters will be kept as they are without escaping
The errors are as follows:
/opt/ltp/testcases/bin/cpuset_funcs.sh:line178: /dev/cpuset/machine.slice/machine-qemux2d157x2dzhx2dsxf.scope/vcpu7/tasks: The file or directory is not available
rmdir: delete '/dev/cpuset/machine.slice/machine-qemux2d157x2dzhx2dsxf.scope/vcpu7' Failure: The file or directory is not available
cpuset_memory_pressure 1 TFAIL: Couldn't remove subdir -
/opt/ltp/testcases/bin/cpuset_funcs.sh:line178: /dev/cpuset/machine.slice/machine-qemux2d157x2dzhx2dsxf.scope/vcpu7/tasks: The file or directory is not available
rmdir: delete '/dev/cpuset/machine.slice/machine-qemux2d157x2dzhx2dsxf.scope/vcpu7' Failure: The file or directory is not available
cpuset_memory_pressure 1 TFAIL: Couldn't remove subdir -

Signed-off-by: Hao Zeng <zenghao@kylinos.cn>
---
testcases/kernel/controllers/cpuctl_fj/run_cpuctl_test_fj.sh | 2 +-
testcases/kernel/controllers/cpuset/cpuset_funcs.sh | 2 +-
testcases/open_posix_testsuite/scripts/generate-makefiles.sh | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/controllers/cpuctl_fj/run_cpuctl_test_fj.sh b/testcases/kernel/controllers/cpuctl_fj/run_cpuctl_test_fj.sh
index ab73c801b..5cb6bb566 100755
--- a/testcases/kernel/controllers/cpuctl_fj/run_cpuctl_test_fj.sh
+++ b/testcases/kernel/controllers/cpuctl_fj/run_cpuctl_test_fj.sh
@@ -63,7 +63,7 @@ cleanup()
return 0
}

- find $CPUCTL -type d | sort | sed -n '2,$p' | tac | while read tmpdir
+ find $CPUCTL -type d | sort | sed -n '2,$p' | tac | while read -r tmpdir
do
while read tmppid
do
diff --git a/testcases/kernel/controllers/cpuset/cpuset_funcs.sh b/testcases/kernel/controllers/cpuset/cpuset_funcs.sh
index 87ba7da1f..0cfa0c17e 100755
--- a/testcases/kernel/controllers/cpuset/cpuset_funcs.sh
+++ b/testcases/kernel/controllers/cpuset/cpuset_funcs.sh
@@ -184,7 +184,7 @@ cleanup()
echo $CHILDREN_VALUE > $CLONE_CHILDREN
echo $SCHED_LB_VALUE > $SCHED_LB

- find "$CPUSET" -type d | sort | sed -n '2,$p' | tac | while read subdir
+ find "$CPUSET" -type d | sort | sed -n '2,$p' | tac | while read -r subdir
do
while read pid
do
diff --git a/testcases/open_posix_testsuite/scripts/generate-makefiles.sh b/testcases/open_posix_testsuite/scripts/generate-makefiles.sh
index 0649c480f..f3af3cede 100755
--- a/testcases/open_posix_testsuite/scripts/generate-makefiles.sh
+++ b/testcases/open_posix_testsuite/scripts/generate-makefiles.sh
@@ -312,7 +312,7 @@ generate_locate_test_makefile buildonly '.test' "$buildonly_compiler_args"
generate_locate_test_makefile runnable '.run-test'
generate_locate_test_makefile test-tools ''

-find . -name Makefile.1 -exec dirname {} \; | while read dir; do
+find . -name Makefile.1 -exec dirname {} \; | while read -r dir; do
if [ -f "$dir/Makefile.2" ]; then
cat $dir/Makefile.1 $dir/Makefile.2 $dir/Makefile.3 > $dir/Makefile
fi
--
2.37.2