[CI/script] Introduce common function script (#9296)
author오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Mon, 2 Dec 2019 02:00:11 +0000 (11:00 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 2 Dec 2019 02:00:11 +0000 (11:00 +0900)
Introduce common function script infra/scripts/common.sh
Update x64 test script to use common function

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
infra/scripts/common.sh [new file with mode: 0644]
infra/scripts/test_neurun_interp.sh
infra/scripts/test_x64_neurun_cpu.sh

diff --git a/infra/scripts/common.sh b/infra/scripts/common.sh
new file mode 100644 (file)
index 0000000..bb77557
--- /dev/null
@@ -0,0 +1,97 @@
+#!/bin/bash
+
+# Don't run this script
+[[ "${BASH_SOURCE[0]}" == "${0}" ]] && echo "Please don't execute ${BASH_SOURCE[0]}, source it" && return
+
+# Global variable
+# CURRENT_PATH: infra/scripts directory absolute path
+# ROOT_PATH: nnfw root directory absolute path
+
+# Functions
+#
+# CheckTestPrepared
+#   Check environment variable setting to run test
+#
+# TFLiteModelVerification $1 $2 $3
+#   Run ./tests/scripts/test_driver.sh script verification test
+#
+# Unittests $1 $2 $3
+#   Run ./tests/scripts/test_driver.sh script unittest
+
+CURRENT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+ROOT_PATH="$(cd ${CURRENT_PATH}/../../ && pwd)"
+
+# $1: (required) backend
+# $2: (required) related framework test list file path from nnfw root directory
+#                pass empty string if there is no test list
+# $3: (required) related report path from nnfw root directory
+function CheckTestPrepared()
+{
+  # Model download server setting
+  if [[ -z "${MODELFILE_SERVER}" ]]; then
+    echo "[WARNING] Model file server is not set"
+    echo "          Try to use pre-downloaed model"
+  else
+    echo "Model Server: ${MODELFILE_SERVER}"
+  fi
+}
+
+# $1: (required) backend
+# $2: (required) related framework skiplist file path from nnfw root directory
+#                pass empty string if there is no skiplist
+# $3: (required) related report path from nnfw root directory
+function TFLiteModelVerification()
+{
+  [[ $# -ne 3 ]] && echo "Invalid function argument setting" && exit 1
+
+  pushd ${ROOT_PATH} > /dev/null
+
+  export BACKENDS=$1
+  if [[ "$2" == "" ]]; then
+    ./tests/scripts/test_driver.sh \
+      --reportdir=$ROOT_PATH/$3 \
+      --verification \
+      .
+  else
+    ./tests/scripts/test_driver.sh \
+      --frameworktest_list_file=$2 \
+      --reportdir=$ROOT_PATH/$3 \
+      --verification \
+      .
+  fi
+  unset BACKENDS
+
+  popd > /dev/null
+}
+
+function Unittests()
+{
+  [[ $# -ne 3 ]] && echo "Invalid function argument setting" && exit 1
+
+  pushd ${ROOT_PATH} > /dev/null
+
+  # Backup original nnapi_gtest.skip
+  # TODO Pass skiplist to test_driver.sh
+  SKIPLIST_FILE="${ROOT_PATH}/Product/out/unittest/nnapi_gtest.skip"
+  BACKUP_FILE="${SKIPLIST_FILE}.backup"
+  if [[ "$2" != "" ]]; then
+    cp ${SKIPLIST_FILE} ${BACKUP_FILE}
+    cp ${ROOT_PATH}/$2 ${SKIPLIST_FILE}
+  fi
+
+  export BACKENDS=$1
+  ./tests/scripts/test_driver.sh \
+    --reportdir=$ROOT_PATH/$3 \
+    --unittest \
+    .
+  unset BACKENDS
+
+  # TODO Pass skiplist to test_driver.sh
+  # Restore original nnapi_gtest.skip
+  if [[ "$2" != "" ]]; then
+    cp ${BACKUP_FILE} ${SKIPLIST_FILE}
+    rm ${BACKUP_FILE}
+  fi
+
+  popd > /dev/null
+}
index 3e0fa0f..01593ac 100755 (executable)
@@ -1,25 +1,9 @@
 #!/bin/bash
 
-[[ "${BASH_SOURCE[0]}" != "${0}" ]] && echo "Please don't source ${BASH_SOURCE[0]}, execute it" && return
-
-CURRENT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-ROOT_PATH="$CURRENT_PATH/../../"
-
-# Model download server setting
-if [[ -z $MODELFILE_SERVER ]]; then
-  echo "Need model file server setting"
-  exit 1
-fi
-
-set -e
-
-pushd $ROOT_PATH > /dev/null
+set -eo pipefail
+source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
 
 export DISABLE_COMPILE=1
-
-cp -v ./Product/out/unittest/nnapi_gtest.skip.noarch.interp ./Product/out/unittest/nnapi_gtest.skip
-./tests/scripts/test_driver.sh \
-  --unittest \
-  --reportdir="$ROOT_PATH/report/interp" .
-
-popd > /dev/null
+CheckTestPrepared
+Unittests "cpu" "Product/out/unittest/nnapi_gtest.skip.noarch.interp" "report/interp"
+unset DISABLE_COMPILE
index 450a5c8..9f321b4 100755 (executable)
@@ -1,23 +1,12 @@
 #!/bin/bash
 
-[[ "${BASH_SOURCE[0]}" != "${0}" ]] && echo "Please don't source ${BASH_SOURCE[0]}, execute it" && return
+set -eo pipefail
+source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
 
-CURRENT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-ROOT_PATH="$CURRENT_PATH/../../"
+pushd ${ROOT_PATH} > /dev/null
 
-# Model download server setting
-if [[ -z $MODELFILE_SERVER ]]; then
-  echo "Need model file server setting"
-  exit 1
-fi
-
-set -e
-
-pushd $ROOT_PATH > /dev/null
-
-export BACKENDS=cpu
-./tests/scripts/test_driver.sh \
-  --frameworktest_list_file=./tests/scripts/neurun_frameworktest_list.x86-64.cpu.txt \
-  --reportdir=$ROOT_PATH/report/ .
+CheckTestPrepared
+Unittests "cpu" "Product/out/unittest/nnapi_gtest.skip.x86_64-linux" "report"
+TFLiteModelVerification "cpu" "tests/scripts/neurun_frameworktest_list.x86-64.cpu.txt" "report"
 
 popd > /dev/null