Imported Upstream version 1.9.0
[platform/core/ml/nnfw.git] / infra / scripts / tizen_xu4_test.sh
1 #!/bin/bash
2
3 SCRIPT_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4 HOST_HOME=$SCRIPT_ROOT/../..
5 if [ -z "$TEST_ROOT" ]; then
6     TEST_ROOT=/opt/usr/nnfw-test
7 fi
8
9 function Usage()
10 {
11     echo "Usage: ./tizen_xu4_test.sh"
12     echo "Usage: ./tizen_xu4_test.sh --rpm-dir=path/to/rpm-dir"
13     echo "Usage: ./tizen_xu4_test.sh --test-suite-path=path/to/test-suite.tar.gz"
14     echo "Usage: ./tizen_xu4_test.sh --skip-install-model"
15     echo "Usage: ./tizen_xu4_test.sh --rpm-dir=path/to/rpm-dir --skip-test"
16     echo ""
17     echo "--rpm-dir <dir>           : directory containing nnfw.rpm and nnfw-test.rpm"
18     echo "--test-suite-path <dir>   : filepath to test-suite.tar.gz"
19     echo "--skip-install-model      : skip install downloaded model"
20     echo "--skip-test               : skip running test"
21     echo "--gcov-dir <dir>          : directory to save gcov files"
22 }
23
24 function install_model()
25 {
26     # download tflite model files
27     pushd $HOST_HOME
28     tests/scripts/models/run_test.sh --download=on --run=off
29     # TODO Since this command removes model file(.zip),
30     # We must always download the file unlike model file(.tflite).
31     # Because caching applies only to tflite file.
32     find tests -name "*.zip" -exec rm {} \;
33     tar -zcf cache.tar.gz -C tests/scripts/models cache
34     $SDB_CMD push cache.tar.gz $TEST_ROOT/.
35     rm -rf cache.tar.gz
36     $SDB_CMD shell tar -zxf $TEST_ROOT/cache.tar.gz -C $TEST_ROOT/Product/out/test/models
37
38     # download api test model file for nnfw_api_gtest
39     MODEL_CACHE_DIR=$(mktemp -d)
40     tests/scripts/models/run_test.sh --download=on --run=off \
41         --configdir=tests/scripts/models/nnfw_api_gtest \
42         --cachedir=$MODEL_CACHE_DIR
43     tar -zcf $MODEL_CACHE_DIR/api_model_test.tar.gz -C $MODEL_CACHE_DIR .
44     $SDB_CMD push $MODEL_CACHE_DIR/api_model_test.tar.gz $TEST_ROOT/Product/out/unittest_standalone/nnfw_api_gtest_models/
45     $SDB_CMD shell tar -zxf $TEST_ROOT/Product/out/unittest_standalone/nnfw_api_gtest_models/api_model_test.tar.gz \
46     -C $TEST_ROOT/Product/out/unittest_standalone/nnfw_api_gtest_models/
47     rm -rf $MODEL_CACHE_DIR
48     popd
49 }
50
51
52 function prepare_rpm_test()
53 {
54     echo "======= Test with rpm packages(gbs build) ======="
55     # clean up
56     $SDB_CMD shell rm -rf $TEST_ROOT
57     $SDB_CMD shell mkdir -p $TEST_ROOT
58     # install nnfw nnfw-test rpms
59     for file in $RPM_DIR/*.rpm
60     do
61         $SDB_CMD push $file $TEST_ROOT
62         $SDB_CMD shell rpm -Uvh $TEST_ROOT/$(basename $file) --force --nodeps
63     done
64 }
65
66 function prepare_suite_test()
67 {
68     echo "======= Test with test-suite(cross build) ======="
69     # clean up
70     $SDB_CMD shell rm -rf $TEST_ROOT
71     $SDB_CMD shell mkdir -p $TEST_ROOT
72
73     # install test-suite
74     $SDB_CMD push $TEST_SUITE_PATH $TEST_ROOT/$(basename $TEST_SUITE_PATH)
75     $SDB_CMD shell tar -zxf $TEST_ROOT/$(basename $TEST_SUITE_PATH) -C $TEST_ROOT
76 }
77
78 INSTALL_MODEL="1"
79 RUN_TEST="1"
80 # Parse command argv
81 for i in "$@"
82 do
83     case $i in
84         -h|--help|help)
85             Usage
86             exit 1
87             ;;
88         --rpm-dir=*)
89             RPM_DIR=${i#*=}
90             ;;
91         --rpm-dir)
92             RPM_DIR="$2"
93             shift
94             ;;
95         --test-suite-path=*)
96             TEST_SUITE_PATH=${i#*=}
97             ;;
98         --test-suite-path)
99             RPM_DIR="$2"
100             shift
101             ;;
102         --skip-install-model)
103             INSTALL_MODEL="0"
104             ;;
105         --gcov-dir=*)
106             GCOV_DIR=${i#*=}
107             ;;
108         --skip-test)
109             RUN_TEST="0"
110             ;;
111     esac
112     shift
113 done
114
115
116 N=`sdb devices 2>/dev/null | wc -l`
117
118 # exit if no device found
119 if [[ $N -le 1 ]]; then
120     echo "No device found."
121     exit 1;
122 fi
123
124 NUM_DEV=$(($N-1))
125 echo "device list"
126 DEVICE_LIST=`sdb devices 2>/dev/null`
127 echo "$DEVICE_LIST" | tail -n"$NUM_DEV"
128
129 if [ -z "$SERIAL" ]; then
130     SERIAL=`echo "$DEVICE_LIST" | tail -n1 | awk '{print $1}'`
131 fi
132 SDB_CMD="sdb -s $SERIAL "
133
134 # root on, remount as rw
135 $SDB_CMD root on
136 $SDB_CMD shell mount -o rw,remount /
137
138 SCRIPT_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
139 ROOT=$SCRIPT_ROOT/../
140
141 if [ -z "$RPM_DIR" ] && [ -z "$TEST_SUITE_PATH" ]; then
142     echo "======= Skip install runtime ======="
143 fi
144
145 if [ ! -z "$RPM_DIR" ]; then
146     prepare_rpm_test
147 elif [ ! -z "$TEST_SUITE_PATH" ]; then
148     prepare_suite_test
149 fi
150
151 if [ $INSTALL_MODEL = "1" ]; then
152     install_model
153 else
154     echo "======= Skip install model ======="
155 fi
156
157 if [ $RUN_TEST = "0" ]; then
158     echo "======= Skip test ======="
159     exit 0
160 fi
161
162 if [ -z "${GCOV_DIR}" ]; then
163   ${SDB_CMD} shell /bin/bash -c "IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime.sh --backend acl_cl --tflite-loader"
164   ${SDB_CMD} shell /bin/bash -c "IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime.sh --backend acl_neon"
165   ${SDB_CMD} shell /bin/bash -c "IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime.sh --backend cpu"
166   ${SDB_CMD} shell /bin/bash -c "IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime_mixed.sh"
167   ${SDB_CMD} shell /bin/bash -c "IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime.sh --interp"
168 else
169   mkdir -p ${GCOV_DIR}
170   rm -rf ${GCOV_DIR}/*
171   pushd ${GCOV_DIR}
172
173   sdb pull ${TEST_ROOT}/Product/out/test/build_path.txt
174   SRC_PREFIX=`cat build_path.txt`
175   GCOV_PREFIX_STRIP=`echo "${SRC_PREFIX}" | grep -o '/' | wc -l`
176   GCOV_DATA_PATH="/opt/usr/nnfw-gcov"
177
178   # TODO For coverage check, we run acl_cl and mixed test
179   ${SDB_CMD} shell /bin/bash -c "GCOV_PREFIX_STRIP=${GCOV_PREFIX_STRIP} IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime.sh --backend acl_cl --tflite-loader"
180   ${SDB_CMD} shell /bin/bash -c "GCOV_PREFIX_STRIP=${GCOV_PREFIX_STRIP} IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime.sh --backend acl_neon"
181   ${SDB_CMD} shell /bin/bash -c "GCOV_PREFIX_STRIP=${GCOV_PREFIX_STRIP} IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime.sh --backend cpu"
182   ${SDB_CMD} shell /bin/bash -c "GCOV_PREFIX_STRIP=${GCOV_PREFIX_STRIP} IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime_mixed.sh"
183   ${SDB_CMD} shell /bin/bash -c "GCOV_PREFIX_STRIP=${GCOV_PREFIX_STRIP} IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime.sh --interp"
184
185   # More test to check coverage
186   ${SDB_CMD} shell "rm -rf ${GCOV_DATA_PATH} && mkdir -p ${GCOV_DATA_PATH}"
187   ${SDB_CMD} shell "find ${TEST_ROOT} -type f \( -iname '*.gcda' -or -iname '*.gcno' \) -exec cp {} ${GCOV_DATA_PATH}/. \;"
188   ${SDB_CMD} shell "cd ${TEST_ROOT} && tar -zcvf coverage-data.tar.gz -C ${GCOV_DATA_PATH} ."
189
190   # pull gcov files
191   sdb pull ${TEST_ROOT}/coverage-data.tar.gz
192   tar -zxvf coverage-data.tar.gz
193   popd
194 fi