Skip to contentSkip to conversation

testcases:Fix the failure of shell script to get path

PATCH In review 曾浩 3 participants 3 messages Apr 4, 2023 – May 6, 2023

lore
Share & tools
lore

曾浩

author
#0 lore raw

PATCH 1/1 testcases:Fix the failure of shell script to get path

From 9f372d2d4c9a9df9cda1a7afceddaa2acca27f03 Mon Sep 17 00:00:00 2001
From: Hao Zeng <[email protected]>
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 -

---
 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(-)
testcases/kernel/controllers/cpuctl_fj/run_cpuctl_test_fj.sh +1 -1
index ab73c801b..5cb6bb566 100755
@@ -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
testcases/kernel/controllers/cpuset/cpuset_funcs.sh +1 -1
index 87ba7da1f..0cfa0c17e 100755
@@ -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
testcases/open_posix_testsuite/scripts/generate-makefiles.sh +1 -1
index 0649c480f..f3af3cede 100755
@@ -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
Signature · 4 lines
2.37.2

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 1/1
#1 lore raw
Quoted 56 lines

From 9f372d2d4c9a9df9cda1a7afceddaa2acca27f03 Mon Sep 17 00:00:00 2001
From: Hao Zeng <[email protected]>
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 -

---
 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(-)
testcases/kernel/controllers/cpuctl_fj/run_cpuctl_test_fj.sh +1 -1
index ab73c801b..5cb6bb566 100755
@@ -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
testcases/kernel/controllers/cpuset/cpuset_funcs.sh +1 -1
index 87ba7da1f..0cfa0c17e 100755
@@ -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
testcases/open_posix_testsuite/scripts/generate-makefiles.sh +0 -0
index 0649c480f..f3af3cede 100755

testcases/open_posix_testsuite/scripts/generate-makefiles.sh generate_locate_test_makefile buildonly '.test' "$buildonly_compiler_args" · line 318

Quoted 8 lines
testcases/open_posix_testsuite/scripts/generate-makefiles.sh +1 -1
@@ -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

I'd remove change in testcases/open_posix_testsuite/scripts/generate-makefiles.sh IMHO problematic are only controllers shell scripts. Only cpuset are relevant to be escaped. Also, we could use systemd-escape:

systemd-escape -u 'machine-qemu\x2d3\x2dzh\x2dnode1.scope' -> machine/qemu-3-zh-node1.scope

but there are SUT without systemd, thus let's keep "read -r".

(We already talked about it, but you weren't subscribed, thus messages got lost, see the details below.)

Kind regards,
Petr

Quoted 52 lines

Dear Petr
Thank you for taking the time to reply to my email. I appreciate your prompt response and the valuable information you have provided.

Quoted 8 lines · Petr Vorel
Quoted 5 lines

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

Could you print the path how it looks like with ls:

ls -l /dev/cpuset/machine.slice/

ls -l /dev/cpuset/machine.slice/

testcases/open_posix_testsuite/scripts/generate-makefiles.sh +0 -15
-rw-r--r-- 1 root root 0  Apr  5 13:44  cgroup.clone_children
-rw-r--r-- 1 root root 0  Apr  5 13:44  cgroup.procs
-rw-r--r-- 1 root root 0  Apr  5 13:44  cpuset.cpu_exclusive
-rw-r--r-- 1 root root 0  Apr  4 17:41  cpuset.cpus
-r--r--r-- 1 root root 0  Apr  5 13:44  cpuset.effective_cpus
-r--r--r-- 1 root root 0  Apr  5 13:44  cpuset.effective_mems
-rw-r--r-- 1 root root 0  Apr  5 13:44  cpuset.mem_exclusive
-rw-r--r-- 1 root root 0  Apr  5 13:44  cpuset.mem_hardwall
-rw-r--r-- 1 root root 0  Apr  4 17:41  cpuset.memory_migrate
-r--r--r-- 1 root root 0  Apr  5 13:44  cpuset.memory_pressure
-rw-r--r-- 1 root root 0  Apr  5 13:44  cpuset.memory_spread_page
-rw-r--r-- 1 root root 0  Apr  5 13:44  cpuset.memory_spread_slab
-rw-r--r-- 1 root root 0  Apr  4 17:41  cpuset.mems
-rw-r--r-- 1 root root 0  Apr  5 13:44  cpuset.sched_load_balance
-rw-r--r-- 1 root root 0  Apr  5 13:44 cpuset.sched_relax_domain_level

drwxr-xr-x 6 root root 0  Apr  5 13:44
'machine-qemu\x2d3\x2dzh\x2dnode1.scope'

testcases/open_posix_testsuite/scripts/generate-makefiles.sh +0 -2
-rw-r--r-- 1 root root 0  Apr  5 13:44  notify_on_release
-rw-r--r-- 1 root root 0  Apr  5 13:44  tasks
Quoted 5 lines

FYI cgroup tests written in shell are broken by design, we write new tests in C. Not sure if these old tests are relevant enough to be rewritten into C.

...

get it

Quoted 7 lines

testcases/open_posix_testsuite/scripts/generate-makefiles.sh generate_locate_test_makefile buildonly '.test' "$buildonly_compiler_args" · line 314

Quoted 6 lines

+++ b/testcases/open_posix_testsuite/scripts/generate-makefiles.sh

testcases/open_posix_testsuite/scripts/generate-makefiles.sh +1 -1
@@ -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

I don't think it's needed for open posix.

I agree with your viewpoint.

Quoted 2 lines

Kind regards,
Petr

Best regards
Hao

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

On Fri, 2023-05-05 at 19:41 +0200, Petr Vorel wrote:

hi Petr
Thanks very much for your reply.
I will follow your suggestion and submit the V2 version

Best regards
Hao

Quoted 184 lines
Quoted 93 lines

From 9f372d2d4c9a9df9cda1a7afceddaa2acca27f03 Mon Sep 17 00:00:00 2001
From: Hao Zeng <[email protected]>
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 -

---
 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

testcases/kernel/controllers/cpuctl_fj/run_cpuctl_test_fj.sh +0 -0
@@ -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

testcases/kernel/controllers/cpuset/cpuset_funcs.sh +0 -0
index 87ba7da1f..0cfa0c17e 100755
@@ -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

(quoted diff) +0 -0

makefiles.sh b/testcases/open_posix_testsuite/scripts/generate- makefiles.sh
index 0649c480f..f3af3cede 100755

testcases/open_posix_testsuite/scripts/generate-makefiles.sh +0 -0
@@ -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 ''

testcases/open_posix_testsuite/scripts/generate-makefiles.sh +1 -1
-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

Quoted 2 lines
Quoted 1 line

$dir/Makefile

        fi

I'd remove change in testcases/open_posix_testsuite/scripts/generate- makefiles.sh
IMHO problematic are only controllers shell scripts. Only cpuset are relevant
to be escaped. Also, we could use systemd-escape:

systemd-escape -u 'machine-qemu\x2d3\x2dzh\x2dnode1.scope' -> machine/qemu-3-zh-node1.scope

but there are SUT without systemd, thus let's keep "read -r".

(We already talked about it, but you weren't subscribed, thus messages got
lost, see the details below.)

Kind regards,
Petr

Quoted 67 lines

Dear Petr
Thank you for taking the time to reply to my email. I appreciate your prompt
response and the valuable information you have provided.

Quoted 12 lines · Petr Vorel
Quoted 4 lines

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

Quoted 8 lines

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

Quoted 3 lines

Could you print the path how it looks like with ls:

ls -l /dev/cpuset/machine.slice/

ls -l /dev/cpuset/machine.slice/

testcases/open_posix_testsuite/scripts/generate-makefiles.sh +0 -15
-rw-r--r-- 1 root root 0  Apr  5 13:44  cgroup.clone_children
-rw-r--r-- 1 root root 0  Apr  5 13:44  cgroup.procs
-rw-r--r-- 1 root root 0  Apr  5 13:44  cpuset.cpu_exclusive
-rw-r--r-- 1 root root 0  Apr  4 17:41  cpuset.cpus
-r--r--r-- 1 root root 0  Apr  5 13:44  cpuset.effective_cpus
-r--r--r-- 1 root root 0  Apr  5 13:44  cpuset.effective_mems
-rw-r--r-- 1 root root 0  Apr  5 13:44  cpuset.mem_exclusive
-rw-r--r-- 1 root root 0  Apr  5 13:44  cpuset.mem_hardwall
-rw-r--r-- 1 root root 0  Apr  4 17:41  cpuset.memory_migrate
-r--r--r-- 1 root root 0  Apr  5 13:44  cpuset.memory_pressure
-rw-r--r-- 1 root root 0  Apr  5 13:44  cpuset.memory_spread_page
-rw-r--r-- 1 root root 0  Apr  5 13:44  cpuset.memory_spread_slab
-rw-r--r-- 1 root root 0  Apr  4 17:41  cpuset.mems
-rw-r--r-- 1 root root 0  Apr  5 13:44  cpuset.sched_load_balance
-rw-r--r-- 1 root root 0  Apr  5 13:44

cpuset.sched_relax_domain_level
drwxr-xr-x 6 root root 0  Apr  5 13:44
'machine-qemu\x2d3\x2dzh\x2dnode1.scope'

testcases/open_posix_testsuite/scripts/generate-makefiles.sh +0 -2
-rw-r--r-- 1 root root 0  Apr  5 13:44  notify_on_release
-rw-r--r-- 1 root root 0  Apr  5 13:44  tasks
Quoted 7 lines

FYI cgroup tests written in shell are broken by design, we write new tests in C.
Not sure if these old tests are relevant enough to be rewritten into C.

...

get it

Quoted 11 lines
Quoted 10 lines

+++ b/testcases/open_posix_testsuite/scripts/generate- makefiles.sh

(quoted diff) +0 -0
@@ -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

I don't think it's needed for open posix.

I agree with your viewpoint.

Quoted 2 lines

Kind regards,
Petr

Best regards
Hao

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp