[dredd] applying error handling code to runner.sh (#8935)
author윤현식/On-Device Lab(SR)/Principal Engineer/삼성전자 <hyunsik.yoon@samsung.com>
Thu, 14 Nov 2019 07:09:21 +0000 (16:09 +0900)
committer박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Thu, 14 Nov 2019 07:09:21 +0000 (16:09 +0900)
* [dredd] applying error handling code to runner.sh

This applies error handling code into runner.sh that was applied in #8888, #8910

Signed-off-by: Hyun Sik Yoon <hyunsik.yoon@samsung.com>
* change comment

compiler/tf2circle-dredd-pb-test/runner.sh
compiler/tf2circle-dredd-pbtxt-test/runner.sh
compiler/tf2tflite-dredd-pb-test/runner.sh
compiler/tf2tflite-dredd-pbtxt-test/runner.sh

index 5745db1..7c7b123 100755 (executable)
@@ -2,6 +2,9 @@
 
 # This script checks circle file generated by tf2circle
 
+# exit if unknown var is used
+set -u
+
 WORKDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
 
 # Need at least toolchain.config
@@ -76,15 +79,23 @@ while [[ $# -ne 0 ]]; do
     COMPILED_FILE=${CIRCLE_PATH}
     INSPECT_PROG_PATH=${CIRCLE_INSPECT_PATH}
     VERIFY_PROG_PATH=${CIRCLE_VERIFY_PATH}
+    ERROR_LOG="${PREFIX}.error"
+
+    rm -f "${ERROR_LOG}"
+
+    # in case error while running ${MODEL_RULE_PATH}, prints error msg
+    trap 'echo "** ERROR **" ; cat "${ERROR_LOG}"' ERR
 
     source rule-lib.sh
     source "${MODEL_RULE_PATH}"
 
+    # unset
+    trap - ERR
     set -x
 
-    if [[ $? -eq 0 ]]; then
-      touch "${PASSED_TAG}"
-    fi
+    # At this point, the exit code of all commands is 0
+    # If not 0, execution of this script ends because of "set -e"
+    touch "${PASSED_TAG}"
   )
 
   if [[ -f "${PASSED_TAG}" ]]; then
index 5745db1..7c7b123 100755 (executable)
@@ -2,6 +2,9 @@
 
 # This script checks circle file generated by tf2circle
 
+# exit if unknown var is used
+set -u
+
 WORKDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
 
 # Need at least toolchain.config
@@ -76,15 +79,23 @@ while [[ $# -ne 0 ]]; do
     COMPILED_FILE=${CIRCLE_PATH}
     INSPECT_PROG_PATH=${CIRCLE_INSPECT_PATH}
     VERIFY_PROG_PATH=${CIRCLE_VERIFY_PATH}
+    ERROR_LOG="${PREFIX}.error"
+
+    rm -f "${ERROR_LOG}"
+
+    # in case error while running ${MODEL_RULE_PATH}, prints error msg
+    trap 'echo "** ERROR **" ; cat "${ERROR_LOG}"' ERR
 
     source rule-lib.sh
     source "${MODEL_RULE_PATH}"
 
+    # unset
+    trap - ERR
     set -x
 
-    if [[ $? -eq 0 ]]; then
-      touch "${PASSED_TAG}"
-    fi
+    # At this point, the exit code of all commands is 0
+    # If not 0, execution of this script ends because of "set -e"
+    touch "${PASSED_TAG}"
   )
 
   if [[ -f "${PASSED_TAG}" ]]; then
index e44d5be..4eef372 100755 (executable)
@@ -2,6 +2,9 @@
 
 # This script checks tflite file generated by tf2tflite
 
+# exit if unknown var is used
+set -u
+
 WORKDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
 
 # Need at least toolchain.config
@@ -76,15 +79,23 @@ while [[ $# -ne 0 ]]; do
     COMPILED_FILE=${TFLITE_PATH}
     INSPECT_PROG_PATH=${TFL_INSPECT_PATH}
     VERIFY_PROG_PATH=${TFL_VERIFY_PATH}
+    ERROR_LOG="${PREFIX}.error"
+
+    rm -f "${ERROR_LOG}"
+
+    # in case error while running ${MODEL_RULE_PATH}, prints error msg
+    trap 'echo "** ERROR **" ; cat "${ERROR_LOG}"' ERR
 
     source rule-lib.sh
     source "${MODEL_RULE_PATH}"
 
+    # unset
+    trap - ERR
     set -x
 
-    if [[ $? -eq 0 ]]; then
-      touch "${PASSED_TAG}"
-    fi
+    # At this point, the exit code of all commands is 0
+    # If not 0, execution of this script ends because of "set -e"
+    touch "${PASSED_TAG}"
   )
 
   if [[ -f "${PASSED_TAG}" ]]; then
index 75a8ad7..8575bc2 100755 (executable)
@@ -89,7 +89,7 @@ while [[ $# -ne 0 ]]; do
     source rule-lib.sh
     source "${MODEL_RULE_PATH}"
 
-    # unset trap and set +x
+    # unset
     trap - ERR
     set -x