summaryrefslogtreecommitdiff
path: root/compiler/tf2circle-dredd-pb-test/runner.sh
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/tf2circle-dredd-pb-test/runner.sh')
-rwxr-xr-xcompiler/tf2circle-dredd-pb-test/runner.sh121
1 files changed, 121 insertions, 0 deletions
diff --git a/compiler/tf2circle-dredd-pb-test/runner.sh b/compiler/tf2circle-dredd-pb-test/runner.sh
new file mode 100755
index 000000000..7c7b123c4
--- /dev/null
+++ b/compiler/tf2circle-dredd-pb-test/runner.sh
@@ -0,0 +1,121 @@
+#!/bin/bash
+
+# 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
+if [[ $# -lt 1 ]]; then
+ echo "USAGE: $0 ..."
+ echo
+ echo "ARGUMENTS:"
+ echo " [toolchain.config path]"
+ echo " [Prefix1]"
+ echo " [Prefix2]"
+ echo " ..."
+ exit 255
+fi
+
+CONFIG_PATH="$1"; shift
+
+source "${CONFIG_PATH}"
+
+echo "-- Found circle-inspect: ${CIRCLE_INSPECT_PATH}"
+echo "-- Found circle-verify: ${CIRCLE_VERIFY_PATH}"
+echo "-- Found tf2circle: ${TF2CIRCLE_PATH}"
+echo "-- Found workdir: ${WORKDIR}"
+
+TESTED=()
+PASSED=()
+FAILED=()
+
+pushd "${WORKDIR}"
+
+# running each rule file
+
+while [[ $# -ne 0 ]]; do
+ PREFIX="$1"; shift
+
+ echo "[ RUN ] ${PREFIX}"
+
+ TESTED+=("${PREFIX}")
+
+ PASSED_TAG="${PREFIX}.passed"
+
+ rm -f "${PASSED_TAG}"
+
+ cat > "${PREFIX}.log" <(
+ exec 2>&1
+
+ source "${PREFIX}.test"
+
+ echo "-- Use '${MODEL_PB_PATH}', '${MODEL_INFO_PATH}', and '${MODEL_RULE_PATH}'"
+
+ # Exit immediately if any command fails
+ set -e
+ # Show commands
+ set -x
+
+ # Generate circle
+ "${TF2CIRCLE_PATH}" \
+ "${MODEL_INFO_PATH}" \
+ "${MODEL_PB_PATH}" \
+ "${WORKDIR}/${PREFIX}.circle"
+
+ #
+ # Run rule prepared to check circle file
+ #
+
+ # set vars needed by rule file
+ CIRCLE_PATH="${WORKDIR}/${PREFIX}.circle"
+
+ # Note: turn off 'command printing'. Otherwise printing will be so messy
+ set +x
+
+ # set vars required by rule-lib.sh and rule file
+ 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
+
+ # 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
+ echo "[ OK ] ${PREFIX}"
+ PASSED+=("$PREFIX")
+ else
+ echo "[ FAIL] ${PREFIX}"
+ FAILED+=("$PREFIX")
+ fi
+done
+popd
+
+if [[ ${#TESTED[@]} -ne ${#PASSED[@]} ]]; then
+ echo "FAILED"
+ for TEST in "${FAILED[@]}"
+ do
+ echo "- ${TEST}"
+ done
+ exit 255
+fi
+
+echo "PASSED"
+exit 0