From d9bcd601907e0c6cb2acdc0534305c3e41d5415f Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=98=A4=ED=98=95=EC=84=9D/On-Device=20Lab=28SR=29/Staff?= =?utf8?q?=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 2 Dec 2019 11:00:11 +0900 Subject: [PATCH] [CI/script] Introduce common function script (#9296) Introduce common function script infra/scripts/common.sh Update x64 test script to use common function Signed-off-by: Hyeongseok Oh --- infra/scripts/common.sh | 97 ++++++++++++++++++++++++++++++++++++ infra/scripts/test_neurun_interp.sh | 26 ++-------- infra/scripts/test_x64_neurun_cpu.sh | 23 +++------ 3 files changed, 108 insertions(+), 38 deletions(-) create mode 100644 infra/scripts/common.sh diff --git a/infra/scripts/common.sh b/infra/scripts/common.sh new file mode 100644 index 0000000..bb77557 --- /dev/null +++ b/infra/scripts/common.sh @@ -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 +} diff --git a/infra/scripts/test_neurun_interp.sh b/infra/scripts/test_neurun_interp.sh index 3e0fa0f..01593ac 100755 --- a/infra/scripts/test_neurun_interp.sh +++ b/infra/scripts/test_neurun_interp.sh @@ -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 diff --git a/infra/scripts/test_x64_neurun_cpu.sh b/infra/scripts/test_x64_neurun_cpu.sh index 450a5c8..9f321b4 100755 --- a/infra/scripts/test_x64_neurun_cpu.sh +++ b/infra/scripts/test_x64_neurun_cpu.sh @@ -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 -- 2.7.4