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

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