?login_element?

Subversion Repositories NedoOS

Rev

Rev 539 | Blame | Compare with Previous | Last modification | View Log | Download

  1. #!/usr/bin/env bash
  2.  
  3. ## script init + helper functions
  4. HELP_STRING="Run the script from \033[96mproject root\033[0m directory."
  5. HELP_STRING+="\nYou can provide one argument to specify particular sub-directory in \033[96mtests\033[0m directory, example:"
  6. HELP_STRING+="\n  $ \033[96mContinuousIntegration/test_folder_tests.sh z80/\033[0m \t\t# to run only tests from \033[96mtests/z80/\033[0m directory"
  7. HELP_STRING+="\nIf partial file name is provided, it'll be searched for (but file names with space break it,\033[1m it's not 100% functional\033[0m):"
  8. HELP_STRING+="\n  $ \033[96mContinuousIntegration/test_folder_tests.sh z8\033[0m \t\t# to run tests from \033[96mtests/z80/\033[0m and \033[96mtests/z80n/\033[0m directories"
  9. PROJECT_DIR=$PWD
  10. TEST_RUNNER="${PROJECT_DIR}/ContinuousIntegration/test_folder_tests.sh"
  11. BUILD_DIR="$PROJECT_DIR/build/tests"
  12. exitCode=0
  13. totalTests=0        # +1 per ASM
  14. totalChecks=0       # +1 per diff/check
  15.  
  16. source ContinuousIntegration/common_fn.sh
  17.  
  18. echo -n -e "Project dir \"\033[96m${PROJECT_DIR}\033[0m\". "
  19.  
  20. # verify the directory structure is set up as expected and the working directory is project root
  21. [[ ! -f "${TEST_RUNNER}" ]] && echo -e "\033[91munexpected working directory\033[0m\n$HELP_STRING" && exit 1
  22.  
  23. # check if `gcmp` or `cmp` accepts stdin input for second file to compare
  24. CMP=gcmp && cat "${TEST_RUNNER}" | $CMP "${TEST_RUNNER}" 2> /dev/null || \
  25. CMP=cmp && cat "${TEST_RUNNER}" | $CMP "${TEST_RUNNER}" 2> /dev/null || CMP=""
  26. [[ -z $CMP ]] && echo -e "\n\033[91mNo \"cmp\" found which accepts stdin\033[0m (gcmp and cmp tried).\n" && exit 1
  27. echo -n -e "Using \033[96m${CMP}\033[0m. "
  28.  
  29. [[ -n "$EXE" ]] && echo -e "Using EXE=\033[96m$EXE\033[0m as assembler binary"
  30.  
  31. ## find the most fresh executable
  32. #[[ -z "$EXE" ]] && find_newest_binary sjasmplus "$PROJECT_DIR" \
  33. #    && echo -e "The most fresh binary found: \033[96m$EXE\033[0m"
  34. # reverted back to hard-coded "sjasmplus" for binary, as the date check seems to not work on some windows machines
  35.  
  36. [[ -z "$EXE" ]] && EXE=sjasmplus
  37.  
  38. # seek for files to be processed (either provided by user argument, or default tests/ dir)
  39. if [[ $# -gt 0 ]]; then
  40.     [[ "-h" == "$1" || "--help" == "$1" ]] && echo -e $HELP_STRING && exit 0
  41. fi
  42. echo -n -e "Searching \033[96mtests/$1**\033[0m for '*.asm'. "
  43. OLD_IFS=$IFS
  44. IFS=$'\n'
  45. TEST_FILES=($(find "$PROJECT_DIR/tests/$1"* -type f | grep -v -E '\.i\.asm$' | grep -E '\.asm$'))
  46. IFS=$OLD_IFS
  47.  
  48. # check if some files were found, print help message if search failed
  49. [[ -z $TEST_FILES ]] && echo -e "\033[91mno files found\033[0m\n$HELP_STRING" && exit 1
  50.  
  51. ## create temporary build directory for output
  52. echo -e "Creating temporary: \033[96m$BUILD_DIR\033[0m"
  53. rm -rf "$BUILD_DIR"
  54. # terminate in case the create+cd will fail, this is vital
  55. # also make sure the build dir has all required permissions
  56. mkdir -p "$BUILD_DIR" && chmod 700 "$BUILD_DIR" && cd "$BUILD_DIR" || exit 1
  57.  
  58. ## go through all asm files in tests directory and verify results
  59. for f in "${TEST_FILES[@]}"; do
  60.     ## standalone .asm file was found, try to build it
  61.     rm -rf *        # clear the temporary build directory
  62.     totalTests=$((totalTests + 1))
  63.     # set up various "test-name" variables for file operations
  64.     src_dir=`dirname "$f"`          # source directory (dst_dir is "." = "build/tests")
  65.     file_asm=`basename "$f"`        # just "file.asm" name
  66.     src_base="${f%.asm}"            # source directory + base ("src_dir/file"), to add extensions
  67.     dst_base="${file_asm%.asm}"     # local-directory base (just "file" basically), to add extensions
  68.     CLI_FILE="${dst_base}.cli"      # sub-script test-runner (internal feature, not documented)
  69.     [[ -d "${src_base}.config" ]] && CFG_BASE="${src_base}.config/${dst_base}" || CFG_BASE="${src_base}"
  70.     OPTIONS_FILE="${CFG_BASE}.options"
  71.     LIST_FILE="${CFG_BASE}.lst"
  72.     MSG_LIST_FILE="${CFG_BASE}.msglst"
  73.     # copy "src_dir/basename*.(asm|lua|cli)" file(s) into working directory
  74.     for subf in "$src_base"*.{asm,lua,cli}; do
  75.         [[ ! -e "$subf" || -d "$subf" ]] && continue
  76.         cp "$subf" ".${subf#$src_dir}"
  77.         chmod 700 ".${subf#$src_dir}"   # force 700 permissions to copied file
  78.     done
  79.     # copy "src_dir/basename*" sub-directories into working directory (ALL files in them)
  80.     for subf in "$src_base"*; do
  81.         [[ ! -d "$subf" ]] && continue
  82.         [[ "${src_base}.config" == "$subf" ]] && continue   # some.config directory is not copied
  83.         cp -r "$subf" ".${subf#$src_dir}"
  84.         chmod -R 700 ".${subf#$src_dir}"   # force 700 permissions to copied files (recursively)
  85.     done
  86.     # see if there are extra options defined (and read them into array)
  87.     options=('--lstlab=sort')   # enforce all symbol dumps to be sorted in any case (even when no --lst)
  88.     options+=('-Wno-behost')    # don't report BE host platform (these kind of tests should pass on any platform)
  89.     options+=('--color=off')    # don't colorize warnings/errors by default
  90.     [[ -s "${OPTIONS_FILE}" ]] && options+=(`cat "${OPTIONS_FILE}"`)
  91.     # check if .lst file is required to verify the test, set up options to produce one
  92.     [[ -s "${LIST_FILE}" ]] && MSG_LIST_FILE="" && options+=("--lst=${dst_base}.lst")
  93.     [[ ! -s "${MSG_LIST_FILE}" ]] && MSG_LIST_FILE="" || LIST_FILE="${MSG_LIST_FILE}"
  94.     ## built it with sjasmplus (remember exit code)
  95.     totalChecks=$((totalChecks + 1))    # assembling is one check
  96.     ok_tick_text="???"
  97.     if [[ -s "${CLI_FILE}" ]]; then
  98.         # custom test-runner detected, run it... WARNING, this acts as part of main script (do not exit(..), etc)
  99.         echo -e "\033[95mRunning\033[0m \"\033[96m${CLI_FILE}\033[0m\" in \"\033[96m${src_dir##$PROJECT_DIR/}\033[0m\""
  100.         last_result=126         # custom script must override this
  101.         source "${CLI_FILE}"
  102.         last_result_origin="custom test script '${CLI_FILE}'"
  103.         ok_tick_text="run"
  104.     else
  105.         echo -e "\033[95mAssembling\033[0m \"\033[96m${file_asm}\033[0m\" in \"\033[96m${src_dir##$PROJECT_DIR/}\033[0m\", options [\033[96m${options[@]}\033[0m]"
  106.         if [[ -z "${MSG_LIST_FILE}" ]]; then
  107.             $MEMCHECK "$EXE" --nologo --msg=none --fullpath "${options[@]}" "$file_asm"
  108.             last_result=$?
  109.             [[ -s "${LIST_FILE}" ]] && ok_tick_text="lst" || ok_tick_text="asm"
  110.         else
  111.             $MEMCHECK "$EXE" --nologo --msg=lstlab --fullpath "${options[@]}" "$file_asm" 2> "${dst_base}.lst"
  112.             last_result=$?
  113.             ok_tick_text="msg"
  114.         fi
  115.         last_result_origin="sjasmplus"
  116.     fi
  117.     ## validate results
  118.     # LST file overrides assembling exit code (new exit code is from diff between lst files)
  119.     if [[ -s "${LIST_FILE}" ]]; then
  120.         diff -a --strip-trailing-cr "${LIST_FILE}" "${dst_base}.lst"
  121.         last_result=$?
  122.         last_result_origin="diff"
  123.     fi
  124.     # report assembling exit code problem here (ahead of binary result tests)
  125.     if [[ $last_result -ne 0 ]]; then
  126.         echo -n -e "\033[91mError status $last_result returned by $last_result_origin\033[0m\n "
  127.         exitCode=$((exitCode + 1))
  128.     else
  129.         echo -n -e "  \\  \033[92m$ok_tick_text OK\033[0m "
  130.     fi
  131.     # check binary results, if TAP, CDT, BIN, RAW or TRD are present in source directory
  132.     for binext in {'tap','cdt','bin','raw','trd'}; do
  133.         if [[ -f "${CFG_BASE}.${binext}" ]]; then
  134.             totalChecks=$((totalChecks + 1))        # +1 for each binary check
  135.             ! $CMP "${CFG_BASE}.${binext}" "${dst_base}.${binext}" \
  136.                 && exitCode=$((exitCode + 1)) && echo -n -e "\033[91mError: $binext DIFFERS\033[0m " \
  137.                 || echo -n -e "\033[0m \\  \033[92m$binext OK\033[0m "
  138.         fi
  139.         # or see if compressed ".gz" binary was provided and compare that
  140.         if [[ -f "${CFG_BASE}.${binext}.gz" ]]; then
  141.             totalChecks=$((totalChecks + 1))        # +1 for each binary check
  142.             ! gunzip -c "${CFG_BASE}.${binext}.gz" | $CMP "${dst_base}.${binext}" \
  143.                 && exitCode=$((exitCode + 1)) && echo -n -e "\033[91mError: $binext DIFFERS\033[0m " \
  144.                 || echo -n -e "\033[0m \\  \033[92m$binext OK\033[0m "
  145.         fi
  146.     done
  147.     # check other text results (not LST), if they are present in source directory
  148.     for txtext in {'sym','exp','lbl'}; do
  149.         if [[ -f "${CFG_BASE}.${txtext}" ]]; then
  150.             totalChecks=$((totalChecks + 1))        # +1 for each text check
  151.             ! diff -a --strip-trailing-cr "${CFG_BASE}.${txtext}" "${dst_base}.${txtext}" \
  152.                 && exitCode=$((exitCode + 1)) && echo -n -e "\033[91mError: $txtext DIFFERS\033[0m " \
  153.                 || echo -n -e "\033[0m \\  \033[92m$txtext OK\033[0m "
  154.         fi
  155.     done
  156.     echo ""     # add new line after each test
  157.     #read -p "press..."      # DEBUG helper to examine produced files
  158. done # end of FOR (go through all asm files)
  159. # display OK message if no error was detected ("\u25A0" is UTF big fat filled rectangle/square)
  160. [[ $exitCode -eq 0 ]] \
  161.     && echo -e "\033[92mFINISHED: OK, $totalChecks checks passed ($totalTests tests) \033[91m\u25A0\033[93m\u25A0\033[32m\u25A0\033[96m\u25A0\033[0m" \
  162.     && exit 0
  163. # display error summary and exit with error code
  164. echo -e "\033[91mFINISHED: $exitCode/$totalChecks checks failed ($totalTests tests) \033[91m\u25A0\033[93m\u25A0\033[32m\u25A0\033[96m\u25A0\033[0m"
  165. exit $exitCode
  166.