[Utils] Add trinity-test script
authorJiho Chu <jiho.chu@samsung.com>
Mon, 8 Aug 2022 04:16:04 +0000 (13:16 +0900)
committer추지호/NPU Lab(SR)/삼성전자 <jiho.chu@samsung.com>
Tue, 16 Aug 2022 01:19:13 +0000 (10:19 +0900)
trinity-test is designed to give convenience when testing unittest and
apptest. It can execute whole tests simply, or execute some of them.

Signed-off-by: Jiho Chu <jiho.chu@samsung.com>
utils/meson.build
utils/trinity_test/meson.build [new file with mode: 0644]
utils/trinity_test/trinity-test [new file with mode: 0755]

index 286acb4bc9eeddbd586ae52feb76c39f5f493454..7dd011139bf90602f2a677cb5572b1263aba79f6 100644 (file)
@@ -1,3 +1,4 @@
 subdir('model_inspect')
 subdir('trinity_smi')
 subdir('trinity_cuse')
+subdir('trinity_test')
diff --git a/utils/trinity_test/meson.build b/utils/trinity_test/meson.build
new file mode 100644 (file)
index 0000000..6086fbb
--- /dev/null
@@ -0,0 +1,2 @@
+install_data(sources : 'trinity-test', install_dir : join_paths(ne_bindir, 'utils'))
+install_data(sources : 'model.xml', install_dir : join_paths(ne_bindir, 'utils'))
diff --git a/utils/trinity_test/trinity-test b/utils/trinity_test/trinity-test
new file mode 100755 (executable)
index 0000000..4995bac
--- /dev/null
@@ -0,0 +1,113 @@
+#!/bin/bash
+
+##
+# @file   trinity-test.sh
+# @brief  execute test using unittest and apptest
+# @see    https://github.sec.samsung.net/AIP/NPU_SystemService
+# @author Jiho Chu <jiho.chu@samsung.com>
+#
+
+# test envs
+NPU_ENGINE_BIN_PATH=/usr/lib64/npu-engine/bin
+TEST_DATA_PATH=/usr/share/npu-engine/testdata
+
+# test global var
+UNITTEST_PATH=$NPU_ENGINE_BIN_PATH/unittests
+APPTEST_PATH=$NPU_ENGINE_BIN_PATH/apptests
+TEST_PATH=$NPU_ENGINE_PATH/utils/trinity_test
+MODEL_PATH=$TEST_DATA_PATH/TRIV238_2TOPS
+
+TEST_UNITTEST_NAME=unittest*
+TEST_APPTEST_NAME=apptest*
+TEST_UNITTEST=false
+TEST_APPTEST=false
+
+
+print_help() {
+       echo -e "Usage: $0 [-u] [-a] [-n NAME]"
+       echo -e "\th: show help"
+       echo -e "\tu: run unittests"
+       echo -e "\ta: run apptests"
+       echo -e "\tn: run specific test with name"
+}
+
+run_unittest() {
+       local test=$1
+       echo "run unittest $UNITTEST_PATH/$test"
+
+       local tests=$(find $UNITTEST_PATH -mindepth 1 -maxdepth 1 -name "$test")
+
+       for t in ${tests[@]}; do
+               sh  -c "$t"
+               [ $? -ne 0 ] && echo Failed: $t && return 1;
+               echo Success: $t
+       done
+}
+
+run_apptest() {
+       local test=$1
+       echo "run apptest $APPTEST_PATH/$test"
+
+       local tests=$(find $APPTEST_PATH -mindepth 1 -maxdepth 1 -name "$test")
+
+       local arg1=
+       local arg2=
+       for t in ${tests[@]}; do
+               case $t in
+               *bulk)
+                       arg1=$MODEL_PATH
+               ;;
+               *aging)
+                       arg1=$MODEL_PATH/CONV_2D_300
+                       arg2="1 10"
+               ;;
+               *preempt)
+                       arg1=$MODEL_PATH/
+               ;;
+               *xml)
+                       arg1=$TEST_PATH/model.xml
+               ;;
+               *interleave)
+                       arg1=10
+                       arg2=$MODEL_PATH/MAX_POOL_2D_000,$MODEL_PATH/CONV_2D_300
+               ;;
+               *profile)
+                       arg1=$MODEL_PATH/ADD_000
+                       arg2="-p visa"
+               ;;
+               *)
+                       arg1=$MODEL_PATH/ADD_000
+               ;;
+               esac
+
+               echo "run: $t $arg1 $arg2"
+               sh  -c "$t $arg1 $arg2"
+               [ $? -ne 0 ] && echo Failed: $t && return 1;
+               echo Success: $t
+       done
+}
+
+while getopts "ahn:u" opt; do
+       case $opt in
+       a)
+               TEST_APPTEST=true
+       ;;
+       h)
+               print_help
+               exit 0
+       ;;
+       n)
+               TEST_UNITTEST_NAME=$OPTARG
+               TEST_APPTEST_NAME=$OPTARG
+       ;;
+       u)
+               TEST_UNITTEST=true
+       ;;
+       esac
+done
+
+[ ! -d "$NPU_ENGINE_BIN_PATH" ] && echo "incorrect npu-engine path: $NPU_ENGINE_BIN_PATH" && exit 1
+[ ! -d "$TEST_DATA_PATH" ] && echo "incorrect testdata path: $TEST_DATA_PATH" && exit 1
+[ $TEST_UNITTEST = false ] && [ $TEST_APPTEST = false ] && print_help && exit 0
+[ $TEST_UNITTEST = true ] && run_unittest "$TEST_UNITTEST_NAME"
+[ $TEST_APPTEST = true ] && run_apptest "$TEST_APPTEST_NAME"