3 # Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 MY_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
19 NNFW_HOME="$(dirname $(dirname $(dirname ${MY_PATH})))"
20 CACHE_ROOT_PATH=$MY_PATH/"cache"
21 TEST_ROOT_PATH=$MY_PATH/"config"
26 function command_exists() {
27 command -v "$@" > /dev/null 2>&1
32 echo "Usage: ./$0 --driverbin={such as tflite_run} {tests to test or empty for all of tests}"
33 echo "Usage: ./$0 --driverbin=Product/out/bin/tflite_run --reportdir=report --tapname=verification.tap avgpool1 avgpool2"
35 echo "--download - (default=on) Download model files"
36 echo "--run - (default=on) Test model files"
37 echo "--driverbin - (default=../../Product/out/bin/tflite_run) Runner for runnning model tests"
38 echo "--reportdir - (default=report) Directory to place tap files"
39 echo "--tapname - (default=framework_test.tap) File name to be written for tap"
40 echo "--md5 - (default=on) MD5 check when download model files"
41 echo "--configdir - (default=$TEST_ROOT_PATH) Config directory to download and test model"
42 echo "--cachedir - (default=$CACHE_ROOT_PATH) Directory to download model"
46 function need_download()
50 if [ ! -e $LOCAL_PATH ]; then
53 # Ignore checking md5 in cache
54 # TODO Use "--md5" option only and remove IGNORE_MD5 environment variable
55 if [ ! -z $IGNORE_MD5 ] && [ "$IGNORE_MD5" == "1" ]; then
58 if [ "$MD5_CHECK" = "off" ]; then
62 LOCAL_HASH=$(md5sum $LOCAL_PATH | awk '{ print $1 }')
63 REMOTE_HASH=$(curl -ss $REMOTE_URL | md5sum | awk '{ print $1 }')
64 # TODO Emit an error when Content-MD5 field was not found. (Server configuration issue)
65 if [ "$LOCAL_HASH" != "$REMOTE_HASH" ]; then
66 echo "Downloaded file is outdated or incomplete."
73 TAP_NAME="framework_test.tap"
79 # Support environment variable setting for mirror server
80 FIXED_MODELFILE_SERVER="${MODELFILE_SERVER:-}"
108 TEST_ROOT_PATH=${i#*=}
111 CACHE_ROOT_PATH=${i#*=}
120 if [[ ${#TEST_LIST[@]} -eq 0 ]]; then
124 if [ ! -n "$DRIVER_BIN" ]; then
125 DRIVER_BIN="$NNFW_HOME/Product/out/bin/tflite_run"
128 if [ ! -d "$TEST_ROOT_PATH" ]; then
129 echo "Cannot find config directory for test: please set proper configdir"
133 # Check test driver setting
134 if [ ! command_exists $DRIVER_BIN ] && [ "$RUN_TEST" = "on" ]; then
135 echo "Cannot find test driver" $DRIVER_BIN ": please set proper DRIVER_BIN"
141 echo "1..$#" > $REPORT_DIR/$TAP_NAME
145 echo "Running tests:"
146 echo "======================"
147 for TEST_NAME in $SELECTED_TESTS; do
150 echo "======================"
152 TOTAL_RESULT=0 # 0(normal) or 1(abnormal)
154 for TEST_NAME in $SELECTED_TESTS; do
155 # Test configure initialization
158 MODELFILE_SERVER_PATH=""
160 source $TEST_ROOT_PATH/$TEST_NAME/config.sh
162 LOWER_STATUS="$(echo $STATUS | awk '{print tolower($0)}')"
163 if [ "$LOWER_STATUS" == "disabled" ] && [ "$RUN_DISABLED" == "false" ]; then
165 echo "Skip $TEST_NAME"
166 echo "======================"
167 echo "ok $i # skip $TEST_NAME" >> $REPORT_DIR/$TAP_NAME
171 TEST_CACHE_PATH=$CACHE_ROOT_PATH/$TEST_NAME
172 MODELFILE=$TEST_CACHE_PATH/$MODELFILE_NAME
174 # Find model file for downloaded by zip
175 if [ "${MODELFILE_NAME##*.}" = "zip" ]; then
176 pushd $TEST_CACHE_PATH
177 MODELFILE=$TEST_CACHE_PATH/$(ls *.tflite)
182 echo "Run $TEST_NAME"
183 echo "======================"
185 # Run driver to test framework
186 $DRIVER_BIN $MODELFILE
188 if [[ $? -eq 0 ]]; then
189 echo "ok $i - $TEST_NAME" >> $REPORT_DIR/$TAP_NAME
191 echo "not ok $i - $TEST_NAME" >> $REPORT_DIR/$TAP_NAME
203 echo "Downloading tests:"
204 echo "======================"
205 for TEST_NAME in $SELECTED_TESTS; do
208 echo "======================"
211 for TEST_NAME in $SELECTED_TESTS; do
212 # Test configure initialization
214 MODELFILE_SERVER_PATH=""
216 source $TEST_ROOT_PATH/$TEST_NAME/config.sh
218 TEST_CACHE_PATH=$CACHE_ROOT_PATH/$TEST_NAME
219 MODELFILE=$TEST_CACHE_PATH/$MODELFILE_NAME
220 MODELFILE_URL="$MODELFILE_SERVER/$MODELFILE_NAME"
221 if [ -n "$FIXED_MODELFILE_SERVER" ]; then
222 MODELFILE_URL="$FIXED_MODELFILE_SERVER/$MODELFILE_NAME"
225 # Download model file
226 if [ ! -e $TEST_CACHE_PATH ]; then
227 mkdir -p $TEST_CACHE_PATH
230 # Download unless we have it in cache (Also check md5sum)
231 if need_download "$MODELFILE" "$MODELFILE_URL"; then
233 echo "Download test file for $TEST_NAME"
234 echo "======================"
236 rm -f $MODELFILE # Remove invalid file if exists
237 pushd $TEST_CACHE_PATH
238 wget -nv $MODELFILE_URL
239 if [ "${MODELFILE_NAME##*.}" == "zip" ]; then
240 unzip -o $MODELFILE_NAME
252 local TESTS_TO_RUN=""
254 if [[ $# -eq 0 ]]; then
260 pushd $TEST_ROOT_PATH > /dev/null
261 for DIR in $TEST_DIRS; do
262 if [ -d "$DIR" ]; then
263 TESTS_FOUND=$(find "$DIR" -type f -name 'config.sh' -exec dirname {} \;| sed 's|^./||' | sort)
264 TESTS_TO_RUN="$TESTS_TO_RUN $TESTS_FOUND"
266 echo "Test $DIR was not found. This test is not added." 1>&2
275 TESTS_TO_RUN=$(find_tests ${TEST_LIST[@]})
277 if [ "$DOWNLOAD_MODEL" = "on" ]; then
278 download_tests $TESTS_TO_RUN
281 if [ "$RUN_TEST" = "on" ]; then
282 run_tests $TESTS_TO_RUN