2019-07-07 11:04:49 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# mftest [name] [index]
|
|
|
|
#
|
|
|
|
# Set configuration options based on a test
|
|
|
|
# By default it will do megaatmega2560
|
|
|
|
# Use 'mftest -' to pick from the list.
|
|
|
|
#
|
|
|
|
|
|
|
|
MFINFO=$(mfinfo) || exit 1
|
|
|
|
[[ -d Marlin/src ]] || { echo "Please 'cd' up to repo root." ; exit 1 ; }
|
|
|
|
|
|
|
|
TESTPATH=buildroot/share/tests
|
2019-10-07 02:03:11 +00:00
|
|
|
STATE_FILE=$( echo ./.pio/.mftestrc )
|
2019-07-07 11:04:49 +00:00
|
|
|
|
|
|
|
shopt -s extglob nocasematch
|
|
|
|
|
2019-10-07 02:03:11 +00:00
|
|
|
# Get the environment and test number from the command
|
2019-07-10 10:55:51 +00:00
|
|
|
TESTENV=${1:-'-'}
|
2019-10-07 02:03:11 +00:00
|
|
|
CHOICE=${2:-0}
|
2019-07-10 10:55:51 +00:00
|
|
|
|
|
|
|
# Allow shorthand for test name
|
2019-07-07 11:04:49 +00:00
|
|
|
case $TESTENV in
|
2019-08-28 01:50:48 +00:00
|
|
|
tree) platformio run --project-dir . -e include_tree ; exit 1 ;;
|
2019-07-07 11:04:49 +00:00
|
|
|
due) TESTENV='DUE' ;;
|
|
|
|
esp) TESTENV='esp32' ;;
|
|
|
|
lin*) TESTENV='linux_native' ;;
|
|
|
|
lpc?(8)) TESTENV='LPC1768' ;;
|
|
|
|
lpc9) TESTENV='LPC1769' ;;
|
2019-09-12 01:49:15 +00:00
|
|
|
m128) TESTENV='megaatmega1280' ;;
|
|
|
|
m256) TESTENV='megaatmega2560' ;;
|
2019-07-07 11:04:49 +00:00
|
|
|
mega) TESTENV='megaatmega2560' ;;
|
2019-09-29 07:04:53 +00:00
|
|
|
stm) TESTENV='STM32F103RE' ;;
|
|
|
|
f1) TESTENV='STM32F103RE' ;;
|
2019-08-19 04:29:59 +00:00
|
|
|
f4) TESTENV='STM32F4' ;;
|
|
|
|
f7) TESTENV='STM32F7' ;;
|
2020-01-14 21:36:47 +00:00
|
|
|
s6) TESTENV='FYSETC_S6' ;;
|
2019-08-02 16:30:30 +00:00
|
|
|
teensy) TESTENV='teensy31' ;;
|
|
|
|
t31) TESTENV='teensy31' ;;
|
|
|
|
t32) TESTENV='teensy31' ;;
|
2019-07-07 11:04:49 +00:00
|
|
|
t35) TESTENV='teensy35' ;;
|
2019-08-02 16:30:30 +00:00
|
|
|
t36) TESTENV='teensy35' ;;
|
2019-10-07 02:03:11 +00:00
|
|
|
# Build with the last-built env
|
|
|
|
-r) [[ -f "$STATE_FILE" ]] || { echo "No previous (-r) build state found." ; exit 1 ; }
|
|
|
|
read TESTENV <"$STATE_FILE"
|
|
|
|
platformio run --project-dir . -e $TESTENV
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
# A -y may come first
|
|
|
|
-y) TESTENV=${2:-'-'} ; CHOICE=${3:-0} ;;
|
|
|
|
-[a-z]) echo "Unknown flag $TESTENV" ; exit 1 ;;
|
2019-07-10 10:55:51 +00:00
|
|
|
-) ;;
|
2019-07-07 11:04:49 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
# Matching patterns
|
|
|
|
ISNUM='^[0-9]+$'
|
|
|
|
ISCMD='^(restore|opt|exec|use|pins|env)_'
|
|
|
|
ISEXEC='^exec_'
|
2019-07-14 16:36:44 +00:00
|
|
|
ISCONT='\\ *$'
|
2019-07-07 11:04:49 +00:00
|
|
|
|
|
|
|
# List available tests and ask for selection
|
2019-07-10 10:55:51 +00:00
|
|
|
if [[ $TESTENV == '-' ]]; then
|
2019-07-07 11:04:49 +00:00
|
|
|
IND=0
|
|
|
|
NAMES=()
|
|
|
|
for FILE in $( ls -1 $TESTPATH/*-tests )
|
|
|
|
do
|
|
|
|
let IND++
|
|
|
|
TNAME=${FILE/-tests/}
|
|
|
|
TNAME=${TNAME/$TESTPATH\//}
|
|
|
|
NAMES+=($TNAME)
|
2019-07-10 10:55:51 +00:00
|
|
|
(( IND < 10 )) && echo -n " "
|
2019-07-07 11:04:49 +00:00
|
|
|
echo " $IND) $TNAME"
|
|
|
|
done
|
|
|
|
|
|
|
|
echo
|
|
|
|
for (( ; ; ))
|
|
|
|
do
|
|
|
|
read -p "Select a test to apply (1-$IND) : " NAMEIND
|
2019-07-10 10:55:51 +00:00
|
|
|
[[ -z "$NAMEIND" ]] && { echo '(canceled)' ; exit 1 ; }
|
|
|
|
[[ $NAMEIND =~ $ISNUM ]] && ((NAMEIND >= 1 && NAMEIND <= IND)) && { TESTENV=${NAMES[$NAMEIND-1]} ; echo ; break ; }
|
2019-07-07 11:04:49 +00:00
|
|
|
echo "Invalid selection."
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Get the contents of the test file
|
|
|
|
OUT=$( cat $TESTPATH/$TESTENV-tests 2>/dev/null ) || { echo "Can't find test '$TESTENV'." ; exit 1 ; }
|
|
|
|
|
|
|
|
# Count up the number of tests
|
|
|
|
# TODO: List test descriptions with numbers
|
|
|
|
TESTCOUNT=$( awk "/$ISEXEC/{a++}END{print a}" <<<"$OUT" )
|
|
|
|
|
2019-07-10 10:55:51 +00:00
|
|
|
# User entered a number?
|
|
|
|
(( CHOICE && CHOICE > TESTCOUNT )) && { echo "Invalid test index '$CHOICE' (1-$TESTCOUNT)." ; exit 1 ; }
|
|
|
|
|
|
|
|
if [[ $CHOICE == 0 ]]; then
|
|
|
|
# List test descriptions with numbers
|
|
|
|
echo "Available '$TESTENV' tests:" ; echo "$OUT" | {
|
|
|
|
IND=0
|
|
|
|
SED=$(which gsed || which sed)
|
|
|
|
while IFS= read -r LINE
|
|
|
|
do
|
|
|
|
if [[ $LINE =~ $ISEXEC ]]; then
|
|
|
|
DESC=$( "$SED" -E 's/^.+"(.*)".*$/\1/g' <<<"$LINE" )
|
|
|
|
(( ++IND < 10 )) && echo -n " "
|
|
|
|
echo " $IND) $DESC"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
CHOICE=1
|
|
|
|
if [[ $TESTCOUNT > 1 ]]; then
|
|
|
|
for (( ; ; ))
|
|
|
|
do
|
|
|
|
read -p "Select a '$TESTENV' test (1-$TESTCOUNT) : " CHOICE
|
|
|
|
[[ -z "$CHOICE" ]] && { echo '(canceled)' ; exit 1 ; }
|
|
|
|
[[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= TESTCOUNT)) && break
|
|
|
|
echo ">>> Invalid test index '$CHOICE'."
|
|
|
|
done
|
|
|
|
fi
|
2019-07-07 11:04:49 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Finally, run the specified test lines
|
|
|
|
echo "$OUT" | {
|
|
|
|
IND=0
|
2019-07-14 16:36:44 +00:00
|
|
|
GOTX=0
|
|
|
|
CMD=""
|
2019-07-07 11:04:49 +00:00
|
|
|
while IFS= read -r LINE
|
|
|
|
do
|
2019-07-14 16:36:44 +00:00
|
|
|
if [[ $LINE =~ $ISCMD || $GOTX == 1 ]]; then
|
2019-07-07 11:04:49 +00:00
|
|
|
((!IND)) && let IND++
|
|
|
|
if [[ $LINE =~ $ISEXEC ]]; then
|
|
|
|
((IND++ > CHOICE)) && break
|
|
|
|
else
|
|
|
|
((!HEADER)) && {
|
|
|
|
HEADER=1
|
|
|
|
echo -e "\n#\n# Test $TESTENV ($CHOICE) $DESC\n#"
|
|
|
|
}
|
2019-07-14 16:36:44 +00:00
|
|
|
((IND == CHOICE)) && {
|
|
|
|
GOTX=1
|
|
|
|
[[ $CMD == "" ]] && CMD="$LINE" || CMD=$( echo -e "$CMD$LINE" | sed -e 's/\\//g' )
|
|
|
|
[[ $LINE =~ $ISCONT ]] || { echo $CMD ; eval "$CMD" ; CMD="" ; }
|
|
|
|
}
|
2019-07-07 11:04:49 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2019-10-07 02:03:11 +00:00
|
|
|
# Get a -y parameter the lazy way
|
|
|
|
[[ "$2" == "-y" || "$3" == "-y" ]] && BUILD_YES='Y'
|
|
|
|
|
2019-07-07 11:04:49 +00:00
|
|
|
# Build the test too?
|
2019-10-07 02:03:11 +00:00
|
|
|
if [[ $BUILD_YES != 'Y' ]]; then
|
|
|
|
echo
|
|
|
|
read -p "Build $TESTENV test #$CHOICE (y/N) ? " BUILD_YES
|
|
|
|
fi
|
|
|
|
|
|
|
|
[[ $BUILD_YES == 'Y' || $BUILD_YES == 'Yes' ]] && {
|
|
|
|
platformio run --project-dir . -e $TESTENV
|
|
|
|
echo "$TESTENV" >"$STATE_FILE"
|
|
|
|
}
|