Subversion Repositories NedoOS

Rev

Rev 126 | Rev 539 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download

  1. #!/bin/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. BUILD_DIR="$PROJECT_DIR/build/tests"
  11. exitCode=0
  12. totalTests=0        # +1 per ASM
  13. totalChecks=0       # +1 per diff/check
  14.  
  15. # verify the directory structure is set up as expected and the working directory is project root
  16. [[ ! -f "${PROJECT_DIR}/ContinuousIntegration/test_folder_tests.sh" ]] && echo -e "\033[91munexpected working directory\033[0m\n$HELP_STRING" && exit 1
  17.  
  18. source ContinuousIntegration/common_fn.sh
  19.  
  20. [[ -n "$EXE" ]] && echo -e "Using EXE=\033[96m$EXE\033[0m as assembler binary"
  21.  
  22. ## find the most fresh executable
  23. #[[ -z "$EXE" ]] && find_newest_binary sjasmplus "$PROJECT_DIR" \
  24. #    && echo -e "The most fresh binary found: \033[96m$EXE\033[0m"
  25. # reverted back to hard-coded "sjasmplus" for binary, as the date check seems to not work on some windows machines
  26.  
  27. [[ -z "$EXE" ]] && EXE=sjasmplus
  28.  
  29. # seek for files to be processed (either provided by user argument, or default tests/ dir)
  30. if [[ $# -gt 0 ]]; then
  31.     [[ "-h" == "$1" || "--help" == "$1" ]] && echo -e $HELP_STRING && exit 0
  32. else
  33.     echo -e "Searching directory \033[96m${PROJECT_DIR}/tests/\033[0m for '.asm' files..."
  34. fi
  35. OLD_IFS=$IFS
  36. IFS=$'\n'
  37. TEST_FILES=($(find "$PROJECT_DIR/tests/$1"* -type f | grep -v -E '\.i\.asm$' | grep -E '\.asm$'))
  38. IFS=$OLD_IFS
  39.  
  40. # check if some files were found, print help message if search failed
  41. [[ -z $TEST_FILES ]] && echo -e "\033[91mno files found\033[0m\n$HELP_STRING" && exit 1
  42.  
  43. ## create temporary build directory for output
  44. echo -e "Creating temporary \033[96m$BUILD_DIR\033[0m directory..."
  45. rm -rf "$BUILD_DIR"
  46. # terminate in case the create+cd will fail, this is vital
  47. mkdir -p "$BUILD_DIR" && cd "$BUILD_DIR" || exit 1
  48.  
  49. ## go through all asm files in tests directory and verify results
  50. for f in "${TEST_FILES[@]}"; do
  51.     ## standalone .asm file was found, try to build it
  52.     rm -rf *        # clear the temporary build directory
  53.     totalTests=$((totalTests + 1))
  54.     # set up various "test-name" variables for file operations
  55.     src_dir=`dirname "$f"`          # source directory (dst_dir is "." = "build/tests")
  56.     file_asm=`basename "$f"`        # just "file.asm" name
  57.     src_base="${f%.asm}"            # source directory + base ("src_dir/file"), to add extensions
  58.     dst_base="${file_asm%.asm}"     # local-directory base (just "file" basically), to add extensions
  59.     CLI_FILE="${dst_base}.cli"      # sub-script test-runner (internal feature, not documented)
  60.     [[ -d "${src_base}.config" ]] && CFG_BASE="${src_base}.config/${dst_base}" || CFG_BASE="${src_base}"
  61.     OPTIONS_FILE="${CFG_BASE}.options"
  62.     LIST_FILE="${CFG_BASE}.lst"
  63.     MSG_LIST_FILE="${CFG_BASE}.msglst"
  64.     # copy "src_dir/basename*.(asm|lua|cli)" file(s) into working directory
  65.     for subf in "$src_base"*.{asm,lua,cli}; do
  66.         [[ ! -e "$subf" || -d "$subf" ]] && continue
  67.         cp "$subf" ".${subf#$src_dir}"
  68.     done
  69.     # copy "src_dir/basename*" sub-directories into working directory (ALL files in them)
  70.     for subf in "$src_base"*; do
  71.         [[ ! -d "$subf" ]] && continue
  72.         [[ "${src_base}.config" == "$subf" ]] && continue   # some.config directory is not copied
  73.         cp -r "$subf" ".${subf#$src_dir}"
  74.     done
  75.     # see if there are extra options defined (and read them into array)
  76.     options=()
  77.     [[ -s "${OPTIONS_FILE}" ]] && options=(`cat "${OPTIONS_FILE}"`)
  78.     # check if .lst file is required to verify the test, set up options to produce one
  79.     [[ -s "${LIST_FILE}" ]] && MSG_LIST_FILE="" && options+=("--lst=${dst_base}.lst") && options+=('--lstlab')
  80.     [[ ! -s "${MSG_LIST_FILE}" ]] && MSG_LIST_FILE="" || LIST_FILE="${MSG_LIST_FILE}"
  81.     ## built it with sjasmplus (remember exit code)
  82.     totalChecks=$((totalChecks + 1))    # assembling is one check
  83.     if [[ -s "${CLI_FILE}" ]]; then
  84.         # custom test-runner detected, run it... WARNING, this acts as part of main script (do not exit(..), etc)
  85.         echo -e "\033[95mRunning\033[0m file \033[96m${CLI_FILE}\033[0m in test \033[96m${src_dir}\033[0m"
  86.         last_result=126         # custom script must override this
  87.         source ${CLI_FILE}
  88.         last_result_origin="custom test script ${CLI_FILE}"
  89.     else
  90.         echo -e "\033[95mAssembling\033[0m file \033[96m${file_asm}\033[0m in test \033[96m${src_dir}\033[0m, options [\033[96m${options[@]}\033[0m]"
  91.         if [[ -z "${MSG_LIST_FILE}" ]]; then
  92.             $MEMCHECK "$EXE" --nologo --msg=none --fullpath "${options[@]}" "$file_asm"
  93.             last_result=$?
  94.         else
  95.             $MEMCHECK "$EXE" --nologo --msg=lstlab --fullpath "${options[@]}" "$file_asm" 2> "${dst_base}.lst"
  96.             last_result=$?
  97.         fi
  98.         last_result_origin="sjasmplus"
  99.     fi
  100.     ## validate results
  101.     # LST file overrides assembling exit code (new exit code is from diff between lst files)
  102.     if [[ -s "${LIST_FILE}" ]]; then
  103.         diff -a --strip-trailing-cr "${LIST_FILE}" "${dst_base}.lst"
  104.         last_result=$?
  105.         last_result_origin="diff"
  106.     fi
  107.     # report assembling exit code problem here (ahead of binary result tests)
  108.     if [[ $last_result -ne 0 ]]; then
  109.         echo -e "\033[91mError status $last_result returned by $last_result_origin\033[0m"
  110.         exitCode=$((exitCode + 1))
  111.     else
  112.         echo -e "\033[92mOK: assembling or listing\033[0m"
  113.     fi
  114.     # check binary results, if TAP, BIN or RAW are present in source directory
  115.     for binext in {'tap','bin','raw'}; do
  116.         if [[ -f "${CFG_BASE}.${binext}" ]]; then
  117.             upExt=`echo $binext | tr '[:lower:]' '[:upper:]'`
  118.             totalChecks=$((totalChecks + 1))        # +1 for each binary check
  119.             echo -n -e "\033[91m"
  120.             ! diff "${CFG_BASE}.${binext}" "${dst_base}.${binext}" \
  121.                 && exitCode=$((exitCode + 1)) && echo -e "Error: $upExt differs\033[0m" \
  122.                 || echo -e "\033[92mOK: $upExt is identical\033[0m"
  123.         fi
  124.     done
  125.     # check other text results (not LST), if they are present in source directory
  126.     for txtext in {'sym','exp','lbl'}; do
  127.         if [[ -f "${CFG_BASE}.${txtext}" ]]; then
  128.             upExt=`echo $txtext | tr '[:lower:]' '[:upper:]'`
  129.             totalChecks=$((totalChecks + 1))        # +1 for each text check
  130.             echo -n -e "\033[91m"
  131.             ! diff -a --strip-trailing-cr "${CFG_BASE}.${txtext}" "${dst_base}.${txtext}" \
  132.                 && exitCode=$((exitCode + 1)) && echo -e "Error: $upExt differs\033[0m" \
  133.                 || echo -e "\033[92mOK: $upExt is identical\033[0m"
  134.         fi
  135.     done
  136.     #read -p "press..."      # DEBUG helper to examine produced files
  137. done # end of FOR (go through all asm files)
  138. # display OK message if no error was detected
  139. [[ $exitCode -eq 0 ]] \
  140.     && echo -e "\033[92mFINISHED: OK, $totalChecks checks passed ($totalTests tests) \033[91m■\033[93m■\033[32m■\033[96m■\033[0m" \
  141.     && exit 0
  142. # display error summary and exit with error code
  143. echo -e "\033[91mFINISHED: $exitCode/$totalChecks checks failed ($totalTests tests) \033[91m■\033[93m■\033[32m■\033[96m■\033[0m"
  144. exit $exitCode
  145.