My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

mftest 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. #!/usr/bin/env bash
  2. #
  3. # mftest Select a test to apply and build
  4. # mftest -b [#] Build the auto-detected environment
  5. # mftest -u [#] Upload the auto-detected environment
  6. # mftest [name] [index] [-y] Set config options and optionally build a test
  7. #
  8. MFINFO=$(mfinfo) || exit 1
  9. [[ -d Marlin/src ]] || { echo "Please 'cd' to the Marlin repo root." ; exit 1 ; }
  10. perror() { echo -e "$0: \033[0;31m$1 -- $2\033[0m" ; }
  11. errout() { echo -e "\033[0;31m$1\033[0m" ; }
  12. bugout() { ((DEBUG)) && echo -e "\033[0;32m$1\033[0m" ; }
  13. usage() {
  14. echo "
  15. Usage: mftest [-t|--env=<env>] [-n|--num=<num>] [-m|--make] [-y|--build=<Y|n>]
  16. mftest [-a|--autobuild]
  17. mftest [-r|--rebuild]
  18. mftest [-u|--autoupload] [-n|--num=<num>]
  19. OPTIONS
  20. -t --env The environment of the test to apply / run. (As named in platformio.ini.)
  21. -n --num The index of the test to run. (In *-tests file order.)
  22. -m --make Use the make / Docker method for the build.
  23. -y --build Skip 'Do you want to build this test?' and assume YES.
  24. -h --help Print this help.
  25. -a --autobuild PIO Build using the MOTHERBOARD environment.
  26. -u --autoupload PIO Upload using the MOTHERBOARD environment.
  27. -v --verbose Extra output for debugging.
  28. env shortcuts: tree due esp lin lpc|lpc8 lpc9 m128 m256|mega stm|f1 f4 f7 s6 teensy|t31|t32 t35|t36 t40|t41
  29. "
  30. }
  31. TESTPATH=buildroot/tests
  32. STATE_FILE=$( echo ./.pio/.mftestrc )
  33. SED=$(which gsed || which sed)
  34. shopt -s extglob nocasematch
  35. # Matching patterns
  36. ISNUM='^[0-9]+$'
  37. ISCMD='^(restore|opt|exec|use|pins|env)_'
  38. ISEXEC='^exec_'
  39. ISCONT='\\ *$'
  40. # Get environment, test number, etc. from the command
  41. TESTENV='-'
  42. CHOICE=0
  43. DEBUG=0
  44. while getopts 'abhmruvyn:t:-:' OFLAG; do
  45. case "${OFLAG}" in
  46. a) AUTO_BUILD=1 ; bugout "Auto-Build target..." ;;
  47. h) EXIT_USAGE=1 ;;
  48. m) USE_MAKE=1 ; bugout "Using make with Docker..." ;;
  49. n) case "$OPTARG" in
  50. *[!0-9]*) perror "option requires a number" $OFLAG ; EXIT_USAGE=1 ;;
  51. *) CHOICE="$OPTARG" ; bugout "Got a number: $CHOICE" ;;
  52. esac
  53. ;;
  54. r) REBUILD=1 ; bugout "Rebuilding previous..." ;;
  55. t) TESTENV="$OPTARG" ; bugout "Got a target: $TESTENV" ;;
  56. u) AUTO_BUILD=2 ; bugout "Auto-Upload target..." ;;
  57. v) DEBUG=1 ; bugout "Debug ON" ;;
  58. y) BUILD_YES='Y' ; bugout "Build will initiate..." ;;
  59. -) IFS="=" read -r ONAM OVAL <<< "$OPTARG"
  60. case "$ONAM" in
  61. help) [[ -z "$OVAL" ]] || perror "option can't take value $OVAL" $ONAM ; EXIT_USAGE=1 ;;
  62. autobuild) AUTO_BUILD=1 ; bugout "Auto-Build target..." ;;
  63. autoupload) AUTO_BUILD=2 ; bugout "Auto-Upload target..." ;;
  64. env) case "$OVAL" in
  65. '') perror "option requires a value" $ONAM ; EXIT_USAGE=1 ;;
  66. *) TESTENV="$OVAL" ; bugout "Got a target: $TESTENV" ;;
  67. esac
  68. ;;
  69. num) case "$OVAL" in
  70. [0-9]+) CHOICE="$OVAL" ; bugout "Got a number: $CHOICE" ;;
  71. *) perror "option requires a value" $ONAM ; EXIT_USAGE=1 ;;
  72. esac
  73. ;;
  74. rebuild) REBUILD=1 ; bugout "Rebuilding previous..." ;;
  75. make) USE_MAKE=1 ; bugout "Using make with Docker..." ;;
  76. debug|verbose) DEBUG=1 ; bugout "Debug ON" ;;
  77. build) case "$OVAL" in
  78. ''|y|yes) BUILD_YES='Y' ;;
  79. n|no) BUILD_YES='N' ;;
  80. *) perror "option value must be y, n, yes, or no" $ONAM ; EXIT_USAGE=1 ;;
  81. esac
  82. bugout "Build will initiate? ($BUILD_YES)"
  83. ;;
  84. *) perror "Unknown flag" "$OPTARG" ; EXIT_USAGE=1 ;;
  85. esac
  86. ;;
  87. esac
  88. done
  89. ((EXIT_USAGE)) && { usage ; exit 1 ; }
  90. if ((REBUILD)); then
  91. bugout "Rebuilding previous..."
  92. # Build with the last-built env
  93. [[ -f "$STATE_FILE" ]] || { errout "No previous (-r) build state found." ; exit 1 ; }
  94. read TESTENV <"$STATE_FILE"
  95. pio run -d . -e $TESTENV
  96. exit
  97. fi
  98. case $TESTENV in
  99. tree) pio run -d . -e include_tree ; exit 1 ;;
  100. due) TESTENV='DUE' ;;
  101. esp) TESTENV='esp32' ;;
  102. lin*) TESTENV='linux_native' ;;
  103. lpc?(8)) TESTENV='LPC1768' ;;
  104. lpc9) TESTENV='LPC1769' ;;
  105. m128) TESTENV='mega1280' ;;
  106. m256) TESTENV='mega2560' ;;
  107. mega) TESTENV='mega2560' ;;
  108. stm) TESTENV='STM32F103RE' ;;
  109. f1) TESTENV='STM32F103RE' ;;
  110. f4) TESTENV='STM32F4' ;;
  111. f7) TESTENV='STM32F7' ;;
  112. s6) TESTENV='FYSETC_S6' ;;
  113. teensy) TESTENV='teensy31' ;;
  114. t31) TESTENV='teensy31' ;;
  115. t32) TESTENV='teensy31' ;;
  116. t35) TESTENV='teensy35' ;;
  117. t36) TESTENV='teensy35' ;;
  118. t40) TESTENV='teensy41' ;;
  119. t41) TESTENV='teensy41' ;;
  120. esac
  121. if ((AUTO_BUILD)); then
  122. #
  123. # List environments that apply to the current MOTHERBOARD.
  124. #
  125. case $(uname | tr '[:upper:]' '[:lower:]') in
  126. darwin) SYS='mac' ;;
  127. *linux) SYS='lin' ;;
  128. win*) SYS='win' ;;
  129. msys*) SYS='win' ;;
  130. cygwin*) SYS='win' ;;
  131. mingw*) SYS='win' ;;
  132. *) SYS='uni' ;;
  133. esac
  134. echo ; echo -n "Auto " ; ((AUTO_BUILD == 2)) && echo "Upload..." || echo "Build..."
  135. MB=$( grep -E "^\s*#define MOTHERBOARD" Marlin/Configuration.h | awk '{ print $3 }' | $SED 's/BOARD_//' )
  136. [[ -z $MB ]] && { echo "Error - Can't read MOTHERBOARD setting." ; exit 1 ; }
  137. BLINE=$( grep -E "define\s+BOARD_$MB\b" Marlin/src/core/boards.h )
  138. BNUM=$( $SED -E 's/^.+BOARD_[^ ]+ +([0-9]+).+$/\1/' <<<"$BLINE" )
  139. BDESC=$( $SED -E 's/^.+\/\/ *(.+)$/\1/' <<<"$BLINE" )
  140. [[ -z $BNUM ]] && { echo "Error - Can't find $MB in boards list." ; exit 1 ; }
  141. ENVS=( $( grep -EA1 "MB\(.*\b$MB\b.*\)" Marlin/src/pins/pins.h | grep -E "#include.+//.+(env|$SYS):[^ ]+" | grep -oE "(env|$SYS):[^ ]+" | $SED -E "s/(env|$SYS)://" ) )
  142. [[ -z $ENVS ]] && { errout "Error - Can't find target(s) for $MB ($BNUM)." ; exit 1 ; }
  143. ECOUNT=${#ENVS[*]}
  144. if [[ $ECOUNT == 1 ]]; then
  145. TARGET=$ENVS
  146. else
  147. if [[ $CHOICE == 0 ]]; then
  148. # List env names and numbers. Get selection.
  149. echo "Available targets for \"$BDESC\" | $MB ($BNUM):"
  150. IND=0 ; for ENV in "${ENVS[@]}"; do let IND++ ; echo " $IND) $ENV" ; done
  151. if [[ $ECOUNT > 1 ]]; then
  152. for (( ; ; ))
  153. do
  154. read -p "Select a target for '$MB' (1-$ECOUNT) : " CHOICE
  155. [[ -z "$CHOICE" ]] && { echo '(canceled)' ; exit 1 ; }
  156. [[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= ECOUNT)) && break
  157. errout ">>> Invalid environment choice '$CHOICE'."
  158. done
  159. echo
  160. fi
  161. else
  162. echo "Detected \"$BDESC\" | $MB ($BNUM)."
  163. [[ $CHOICE > $ECOUNT ]] && { echo "Environment selection out of range." ; exit 1 ; }
  164. fi
  165. TARGET="${ENVS[$CHOICE-1]}"
  166. echo "Selected $TARGET"
  167. fi
  168. echo "$TARGET" >"$STATE_FILE"
  169. if ((AUTO_BUILD == 2)); then
  170. echo "Uploading environment $TARGET for board $MB ($BNUM)..." ; echo
  171. pio run -t upload -e $TARGET
  172. else
  173. echo "Building environment $TARGET for board $MB ($BNUM)..." ; echo
  174. pio run -e $TARGET
  175. fi
  176. exit
  177. fi
  178. #
  179. # List available tests and ask for selection
  180. #
  181. if [[ $TESTENV == '-' ]]; then
  182. IND=0
  183. NAMES=()
  184. for FILE in $( ls -1 $TESTPATH/*-tests )
  185. do
  186. let IND++
  187. TNAME=${FILE/-tests/}
  188. TNAME=${TNAME/$TESTPATH\//}
  189. NAMES+=($TNAME)
  190. (( IND < 10 )) && echo -n " "
  191. echo " $IND) $TNAME"
  192. done
  193. echo
  194. for (( ; ; ))
  195. do
  196. read -p "Select a test to apply (1-$IND) : " NAMEIND
  197. [[ -z "$NAMEIND" ]] && { errout "(canceled)" ; exit 1 ; }
  198. [[ $NAMEIND =~ $ISNUM ]] && ((NAMEIND >= 1 && NAMEIND <= IND)) && { TESTENV=${NAMES[$NAMEIND-1]} ; echo ; break ; }
  199. errout "Invalid selection."
  200. done
  201. fi
  202. # Get the contents of the test file
  203. OUT=$( cat $TESTPATH/$TESTENV-tests 2>/dev/null ) || { errout "Can't find test '$TESTENV'." ; exit 1 ; }
  204. # Count up the number of tests
  205. TESTCOUNT=$( awk "/$ISEXEC/{a++}END{print a}" <<<"$OUT" )
  206. # User entered a number?
  207. (( CHOICE && CHOICE > TESTCOUNT )) && { errout "Invalid test selection '$CHOICE' (1-$TESTCOUNT)." ; exit 1 ; }
  208. if [[ $CHOICE == 0 ]]; then
  209. #
  210. # List test descriptions with numbers and get selection
  211. #
  212. echo "Available '$TESTENV' tests:" ; echo "$OUT" | {
  213. IND=0
  214. while IFS= read -r LINE
  215. do
  216. if [[ $LINE =~ $ISEXEC ]]; then
  217. DESC=$( "$SED" -E 's/^exec_test \$1 \$2 "([^"]+)".*$/\1/g' <<<"$LINE" )
  218. (( ++IND < 10 )) && echo -n " "
  219. echo " $IND) $DESC"
  220. fi
  221. done
  222. }
  223. CHOICE=1
  224. if [[ $TESTCOUNT > 1 ]]; then
  225. for (( ; ; ))
  226. do
  227. read -p "Select a '$TESTENV' test (1-$TESTCOUNT) : " CHOICE
  228. [[ -z "$CHOICE" ]] && { errout "(canceled)" ; exit 1 ; }
  229. [[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= TESTCOUNT)) && break
  230. errout ">>> Invalid test selection '$CHOICE'."
  231. done
  232. fi
  233. fi
  234. #
  235. # Run the specified test lines
  236. #
  237. echo -ne "\033[0;33m"
  238. echo "$OUT" | {
  239. IND=0
  240. GOTX=0
  241. CMD=""
  242. while IFS= read -r LINE
  243. do
  244. if [[ $LINE =~ $ISCMD || $GOTX == 1 ]]; then
  245. ((!IND)) && let IND++
  246. if [[ $LINE =~ $ISEXEC ]]; then
  247. ((IND++ > CHOICE)) && break
  248. else
  249. ((!HEADER)) && {
  250. HEADER=1
  251. echo -e "\n#\n# Test $TESTENV ($CHOICE) $DESC\n#"
  252. }
  253. ((IND == CHOICE)) && {
  254. GOTX=1
  255. [[ $CMD == "" ]] && CMD="$LINE" || CMD=$( echo -e "$CMD$LINE" | $SED -e 's/\\//g' | $SED -E 's/ +/ /g' )
  256. [[ $LINE =~ $ISCONT ]] || { echo "$CMD" ; eval "$CMD" ; CMD="" ; }
  257. }
  258. fi
  259. fi
  260. done
  261. }
  262. echo -ne "\033[0m"
  263. # Make clear it's a TEST
  264. opt_set CUSTOM_MACHINE_NAME "\"$TESTENV-tests ($CHOICE)\""
  265. # Build the test too?
  266. if [[ -z "$BUILD_YES" ]]; then
  267. echo
  268. read -p "Build $TESTENV test #$CHOICE (y/N) ? " BUILD_YES
  269. fi
  270. [[ $BUILD_YES == 'Y' || $BUILD_YES == 'Yes' ]] && {
  271. ((USE_MAKE)) && make tests-single-local TEST_TARGET=$TESTENV ONLY_TEST=$CHOICE
  272. ((USE_MAKE)) || pio run -d . -e $TESTENV
  273. echo "$TESTENV" >"$STATE_FILE"
  274. }