Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / tests / scripts / command / verify-tflite
1 #!/bin/bash
2 #
3 # Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
4 #
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
8 #
9 #    http://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16
17 COMMAND_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
18 INSTALL_DIR="$(dirname $(dirname $COMMAND_DIR))"
19
20 MD5_CHECK="on"
21 TFLITE_LOADER="nnapi"
22 REPORT_DIR="report"
23 TEST_LIST_FILE=
24
25 function Usage()
26 {
27     echo "Usage: $0 $(basename ${BASH_SOURCE[0]}) [OPTIONS]"
28     echo ""
29     echo "Options:"
30     echo "      --ignoremd5             Ignore MD5 check when download model files"
31     echo "      --api=(nnapi|loader)    TFLite model file loading API (default=$TFLITE_LOADER)"
32     echo "      --reportdir=PATH        Path to write report (default=$REPORT_DIR)"
33     echo "      --list=FILE             List file to test. Test all if list option is not passed"
34 }
35
36 for i in "$@"
37 do
38     case $i in
39         -h|--help|help)
40             Usage
41             exit 1
42             ;;
43         --ignoremd5)
44             MD5_CHECK="off"
45             ;;
46         --api=*)
47             TFLITE_LOADER=${i#*=}
48             ;;
49         --reportdir=*)
50             REPORT_DIR=${i#*=}
51             ;;
52         --list=*)
53             TEST_LIST_FILE=${i#*=}
54             ;;
55         *)
56             echo "Unknown option: $i"
57             exit 1
58         ;;
59     esac
60     shift
61 done
62
63 if [ ! -z "$TEST_LIST_FILE" ]; then
64     MODELLIST=$(cat "${TEST_LIST_FILE}")
65 fi
66
67 if [ ! -e "$REPORT_DIR" ]; then
68     mkdir -p $REPORT_DIR
69 fi
70
71 TEST_RESULT=0
72 TAP_NAME=verification_test.tap
73 TEST_NAME="Verification"
74 TEST_DRIVER=
75
76 if [[ $TFLITE_LOADER == "nnapi" ]]; then
77     TEST_NAME="NNAPI Verification"
78     TEST_DRIVER=nnapi_test
79 elif [[ $TFLITE_LOADER == "loader" ]]; then
80     TEST_NAME="Loader Verification"
81     TEST_DRIVER=tflite_loader_test_tool
82 else
83     Usage
84     exit 1
85 fi
86
87 $INSTALL_DIR/test/models/run_test.sh --driverbin=$TEST_DRIVER \
88     --reportdir=$REPORT_DIR \
89     --tapname=$TAP_NAME \
90     ${MODELLIST:-} > $REPORT_DIR/verification_test.log 2>&1
91 TEST_RESULT=$?
92
93 if [[ $TEST_RESULT -ne 0 ]]; then
94     echo ""
95     cat $REPORT_DIR/$TAP_NAME
96     echo ""
97     echo "$TEST_NAME failed... exit code: $TEST_RESULT"
98     echo "============================================"
99     echo ""
100     exit $TEST_RESULT
101 fi
102
103 echo ""
104 cat $REPORT_DIR/$TAP_NAME
105 echo "============================================"
106 echo ""