Skip to contentSkip to conversation

selftests/ftrace: Quote check_requires comparisons

PATCH In review Cao Ruichuang 3 participants 3 messages Apr 8

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/ftrace: Quote check_requires comparisons

check_requires() compares requirement strings that can contain shell pattern characters such as '[' and ']'. Under /bin/sh, the unquoted test expressions can emit 'unexpected operator' warnings while parsing README-backed requirements.

Quote the relevant comparisons and path checks so the helper handles those patterns without spurious shell warnings.

Validated by rerunning fprobe_syntax_errors.tc and confirming the previous '/bin/sh: unexpected operator' lines disappear from the detailed ftracetest log.

---
 tools/testing/selftests/ftrace/test.d/functions | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +7 -7
index e8e718139..442aa28ff 100644
@@ -145,13 +145,13 @@ check_requires() { # Check required files and tracers
 	p=${i%:program}
         r=${i%:README}
         t=${i%:tracer}
-	if [ $p != $i ]; then
-	    if ! which $p ; then
+	if [ "$p" != "$i" ]; then
+	    if ! which "$p" ; then
                 echo "Required program $p is not found."
                 exit_unresolved
 	    fi
-        elif [ $t != $i ]; then
-            if ! grep -wq $t available_tracers ; then
+        elif [ "$t" != "$i" ]; then
+            if ! grep -wq "$t" available_tracers ; then
                 echo "Required tracer $t is not configured."
                 exit_unsupported
             fi
@@ -162,11 +162,11 @@ check_requires() { # Check required files and tracers
 	    else
 		test=$TRACING_DIR
 	    fi
-            if ! grep -Fq "$r" $test/README ; then
+            if ! grep -Fq "$r" "$test"/README ; then
                 echo "Required feature pattern \"$r\" is not in README."
                 exit_unsupported
             fi
-        elif [ ! -e $i ]; then
+        elif [ ! -e "$i" ]; then
             echo "Required feature interface $i doesn't exist."
             exit_unsupported
         fi
@@ -223,4 +223,4 @@ get_mnt_options() {
 	local opts=$(mount | grep -m1 "$mnt_point" | sed -e 's/.*(\(.*\)).*/\1/')
 
 	echo "$opts"
-}
\ No newline at end of file
+}
Signature · 1 line
2.39.5 (Apple Git-154)
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · On Wed, 8 Apr 2026 12:32:12 +0800 Cao Ruichuang <[email protected]> wrote:

check_requires() compares requirement strings that can contain shell pattern characters such as '[' and ']'. Under /bin/sh, the unquoted test expressions can emit 'unexpected operator' warnings while parsing README-backed requirements.

Quoted 8 lines

Quote the relevant comparisons and path checks so the helper handles those patterns without spurious shell warnings.

Validated by rerunning fprobe_syntax_errors.tc and confirming the previous '/bin/sh: unexpected operator' lines disappear from the detailed ftracetest log.

Shuah,

Care to take this through your tree?

-- Steve

Quoted 47 lines
---
 tools/testing/selftests/ftrace/test.d/functions | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +7 -7
index e8e718139..442aa28ff 100644
@@ -145,13 +145,13 @@ check_requires() { # Check required files and tracers
 	p=${i%:program}
         r=${i%:README}
         t=${i%:tracer}
-	if [ $p != $i ]; then
-	    if ! which $p ; then
+	if [ "$p" != "$i" ]; then
+	    if ! which "$p" ; then
                 echo "Required program $p is not found."
                 exit_unresolved
 	    fi
-        elif [ $t != $i ]; then
-            if ! grep -wq $t available_tracers ; then
+        elif [ "$t" != "$i" ]; then
+            if ! grep -wq "$t" available_tracers ; then
                 echo "Required tracer $t is not configured."
                 exit_unsupported
             fi
@@ -162,11 +162,11 @@ check_requires() { # Check required files and tracers
 	    else
 		test=$TRACING_DIR
 	    fi
-            if ! grep -Fq "$r" $test/README ; then
+            if ! grep -Fq "$r" "$test"/README ; then
                 echo "Required feature pattern \"$r\" is not in README."
                 exit_unsupported
             fi
-        elif [ ! -e $i ]; then
+        elif [ ! -e "$i" ]; then
             echo "Required feature interface $i doesn't exist."
             exit_unsupported
         fi
@@ -223,4 +223,4 @@ get_mnt_options() {
 	local opts=$(mount | grep -m1 "$mnt_point" | sed -e 's/.*(\(.*\)).*/\1/')
 
 	echo "$opts"
-}
\ No newline at end of file
+}
maintainer
#2 lore raw
Quoted 17 lines · Steven Rostedt
Quoted 5 lines · On Wed, 8 Apr 2026 12:32:12 +0800 Cao Ruichuang <[email protected]> wrote:

check_requires() compares requirement strings that can contain shell pattern characters such as '[' and ']'. Under /bin/sh, the unquoted test expressions can emit 'unexpected operator' warnings while parsing README-backed requirements.

Quoted 8 lines

Quote the relevant comparisons and path checks so the helper handles those patterns without spurious shell warnings.

Validated by rerunning fprobe_syntax_errors.tc and confirming the previous '/bin/sh: unexpected operator' lines disappear from the detailed ftracetest log.

Quoted 7 lines

Shuah,

Care to take this through your tree?

-- Steve

Yes - I can take this for the merge window.

thanks,
-- Shuah