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