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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. m128) TESTENV='megaatmega1280' ;;
  24. m256) TESTENV='megaatmega2560' ;;
  25. mega) TESTENV='megaatmega2560' ;;
  26. stm) TESTENV='STM32F103RE' ;;
  27. f1) TESTENV='STM32F103RE' ;;
  28. f4) TESTENV='STM32F4' ;;
  29. f7) TESTENV='STM32F7' ;;
  30. teensy) TESTENV='teensy31' ;;
  31. t31) TESTENV='teensy31' ;;
  32. t32) TESTENV='teensy31' ;;
  33. t35) TESTENV='teensy35' ;;
  34. t36) TESTENV='teensy35' ;;
  35. -) ;;
  36. esac
  37. # Matching patterns
  38. ISNUM='^[0-9]+$'
  39. ISCMD='^(restore|opt|exec|use|pins|env)_'
  40. ISEXEC='^exec_'
  41. ISCONT='\\ *$'
  42. # List available tests and ask for selection
  43. if [[ $TESTENV == '-' ]]; then
  44. IND=0
  45. NAMES=()
  46. for FILE in $( ls -1 $TESTPATH/*-tests )
  47. do
  48. let IND++
  49. TNAME=${FILE/-tests/}
  50. TNAME=${TNAME/$TESTPATH\//}
  51. NAMES+=($TNAME)
  52. (( IND < 10 )) && echo -n " "
  53. echo " $IND) $TNAME"
  54. done
  55. echo
  56. for (( ; ; ))
  57. do
  58. read -p "Select a test to apply (1-$IND) : " NAMEIND
  59. [[ -z "$NAMEIND" ]] && { echo '(canceled)' ; exit 1 ; }
  60. [[ $NAMEIND =~ $ISNUM ]] && ((NAMEIND >= 1 && NAMEIND <= IND)) && { TESTENV=${NAMES[$NAMEIND-1]} ; echo ; break ; }
  61. echo "Invalid selection."
  62. done
  63. fi
  64. # Get the contents of the test file
  65. OUT=$( cat $TESTPATH/$TESTENV-tests 2>/dev/null ) || { echo "Can't find test '$TESTENV'." ; exit 1 ; }
  66. # Count up the number of tests
  67. # TODO: List test descriptions with numbers
  68. TESTCOUNT=$( awk "/$ISEXEC/{a++}END{print a}" <<<"$OUT" )
  69. # Get the entered or interactive test index
  70. CHOICE=${2:-0}
  71. # User entered a number?
  72. (( CHOICE && CHOICE > TESTCOUNT )) && { echo "Invalid test index '$CHOICE' (1-$TESTCOUNT)." ; exit 1 ; }
  73. if [[ $CHOICE == 0 ]]; then
  74. # List test descriptions with numbers
  75. echo "Available '$TESTENV' tests:" ; echo "$OUT" | {
  76. IND=0
  77. SED=$(which gsed || which sed)
  78. while IFS= read -r LINE
  79. do
  80. if [[ $LINE =~ $ISEXEC ]]; then
  81. DESC=$( "$SED" -E 's/^.+"(.*)".*$/\1/g' <<<"$LINE" )
  82. (( ++IND < 10 )) && echo -n " "
  83. echo " $IND) $DESC"
  84. fi
  85. done
  86. }
  87. CHOICE=1
  88. if [[ $TESTCOUNT > 1 ]]; then
  89. for (( ; ; ))
  90. do
  91. read -p "Select a '$TESTENV' test (1-$TESTCOUNT) : " CHOICE
  92. [[ -z "$CHOICE" ]] && { echo '(canceled)' ; exit 1 ; }
  93. [[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= TESTCOUNT)) && break
  94. echo ">>> Invalid test index '$CHOICE'."
  95. done
  96. fi
  97. fi
  98. # Finally, run the specified test lines
  99. echo "$OUT" | {
  100. IND=0
  101. GOTX=0
  102. CMD=""
  103. while IFS= read -r LINE
  104. do
  105. if [[ $LINE =~ $ISCMD || $GOTX == 1 ]]; then
  106. ((!IND)) && let IND++
  107. if [[ $LINE =~ $ISEXEC ]]; then
  108. ((IND++ > CHOICE)) && break
  109. else
  110. ((!HEADER)) && {
  111. HEADER=1
  112. echo -e "\n#\n# Test $TESTENV ($CHOICE) $DESC\n#"
  113. }
  114. ((IND == CHOICE)) && {
  115. GOTX=1
  116. [[ $CMD == "" ]] && CMD="$LINE" || CMD=$( echo -e "$CMD$LINE" | sed -e 's/\\//g' )
  117. [[ $LINE =~ $ISCONT ]] || { echo $CMD ; eval "$CMD" ; CMD="" ; }
  118. }
  119. fi
  120. fi
  121. done
  122. }
  123. # Build the test too?
  124. echo ; read -p "Build $TESTENV test #$CHOICE (y/N) ? " BUILD_YES
  125. [[ $BUILD_YES == 'Y' || $BUILD_YES == 'Yes' ]] && platformio run --project-dir . -e $TESTENV