My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mftest 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #!/usr/bin/env bash
  2. #
  3. # mftest [name] [index]
  4. #
  5. # Set configuration options based on a test
  6. # By default it will do megaatmega2560
  7. # Use 'mftest -' to pick from the list.
  8. #
  9. MFINFO=$(mfinfo) || exit 1
  10. [[ -d Marlin/src ]] || { echo "Please 'cd' up to repo root." ; exit 1 ; }
  11. TESTPATH=buildroot/share/tests
  12. shopt -s extglob nocasematch
  13. # Get test
  14. TESTENV=${1:-'-'}
  15. # Allow shorthand for test name
  16. case $TESTENV in
  17. tree) platformio run --project-dir . -e include_tree ; exit 1 ;;
  18. due) TESTENV='DUE' ;;
  19. esp) TESTENV='esp32' ;;
  20. lin*) TESTENV='linux_native' ;;
  21. lpc?(8)) TESTENV='LPC1768' ;;
  22. lpc9) TESTENV='LPC1769' ;;
  23. mega) TESTENV='megaatmega2560' ;;
  24. stm) TESTENV='STM32F103R' ;;
  25. f1) TESTENV='STM32F103R' ;;
  26. f4) TESTENV='STM32F4' ;;
  27. f7) TESTENV='STM32F7' ;;
  28. teensy) TESTENV='teensy31' ;;
  29. t31) TESTENV='teensy31' ;;
  30. t32) TESTENV='teensy31' ;;
  31. t35) TESTENV='teensy35' ;;
  32. t36) TESTENV='teensy35' ;;
  33. -) ;;
  34. esac
  35. # Matching patterns
  36. ISNUM='^[0-9]+$'
  37. ISCMD='^(restore|opt|exec|use|pins|env)_'
  38. ISEXEC='^exec_'
  39. ISCONT='\\ *$'
  40. # List available tests and ask for selection
  41. if [[ $TESTENV == '-' ]]; then
  42. IND=0
  43. NAMES=()
  44. for FILE in $( ls -1 $TESTPATH/*-tests )
  45. do
  46. let IND++
  47. TNAME=${FILE/-tests/}
  48. TNAME=${TNAME/$TESTPATH\//}
  49. NAMES+=($TNAME)
  50. (( IND < 10 )) && echo -n " "
  51. echo " $IND) $TNAME"
  52. done
  53. echo
  54. for (( ; ; ))
  55. do
  56. read -p "Select a test to apply (1-$IND) : " NAMEIND
  57. [[ -z "$NAMEIND" ]] && { echo '(canceled)' ; exit 1 ; }
  58. [[ $NAMEIND =~ $ISNUM ]] && ((NAMEIND >= 1 && NAMEIND <= IND)) && { TESTENV=${NAMES[$NAMEIND-1]} ; echo ; break ; }
  59. echo "Invalid selection."
  60. done
  61. fi
  62. # Get the contents of the test file
  63. OUT=$( cat $TESTPATH/$TESTENV-tests 2>/dev/null ) || { echo "Can't find test '$TESTENV'." ; exit 1 ; }
  64. # Count up the number of tests
  65. # TODO: List test descriptions with numbers
  66. TESTCOUNT=$( awk "/$ISEXEC/{a++}END{print a}" <<<"$OUT" )
  67. # Get the entered or interactive test index
  68. CHOICE=${2:-0}
  69. # User entered a number?
  70. (( CHOICE && CHOICE > TESTCOUNT )) && { echo "Invalid test index '$CHOICE' (1-$TESTCOUNT)." ; exit 1 ; }
  71. if [[ $CHOICE == 0 ]]; then
  72. # List test descriptions with numbers
  73. echo "Available '$TESTENV' tests:" ; echo "$OUT" | {
  74. IND=0
  75. SED=$(which gsed || which sed)
  76. while IFS= read -r LINE
  77. do
  78. if [[ $LINE =~ $ISEXEC ]]; then
  79. DESC=$( "$SED" -E 's/^.+"(.*)".*$/\1/g' <<<"$LINE" )
  80. (( ++IND < 10 )) && echo -n " "
  81. echo " $IND) $DESC"
  82. fi
  83. done
  84. }
  85. CHOICE=1
  86. if [[ $TESTCOUNT > 1 ]]; then
  87. for (( ; ; ))
  88. do
  89. read -p "Select a '$TESTENV' test (1-$TESTCOUNT) : " CHOICE
  90. [[ -z "$CHOICE" ]] && { echo '(canceled)' ; exit 1 ; }
  91. [[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= TESTCOUNT)) && break
  92. echo ">>> Invalid test index '$CHOICE'."
  93. done
  94. fi
  95. fi
  96. # Finally, run the specified test lines
  97. echo "$OUT" | {
  98. IND=0
  99. GOTX=0
  100. CMD=""
  101. while IFS= read -r LINE
  102. do
  103. if [[ $LINE =~ $ISCMD || $GOTX == 1 ]]; then
  104. ((!IND)) && let IND++
  105. if [[ $LINE =~ $ISEXEC ]]; then
  106. ((IND++ > CHOICE)) && break
  107. else
  108. ((!HEADER)) && {
  109. HEADER=1
  110. echo -e "\n#\n# Test $TESTENV ($CHOICE) $DESC\n#"
  111. }
  112. ((IND == CHOICE)) && {
  113. GOTX=1
  114. [[ $CMD == "" ]] && CMD="$LINE" || CMD=$( echo -e "$CMD$LINE" | sed -e 's/\\//g' )
  115. [[ $LINE =~ $ISCONT ]] || { echo $CMD ; eval "$CMD" ; CMD="" ; }
  116. }
  117. fi
  118. fi
  119. done
  120. }
  121. # Build the test too?
  122. echo ; read -p "Build $TESTENV test #$CHOICE (y/N) ? " BUILD_YES
  123. [[ $BUILD_YES == 'Y' || $BUILD_YES == 'Yes' ]] && platformio run --project-dir . -e $TESTENV