File indexing completed on 2024-05-12 16:02:32

0001 #!/usr/bin/env zsh
0002 #
0003 #  SPDX-License-Identifier: GPL-3.0-or-later
0004 #
0005 
0006 # Simple script to test all .app test's
0007 #
0008 # 1. Find any ./test/*.app
0009 # 2. Copies file to install folder (Assumed i/bin)
0010 # 3. Executes test
0011 # 4. Report back pass/fail status
0012 #
0013 
0014 if test -z $BUILDROOT; then
0015     echo "ERROR: BUILDROOT env not set, exiting!"
0016     echo "\t Must point to the root of the buildfiles as stated in 3rdparty Readme"
0017     exit 1
0018 fi
0019 
0020 BUILDROOT="${BUILDROOT%/}"
0021 INSTALL_DIR="${BUILDROOT}/i/bin"
0022 WORK_DIR=${PWD}
0023 
0024 # If current directory inside buildroot
0025 if [[ ! $(grep "${BUILDROOT}" <<< "${PWD}") ]] ; then
0026     WORK_DIR_CHECK="TRUE"
0027 fi
0028 
0029 SKIP_TESTS=(\
0030     "KisRandomGeneratorDemo.app"\
0031     "storedroptest.app"\
0032     "kis_action_manager_test.app"\
0033     "kis_node_manager_test.app"\
0034     "kis_selection_manager_test.app"\
0035     "KisActionManagerTest.app"\
0036     "KisNodeManagerTest.app"\
0037     "KisSelectionManagerTest.app"\
0038     "KisZoomAndPanTest.app"\
0039     "kis_crash_filter_test.app"\
0040     "FreehandStrokeBenchmark.app")
0041 
0042 
0043 find_execute_tests() {
0044 
0045     local test_found=($(find "${WORK_DIR}" -type d -name "*.app"))
0046     local total_tests=${#test_found[@]}
0047 
0048     if [[ ${#} > 0 ]]; then
0049         local specifyc_tests="TRUE"
0050         local total_tests=${#}
0051     fi
0052 
0053 
0054     local failed_tests=()
0055     local fails=0
0056     local i=1
0057 
0058     for FILE_PATH in "${test_found[@]}"; do
0059         if [[ $(grep "tests" <<< "${FILE_PATH}") ]]; then
0060 
0061             local app_name="$(basename ${FILE_PATH})"
0062 
0063             # if names supplied skip any test not in args
0064             if [[ -n "${specifyc_tests}" && ! "${@[@]}" =~ "${app_name%%.app}" ]]; then
0065                 continue
0066             fi
0067 
0068             # skip GUI locking tests
0069             # if ((${SKIP_TESTS[(Ie)${foo}]})) ; then ## zsh
0070             if [[ "${SKIP_TESTS[@]}" =~ "${app_name}" ]]; then
0071                 echo "skipping ------------------ ${app_name}"
0072                 continue
0073             fi
0074 
0075             rsync -aq "${FILE_PATH}/" "${INSTALL_DIR}/${app_name}"
0076             printf "\tStart %d: %s\n" ${i} "${FILE_PATH}"
0077             printf "%d/%d\t%s ...  " ${i} ${total_tests} "${app_name}"
0078 
0079             "${INSTALL_DIR}/${app_name}/Contents/MacOS/${app_name%%.app}" &> /dev/null
0080 
0081             if [[ ${?} != 0 ]]; then
0082                 printf "\e[31m%s\e[0m\n" "Fail!"
0083                 failed_tests+=("${app_name}")
0084                 fails=$((${fails} + 1))
0085             else
0086                 echo "Passed"
0087             fi
0088             local i=$((${i} + 1))
0089         else
0090             echo "skipping ------------------ ${FILE_PATH}"
0091         fi
0092     done
0093 
0094     # failed_tests_array=("${failed_tests}")
0095 
0096     printf "\n%d tests out of %s failed\n\n" ${#failed_tests[@]} ${total_tests}
0097     echo "Failed tests:"
0098     printf '\t\e[31m%s\e[0m\n' "${failed_tests[@]}"
0099 
0100 }
0101 
0102 echo "BUILDROOT set to ${BUILDROOT}"
0103 
0104 # -- Parse input args
0105 for arg in "${@}"; do
0106     if [[ ${arg} = --install_dir=* ]]; then
0107         INSTALL_DIR="${arg#*=}"
0108     elif [[ ${arg} = --work_dir=* ]]; then
0109         WORK_DIR="${arg#*=}"
0110         WORK_DIR_CHECK="SET"
0111     else
0112         parsed_args="${parsed_args} ${arg}"
0113     fi
0114 done
0115 
0116 
0117 if [[ -n "${WORK_DIR_CHECK}" && "${WORK_DIR_CHECK}" != "SET" ]] ; then
0118     echo "Current directory not inside buildroot"
0119     echo "use --work_dir=<path> to set custom"
0120     exit 1
0121 fi
0122 
0123 find_execute_tests ${parsed_args}