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

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