Skip to contentSkip to conversation

perf test: Fixed masked error condition in perf data convert test

PATCH In review James Clark 3 participants 3 messages Jan 12, 2024 – Jan 17, 2024 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf test: Fixed masked error condition in perf data convert test

The test does set -e, so any errors go straight to the exit handler, where it returns err=0 (success). Fix it by leaving err=1 from the beginning and only set the success code if it ran all the way to the end without errors.

Also remove the exit code argument from the last exit because it doesn't do anything, it's always replaced by err in the exit handler.

Fixes 68d124182610 ("perf test: Add test validating JSON generated by 'perf data convert --to-json'")
---
 tools/perf/tests/shell/test_perf_data_converter_json.sh | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
tools/perf/tests/shell/test_perf_data_converter_json.sh +5 -4
index c4f1b59d116f..1781b7215c11 100755
@@ -4,7 +4,7 @@
 
 set -e
 
-err=0
+err=1
 
 shelldir=$(dirname "$0")
 # shellcheck source=lib/setup_python.sh
@@ -36,7 +36,6 @@ test_json_converter_command()
 		echo "Perf Data Converter Command to JSON [SUCCESS]"
 	else
 		echo "Perf Data Converter Command to JSON [FAILED]"
-		err=1
 		exit
 	fi
 }
@@ -49,7 +48,6 @@ validate_json_format()
 			echo "The file contains valid JSON format [SUCCESS]"
 		else
 			echo "The file does not contain valid JSON format [FAILED]"
-			err=1
 			exit
 		fi
 	else
@@ -62,4 +60,7 @@ validate_json_format()
 test_json_converter_command
 validate_json_format
 
-exit ${err}
+# Set -e is on, so it was only successful if it ran up to this point.
+# Therefore only set err=0 here.
+err=0
+exit
Signature · 1 line
2.34.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · James Clark

The test does set -e, so any errors go straight to the exit handler, where it returns err=0 (success). Fix it by leaving err=1 from the beginning and only set the success code if it ran all the way to the end without errors.

Also remove the exit code argument from the last exit because it doesn't do anything, it's always replaced by err in the exit handler.

Fixes 68d124182610 ("perf test: Add test validating JSON generated by 'perf data convert --to-json'")

Thanks,
Namhyung

Quoted 45 lines
---
 tools/perf/tests/shell/test_perf_data_converter_json.sh | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
tools/perf/tests/shell/test_perf_data_converter_json.sh +5 -5
index c4f1b59d116f..1781b7215c11 100755
@@ -4,7 +4,7 @@
 
 set -e
 
-err=0
+err=1
 
 shelldir=$(dirname "$0")
 # shellcheck source=lib/setup_python.sh
@@ -36,7 +36,6 @@ test_json_converter_command()
                echo "Perf Data Converter Command to JSON [SUCCESS]"
        else
                echo "Perf Data Converter Command to JSON [FAILED]"
-               err=1
                exit
        fi
 }
@@ -49,7 +48,6 @@ validate_json_format()
                        echo "The file contains valid JSON format [SUCCESS]"
                else
                        echo "The file does not contain valid JSON format [FAILED]"
-                       err=1
                        exit
                fi
        else
@@ -62,4 +60,7 @@ validate_json_format()
 test_json_converter_command
 validate_json_format
 
-exit ${err}
+# Set -e is on, so it was only successful if it ran up to this point.
+# Therefore only set err=0 here.
+err=0
+exit
--

2.34.1

Reviewed-by on v1 1/1
#2 lore raw
In reply to James Clark
Quoted 10 lines · James Clark

The test does set -e, so any errors go straight to the exit handler, where it returns err=0 (success). Fix it by leaving err=1 from the beginning and only set the success code if it ran all the way to the end without errors.

Also remove the exit code argument from the last exit because it doesn't do anything, it's always replaced by err in the exit handler.

Fixes 68d124182610 ("perf test: Add test validating JSON generated by 'perf data convert --to-json'")

Looks good to me.

Cheers, Ilkka

Quoted 46 lines

---
tools/perf/tests/shell/test_perf_data_converter_json.sh | 9 +++++----

1 file changed, 5 insertions(+), 4 deletions(-)
tools/perf/tests/shell/test_perf_data_converter_json.sh +0 -0
index c4f1b59d116f..1781b7215c11 100755
@@ -4,7 +4,7 @@
 

set -e

tools/perf/tests/shell/test_perf_data_converter_json.sh +1 -1
-err=0
+err=1

shelldir=$(dirname "$0")

# shellcheck source=lib/setup_python.sh
tools/perf/tests/shell/test_perf_data_converter_json.sh +0 -2
@@ -36,7 +36,6 @@ test_json_converter_command()
 		echo "Perf Data Converter Command to JSON [SUCCESS]"
 	else
 		echo "Perf Data Converter Command to JSON [FAILED]"
-		err=1
 		exit
 	fi
 }
@@ -49,7 +48,6 @@ validate_json_format()
 			echo "The file contains valid JSON format [SUCCESS]"
 		else
 			echo "The file does not contain valid JSON format [FAILED]"
-			err=1
 			exit
 		fi
 	else
@@ -62,4 +60,7 @@ validate_json_format()

test_json_converter_command
validate_json_format

tools/perf/tests/shell/test_perf_data_converter_json.sh +4 -1
-exit ${err}
+# Set -e is on, so it was only successful if it ran up to this point.
+# Therefore only set err=0 here.
+err=0
+exit
Signature · 1 line
2.34.1